Fix cache for video and some cleanup
This commit is contained in:
parent
144040f126
commit
c310dfba83
2 changed files with 18 additions and 21 deletions
|
@ -129,7 +129,7 @@
|
||||||
{% if (a.mediaType and a.mediaType.startswith("image/")) or (a.type and a.type == 'Image') %}
|
{% if (a.mediaType and a.mediaType.startswith("image/")) or (a.type and a.type == 'Image') %}
|
||||||
<a href="{{ a.url | get_attachment_url(None) }}"><img src="{{a.url | get_attachment_url(720) }}" class="img-attachment"></a>
|
<a href="{{ a.url | get_attachment_url(None) }}"><img src="{{a.url | get_attachment_url(720) }}" class="img-attachment"></a>
|
||||||
{% elif (a.mediaType and a.mediaType.startswith("video/")) %}
|
{% elif (a.mediaType and a.mediaType.startswith("video/")) %}
|
||||||
<li><video controls preload="metadata" src="{{ a.url }}" width="480"></video></li>
|
<li><video controls preload="metadata" src="{{ a.url | get_attachment_url(None) }}" width="480"></video></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="{{a.url }}" class="l">{% if a.filename %}{{ a.filename }}{% else %}{{ a.url }}{% endif %}</a></li>
|
<li><a href="{{a.url }}" class="l">{% if a.filename %}{{ a.filename }}{% else %}{{ a.url }}{% endif %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import logging
|
import logging
|
||||||
|
import mimetypes
|
||||||
import urllib
|
import urllib
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
|
from functools import lru_cache
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
@ -79,6 +81,15 @@ ALLOWED_TAGS = [
|
||||||
"h4",
|
"h4",
|
||||||
"h5",
|
"h5",
|
||||||
"h6",
|
"h6",
|
||||||
|
"table",
|
||||||
|
"th",
|
||||||
|
"tr",
|
||||||
|
"td",
|
||||||
|
"thead",
|
||||||
|
"tbody",
|
||||||
|
"tfoot",
|
||||||
|
"colgroup",
|
||||||
|
"caption",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -219,20 +230,11 @@ def get_total_answers_count(obj, meta):
|
||||||
return cnt
|
return cnt
|
||||||
|
|
||||||
|
|
||||||
_GRIDFS_CACHE: Dict[Tuple[Kind, str, Optional[int]], str] = {}
|
@lru_cache(512)
|
||||||
|
def _get_file_url(url, size, kind) -> str:
|
||||||
|
|
||||||
def _get_file_url(url, size, kind):
|
|
||||||
k = (kind, url, size)
|
|
||||||
cached = _GRIDFS_CACHE.get(k)
|
|
||||||
if cached:
|
|
||||||
return cached
|
|
||||||
|
|
||||||
doc = MEDIA_CACHE.get_file(url, size, kind)
|
doc = MEDIA_CACHE.get_file(url, size, kind)
|
||||||
if doc:
|
if doc:
|
||||||
u = f"/media/{str(doc._id)}"
|
return f"/media/{str(doc._id)}"
|
||||||
_GRIDFS_CACHE[k] = u
|
|
||||||
return u
|
|
||||||
|
|
||||||
# MEDIA_CACHE.cache(url, kind)
|
# MEDIA_CACHE.cache(url, kind)
|
||||||
_logger.error(f"cache not available for {url}/{size}/{kind}")
|
_logger.error(f"cache not available for {url}/{size}/{kind}")
|
||||||
|
@ -308,15 +310,10 @@ def has_actor_type(doc):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(512)
|
||||||
def _is_img(filename):
|
def _is_img(filename):
|
||||||
filename = filename.lower()
|
mimetype, _ = mimetypes.guess_type(filename.lower())
|
||||||
if (
|
if mimetype and mimetype.split("/")[0] in ["image"]:
|
||||||
filename.endswith(".png")
|
|
||||||
or filename.endswith(".jpg")
|
|
||||||
or filename.endswith(".jpeg")
|
|
||||||
or filename.endswith(".gif")
|
|
||||||
or filename.endswith(".svg")
|
|
||||||
):
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue