mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
make downloading themes possible from background script
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//import PocketBase from 'pocketbase';
|
||||
import localforage from 'localforage';
|
||||
import { ThemesResponse } from '../../../interface/types/pocketbase-types';
|
||||
import { CustomTheme } from '../../../interface/types/CustomThemes';
|
||||
|
||||
const DownloadTheme = async (theme: ThemesResponse & { theme: CustomTheme & { images: { id: string, variableName: string }[] } }) => {
|
||||
const images: { imageData: Blob, imageID: string }[] = []
|
||||
for (const imageID of theme.images) {
|
||||
console.log(theme.images, `https://betterseqta.pockethost.io/api/files/${theme.collectionId}/${theme.id}/${imageID}`);
|
||||
const image = await fetch(
|
||||
`https://betterseqta.pockethost.io/api/files/${theme.collectionId}/${theme.id}/${imageID}`
|
||||
)
|
||||
const imageData = await image.blob();
|
||||
|
||||
images.push({ imageData, imageID });
|
||||
}
|
||||
|
||||
console.log("Original Theme", theme);
|
||||
|
||||
// add to temp storage index
|
||||
let availableThemes = await localforage.getItem('availableThemes') as string[];
|
||||
if (availableThemes && !availableThemes.includes(theme.theme.id)) {
|
||||
availableThemes.push(theme.theme.id);
|
||||
} else if (!availableThemes) {
|
||||
availableThemes = [theme.theme.id];
|
||||
}
|
||||
localforage.setItem('availableThemes', availableThemes);
|
||||
|
||||
// save the theme to the temp storage
|
||||
localforage.setItem(theme.theme.id, {
|
||||
...theme.theme,
|
||||
images: theme.theme.images.map((image) => {
|
||||
return {
|
||||
...image,
|
||||
imageData: images.find((i) => i.imageID.split('_')[0] === image.id)?.imageData
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export default DownloadTheme;
|
||||
|
||||
@@ -25,7 +25,6 @@ const shareTheme = async (themeID: string) => {
|
||||
id: image.id,
|
||||
data: finalImage,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user