switch back to url #5
This commit is contained in:
parent
82bf59690b
commit
39840b5b3c
|
@ -93,7 +93,9 @@ if i'm unavalible or you're in a hurry, you can decode the links manually:
|
|||
newer formats are complicated, so i'll only provide commit hashes and the code locations.
|
||||
|
||||
- `#5`: commit 8acb6ab, grep for "location.hash"
|
||||
- `#6` is the latest, and may even change. first version is in a36406d src/url/mod.ts
|
||||
- `#6` commit a36406d, src/url/mod.ts. this version was reverted because the urls broke markdown
|
||||
- `#5` after commit a36406d, src/url/mod.ts
|
||||
|
||||
|
||||
|
||||
## building
|
||||
|
|
|
@ -109,6 +109,9 @@ async function fromUrlData(hash: string): Promise<Song | undefined> {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//version 6 breaks markdown and probably other things
|
||||
/*
|
||||
async function setUrlData({ code, mode, sampleRate }: Song) {
|
||||
const smallmode = smallmode_table[mode];
|
||||
|
||||
|
@ -128,6 +131,27 @@ async function setUrlData({ code, mode, sampleRate }: Song) {
|
|||
const base89 = into89(dataArray, 4);
|
||||
|
||||
window.location.hash = `#6${base89}`;
|
||||
}*/
|
||||
|
||||
async function setUrlData({ code, mode, sampleRate }: Song) {
|
||||
const smallmode = smallmode_table[mode];
|
||||
|
||||
const compressedCode = deflateSync(new TextEncoder().encode(code), {
|
||||
level: 8,
|
||||
});
|
||||
|
||||
const buffer = new ArrayBuffer(6 + compressedCode.length);
|
||||
const dataview = new DataView(buffer);
|
||||
dataview.setFloat32(1, sampleRate);
|
||||
dataview.setUint8(5, smallmode);
|
||||
|
||||
const dataArray = new Uint8Array(buffer);
|
||||
dataArray.set(compressedCode, 6);
|
||||
|
||||
const dataString = dataArray.reduce((a, b) => a + String.fromCharCode(b), "");
|
||||
const base64 = btoa(dataString).substring(2).replaceAll("=", "");
|
||||
|
||||
window.location.hash = `#5${base64}`;
|
||||
}
|
||||
|
||||
export { fromUrlData, setUrlData };
|
||||
|
|
Loading…
Reference in New Issue