mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 11:36:16 +00:00
Fixed Flask not choosing new name for uploading
Moved uploading and removing files to APIs Added max file upload to config from yml file Jquery is now a file not a CDN General Sass(y) fixes
This commit is contained in:
parent
5db8fa52e8
commit
2455d3f88c
13 changed files with 131 additions and 95 deletions
|
@ -10,46 +10,8 @@ dt = datetime.datetime.now()
|
|||
|
||||
blueprint = Blueprint('image', __name__, url_prefix='/image')
|
||||
|
||||
|
||||
def get_post(id, check_author=True):
|
||||
post = get_db().execute(
|
||||
'SELECT p.author_id FROM posts p JOIN users u ON p.author_id = u.id'
|
||||
' WHERE p.id = ?',
|
||||
(id,)
|
||||
).fetchone()
|
||||
|
||||
if post is None:
|
||||
return False
|
||||
|
||||
if check_author and post['author_id'] != g.user['id']:
|
||||
return False
|
||||
|
||||
return post
|
||||
|
||||
|
||||
@blueprint.route('/<int:id>', methods=('GET', 'POST'))
|
||||
@blueprint.route('/<int:id>')
|
||||
def image(id):
|
||||
if request.method == 'POST':
|
||||
image = get_post(id)
|
||||
action = request.form['action']
|
||||
|
||||
if not image:
|
||||
abort(403)
|
||||
|
||||
if action == 'delete':
|
||||
try:
|
||||
db = get_db()
|
||||
db.execute('DELETE FROM posts WHERE id = ?', (id,))
|
||||
db.commit()
|
||||
except:
|
||||
return 'database error'
|
||||
|
||||
try:
|
||||
os.remove(os.path.join(current_app.config['UPLOAD_FOLDER'], 'original', image['file_name']))
|
||||
except:
|
||||
return 'os error'
|
||||
|
||||
# GET, it should be called Gwa Gwa because it sounds funny
|
||||
# Get image from database
|
||||
db = get_db()
|
||||
image = db.execute(
|
||||
|
@ -63,7 +25,7 @@ def image(id):
|
|||
|
||||
# Get exif data from image
|
||||
try:
|
||||
file = Image.open(os.path.join(current_app.config['UPLOAD_FOLDER'], 'original', image['file_name']))
|
||||
file = Image.open(os.path.join(current_app.instance_path, current_app.config['UPLOAD_FOLDER'], 'original', image['file_name']))
|
||||
raw_exif = file.getexif()
|
||||
human_exif = {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue