fix: themes failing to install from coverImage decoding error

This commit is contained in:
SethBurkart123
2024-11-15 16:35:28 +11:00
parent 8e11ab821b
commit 21a8472c94
2 changed files with 345 additions and 2 deletions
+15 -2
View File
@@ -1,7 +1,14 @@
import localforage from 'localforage'; import localforage from 'localforage';
import type { Theme } from '@/old-interface/pages/Store';
import base64ToBlob from '@/seqta/utils/base64ToBlob'; import base64ToBlob from '@/seqta/utils/base64ToBlob';
type Theme = {
name: string;
description: string;
coverImage: string;
marqueeImage: string;
id: string;
}
type ThemeContent = { type ThemeContent = {
id: string; id: string;
name: string; name: string;
@@ -14,6 +21,11 @@ type ThemeContent = {
images: { id: string, variableName: string, data: string }[]; // data: base64 images: { id: string, variableName: string, data: string }[]; // data: base64
}; };
function stripBase64Prefix(base64String: string): string {
const prefixRegex = /^data:image\/\w+;base64,/;
return base64String.replace(prefixRegex, '');
}
export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => { export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => {
if (!theme.themeContent.id) return; if (!theme.themeContent.id) return;
@@ -24,7 +36,8 @@ export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => {
}; };
export const InstallTheme = async (themeData: ThemeContent) => { export const InstallTheme = async (themeData: ThemeContent) => {
const coverImageBlob = base64ToBlob(themeData.coverImage); const strippedCoverImage = stripBase64Prefix(themeData.coverImage);
const coverImageBlob = base64ToBlob(strippedCoverImage);
const images = themeData.images.map((image) => ({ const images = themeData.images.map((image) => ({
...image, ...image,
File diff suppressed because one or more lines are too long