Skip to content

Commit 33c8159

Browse files
committed
fix url decoder and update engine
1 parent 203a590 commit 33c8159

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/app.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/litecanvas.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/sw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const cacheName = "luizbills.litecanvas-editor-v1";
2-
const version = "1.35.0";
2+
const version = "1.36.0";
33

44
const precacheResources = [
55
"/",

src/index.js

+35-12
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,42 @@ function compressString(str) {
219219

220220
function decompressString(str) {
221221
let code = null;
222-
try {
223-
code = pako.inflate(
224-
new Uint8Array(
225-
atob(str)
226-
.split("")
227-
.map((c) => c.charCodeAt(0))
228-
),
229-
{ to: "string" }
230-
);
231-
} catch (e) {
232-
alert("Invalid playground url: " + e.message);
233-
code = null;
222+
let attempts = 0;
223+
224+
while (attempts < 2) {
225+
try {
226+
if (attempts === 1) {
227+
// try a second time fixing some characters
228+
str = decodeURIComponent(str);
229+
str = str.replace(/ /g, "+");
230+
}
231+
232+
// decode
233+
code = pako.inflate(
234+
new Uint8Array(
235+
atob(str)
236+
.split("")
237+
.map((c) => c.charCodeAt(0))
238+
),
239+
{ to: "string" }
240+
);
241+
console.log("Playground url decoded successfully!");
242+
break;
243+
} catch (e) {
244+
console.error(
245+
`Failed decode the playground url (${attempts + 1}/2). Error:`,
246+
e
247+
);
248+
console.log("Trying to decode again (fixing some characters)...");
249+
code = null;
250+
attempts++;
251+
}
252+
}
253+
254+
if (!code) {
255+
alert("Invalid playground url.");
234256
}
257+
235258
return code;
236259
}
237260

0 commit comments

Comments
 (0)