mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
add store downloading
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user