Render non-media PostAttachments (#420)
This commit is contained in:
parent
9dded19172
commit
06f6257645
|
@ -73,7 +73,11 @@ class PostAttachment(StatorModel):
|
||||||
]
|
]
|
||||||
|
|
||||||
def is_video(self):
|
def is_video(self):
|
||||||
return self.mimetype in ["video/webm"]
|
return self.mimetype in [
|
||||||
|
"video/mp4",
|
||||||
|
"video/ogg",
|
||||||
|
"video/webm",
|
||||||
|
]
|
||||||
|
|
||||||
def thumbnail_url(self) -> RelativeAbsoluteUrl:
|
def thumbnail_url(self) -> RelativeAbsoluteUrl:
|
||||||
if self.thumbnail:
|
if self.thumbnail:
|
||||||
|
@ -89,11 +93,20 @@ class PostAttachment(StatorModel):
|
||||||
def full_url(self):
|
def full_url(self):
|
||||||
if self.file:
|
if self.file:
|
||||||
return RelativeAbsoluteUrl(self.file.url)
|
return RelativeAbsoluteUrl(self.file.url)
|
||||||
else:
|
if self.is_image():
|
||||||
return ProxyAbsoluteUrl(
|
return ProxyAbsoluteUrl(
|
||||||
f"/proxy/post_attachment/{self.pk}/",
|
f"/proxy/post_attachment/{self.pk}/",
|
||||||
remote_url=self.remote_url,
|
remote_url=self.remote_url,
|
||||||
)
|
)
|
||||||
|
return RelativeAbsoluteUrl(self.remote_url)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def file_display_name(self):
|
||||||
|
if self.remote_url:
|
||||||
|
return self.remote_url.rsplit("/", 1)[-1]
|
||||||
|
if self.file:
|
||||||
|
return self.file.name
|
||||||
|
return f"attachment ({self.mimetype})"
|
||||||
|
|
||||||
### ActivityPub ###
|
### ActivityPub ###
|
||||||
|
|
||||||
|
|
|
@ -1497,6 +1497,32 @@ form .post {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post .attachments .other {
|
||||||
|
grid-column: span 2;
|
||||||
|
padding: 8px;
|
||||||
|
border: 1px solid var(--color-text-duller);
|
||||||
|
background: var(--color-bg-menu);
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-top: 8px;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post .attachments .other-label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post .attachments .other-label > i {
|
||||||
|
margin-right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post .attachments .other:hover {
|
||||||
|
text-decoration: none;
|
||||||
|
background: var(--color-bg-main);
|
||||||
|
color: #FFF;
|
||||||
|
border-color: var(--color-highlight);
|
||||||
|
}
|
||||||
|
|
||||||
.post .actions {
|
.post .actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
|
@ -50,11 +50,20 @@
|
||||||
{% elif attachment.is_video %}
|
{% elif attachment.is_video %}
|
||||||
<a href="{{ attachment.full_url.relative }}" class="video">
|
<a href="{{ attachment.full_url.relative }}" class="video">
|
||||||
<video muted controls loop>
|
<video muted controls loop>
|
||||||
<source src="{{ attachment.full_url.relative }}">
|
<source src="{{ attachment.full_url.relative }}" type="{{ attachment.mimetype }}">
|
||||||
</video>
|
</video>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% for attachment in post.attachments.all %}
|
||||||
|
{% if not attachment.is_image and not attachment.is_video %}
|
||||||
|
<a href="{{ attachment.full_url.relative }}" class="other">
|
||||||
|
<div class="other-label">
|
||||||
|
<i class="fa-solid fa-download"></i> {{ attachment.file_display_name }}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue