From c4b322b883366c44e5207ef29a8faae632510055 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 1 Dec 2020 02:25:46 +0100 Subject: [PATCH] this commit sponsored by eslint --- .eslintrc.json | 12 ++++++++++++ copyparty/httpcli.py | 9 ++++++--- copyparty/web/browser.js | 5 ++--- copyparty/web/md.js | 2 +- copyparty/web/md2.js | 20 ++++++++++++-------- copyparty/web/up2k.js | 29 ++--------------------------- copyparty/web/util.js | 2 +- scripts/copyparty-repack.sh | 1 - 8 files changed, 36 insertions(+), 44 deletions(-) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..f6aed758 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 12 + }, + "rules": { + } +} diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 6b51b2e4..1f8fb7e1 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -756,9 +756,12 @@ class HttpCli(object): cli_dt = time.strptime(cli_lastmod, "%a, %d %b %Y %H:%M:%S GMT") cli_ts = calendar.timegm(cli_dt) return file_lastmod, int(file_ts) > int(cli_ts) - except: - self.log("bad lastmod format: {}".format(cli_lastmod)) - self.log(" expected format: {}".format(file_lastmod)) + except Exception as ex: + self.log( + "lastmod {}\nremote: [{}]\n local: [{}]".format( + repr(ex), cli_lastmod, file_lastmod + ) + ) return file_lastmod, file_lastmod != cli_lastmod return file_lastmod, True diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 236f1408..c46afd9f 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -25,7 +25,7 @@ var mp = (function () { 'tracks': tracks, 'cover_url': '' }; - var re_audio = new RegExp('\.(opus|ogg|m4a|aac|mp3|wav|flac)$', 'i'); + var re_audio = /\.(opus|ogg|m4a|aac|mp3|wav|flac)$/i; var trs = ebi('files').getElementsByTagName('tbody')[0].getElementsByTagName('tr'); for (var a = 0, aa = trs.length; a < aa; a++) { @@ -468,7 +468,6 @@ function play(tid, call_depth) { function evau_error(e) { var err = ''; var eplaya = (e && e.target) || (window.event && window.event.srcElement); - var url = eplaya.src; switch (eplaya.error.code) { case eplaya.error.MEDIA_ERR_ABORTED: @@ -516,7 +515,7 @@ function unblocked() { // show ui to manually start playback of a linked song -function autoplay_blocked(tid) { +function autoplay_blocked() { show_modal( '
' + '
Cancel
(show file list)
'); diff --git a/copyparty/web/md.js b/copyparty/web/md.js index 74d4b57e..5a752a9a 100644 --- a/copyparty/web/md.js +++ b/copyparty/web/md.js @@ -299,7 +299,7 @@ function convert_markdown(md_text, dest_dom) { } // separate for each line in
-    var nodes = md_dom.getElementsByTagName('pre');
+    nodes = md_dom.getElementsByTagName('pre');
     for (var a = nodes.length - 1; a >= 0; a--) {
         var el = nodes[a];
 
diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js
index 74dca04a..93b6d715 100644
--- a/copyparty/web/md2.js
+++ b/copyparty/web/md2.js
@@ -144,7 +144,7 @@ redraw = (function () {
         onresize();
     }
     function modetoggle() {
-        mode = dom_nsbs.innerHTML;
+        var mode = dom_nsbs.innerHTML;
         dom_nsbs.innerHTML = mode == 'editor' ? 'preview' : 'editor';
         mode += ' single';
         dom_wrap.setAttribute('class', mode);
@@ -304,7 +304,7 @@ function Modpoll() {
         this.periodic();
 
     return this;
-};
+}
 var modpoll = new Modpoll();
 
 
@@ -743,7 +743,8 @@ function fmt_table(e) {
         lpipe = tab[1].indexOf('|') < tab[1].indexOf('-'),
         rpipe = tab[1].lastIndexOf('|') > tab[1].lastIndexOf('-'),
         re_lpipe = lpipe ? /^\s*\|\s*/ : /^\s*/,
-        re_rpipe = rpipe ? /\s*\|\s*$/ : /\s*$/;
+        re_rpipe = rpipe ? /\s*\|\s*$/ : /\s*$/,
+        ncols;
 
     // the second row defines the table,
     // need to process that first
@@ -868,9 +869,8 @@ function mark_uni(e) {
     dom_tbox.setAttribute('class', '');
 
     var txt = dom_src.value,
-        ptn = new RegExp('([^' + js_uni_whitelist + ']+)', 'g');
-
-    mod = txt.replace(/\r/g, "").replace(ptn, "\u2588\u2770$1\u2771");
+        ptn = new RegExp('([^' + js_uni_whitelist + ']+)', 'g'),
+        mod = txt.replace(/\r/g, "").replace(ptn, "\u2588\u2770$1\u2771");
 
     if (txt == mod) {
         alert('no results;  no modifications were made');
@@ -906,7 +906,12 @@ function iter_uni(e) {
 // configure whitelist
 function cfg_uni(e) {
     if (e) e.preventDefault();
-    esc_uni_whitelist = prompt("unicode whitelist", esc_uni_whitelist);
+
+    var reply = prompt("unicode whitelist", esc_uni_whitelist);
+    if (reply === null)
+        return;
+
+    esc_uni_whitelist = reply;
     js_uni_whitelist = eval('\'' + esc_uni_whitelist + '\'');
 }
 
@@ -1126,7 +1131,6 @@ action_stack = (function () {
     }
 
     return {
-        push: push,
         undo: undo,
         redo: redo,
         push: schedule_push,
diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js
index 1e4cd9a3..09ea8b03 100644
--- a/copyparty/web/up2k.js
+++ b/copyparty/web/up2k.js
@@ -33,7 +33,7 @@ function goto(dest) {
     for (var a = obj.length - 1; a >= 0; a--)
         obj[a].classList.remove('act');
 
-    var obj = document.querySelectorAll('#ops>a');
+    obj = document.querySelectorAll('#ops>a');
     for (var a = obj.length - 1; a >= 0; a--)
         obj[a].classList.remove('act');
 
@@ -130,7 +130,7 @@ function up2k_init(have_crypto) {
             else
                 ebi('u2foot').innerHTML = 'seems like ' + shame + ' so do that if you want more performance';
         }
-    };
+    }
 
     // show uploader if the user only has write-access
     if (!ebi('files'))
@@ -396,17 +396,6 @@ function up2k_init(have_crypto) {
     ///   hashing
     //
 
-    // https://gist.github.com/jonleighton/958841
-    function buf2b64_maybe_fucky(buffer) {
-        var ret = '';
-        var view = new DataView(buffer);
-        for (var i = 0; i < view.byteLength; i++) {
-            ret += String.fromCharCode(view.getUint8(i));
-        }
-        return window.btoa(ret).replace(
-            /\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
-    }
-
     // https://gist.github.com/jonleighton/958841
     function buf2b64(arrayBuffer) {
         var base64 = '';
@@ -447,20 +436,6 @@ function up2k_init(have_crypto) {
         return base64;
     }
 
-    // https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
-    function buf2hex(buffer) {
-        var hexCodes = [];
-        var view = new DataView(buffer);
-        for (var i = 0; i < view.byteLength; i += 4) {
-            var value = view.getUint32(i) // 4 bytes per iter
-            var stringValue = value.toString(16) // doesn't pad
-            var padding = '00000000'
-            var paddedValue = (padding + stringValue).slice(-padding.length)
-            hexCodes.push(paddedValue);
-        }
-        return hexCodes.join("");
-    }
-
     function get_chunksize(filesize) {
         var chunksize = 1024 * 1024;
         var stepsize = 512 * 1024;
diff --git a/copyparty/web/util.js b/copyparty/web/util.js
index f8aae712..50cf70df 100644
--- a/copyparty/web/util.js
+++ b/copyparty/web/util.js
@@ -36,7 +36,7 @@ function vis_exh(msg, url, lineNo, columnNo, error) {
     document.body.style.fontSize = '0.8em';
     document.body.style.padding = '0 1em 1em 1em';
     hcroak(html.join('\n'));
-};
+}
 
 
 function ebi(id) {
diff --git a/scripts/copyparty-repack.sh b/scripts/copyparty-repack.sh
index f9966f81..1b7cb44c 100755
--- a/scripts/copyparty-repack.sh
+++ b/scripts/copyparty-repack.sh
@@ -72,7 +72,6 @@ chmod 755 \
 ( cd copyparty-extras/sfx-full/
 ./copyparty-sfx.py -h
 cd ../copyparty-*/
-sed -ri 's`^command -v git >/dev/null`false`' ./scripts/make-sfx.sh  # TODO remove on next rls
 ./scripts/make-sfx.sh re no-ogv no-cm
 )