comic upload optimization

This commit is contained in:
aneuhmanh 2025-02-19 23:44:38 +02:00
parent 7baff5ec76
commit dfa6c89311
2 changed files with 15 additions and 13 deletions

28
app.py
View File

@ -677,14 +677,13 @@ async def upload_video():
@app.route('/comic_upload', methods=['GET', 'POST'])
@login_required
def comic_upload():
async def comic_upload():
if request.method == 'POST':
ct = request.files['thumbnail']
n = request.form['title']
tags = request.form.get('tags', '')
if Comic.query.filter_by(name=n).first():
if db.session.execute(db.select(Comic).filter_by(name=n)).scalar():
return render_template('comic_upload.html')
if ct:
@ -703,16 +702,22 @@ def comic_upload():
tags=tags
)
db.session.add(new_comic)
db.session.commit()
try:
db.session.commit()
except IntegrityError:
db.session.rollback()
return render_template('comic_upload.html')
for p in request.files.getlist('pages[]'):
if p:
p.save(os.path.join(cf, secure_filename(p.filename)))
async def save_pages():
for p in request.files.getlist('pages[]'):
if p:
async with aiofiles.open(os.path.join(cf, secure_filename(p.filename)), 'wb') as f:
await f.write(p.read())
await save_pages()
return redirect(url_for('comics'))
return render_template('comic_upload.html')
@app.route('/user_pubs/<pub_type>/<username>')
def user_pubs(pub_type, username):
p = request.args.get('page', 1, type=int)
@ -886,7 +891,7 @@ def delete(content_type, content_id):
@app.route('/delete_comment/<int:comment_id>', methods=['POST'])
@login_required
def delete_comment(comment_id):
comment = Comments.query.get_or_404(comment_id)
comment = db.session.get(Comments, comment_id) or abort(404)
if comment.image_id:
content_type = 'art'
@ -900,7 +905,6 @@ def delete_comment(comment_id):
if comment.username == current_user.username:
try:
if hasattr(comment, 'post_id') and comment.post_id:
post_id = comment.post_id
db.session.delete(comment)
@ -910,10 +914,8 @@ def delete_comment(comment_id):
db.session.delete(comment)
db.session.commit()
return redirect(url_for('view', content_type=content_type, id=content_id))
except IntegrityError:
db.session.rollback()
return redirect(url_for('view', content_type=content_type, id=content_id))
return redirect(request.referrer or url_for('index'))

Binary file not shown.