diff --git a/dist/assets/index-BnmZvFVF.js b/dist/assets/index-DCGgTNoY.js similarity index 99% rename from dist/assets/index-BnmZvFVF.js rename to dist/assets/index-DCGgTNoY.js index 76b0e55..e91c568 100644 --- a/dist/assets/index-BnmZvFVF.js +++ b/dist/assets/index-DCGgTNoY.js @@ -274,6 +274,7 @@ const imgToWebp = (f, D = 128, q = 80) => new Promise((r, j) => { i.src = URL.createObjectURL(f); }); const b64 = (x) => x.split(",")[1] || ""; +const utob = (s) => btoa(unescape(encodeURIComponent(s))), btou = (s) => decodeURIComponent(escape(atob(s.replace(/\s/g, "")))); const su = { key: "sunes_v1", activeKey: "active_sune_id", load() { try { return JSON.parse(localStorage.getItem(this.key) || "[]"); @@ -1370,7 +1371,7 @@ const ghApi = async (path, method = "GET", body = null) => { }; const parseGhUrl = (u) => { const p = u.substring(5).split("/"), owner = p[0], repo = p[1], branch = repo?.includes("@") ? repo.split("@")[1] : "main", cleanRepo = repo?.split("@")[0], path = p.slice(2).join("/"); - return { owner, repo: cleanRepo, branch, path, full: `${owner}/${cleanRepo}/contents/${path ? path + "/" : ""}index.json?ref=${branch}`, dir: `${owner}/${cleanRepo}/contents/${path ? path + "/" : ""}` }; + return { owner, repo: cleanRepo, branch, path, full: `${owner}/${cleanRepo}/contents/${path ? path + "/" : ""}index.json?ref=${branch}`, dir: `${owner}/${cleanRepo}/contents/${path ? path + "/" : " "}`.trim() }; }; $(el.threadRepoInput).on("change", async () => { const u = el.threadRepoInput.value.trim(); @@ -1407,19 +1408,24 @@ $(el.threadSyncBtn).on("click", async () => { for (const t of THREAD.list) { if (t.type === "thread" && (t.status === "modified" || t.status === "new")) { const msgs = await localforage.getItem("rem_t_" + t.id), fPath = `${info.dir}${t.id}.json`, ex = await ghApi(fPath + "?ref=" + info.branch); - await ghApi(fPath, "PUT", { message: `Sync thread ${t.id}`, content: btoa(JSON.stringify(msgs)), branch: info.branch, sha: ex?.sha }); + await ghApi(fPath, "PUT", { message: `Sync thread ${t.id}`, content: utob(JSON.stringify(msgs)), branch: info.branch, sha: ex?.sha }); t.status = "synced"; } } - await ghApi(info.full, "PUT", { message: "Update index.json", content: btoa(JSON.stringify(THREAD.list)), branch: info.branch, sha }); + await ghApi(info.full, "PUT", { message: "Update index.json", content: utob(JSON.stringify(THREAD.list)), branch: info.branch, sha }); alert("Pushed to GitHub."); } else { const idxFile = await ghApi(info.full); - if (!idxFile) throw new Error("Remote index.json not found"); - const remoteList = JSON.parse(atob(idxFile.content)); - THREAD.list = remoteList.map((t) => ({ ...t, status: "synced" })); - await THREAD.save(); - alert("Pulled from GitHub."); + if (!idxFile) { + THREAD.list = []; + await THREAD.save(); + alert("Remote is empty. Local list cleared."); + } else { + const remoteList = JSON.parse(btou(idxFile.content)); + THREAD.list = remoteList.map((t) => ({ ...t, status: "synced" })); + await THREAD.save(); + alert("Pulled from GitHub."); + } } await renderThreads(); } catch (e) { diff --git a/dist/index.html b/dist/index.html index 3d62d91..61c524e 100644 --- a/dist/index.html +++ b/dist/index.html @@ -12,7 +12,7 @@ - + diff --git a/dist/sw.js b/dist/sw.js index ae072a2..4c8b6e6 100644 --- a/dist/sw.js +++ b/dist/sw.js @@ -1 +1 @@ -if(!self.define){let e,s={};const i=(i,n)=>(i=new URL(i+".js",n).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(n,r)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let o={};const c=e=>i(e,t),l={module:{uri:t},exports:o,require:c};s[t]=Promise.all(n.map(e=>l[e]||c(e))).then(e=>(r(...e),o))}}define(["./workbox-8c29f6e4"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"928142cad5abfc7eb0ffef5a014c3b44"},{url:"assets/index-JLEDB1oP.css",revision:null},{url:"assets/index-BnmZvFVF.js",revision:null},{url:"manifest.webmanifest",revision:"7a6c5c6ab9cb5d3605d21df44c6b17a2"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))}); +if(!self.define){let e,s={};const i=(i,n)=>(i=new URL(i+".js",n).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(n,r)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let o={};const d=e=>i(e,t),l={module:{uri:t},exports:o,require:d};s[t]=Promise.all(n.map(e=>l[e]||d(e))).then(e=>(r(...e),o))}}define(["./workbox-8c29f6e4"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"7f332605d7f06540e2fd04507dd0dd8f"},{url:"assets/index-JLEDB1oP.css",revision:null},{url:"assets/index-DCGgTNoY.js",revision:null},{url:"manifest.webmanifest",revision:"7a6c5c6ab9cb5d3605d21df44c6b17a2"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))});