mirror of
https://gitlab.com/bashrc2/epicyon
synced 2026-11-01 18:29:54 +00:00
Create etag at time of media upload
This commit is contained in:
1 parent
085ea620b8
commit
f029c07a61
3 files changed
+35
-1
No files matched your search
@@ -471,6 +471,7 @@ def saveMediaInFormPOST(mediaBytes,debug: bool, \
|
||||
fd = open(filename, 'wb')
|
||||
fd.write(mediaBytes[startPos:])
|
||||
fd.close()
|
||||
|
||||
return filename,attachmentMediaType
|
||||
|
||||
def extractTextFieldsInPOST(postBytes,boundary,debug: bool) -> {}:
|
||||
|
||||
@@ -3626,6 +3626,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||
if filename:
|
||||
if filename.endswith('.png') or \
|
||||
filename.endswith('.jpg') or \
|
||||
filename.endswith('.webp') or \
|
||||
filename.endswith('.gif'):
|
||||
if self.server.debug:
|
||||
print('DEBUG: POST media removing metadata')
|
||||
|
||||
@@ -13,6 +13,7 @@ import os
|
||||
import sys
|
||||
import json
|
||||
import datetime
|
||||
from hashlib import sha1
|
||||
from auth import createPassword
|
||||
from shutil import copyfile
|
||||
from shutil import rmtree
|
||||
@@ -71,6 +72,36 @@ def getAttachmentMediaType(filename: str) -> str:
|
||||
return 'audio'
|
||||
return mediaType
|
||||
|
||||
def updateEtag(mediaFilename: str) -> None:
|
||||
""" calculate the etag, which is a sha1 of the data
|
||||
"""
|
||||
# only create etags for media
|
||||
if '/media/' not in mediaFilename:
|
||||
return
|
||||
|
||||
# check that the media exists
|
||||
if not os.path.isfile(mediaFilename):
|
||||
return
|
||||
|
||||
# read the binary data
|
||||
data=None
|
||||
try:
|
||||
with open(mediaFilename+, 'rb') as mediaFile:
|
||||
data=mediaFile.read()
|
||||
except:
|
||||
pass
|
||||
|
||||
if not data:
|
||||
return
|
||||
# calculate hash
|
||||
etag=sha1(data).hexdigest()
|
||||
# save the hash
|
||||
try:
|
||||
with open(mediaFilename+'.etag', 'w') as etagFile:
|
||||
etagFile.write(etag)
|
||||
except:
|
||||
pass
|
||||
|
||||
def attachMedia(baseDir: str,httpPrefix: str,domain: str,port: int, \
|
||||
postJson: {},imageFilename: str, \
|
||||
mediaType: str,description: str, \
|
||||
@@ -127,7 +158,8 @@ def attachMedia(baseDir: str,httpPrefix: str,domain: str,port: int, \
|
||||
removeMetaData(imageFilename,mediaFilename)
|
||||
else:
|
||||
copyfile(imageFilename,mediaFilename)
|
||||
|
||||
updateEtag(mediaFilename)
|
||||
|
||||
return postJson
|
||||
|
||||
def archiveMedia(baseDir: str,archiveDirectory: str,maxWeeks=4) -> None:
|
||||
|
||||
Reference in new issue
Block a user