mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-10 01:13:33 +00:00
First step format upload with progress
This commit is contained in:
parent
8f2f6f5c91
commit
d8d9d405e9
@ -131,18 +131,12 @@ def edit_book(book_id):
|
||||
calibre_db.session.rollback()
|
||||
book = calibre_db.get_filtered_book(book_id, allow_show_archived=True)
|
||||
|
||||
# handle upload other formats from local disk
|
||||
meta = upload_single_file(request, book, book_id)
|
||||
# only merge metadata if file was uploaded and no error occurred (meta equals not false or none)
|
||||
upload_format = False
|
||||
if meta:
|
||||
upload_format = merge_metadata(to_save, meta)
|
||||
# handle upload covers from local disk
|
||||
cover_upload_success = upload_cover(request, book)
|
||||
if cover_upload_success:
|
||||
book.has_cover = 1
|
||||
modify_date = True
|
||||
|
||||
meta ={}
|
||||
# upload new covers or new file formats to google drive
|
||||
if config.config_use_google_drive:
|
||||
gdriveutils.updateGdriveCalibreFromLocal()
|
||||
@ -180,7 +174,7 @@ def edit_book(book_id):
|
||||
modify_date |= edit_book_publisher(to_save['publisher'], book)
|
||||
# handle book languages
|
||||
try:
|
||||
modify_date |= edit_book_languages(to_save['languages'], book, upload_format)
|
||||
modify_date |= edit_book_languages(to_save['languages'], book)
|
||||
except ValueError as e:
|
||||
flash(str(e), category="error")
|
||||
edit_error = True
|
||||
@ -238,9 +232,31 @@ def edit_book(book_id):
|
||||
@login_required_if_no_ano
|
||||
@upload_required
|
||||
def upload():
|
||||
if not config.config_uploading:
|
||||
abort(404)
|
||||
if request.method == 'POST' and 'btn-upload' in request.files:
|
||||
if len(request.files.getlist("btn-upload-format")):
|
||||
# create the function for sorting...
|
||||
calibre_db.update_title_sort(config)
|
||||
book_id = request.form.get('book_id', -1)
|
||||
|
||||
book = calibre_db.get_filtered_book(book_id, allow_show_archived=True)
|
||||
# Book not found
|
||||
if not book:
|
||||
flash(_("Oops! Selected book is unavailable. File does not exist or is not accessible"),
|
||||
category="error")
|
||||
return redirect(url_for("web.index"))
|
||||
|
||||
# handle upload other formats from local disk
|
||||
for requested_file in request.files.getlist("btn-upload-format"):
|
||||
meta = upload_single_file(requested_file, book, book_id)
|
||||
# save data to database, reread data
|
||||
calibre_db.session.commit()
|
||||
|
||||
resp = {"location": url_for('edit-book.show_edit_book', book_id=book_id)}
|
||||
return Response(json.dumps(resp), mimetype='application/json')
|
||||
|
||||
# only merge metadata if file was uploaded and no error occurred (meta equals not false or none)
|
||||
|
||||
|
||||
elif len(request.files.getlist("btn-upload")):
|
||||
for requested_file in request.files.getlist("btn-upload"):
|
||||
try:
|
||||
modify_date = False
|
||||
@ -309,6 +325,7 @@ def upload():
|
||||
flash(_("Oops! Database Error: %(error)s.", error=e.orig if hasattr(e, "orig") else e),
|
||||
category="error")
|
||||
return Response(json.dumps({"location": url_for("web.index")}), mimetype='application/json')
|
||||
abort(404)
|
||||
|
||||
|
||||
@editbook.route("/admin/book/convert/<int:book_id>", methods=['POST'])
|
||||
@ -1192,9 +1209,9 @@ def edit_cc_data(book_id, book, to_save, cc):
|
||||
|
||||
# returns None if no file is uploaded
|
||||
# returns False if an error occurs, in all other cases the ebook metadata is returned
|
||||
def upload_single_file(file_request, book, book_id):
|
||||
def upload_single_file(requested_file, book, book_id):
|
||||
# Check and handle Uploaded file
|
||||
requested_file = file_request.files.get('btn-upload-format', None)
|
||||
# requested_file = file_request.files.get('btn-upload-format', None)
|
||||
allowed_extensions = config.config_upload_formats.split(',')
|
||||
if requested_file:
|
||||
if config.config_check_extensions and allowed_extensions != ['']:
|
||||
|
@ -243,13 +243,13 @@ $("#search").on("change input.typeahead:selected", function(event) {
|
||||
});
|
||||
});
|
||||
|
||||
$("#btn-upload-format").on("change", function () {
|
||||
/*$("#btn-upload-format").on("change", function () {
|
||||
var filename = $(this).val();
|
||||
if (filename.substring(3, 11) === "fakepath") {
|
||||
filename = filename.substring(12);
|
||||
} // Remove c:\fake at beginning from localhost chrome
|
||||
$("#upload-format").text(filename);
|
||||
});
|
||||
});*/
|
||||
|
||||
$("#btn-upload-cover").on("change", function () {
|
||||
var filename = $(this).val();
|
||||
|
@ -130,24 +130,43 @@ $(".container-fluid").bind('drop', function (e) {
|
||||
}
|
||||
});
|
||||
if (dt.files.length) {
|
||||
if($("btn-upload-format").length) {
|
||||
$("#btn-upload-format")[0].files = dt.files;
|
||||
$("#form-upload-format").submit();
|
||||
} else {
|
||||
$("#btn-upload")[0].files = dt.files;
|
||||
$("#form-upload").submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#btn-upload").change(function() {
|
||||
$("#form-upload").submit();
|
||||
});
|
||||
|
||||
$("#form-upload").uploadprogress({
|
||||
redirect_url: getPath() + "/", //"{{ url_for('web.index')}}",
|
||||
uploadedMsg: $("#form-upload").data("message"), //"{{_('Upload done, processing, please wait...')}}",
|
||||
modalTitle: $("#form-upload").data("title"), //"{{_('Uploading...')}}",
|
||||
modalFooter: $("#form-upload").data("footer"), //"{{_('Close')}}",
|
||||
modalTitleFailed: $("#form-upload").data("failed") //"{{_('Error')}}"
|
||||
$("#btn-upload-format").change(function() {
|
||||
$("#form-upload-format").submit();
|
||||
});
|
||||
|
||||
|
||||
$("#form-upload").uploadprogress({
|
||||
redirect_url: getPath() + "/",
|
||||
uploadedMsg: $("#form-upload").data("message"),
|
||||
modalTitle: $("#form-upload").data("title"),
|
||||
modalFooter: $("#form-upload").data("footer"),
|
||||
modalTitleFailed: $("#form-upload").data("failed")
|
||||
});
|
||||
|
||||
$("#form-upload-format").uploadprogress({
|
||||
redirect_url: getPath() + "/",
|
||||
uploadedMsg: $("#form-upload-format").data("message"),
|
||||
modalTitle: $("#form-upload-format").data("title"),
|
||||
modalFooter: $("#form-upload-format").data("footer"),
|
||||
modalTitleFailed: $("#form-upload-format").data("failed")
|
||||
});
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
var inp = $('#query').first()
|
||||
if (inp.length) {
|
||||
|
@ -47,8 +47,23 @@
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if current_user.role_upload() and g.allow_upload %}
|
||||
|
||||
<div class="text-center more-stuff"><!--h4 aria-label="Upload new book format"></h4-->
|
||||
<form id="form-upload-format" action="{{ url_for('edit-book.upload') }}" data-title="{{_('Uploading...')}}" data-footer="{{_('Close')}}" data-failed="{{_('Error')}}" data-message="{{_('Upload done, processing, please wait...')}}" method="post" enctype="multipart/form-data">
|
||||
<div class="text-center">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<input type="hidden" name="book_id" value="{{ book.id }}">
|
||||
<div role="group" aria-label="Upload new book format">
|
||||
<label class="btn btn-primary btn-file" for="btn-upload-format">{{ _('Upload Format') }}</label>
|
||||
<div class="upload-format-input-text" id="upload-format"></div>
|
||||
<input id="btn-upload-format" name="btn-upload-format" type="file" accept="{% for format in accept %}.{% if format != ''%}{{format}}{% else %}*{% endif %}{{ ',' if not loop.last }}{% endfor %}" multiple>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<form role="form" action="{{ url_for('edit-book.edit_book', book_id=book.id) }}" method="post" enctype="multipart/form-data" id="book_edit_frm">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<div class="col-sm-9 col-xs-12">
|
||||
@ -196,13 +211,6 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if current_user.role_upload() and g.allow_upload %}
|
||||
<div role="group" aria-label="Upload new book format">
|
||||
<label class="btn btn-primary btn-file" for="btn-upload-format">{{ _('Upload Format') }}</label>
|
||||
<div class="upload-format-input-text" id="upload-format"></div>
|
||||
<input id="btn-upload-format" name="btn-upload-format" type="file">
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
|
@ -80,6 +80,7 @@
|
||||
<div class="form-group">
|
||||
<span class="btn btn-default btn-file">{{_('Upload')}}<input id="btn-upload" name="btn-upload"
|
||||
type="file" accept="{% for format in accept %}.{% if format != ''%}{{format}}{% else %}*{% endif %}{{ ',' if not loop.last }}{% endfor %}" multiple></span>
|
||||
<input class="hide" id="btn-upload2" name="btn-upload2" type="file" accept="{% for format in accept %}.{% if format != ''%}{{format}}{% else %}*{% endif %}{{ ',' if not loop.last }}{% endfor %}">
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
|
Loading…
Reference in New Issue
Block a user