mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 21:03:08 +00:00
feat: enhance background image handling with cache-busting
- Added a cache-busting query parameter to the background image URL to ensure the browser reloads the image when updated. - Updated the AppState to include an optional imageVersion property for managing image updates. - Modified the BoardBackgroundModal and BoardView components to utilize the new imageVersion for dynamic image loading.
This commit is contained in:
@@ -90,14 +90,22 @@ export function BoardBackgroundModal({
|
|||||||
if (currentProject && backgroundSettings.imagePath) {
|
if (currentProject && backgroundSettings.imagePath) {
|
||||||
const serverUrl =
|
const serverUrl =
|
||||||
process.env.NEXT_PUBLIC_SERVER_URL || "http://localhost:3008";
|
process.env.NEXT_PUBLIC_SERVER_URL || "http://localhost:3008";
|
||||||
|
// Add cache-busting query parameter to force browser to reload image
|
||||||
|
const cacheBuster = backgroundSettings.imageVersion
|
||||||
|
? `&v=${backgroundSettings.imageVersion}`
|
||||||
|
: `&v=${Date.now()}`;
|
||||||
const imagePath = `${serverUrl}/api/fs/image?path=${encodeURIComponent(
|
const imagePath = `${serverUrl}/api/fs/image?path=${encodeURIComponent(
|
||||||
backgroundSettings.imagePath
|
backgroundSettings.imagePath
|
||||||
)}&projectPath=${encodeURIComponent(currentProject.path)}`;
|
)}&projectPath=${encodeURIComponent(currentProject.path)}${cacheBuster}`;
|
||||||
setPreviewImage(imagePath);
|
setPreviewImage(imagePath);
|
||||||
} else {
|
} else {
|
||||||
setPreviewImage(null);
|
setPreviewImage(null);
|
||||||
}
|
}
|
||||||
}, [currentProject, backgroundSettings.imagePath]);
|
}, [
|
||||||
|
currentProject,
|
||||||
|
backgroundSettings.imagePath,
|
||||||
|
backgroundSettings.imageVersion,
|
||||||
|
]);
|
||||||
|
|
||||||
const fileToBase64 = (file: File): Promise<string> => {
|
const fileToBase64 = (file: File): Promise<string> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -1999,7 +1999,11 @@ export function BoardView() {
|
|||||||
backgroundSettings.imagePath
|
backgroundSettings.imagePath
|
||||||
)}&projectPath=${encodeURIComponent(
|
)}&projectPath=${encodeURIComponent(
|
||||||
currentProject?.path || ""
|
currentProject?.path || ""
|
||||||
)})`,
|
)}${
|
||||||
|
backgroundSettings.imageVersion
|
||||||
|
? `&v=${backgroundSettings.imageVersion}`
|
||||||
|
: ""
|
||||||
|
})`,
|
||||||
backgroundSize: "cover",
|
backgroundSize: "cover",
|
||||||
backgroundPosition: "center",
|
backgroundPosition: "center",
|
||||||
backgroundRepeat: "no-repeat",
|
backgroundRepeat: "no-repeat",
|
||||||
|
|||||||
@@ -372,6 +372,7 @@ export interface AppState {
|
|||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
imagePath: string | null; // Path to background image in .automaker directory
|
imagePath: string | null; // Path to background image in .automaker directory
|
||||||
|
imageVersion?: number; // Timestamp to bust browser cache when image is updated
|
||||||
cardOpacity: number; // Opacity of cards (0-100)
|
cardOpacity: number; // Opacity of cards (0-100)
|
||||||
columnOpacity: number; // Opacity of columns (0-100)
|
columnOpacity: number; // Opacity of columns (0-100)
|
||||||
columnBorderEnabled: boolean; // Whether to show column borders
|
columnBorderEnabled: boolean; // Whether to show column borders
|
||||||
@@ -1316,6 +1317,8 @@ export const useAppStore = create<AppState & AppActions>()(
|
|||||||
[projectPath]: {
|
[projectPath]: {
|
||||||
...existing,
|
...existing,
|
||||||
imagePath,
|
imagePath,
|
||||||
|
// Update imageVersion timestamp to bust browser cache when image changes
|
||||||
|
imageVersion: imagePath ? Date.now() : undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -1516,6 +1519,7 @@ export const useAppStore = create<AppState & AppActions>()(
|
|||||||
[projectPath]: {
|
[projectPath]: {
|
||||||
...existing,
|
...existing,
|
||||||
imagePath: null, // Only clear the image, preserve other settings
|
imagePath: null, // Only clear the image, preserve other settings
|
||||||
|
imageVersion: undefined, // Clear version when clearing image
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user