Make Metadata Parser readable with ChatGPT 💀

Remove useless code for fullscreening image
This commit is contained in:
Michał Gdula 2023-03-10 12:32:23 +00:00
parent e6d289ed64
commit b0a9271265
7 changed files with 48 additions and 103 deletions

View file

@ -5,7 +5,7 @@
| |_| | | | | | |_| | |__| __/ (_| \__ \
\___/|_| |_|_|\__, |_____\___|\__, |___/
|___/ |___/
Created by Fluffy Bean - Version 23.03.09
Created by Fluffy Bean - Version 23.03.10
"""
# Import system modules
@ -48,7 +48,7 @@ def create_app(test_config=None):
"""
app = Flask(__name__,instance_path=os.path.join(USER_DIR, 'instance'))
assets = Environment()
cache = Cache(config={'CACHE_TYPE': 'SimpleCache', 'CACHE_DEFAULT_TIMEOUT': 69})
cache = Cache(config={'CACHE_TYPE': 'SimpleCache', 'CACHE_DEFAULT_TIMEOUT': 300})
compress = Compress()
# App configuration
@ -59,8 +59,6 @@ def create_app(test_config=None):
ALLOWED_EXTENSIONS=conf['upload']['allowed-extensions'],
MAX_CONTENT_LENGTH=1024 * 1024 * conf['upload']['max-size'],
WEBSITE=conf['website'],
ADMIN=conf['admin'],
APP_VERSION='23.03.09',
)
if test_config is None:
@ -74,43 +72,23 @@ def create_app(test_config=None):
pass
# Load theme
theme_manager.CompileTheme('default', app.root_path)
# Bundle JS files
js = Bundle('js/*.js', output='gen/packed.js')
assets.register('js_all', js)
@app.errorhandler(405)
def method_not_allowed(err):
error = '405'
msg = err.description
return render_template('error.html', error=error, msg=msg), 404
@app.errorhandler(404)
def page_not_found(err):
error = '404'
msg = err.description
return render_template('error.html', error=error, msg=msg), 404
@app.errorhandler(403)
def forbidden(err):
error = '403'
msg = err.description
return render_template('error.html', error=error, msg=msg), 403
@app.errorhandler(404)
@app.errorhandler(405)
@app.errorhandler(410)
def gone(err):
error = '410'
msg = err.description
return render_template('error.html', error=error, msg=msg), 410
@app.errorhandler(500)
def internal_server_error(err):
error = '500'
def error_page(err):
error = err.code
msg = err.description
return render_template('error.html', error=error, msg=msg), 500
return render_template('error.html', error=error, msg=msg), err.code
# Load login, registration and logout manager
from . import auth
@ -136,6 +114,7 @@ def create_app(test_config=None):
logging.info('Gallery started successfully!')
assets.init_app(app)
cache.init_app(app)
compress.init_app(app)

View file

@ -63,48 +63,19 @@ class Metadata:
'Software': {},
'File': {},
}
for data in encoded_exif:
if data in PHOTOGRAHER_MAPPING:
exif['Photographer'][PHOTOGRAHER_MAPPING[data][0]] = {
'raw': encoded_exif[data],
}
continue
elif data in CAMERA_MAPPING:
if len(CAMERA_MAPPING[data]) == 2:
# Camera - Exif Tag name
exif['Camera'][CAMERA_MAPPING[data][0]] = {
'raw': encoded_exif[data],
'formatted':
getattr(helpers, CAMERA_MAPPING[data][1])(encoded_exif[data]), # pylint: disable=E0602
# Thanks chatGPT xP
for key, value in encoded_exif.items():
for mapping_name, mapping in EXIF_MAPPING:
if key in mapping:
if len(mapping[key]) == 2:
exif[mapping_name][mapping[key][0]] = {
'raw': value,
'formatted': getattr(helpers, mapping[key][1])(value),
}
else:
exif['Camera'][CAMERA_MAPPING[data][0]] = {
'raw': encoded_exif[data],
}
continue
elif data in SOFTWARE_MAPPING:
if len(SOFTWARE_MAPPING[data]) == 2:
exif['Software'][SOFTWARE_MAPPING[data][0]] = {
'raw': encoded_exif[data],
'formatted':
getattr(helpers, SOFTWARE_MAPPING[data][1])(encoded_exif[data]), # pylint: disable=E0602
}
else:
exif['Software'][SOFTWARE_MAPPING[data][0]] = {
'raw': encoded_exif[data],
}
continue
elif data in FILE_MAPPING:
if len(FILE_MAPPING[data]) == 2:
exif['File'][FILE_MAPPING[data][0]] = {
'raw': encoded_exif[data],
'formatted':
getattr(helpers, FILE_MAPPING[data][1])(encoded_exif[data]), # pylint: disable=E0602
}
else:
exif['File'][FILE_MAPPING[data][0]] = {
'raw': encoded_exif[data]
else:
exif[mapping_name][mapping[key][0]] = {
'raw': value,
}
# Remove empty keys

View file

@ -2,6 +2,7 @@
OnlyLegs - Metatada Parser
Mapping for metadata
"""
PHOTOGRAHER_MAPPING = {
'Artist': ['Artist'],
'UserComment': ['Comment'],
@ -59,3 +60,5 @@ FILE_MAPPING = {
'Rating': ['Rating', 'rating'],
'RatingPercent': ['Rating Percent', 'rating_percent'],
}
EXIF_MAPPING = [('Photographer', PHOTOGRAHER_MAPPING),('Camera', CAMERA_MAPPING),('Software', SOFTWARE_MAPPING),('File', FILE_MAPPING)]

View file

@ -124,6 +124,7 @@ function uploadFile() {
function openUploadTab() {
// Stop scrolling
document.querySelector("html").style.overflow = "hidden";
document.querySelector(".content").tabIndex = "-1";
// Open upload tab
const uploadTab = document.querySelector(".upload-panel");
@ -137,6 +138,7 @@ function openUploadTab() {
function closeUploadTab() {
// un-Stop scrolling
document.querySelector("html").style.overflow = "auto";
document.querySelector(".content").tabIndex = "";
// Close upload tab
const uploadTab = document.querySelector(".upload-panel");

View file

@ -52,7 +52,7 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 256 256"><path d="M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,48,88H208a8,8,0,0,1,5.66,13.66Z"></path></svg>
</span>
</button>
<a class="pill-item" id="img-download" href="/api/uploads/{{ image.file_name }}" download>
<a class="pill-item" href="/api/uploads/{{ image.file_name }}" download onclick="addNotification('Download started!', 4)">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 256 256"><path d="M232,136v64a8,8,0,0,1-8,8H32a8,8,0,0,1-8-8V136a8,8,0,0,1,8-8H224A8,8,0,0,1,232,136Z" opacity="0.2"></path><path d="M240,136v64a16,16,0,0,1-16,16H32a16,16,0,0,1-16-16V136a16,16,0,0,1,16-16H72a8,8,0,0,1,0,16H32v64H224V136H184a8,8,0,0,1,0-16h40A16,16,0,0,1,240,136Zm-117.66-2.34a8,8,0,0,0,11.32,0l48-48a8,8,0,0,0-11.32-11.32L136,108.69V24a8,8,0,0,0-16,0v84.69L85.66,74.34A8,8,0,0,0,74.34,85.66ZM200,168a12,12,0,1,0-12,12A12,12,0,0,0,200,168Z"></path></svg>
<span class="tool-tip">
Download
@ -213,22 +213,25 @@
$('.image-fullscreen').click(function() {
// un-Stop scrolling
document.querySelector("html").style.overflow = "auto";
let fullscreen = document.querySelector('.image-fullscreen')
$('.image-fullscreen').addClass('image-fullscreen__hide');
fullscreen.classList.remove('active');
setTimeout(function() {
$('.image-fullscreen').removeClass('image-fullscreen__active image-fullscreen__hide');
fullscreen.style.display = 'none';
}, 200);
});
$('#img-fullscreen').click(function() {
// Stop scrolling
document.querySelector("html").style.overflow = "hidden";
$('.image-fullscreen').addClass('image-fullscreen__active');
if ($('.image-fullscreen img').attr('src') == '') {
$('.image-fullscreen img').attr('src', '/api/uploads/{{ image.file_name }}');
}
let fullscreen = document.querySelector('.image-fullscreen')
fullscreen.querySelector('img').src = '/api/uploads/{{ image.file_name }}';
fullscreen.style.display = 'flex';
setTimeout(function() {
fullscreen.classList.add('active');
}, 10);
});
$('#img-share').click(function() {
@ -239,9 +242,6 @@
addNotification("Failed to copy link! Are you on HTTP?", 2);
}
});
$('#img-download').click(function() {
addNotification("Download started!", 4);
});
{% if g.user['id'] == image['author_id'] %}
$('#img-delete').click(function() {

View file

@ -6,10 +6,10 @@
height: 100dvh
position: fixed
top: -100%
top: 0
left: 0
display: flex
display: none
opacity: 0 // hide
background-color: rgba($black, 0.8)
@ -17,6 +17,8 @@
box-sizing: border-box
transition: opacity 0.2s cubic-bezier(.79, .14, .15, .86)
img
margin: auto
padding: 0
@ -30,22 +32,10 @@
object-position: center
transform: scale(0.8)
.image-fullscreen__active
top: 0
opacity: 1 // show
transition: opacity 0.3s cubic-bezier(.79, .14, .15, .86)
img
transform: scale(1)
transition: transform 0.2s cubic-bezier(.68,-0.55,.27,1.55)
.image-fullscreen__hide
opacity: 0 // hide
transition: opacity 0.2s cubic-bezier(.79, .14, .15, .86)
&.active
opacity: 1 // show
img
transform: scaleY(0) // scale(0.8)
transition: transform 0.2s ease
img
transform: scale(1)

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "onlylegs"
version = "23.03.09"
version = "23.03.10"
description = "Gallery built for fast and simple image management"
authors = ["Fluffy-Bean <michal-gdula@protonmail.com>"]
license = "MIT"