forked from forks/microblog.pub
Fix attachment display and tweak actor lookup
This commit is contained in:
parent
bc7a8db640
commit
afa33b4e7c
3 changed files with 46 additions and 4 deletions
|
@ -191,11 +191,32 @@ def admin_tasks() -> _Response:
|
||||||
def admin_lookup() -> _Response:
|
def admin_lookup() -> _Response:
|
||||||
data = None
|
data = None
|
||||||
meta = None
|
meta = None
|
||||||
|
follower = None
|
||||||
|
following = None
|
||||||
if request.args.get("url"):
|
if request.args.get("url"):
|
||||||
data = lookup(request.args.get("url")) # type: ignore
|
data = lookup(request.args.get("url")) # type: ignore
|
||||||
if data:
|
if data:
|
||||||
if not data.has_type(ap.ACTOR_TYPES):
|
if not data.has_type(ap.ACTOR_TYPES):
|
||||||
meta = _meta(data)
|
meta = _meta(data)
|
||||||
|
else:
|
||||||
|
follower = find_one_activity(
|
||||||
|
{
|
||||||
|
"box": "inbox",
|
||||||
|
"type": ap.ActivityType.FOLLOW.value,
|
||||||
|
"meta.actor_id": data.id,
|
||||||
|
"meta.undo": False,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
following = find_one_activity(
|
||||||
|
{
|
||||||
|
**by_type(ap.ActivityType.FOLLOW),
|
||||||
|
**by_object_id(data.id),
|
||||||
|
**not_undo(),
|
||||||
|
**in_outbox(),
|
||||||
|
**follow_request_accepted(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if data.has_type(ap.ActivityType.QUESTION):
|
if data.has_type(ap.ActivityType.QUESTION):
|
||||||
p.push(data.id, "/task/fetch_remote_question")
|
p.push(data.id, "/task/fetch_remote_question")
|
||||||
|
|
||||||
|
@ -203,7 +224,12 @@ def admin_lookup() -> _Response:
|
||||||
app.logger.debug(data.to_dict())
|
app.logger.debug(data.to_dict())
|
||||||
return htmlify(
|
return htmlify(
|
||||||
render_template(
|
render_template(
|
||||||
"lookup.html", data=data, meta=meta, url=request.args.get("url")
|
"lookup.html",
|
||||||
|
data=data,
|
||||||
|
meta=meta,
|
||||||
|
follower=follower,
|
||||||
|
following=following,
|
||||||
|
url=request.args.get("url"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,20 @@
|
||||||
<div id="lookup-result" style="margin-top:30px;">
|
<div id="lookup-result" style="margin-top:30px;">
|
||||||
{% if data | has_actor_type %}
|
{% if data | has_actor_type %}
|
||||||
<div style="margin-left:95px;padding-bottom:5px;margin-bottom:15px;display:inline-block;">
|
<div style="margin-left:95px;padding-bottom:5px;margin-bottom:15px;display:inline-block;">
|
||||||
|
{% if following %}
|
||||||
|
<form action="/api/undo" class="action-form" method="post">
|
||||||
|
<input type="hidden" name="redirect" value="{{ request.path }}?url={{request.args.get('url')}}"/>
|
||||||
|
<input type="hidden" name="id" value="{{ following.remote_id }}"/>
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
||||||
|
<button type="submit" class="bar-item">unfollow</button>
|
||||||
|
</form>
|
||||||
|
<form action="/api/block" class="action-form" method="POST">
|
||||||
|
<input type="hidden" name="redirect" value="{{ request.path }}?url={{request.args.get('url')}}"/>
|
||||||
|
<input type="hidden" name="actor" value="{{ data.id }}">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||||
|
<button type="submit" class="bar-item" onclick="return confirm('Confirm the block action?');">block</button>
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
<a class="bar-item" href="/admin/profile?actor_id={{data.id}}">profile</a>
|
<a class="bar-item" href="/admin/profile?actor_id={{data.id}}">profile</a>
|
||||||
<form action="/api/follow" class="action-form" method="POST">
|
<form action="/api/follow" class="action-form" method="POST">
|
||||||
<input type="hidden" name="redirect" value="{{ request.path }}"/>
|
<input type="hidden" name="redirect" value="{{ request.path }}"/>
|
||||||
|
@ -24,6 +38,8 @@
|
||||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
|
||||||
<button type="submit" class="bar-item">follow</button>
|
<button type="submit" class="bar-item">follow</button>
|
||||||
</form>
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
{% if follower %}<span class="bar-item-no-hover">follows you!</span>{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -273,9 +273,6 @@ _FILE_URL_CACHE = LRUCache(4096)
|
||||||
|
|
||||||
|
|
||||||
def _get_file_url(url, size, kind) -> str:
|
def _get_file_url(url, size, kind) -> str:
|
||||||
if url.startswith(BASE_URL):
|
|
||||||
return url
|
|
||||||
|
|
||||||
k = (url, size, kind)
|
k = (url, size, kind)
|
||||||
cached = _FILE_URL_CACHE.get(k)
|
cached = _FILE_URL_CACHE.get(k)
|
||||||
if cached:
|
if cached:
|
||||||
|
@ -288,6 +285,9 @@ def _get_file_url(url, size, kind) -> str:
|
||||||
return out
|
return out
|
||||||
|
|
||||||
_logger.error(f"cache not available for {url}/{size}/{kind}")
|
_logger.error(f"cache not available for {url}/{size}/{kind}")
|
||||||
|
if url.startswith(BASE_URL):
|
||||||
|
return url
|
||||||
|
|
||||||
p = urlparse(url)
|
p = urlparse(url)
|
||||||
return f"/p/{p.scheme}" + p._replace(scheme="").geturl()[1:]
|
return f"/p/{p.scheme}" + p._replace(scheme="").geturl()[1:]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue