Refactor localStorage import and update .gitignore for localstorage.json
This commit is contained in:
parent
67dce9ddc0
commit
43667b79f0
4 changed files with 61 additions and 30 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -35,5 +35,5 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|||
|
||||
|
||||
tmp
|
||||
localstorage
|
||||
localstorage.json
|
||||
downloaded
|
|
@ -1,4 +1,4 @@
|
|||
import "../localstorage";
|
||||
import "./localStorage";
|
||||
|
||||
import { init, initializeDeviceLogin, finalizeDeviceLogin, credentialsProvider } from "@tidal-music/auth";
|
||||
|
||||
|
|
29
src/helpers/localStorage.ts
Normal file
29
src/helpers/localStorage.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
const database = Bun.file('localStorage.json');
|
||||
|
||||
if (!await database.exists()) {
|
||||
await Bun.write(database, JSON.stringify({}));
|
||||
}
|
||||
|
||||
let data = {};
|
||||
|
||||
data = await database.json() || {};
|
||||
|
||||
globalThis.localStorage = {
|
||||
getItem: (key) => {
|
||||
return data[key] || null;
|
||||
},
|
||||
setItem: (key, value) => {
|
||||
data[key] = value;
|
||||
Bun.write(database, JSON.stringify(data));
|
||||
},
|
||||
removeItem: (key) => {
|
||||
delete data[key];
|
||||
Bun.write(database, JSON.stringify(data));
|
||||
},
|
||||
clear: () => {
|
||||
data = {};
|
||||
Bun.write(database, JSON.stringify(data));
|
||||
}
|
||||
};
|
||||
|
||||
export { }
|
|
@ -113,12 +113,14 @@ export default class {
|
|||
],
|
||||
}
|
||||
|
||||
console.log(track)
|
||||
|
||||
return FlacStreamTagger.fromBuffer(Buffer.from(audioBuffer), {
|
||||
tagMap: {
|
||||
title: track.title,
|
||||
trackNumber: track.trackNumber.toString(),
|
||||
discNumber: track.volumeNumber.toString(),
|
||||
bpm: track.bpm.toString(),
|
||||
bpm: (track.bpm || 0).toString(),
|
||||
date: track.streamStartDate,
|
||||
copyright: track.copyright,
|
||||
REPLAYGAIN_TRACK_GAIN: track.replayGain.toString(),
|
||||
|
|
Loading…
Add table
Reference in a new issue