mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
deal with a soho nas (and FF60esr)
This commit is contained in:
parent
79b7d3316a
commit
1c3aa0d2c5
|
@ -864,6 +864,9 @@ class HttpCli(object):
|
||||||
#
|
#
|
||||||
# send reply
|
# send reply
|
||||||
|
|
||||||
|
if not is_compressed:
|
||||||
|
self.out_headers["Cache-Control"] = "no-cache"
|
||||||
|
|
||||||
self.out_headers["Accept-Ranges"] = "bytes"
|
self.out_headers["Accept-Ranges"] = "bytes"
|
||||||
self.send_headers(
|
self.send_headers(
|
||||||
length=upper - lower,
|
length=upper - lower,
|
||||||
|
|
|
@ -289,19 +289,24 @@ function save_cb() {
|
||||||
this.btn.classList.remove('force-save');
|
this.btn.classList.remove('force-save');
|
||||||
//alert('save OK -- wrote ' + r.size + ' bytes.\n\nsha512: ' + r.sha512);
|
//alert('save OK -- wrote ' + r.size + ' bytes.\n\nsha512: ' + r.sha512);
|
||||||
|
|
||||||
|
run_savechk(r.lastmod, this.txt, this.btn, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_savechk(lastmod, txt, btn, ntry) {
|
||||||
// download the saved doc from the server and compare
|
// download the saved doc from the server and compare
|
||||||
var url = (document.location + '').split('?')[0] + '?raw';
|
var url = (document.location + '').split('?')[0] + '?raw&_=' + new Date().getTime();
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open('GET', url, true);
|
xhr.open('GET', url, true);
|
||||||
xhr.responseType = 'text';
|
xhr.responseType = 'text';
|
||||||
xhr.onreadystatechange = save_chk;
|
xhr.onreadystatechange = savechk_cb;
|
||||||
xhr.btn = this.save_btn;
|
xhr.lastmod = lastmod;
|
||||||
xhr.txt = this.txt;
|
xhr.txt = txt;
|
||||||
xhr.lastmod = r.lastmod;
|
xhr.btn = btn;
|
||||||
|
xhr.ntry = ntry;
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function save_chk() {
|
function savechk_cb() {
|
||||||
if (this.readyState != XMLHttpRequest.DONE)
|
if (this.readyState != XMLHttpRequest.DONE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -313,6 +318,14 @@ function save_chk() {
|
||||||
var doc1 = this.txt.replace(/\r\n/g, "\n");
|
var doc1 = this.txt.replace(/\r\n/g, "\n");
|
||||||
var doc2 = this.responseText.replace(/\r\n/g, "\n");
|
var doc2 = this.responseText.replace(/\r\n/g, "\n");
|
||||||
if (doc1 != doc2) {
|
if (doc1 != doc2) {
|
||||||
|
var that = this;
|
||||||
|
if (that.ntry < 10) {
|
||||||
|
// qnap funny, try a few more times
|
||||||
|
setTimeout(function () {
|
||||||
|
run_savechk(that.lastmod, that.txt, that.btn, that.ntry + 1)
|
||||||
|
}, 100);
|
||||||
|
return;
|
||||||
|
}
|
||||||
alert(
|
alert(
|
||||||
'Error! The document on the server does not appear to have saved correctly (your editor contents and the server copy is not identical). Place the document on your clipboard for now and check the server logs for hints\n\n' +
|
'Error! The document on the server does not appear to have saved correctly (your editor contents and the server copy is not identical). Place the document on your clipboard for now and check the server logs for hints\n\n' +
|
||||||
'Length: yours=' + doc1.length + ', server=' + doc2.length
|
'Length: yours=' + doc1.length + ', server=' + doc2.length
|
||||||
|
@ -325,7 +338,8 @@ function save_chk() {
|
||||||
last_modified = this.lastmod;
|
last_modified = this.lastmod;
|
||||||
server_md = this.txt;
|
server_md = this.txt;
|
||||||
draw_md();
|
draw_md();
|
||||||
toast('font-size:6em;font-family:serif;color:#cf6;width:4em;', 'OK✔️');
|
toast('font-size:6em;font-family:serif;color:#cf6;width:4em;',
|
||||||
|
'OK✔️<span style="font-size:.2em;color:#999">' + this.ntry + '</span>');
|
||||||
}
|
}
|
||||||
|
|
||||||
function toast(style, msg) {
|
function toast(style, msg) {
|
||||||
|
|
35
docs/pretend-youre-qnap.patch
Normal file
35
docs/pretend-youre-qnap.patch
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py
|
||||||
|
index 2d3c1ad..e1e85a0 100644
|
||||||
|
--- a/copyparty/httpcli.py
|
||||||
|
+++ b/copyparty/httpcli.py
|
||||||
|
@@ -864,6 +864,30 @@ class HttpCli(object):
|
||||||
|
#
|
||||||
|
# send reply
|
||||||
|
|
||||||
|
+ try:
|
||||||
|
+ fakefn = self.conn.hsrv.fakefn
|
||||||
|
+ fakectr = self.conn.hsrv.fakectr
|
||||||
|
+ fakedata = self.conn.hsrv.fakedata
|
||||||
|
+ except:
|
||||||
|
+ fakefn = b''
|
||||||
|
+ fakectr = 0
|
||||||
|
+ fakedata = b''
|
||||||
|
+
|
||||||
|
+ self.log('\n{} {}\n{}'.format(fakefn, fakectr, open_args[0]))
|
||||||
|
+ if fakefn == open_args[0] and fakectr > 0:
|
||||||
|
+ self.reply(fakedata, mime=guess_mime(req_path)[0])
|
||||||
|
+ self.conn.hsrv.fakectr = fakectr - 1
|
||||||
|
+ else:
|
||||||
|
+ with open_func(*open_args) as f:
|
||||||
|
+ fakedata = f.read()
|
||||||
|
+
|
||||||
|
+ self.conn.hsrv.fakefn = open_args[0]
|
||||||
|
+ self.conn.hsrv.fakedata = fakedata
|
||||||
|
+ self.conn.hsrv.fakectr = 15
|
||||||
|
+ self.reply(fakedata, mime=guess_mime(req_path)[0])
|
||||||
|
+
|
||||||
|
+ return True
|
||||||
|
+
|
||||||
|
self.out_headers["Accept-Ranges"] = "bytes"
|
||||||
|
self.send_headers(
|
||||||
|
length=upper - lower,
|
Loading…
Reference in a new issue