fix(ui): preserve Garden favorite media fallback
This commit is contained in:
1 parent
81ad5cc32c
commit
6506c5436a
2 files changed
+23
-16
No files matched your search
@@ -313,7 +313,7 @@ const saveImportedPromptToFavorites = async (opts: {
|
||||
const snapshot = await buildStorableGardenSnapshot(
|
||||
fetched.gardenSnapshot,
|
||||
imageStorageService,
|
||||
{ allowImageFallback: false },
|
||||
{ allowImageFallback: true },
|
||||
)
|
||||
const media = buildFavoriteMediaFromSnapshot(snapshot)
|
||||
const favorites = await manager.getFavorites()
|
||||
@@ -885,7 +885,8 @@ const persistSourcesToAssetIdsWithFallback = async (opts: {
|
||||
fallbackSources.push(source)
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('[PromptGardenImport] Failed to persist snapshot image source:', source, error)
|
||||
const log = allowSourceFallback ? console.info : console.warn
|
||||
log('[PromptGardenImport] Failed to persist snapshot image source:', source, error)
|
||||
if (!allowSourceFallback) {
|
||||
throw error
|
||||
}
|
||||
@@ -1399,24 +1400,18 @@ export function useAppPromptGardenImport(options: AppPromptGardenImportOptions)
|
||||
getFavoriteImageStorageService?.() || getImageStorageService?.() || null
|
||||
|
||||
let snapshot = fetched.gardenSnapshot
|
||||
let includeMedia = true
|
||||
try {
|
||||
snapshot = await buildStorableGardenSnapshot(snapshot, imageStorageService, {
|
||||
allowImageFallback: false,
|
||||
allowImageFallback: true,
|
||||
})
|
||||
} catch (error) {
|
||||
console.info('[PromptGardenImport] Failed to persist snapshot assets for favorite dialog:', error)
|
||||
includeMedia = false
|
||||
}
|
||||
|
||||
const media = buildFavoriteMediaFromSnapshot(snapshot)
|
||||
const metadata: Record<string, unknown> = {
|
||||
gardenSnapshot: snapshot,
|
||||
...(includeMedia
|
||||
? (() => {
|
||||
const media = buildFavoriteMediaFromSnapshot(snapshot)
|
||||
return media ? { media } : {}
|
||||
})()
|
||||
: {}),
|
||||
...(media ? { media } : {}),
|
||||
}
|
||||
|
||||
openSaveFavoriteDialog({
|
||||
|
||||
@@ -1880,7 +1880,7 @@ describe('useAppPromptGardenImport', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('skips auto-save to favorites when snapshot image persistence fails', async () => {
|
||||
it('auto-saves to favorites with URL media fallback when snapshot image persistence fails', async () => {
|
||||
const { pinia } = createTestPinia()
|
||||
|
||||
const createReactive = (): MessageReactive => ({
|
||||
@@ -2005,15 +2005,22 @@ describe('useAppPromptGardenImport', () => {
|
||||
await replaceDone
|
||||
await waitForCondition(() => isLoadingExternalData.value === false)
|
||||
|
||||
expect(favoriteManager.getFavorites).not.toHaveBeenCalled()
|
||||
expect(favoriteManager.addFavorite).not.toHaveBeenCalled()
|
||||
expect(favoriteManager.getFavorites).toHaveBeenCalledTimes(1)
|
||||
expect(favoriteManager.addFavorite).toHaveBeenCalledTimes(1)
|
||||
expect(favoriteManager.updateFavorite).not.toHaveBeenCalled()
|
||||
const favoriteArg = favoriteManager.addFavorite.mock.calls[0]?.[0]
|
||||
expect(favoriteArg?.metadata?.media).toEqual({
|
||||
coverAssetId: undefined,
|
||||
coverUrl: 'http://garden.local/prompt-assets/cover.png',
|
||||
assetIds: [],
|
||||
urls: ['http://garden.local/prompt-assets/show-1.png'],
|
||||
})
|
||||
} finally {
|
||||
scope.stop()
|
||||
}
|
||||
})
|
||||
|
||||
it('opens save-favorite dialog without media fallback when snapshot image persistence fails', async () => {
|
||||
it('opens save-favorite dialog with URL media fallback when snapshot image persistence fails', async () => {
|
||||
const { pinia } = createTestPinia()
|
||||
|
||||
const createReactive = (): MessageReactive => ({
|
||||
@@ -2141,7 +2148,12 @@ describe('useAppPromptGardenImport', () => {
|
||||
}
|
||||
}
|
||||
|
||||
expect(savedArg.prefill?.metadata?.media).toBeUndefined()
|
||||
expect(savedArg.prefill?.metadata?.media).toEqual({
|
||||
coverAssetId: undefined,
|
||||
coverUrl: 'http://garden.local/prompt-assets/cover.png',
|
||||
assetIds: [],
|
||||
urls: ['http://garden.local/prompt-assets/show-1.png'],
|
||||
})
|
||||
} finally {
|
||||
scope.stop()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user