mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 03:26:16 +00:00
Formatted metadata
Add API for metadata Load more images if page is resized Adjusted animations
This commit is contained in:
parent
651fd8aa49
commit
da1579555b
9 changed files with 742 additions and 86 deletions
|
@ -1,8 +1,9 @@
|
|||
from flask import Blueprint, render_template, current_app, send_from_directory, send_file, request, g, abort, flash
|
||||
from flask import Blueprint, render_template, current_app, send_from_directory, send_file, request, g, abort, flash, jsonify
|
||||
from werkzeug.utils import secure_filename
|
||||
from gallery.auth import login_required
|
||||
from gallery.db import get_db
|
||||
from PIL import Image, ImageOps
|
||||
from . import metadata as mt
|
||||
import io
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
@ -10,6 +11,14 @@ from uuid import uuid4
|
|||
blueprint = Blueprint('viewsbp', __name__, url_prefix='/api')
|
||||
|
||||
|
||||
def human_size(num, suffix="B"):
|
||||
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
|
||||
if abs(num) < 1024.0:
|
||||
return f"{num:3.1f}{unit}{suffix}"
|
||||
num /= 1024.0
|
||||
return f"{num:.1f}Yi{suffix}"
|
||||
|
||||
|
||||
@blueprint.route('/uploads/<file>/<int:quality>', methods=['GET'])
|
||||
def uploads(file, quality):
|
||||
# If quality is 0, return original file
|
||||
|
@ -106,4 +115,18 @@ def remove(id):
|
|||
abort(500)
|
||||
|
||||
flash(['Image was all in Le Head!', 1])
|
||||
return 'Gwa Gwa'
|
||||
return 'Gwa Gwa'
|
||||
|
||||
@blueprint.route('/metadata/<int:id>', methods=['GET'])
|
||||
def metadata(id):
|
||||
img = get_db().execute(
|
||||
'SELECT file_name, description, alt FROM posts WHERE id = ?',
|
||||
(id, )).fetchone()
|
||||
|
||||
if img is None:
|
||||
abort(404)
|
||||
|
||||
exif = mt.metadata.yoink(os.path.join(current_app.config['UPLOAD_FOLDER'], img['file_name']))
|
||||
filesize = os.path.getsize(os.path.join(current_app.config['UPLOAD_FOLDER'], img['file_name']))
|
||||
|
||||
return jsonify({'metadata': exif, 'filesize': {'bytes': filesize, 'human': human_size(filesize)}})
|
Loading…
Add table
Add a link
Reference in a new issue