flask-server/kinolist/posters.py
2024-10-13 10:58:48 +02:00

18 lines
474 B
Python

from flask import (current_app, send_from_directory)
from hashlib import sha1
from pathlib import Path
import os
def save(name, content):
h = sha1(content).hexdigest()
filename = h + Path(name).suffix
file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], filename)
with open(file_path, "wb") as file:
file.write(content)
return filename
def get(name):
return send_from_directory(current_app.config['UPLOAD_FOLDER'], name)