Storing imported tracks in local "forage".
This commit is contained in:
1 parent
bb2130793d
commit
d0bac1c509
9 files changed
+1276
-53
No files matched your search
+28
-2
@@ -1,5 +1,12 @@
|
||||
import { createSlice } from '@reduxjs/toolkit';
|
||||
|
||||
import {
|
||||
Sha256,
|
||||
Sha512,
|
||||
string_to_bytes,
|
||||
bytes_to_base64,
|
||||
} from '@openpgp/asmcrypto.js';
|
||||
|
||||
interface TracksState {
|
||||
tracks: { [index: string]: any };
|
||||
}
|
||||
@@ -13,10 +20,29 @@ const tracksSlice = createSlice({
|
||||
initialState: initialTracks,
|
||||
reducers: {
|
||||
add: (state, action) => {
|
||||
state.tracks[action.payload.id] = action.payload.track;
|
||||
const { id, ...data } = action.payload;
|
||||
state.tracks[action.payload.id] = data;
|
||||
},
|
||||
push: (state, action) => {
|
||||
state.tracks[crypto.randomUUID()] = action.payload;
|
||||
const sha = new Sha512();
|
||||
const result = sha
|
||||
.process(string_to_bytes(JSON.stringify(action.payload.track)))
|
||||
.finish().result;
|
||||
var id;
|
||||
if (result === null) {
|
||||
console.log(`Can't hash`);
|
||||
id = crypto.randomUUID();
|
||||
} else {
|
||||
id = bytes_to_base64(result);
|
||||
console.log(`Digest: ${id}`);
|
||||
}
|
||||
if (state.tracks.hasOwnProperty(id)) {
|
||||
console.log('Track had already been imported');
|
||||
} else {
|
||||
state.tracks[id] = {
|
||||
...action.payload,
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user