mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-05 19:24:39 +00:00
fix: theme exports and imports sometimes failing due to attached images
This commit is contained in:
@@ -22,8 +22,20 @@ type ThemeContent = {
|
||||
};
|
||||
|
||||
function stripBase64Prefix(base64String: string): string {
|
||||
const prefixRegex = /^data:image\/\w+;base64,/;
|
||||
if (!base64String) return '';
|
||||
|
||||
const prefixRegex = /^data:[^;]+;base64,/;
|
||||
try {
|
||||
// Check if the string actually has a base64 prefix
|
||||
if (prefixRegex.test(base64String)) {
|
||||
return base64String.replace(prefixRegex, '');
|
||||
}
|
||||
// If no prefix found, return the original string (assuming it's already base64)
|
||||
return base64String;
|
||||
} catch(err) {
|
||||
console.error('Error stripping base64 prefix:', err);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => {
|
||||
@@ -37,13 +49,14 @@ export const StoreDownloadTheme = async (theme: { themeContent: Theme }) => {
|
||||
|
||||
export const InstallTheme = async (themeData: ThemeContent) => {
|
||||
const strippedCoverImage = stripBase64Prefix(themeData.coverImage);
|
||||
console.log('1!')
|
||||
const coverImageBlob = base64ToBlob(strippedCoverImage);
|
||||
|
||||
console.log('2!')
|
||||
const images = themeData.images.map((image) => ({
|
||||
...image,
|
||||
blob: base64ToBlob(image.data)
|
||||
blob: base64ToBlob(stripBase64Prefix(image.data))
|
||||
}));
|
||||
|
||||
console.log('3!')
|
||||
let availableThemes = await localforage.getItem('customThemes') as string[];
|
||||
if (availableThemes && !availableThemes.includes(themeData.id)) {
|
||||
availableThemes.push(themeData.id);
|
||||
|
||||
@@ -28,7 +28,12 @@ const shareTheme = async (themeID: string) => {
|
||||
// Helper function to convert Blob to Base64
|
||||
const blobToBase64 = (blob: Blob) => new Promise<string>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => resolve(reader.result as string);
|
||||
reader.onloadend = () => {
|
||||
const base64String = reader.result as string;
|
||||
// Extract just the base64 data without the data URL prefix
|
||||
const base64Data = base64String.split(',')[1];
|
||||
resolve(base64Data);
|
||||
};
|
||||
reader.onerror = reject;
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user