diff --git a/app.py b/app.py index 1984c71..637e7fd 100644 --- a/app.py +++ b/app.py @@ -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//') 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/', 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')) diff --git a/requirements.txt b/requirements.txt index a91a4ec..1085bb0 100644 Binary files a/requirements.txt and b/requirements.txt differ