diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 2d3c1ad9..5225371b 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -864,6 +864,9 @@ class HttpCli(object): # # send reply + if not is_compressed: + self.out_headers["Cache-Control"] = "no-cache" + self.out_headers["Accept-Ranges"] = "bytes" self.send_headers( length=upper - lower, diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js index f4befa98..318ba9fd 100644 --- a/copyparty/web/md2.js +++ b/copyparty/web/md2.js @@ -289,19 +289,24 @@ function save_cb() { this.btn.classList.remove('force-save'); //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 - var url = (document.location + '').split('?')[0] + '?raw'; + var url = (document.location + '').split('?')[0] + '?raw&_=' + new Date().getTime(); var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'text'; - xhr.onreadystatechange = save_chk; - xhr.btn = this.save_btn; - xhr.txt = this.txt; - xhr.lastmod = r.lastmod; + xhr.onreadystatechange = savechk_cb; + xhr.lastmod = lastmod; + xhr.txt = txt; + xhr.btn = btn; + xhr.ntry = ntry; xhr.send(); } -function save_chk() { +function savechk_cb() { if (this.readyState != XMLHttpRequest.DONE) return; @@ -313,6 +318,14 @@ function save_chk() { var doc1 = this.txt.replace(/\r\n/g, "\n"); var doc2 = this.responseText.replace(/\r\n/g, "\n"); 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( '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 @@ -325,7 +338,8 @@ function save_chk() { last_modified = this.lastmod; server_md = this.txt; 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✔️' + this.ntry + ''); } function toast(style, msg) { diff --git a/docs/pretend-youre-qnap.patch b/docs/pretend-youre-qnap.patch new file mode 100644 index 00000000..717c4054 --- /dev/null +++ b/docs/pretend-youre-qnap.patch @@ -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,