-
Notifications
You must be signed in to change notification settings - Fork 451
Media Assets Management Sidebar Tab Implementation #6112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f042042
feat: Add Media Assets sidebar tab for file management
viva-jinyi c20ea26
refactor: Apply PR #6112 review feedback for Media Assets feature
viva-jinyi fffdae1
chore: unexpected export
viva-jinyi 8765a10
feat: Improve media asset display with file format tags and filename …
viva-jinyi 52b2129
feat: Add includePublic parameter to getAssetsByTag API
viva-jinyi aa3354a
fix: test code
viva-jinyi cddd8ea
refactor: useQueueStore
viva-jinyi ea7e910
refactor: Apply review feedback for media assets implementation
viva-jinyi 02a1810
Extract AssetsSidebarTab template and improve UI structure (#6164)
viva-jinyi 5c01e61
feat: Implement centralized AssetsStore for reactive assets updates
viva-jinyi 38885b7
refactor: Apply formatUtil code review feedback and improve type safety
viva-jinyi fd953c6
[automated] Update test expectations
invalid-email-address 4e2fc4a
feat: Auto-refresh assets on file upload
viva-jinyi 9d28ec8
fix: Add AssetsStore update trigger to WidgetSelectDropdown uploads
viva-jinyi cb33c8f
refactor:
viva-jinyi 9125459
fix: Prevent gallery index shift when new outputs are generated
viva-jinyi 993f08f
refactor: delete unused export
viva-jinyi e0a0d9f
refactor: Simplify asset ID handling and remove UUID extraction, Acce…
viva-jinyi b778cde
feat: implement asset deletion functionality (#6203)
viva-jinyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Implement centralized AssetsStore for reactive assets updates
- Create AssetsStore following QueueStore pattern for history-based assets - Use useAsyncState for async state management (loading/error handling) - Support both cloud and local environments (via isCloud flag) - Auto-update history assets on status events in GraphView - Refactor useMediaAssets composables to use AssetsStore
- Loading branch information
commit 5c01e61c9d9d967215f28f4e658737df2e2d6b1a
There are no files selected for viewing
75 changes: 22 additions & 53 deletions
75
src/platform/assets/composables/useMediaAssets/useAssetsApi.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 20 additions & 71 deletions
91
src/platform/assets/composables/useMediaAssets/useInternalFilesApi.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { useAsyncState } from '@vueuse/core' | ||
| import { defineStore } from 'pinia' | ||
| import { computed } from 'vue' | ||
|
|
||
| import { | ||
| mapInputFileToAssetItem, | ||
| mapTaskOutputToAssetItem | ||
| } from '@/platform/assets/composables/useMediaAssets/assetMappers' | ||
| import type { AssetItem } from '@/platform/assets/schemas/assetSchema' | ||
| import { assetService } from '@/platform/assets/services/assetService' | ||
| import { isCloud } from '@/platform/distribution/types' | ||
| import { api } from '@/scripts/api' | ||
|
|
||
| import { TaskItemImpl } from './queueStore' | ||
|
|
||
| /** | ||
| * Fetch input files from the internal API (OSS version) | ||
| */ | ||
| async function fetchInputFilesFromAPI(): Promise<AssetItem[]> { | ||
| const response = await fetch(api.internalURL('/files/input'), { | ||
| headers: { | ||
| 'Comfy-User': api.user | ||
| } | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error('Failed to fetch input files') | ||
| } | ||
|
|
||
| const filenames: string[] = await response.json() | ||
| return filenames.map((name, index) => | ||
| mapInputFileToAssetItem(name, index, 'input') | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Fetch input files from cloud service | ||
| */ | ||
| async function fetchInputFilesFromCloud(): Promise<AssetItem[]> { | ||
| return await assetService.getAssetsByTag('input', false) | ||
| } | ||
|
|
||
| /** | ||
| * Convert history task items to asset items | ||
| */ | ||
| function mapHistoryToAssets(historyItems: any[]): AssetItem[] { | ||
| const assetItems: AssetItem[] = [] | ||
|
|
||
| for (const item of historyItems) { | ||
| if (!item.outputs || !item.status || item.status?.status_str === 'error') { | ||
| continue | ||
| } | ||
|
|
||
| const task = new TaskItemImpl( | ||
| 'History', | ||
| item.prompt, | ||
| item.status, | ||
| item.outputs | ||
| ) | ||
|
|
||
| if (!task.previewOutput) { | ||
| continue | ||
| } | ||
|
|
||
| const assetItem = mapTaskOutputToAssetItem(task, task.previewOutput) | ||
|
|
||
| const supportedOutputs = task.flatOutputs.filter((o) => o.supportsPreview) | ||
| assetItem.user_metadata = { | ||
| ...assetItem.user_metadata, | ||
| outputCount: supportedOutputs.length, | ||
| allOutputs: supportedOutputs | ||
| } | ||
|
|
||
| assetItems.push(assetItem) | ||
| } | ||
|
|
||
| return assetItems.sort( | ||
| (a, b) => | ||
| new Date(b.created_at).getTime() - new Date(a.created_at).getTime() | ||
| ) | ||
| } | ||
|
|
||
| export const useAssetsStore = defineStore('assets', () => { | ||
| const maxHistoryItems = 200 | ||
|
|
||
| const fetchInputFiles = isCloud | ||
| ? fetchInputFilesFromCloud | ||
| : fetchInputFilesFromAPI | ||
|
|
||
| const { | ||
| state: inputAssets, | ||
| isLoading: inputLoading, | ||
| error: inputError, | ||
| execute: updateInputs | ||
| } = useAsyncState(fetchInputFiles, [], { | ||
| immediate: false, | ||
| resetOnExecute: false, | ||
| onError: (err) => { | ||
| console.error('Error fetching input assets:', err) | ||
| } | ||
| }) | ||
|
|
||
| const fetchHistoryAssets = async (): Promise<AssetItem[]> => { | ||
| const history = await api.getHistory(maxHistoryItems) | ||
| return mapHistoryToAssets(history.History) | ||
| } | ||
|
|
||
| const { | ||
| state: historyAssets, | ||
| isLoading: historyLoading, | ||
| error: historyError, | ||
| execute: updateHistory | ||
| } = useAsyncState(fetchHistoryAssets, [], { | ||
| immediate: false, | ||
| resetOnExecute: false, | ||
| onError: (err) => { | ||
| console.error('Error fetching history assets:', err) | ||
| } | ||
| }) | ||
|
|
||
| const isLoading = computed(() => inputLoading.value || historyLoading.value) | ||
|
|
||
| const update = async () => { | ||
| await Promise.all([updateInputs(), updateHistory()]) | ||
| } | ||
|
|
||
| return { | ||
| // States | ||
| inputAssets, | ||
| historyAssets, | ||
| inputLoading, | ||
| historyLoading, | ||
| inputError, | ||
| historyError, | ||
| isLoading, | ||
|
|
||
| // Actions | ||
| updateInputs, | ||
| updateHistory, | ||
| update | ||
viva-jinyi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow-up: This should go in /platform/assets