diff --git a/gallery/__init__.py b/gallery/__init__.py index 9bad318..ccb3cec 100644 --- a/gallery/__init__.py +++ b/gallery/__init__.py @@ -15,6 +15,7 @@ import logging # Flask from flask_compress import Compress +from flask_caching import Cache from flask import Flask, render_template # Configuration @@ -73,6 +74,7 @@ def create_app(test_config=None): """ app = Flask(__name__,instance_path=INSTANCE_PATH) compress = Compress() + cache = Cache(config={'CACHE_TYPE': 'SimpleCache', 'CACHE_DEFAULT_TIMEOUT': 69}) # App configuration app.config.from_mapping( @@ -146,4 +148,5 @@ def create_app(test_config=None): app.register_blueprint(api.blueprint) compress.init_app(app) + cache.init_app(app) return app diff --git a/gallery/api.py b/gallery/api.py index 7952ddc..f20ee23 100644 --- a/gallery/api.py +++ b/gallery/api.py @@ -13,7 +13,7 @@ from flask import ( from werkzeug.utils import secure_filename from colorthief import ColorThief -from PIL import Image, ImageOps # ImageFilter +from PIL import Image, ImageOps, ImageFilter from sqlalchemy.orm import sessionmaker from gallery.auth import login_required @@ -33,11 +33,13 @@ def uploads(file): Returns a file from the uploads folder w and h are the width and height of the image for resizing f is whether to apply filters to the image, such as blurring NSFW images + b is whether to force blur the image, even if it's not NSFW """ # Get args width = request.args.get('w', default=0, type=int) # Width of image height = request.args.get('h', default=0, type=int) # Height of image - filtered = request.args.get('f', default=False, type=bool) # Whether to apply filters + filtered = request.args.get('f', default=False, type=bool) # Whether to apply filters + blur = request.args.get('b', default=False, type=bool) # Whether to force blur # if no args are passed, return the raw file if width == 0 and height == 0 and not filtered: @@ -78,6 +80,10 @@ def uploads(file): if filtered: #img = img.filter(ImageFilter.GaussianBlur(20)) pass + + # If forced to blur, blur image + if blur: + img = img.filter(ImageFilter.GaussianBlur(20)) try: img.save(buff, img_ext, icc_profile=img_icc) diff --git a/gallery/metadata/__init__.py b/gallery/metadata/__init__.py index 114cbaa..430ce53 100644 --- a/gallery/metadata/__init__.py +++ b/gallery/metadata/__init__.py @@ -69,6 +69,7 @@ class Metadata: 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 @@ -81,6 +82,7 @@ class Metadata: 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]] = { @@ -92,6 +94,7 @@ class Metadata: 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]] = { diff --git a/gallery/metadata/helpers.py b/gallery/metadata/helpers.py index 5dc4703..e642fec 100644 --- a/gallery/metadata/helpers.py +++ b/gallery/metadata/helpers.py @@ -352,6 +352,7 @@ def orientation(value): Maps the value of the orientation to a human readable format """ value_map = { + 0: 'Undefined', 1: 'Horizontal (normal)', 2: 'Mirror horizontal', 3: 'Rotate 180', diff --git a/gallery/metadata/mapping.py b/gallery/metadata/mapping.py index 625dfac..a45188c 100644 --- a/gallery/metadata/mapping.py +++ b/gallery/metadata/mapping.py @@ -31,7 +31,7 @@ CAMERA_MAPPING = { 'ISOSpeedRatings': ['ISO Speed Ratings', 'iso'], 'ISOSpeed': ['ISO Speed', 'iso'], 'SensitivityType': ['Sensitivity Type', 'sensitivity_type'], - 'ExposureBiasValue': ['Exposure Bias', 'ev'], + 'ExposureBiasValue': ['Exposure Bias', 'exposure'], 'ExposureTime': ['Exposure Time', 'shutter'], 'ExposureMode': ['Exposure Mode', 'exposure_mode'], 'ExposureProgram': ['Exposure Program', 'exposure_program'], diff --git a/gallery/routing.py b/gallery/routing.py index 343a18b..02b9f11 100644 --- a/gallery/routing.py +++ b/gallery/routing.py @@ -2,8 +2,9 @@ Onlylegs Gallery - Routing """ import os +from datetime import datetime as dt -from flask import Blueprint, render_template, current_app +from flask import Blueprint, render_template, current_app, request, g from werkzeug.exceptions import abort from sqlalchemy.orm import sessionmaker @@ -23,9 +24,10 @@ def index(): Home page of the website, shows the feed of latest images """ images = db_session.query(db.Posts.file_name, - db.Posts.id, - db.Posts.created_at - ).order_by(db.Posts.id.desc()).all() + db.Posts.image_colours, + db.Posts.author_id, + db.Posts.created_at, + db.Posts.id).order_by(db.Posts.id.desc()).all() return render_template('index.html', images=images, @@ -47,12 +49,25 @@ def image(image_id): return render_template('image.html', image=img, exif=img.image_exif) -@blueprint.route('/group') +@blueprint.route('/group', methods=['GET', 'POST']) def groups(): """ Group overview, shows all image groups """ - return render_template('group.html', group_id='gwa gwa') + if request.method == 'GET': + groups = db_session.query(db.Groups.name, db.Groups.author_id).all() + + return render_template('group.html', groups=groups) + elif request.method == 'POST': + group_name = request.form['name'] + group_description = request.form['description'] + group_author = g.user.id + + new_group = db.Groups(name=group_name, description=group_description, author_id=group_author, created_at=dt.now()) + + db_session.add(new_group) + + return ':3' @blueprint.route('/group/') def group(group_id): @@ -73,4 +88,4 @@ def profile_id(user_id): """ Shows user ofa given id, displays their uploads and other info """ - return render_template('profile.html', user_id=user_id) + return render_template('profile.html', user_id=user_id) \ No newline at end of file diff --git a/gallery/static/images/background.svg b/gallery/static/images/background.svg deleted file mode 100644 index ef824d3..0000000 --- a/gallery/static/images/background.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/gallery/static/images/bg.svg b/gallery/static/images/bg.svg new file mode 100644 index 0000000..b133190 --- /dev/null +++ b/gallery/static/images/bg.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/gallery/static/images/leaves.jpg b/gallery/static/images/leaves.jpg deleted file mode 100644 index 5a8e723..0000000 Binary files a/gallery/static/images/leaves.jpg and /dev/null differ diff --git a/gallery/static/js/upload.js b/gallery/static/js/upload.js index 3753f02..bc2bd56 100644 --- a/gallery/static/js/upload.js +++ b/gallery/static/js/upload.js @@ -1,20 +1,9 @@ -function showUpload() { - popUpShow( - 'Upload funny stuff', - 'May the world see your stuff 👀', - '', - '
\ - \ - \ - \ - \ -
' - ); -}; function uploadFile(){ // AJAX takes control of subby form event.preventDefault(); + const jobList = document.querySelector(".upload-jobs"); + // Check for empty upload if ($("#file").val() === "") { addNotification("Please select a file to upload", 2); @@ -35,32 +24,58 @@ function uploadFile(){ contentType: false, processData: false, beforeSend: function() { - console.log("Uploading..."); + jobContainer = document.createElement("div"); + jobContainer.classList.add("job"); + + jobStatus = document.createElement("span"); + jobStatus.classList.add("job__status"); + jobStatus.innerHTML = "Uploading..."; + + jobProgress = document.createElement("span"); + jobProgress.classList.add("progress"); + + jobImg = document.createElement("img"); + jobImg.src = URL.createObjectURL($("#file").prop("files")[0]); + + jobImgFilter = document.createElement("span"); + jobImgFilter.classList.add("img-filter"); + + jobContainer.appendChild(jobStatus); + jobContainer.appendChild(jobProgress); + jobContainer.appendChild(jobImg); + jobContainer.appendChild(jobImgFilter); + jobList.appendChild(jobContainer); }, success: function (response) { - addNotification("File uploaded successfully!", 1); - console.log('File processed successfully'); + jobContainer.classList.add("success"); + jobStatus.innerHTML = "Uploaded!"; + if (!document.querySelector(".upload-panel").classList.contains("open")) { + addNotification("Image uploaded successfully", 1); + } }, error: function (response) { + jobContainer.classList.add("critical"); switch (response.status) { case 500: - addNotification('Server exploded, F\'s in chat', 2); + jobStatus.innerHTML = "Server exploded, F's in chat"; break; case 400: case 404: - addNotification('Error uploading. Blame yourself', 2); + jobStatus.innerHTML = "Error uploading. Blame yourself"; break; case 403: - addNotification('None but devils play past here...', 2); + jobStatus.innerHTML = "None but devils play past here..."; break; case 413: - addNotification('File too large!!!!!!', 3); + jobStatus.innerHTML = "File too large!!!!!!"; break; default: - addNotification('Error uploading file, blame someone', 2); + jobStatus.innerHTML = "Error uploading file, blame someone"; break; } - console.log('Error uploading file'); + if (!document.querySelector(".upload-panel").classList.contains("open")) { + addNotification("Error uploading file", 2); + } }, }); @@ -70,4 +85,23 @@ function uploadFile(){ $("#description").val(""); $("#tags").val(""); } -}; \ No newline at end of file +}; + +function openUploadTab() { + // Open upload tab + const uploadTab = document.querySelector(".upload-panel"); + uploadTab.style.display = "block"; + + setTimeout( function() { + uploadTab.classList.add("open"); + }, 10); +} + +function closeUploadTab() { + // Close upload tab + const uploadTab = document.querySelector(".upload-panel"); + uploadTab.classList.remove("open"); + setTimeout( function() { + uploadTab.style.display = "none"; + }, 250); +} \ No newline at end of file diff --git a/gallery/templates/group.html b/gallery/templates/group.html index c18f4df..3503fd1 100644 --- a/gallery/templates/group.html +++ b/gallery/templates/group.html @@ -1,15 +1,45 @@ {% extends 'layout.html' %} {% block header %} -
- + {% endblock %} - {% block nav_groups %}navigation-item__selected{% endblock %} {% block content %} -

Image Group

-

{{group_id}}

+ +
+ + + +
+{% endblock %} + +{% block script %} + {% endblock %} \ No newline at end of file diff --git a/gallery/templates/image.html b/gallery/templates/image.html index 80dd57a..d218f76 100644 --- a/gallery/templates/image.html +++ b/gallery/templates/image.html @@ -3,7 +3,7 @@ {% block header %}
- +
{% endblock %} {% block wrapper_class %}image-wrapper{% endblock %} diff --git a/gallery/templates/index.html b/gallery/templates/index.html index 89bd7aa..aee36d0 100644 --- a/gallery/templates/index.html +++ b/gallery/templates/index.html @@ -2,7 +2,7 @@ {% block header %}