add store downloading

This commit is contained in:
SethBurkart123
2024-05-07 12:03:38 +10:00
parent 3db51fb6d5
commit 2408fb1028
4 changed files with 79 additions and 9 deletions
+58
View File
@@ -2,6 +2,7 @@
import localforage from 'localforage';
import { ThemesResponse } from '../../../interface/types/pocketbase-types';
import { CustomTheme } from '../../../interface/types/CustomThemes';
import { Theme } from '../../../interface/pages/Store';
const DownloadTheme = async (theme: ThemesResponse & { theme: CustomTheme & { images: { id: string, variableName: string }[] } }) => {
const images: { imageData: Blob, imageID: string }[] = []
@@ -43,4 +44,61 @@ const DownloadTheme = async (theme: ThemesResponse & { theme: CustomTheme & { im
});
}
type ThemeContent = {
id: string;
name: string;
coverImage: string;
description: string;
defaultColour: string;
CanChangeColour: boolean;
CustomCSS: string;
hideThemeName: boolean;
images: { id: string, variableName: string }[];
}
export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => {
console.log(theme.themeContent.id);
if (!theme.themeContent.id) return;
const themeContent = await fetch(`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes/${theme.themeContent.id}/theme.json`);
const themeData = await themeContent.json() as ThemeContent;
const images: { imageData: Blob, imageID: string }[] = []
for (const image of themeData.images) {
const data = await fetch(
`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes/${themeData.id}/images/${image.id}`
)
const imageData = await data.blob();
images.push({ imageData, imageID: image.id });
}
const coverImage = await fetch(
`https://raw.githubusercontent.com/BetterSEQTA/BetterSEQTA-Themes/main/store/themes/${themeData.id}/images/${themeData.coverImage}`
);
// add to temp storage index
let availableThemes = await localforage.getItem('availableThemes') as string[];
if (availableThemes && !availableThemes.includes(themeData.id)) {
availableThemes.push(themeData.id);
} else if (!availableThemes) {
availableThemes = [themeData.id];
}
localforage.setItem('availableThemes', availableThemes);
localforage.setItem(themeData.id, {
...themeData,
webURL: theme.themeContent.id,
coverImage: await coverImage.blob(),
CustomImages: themeData.images.map((image) => {
return {
...image,
blob: images.find((img) => {
return image.id.includes(img.imageID.split('_')[0]);
})?.imageData
}
})
});
}
export default DownloadTheme;