flask-server/kinolist/posters.py

35 lines
1.1 KiB
Python
Raw Normal View History

2024-10-10 17:44:47 -04:00
#
# Copyright (c) 2024 bartholin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
2024-10-08 13:20:00 -04:00
from flask import (current_app, send_from_directory)
from hashlib import sha1
from pathlib import Path
2024-10-13 04:58:48 -04:00
import os
2024-10-08 13:20:00 -04:00
def save(name, content):
h = sha1(content).hexdigest()
filename = h + Path(name).suffix
2024-10-13 04:58:48 -04:00
file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], filename)
with open(file_path, "wb") as file:
file.write(content)
2024-10-08 13:20:00 -04:00
return filename
def get(name):
2024-10-13 04:58:48 -04:00
return send_from_directory(current_app.config['UPLOAD_FOLDER'], name)