Repository navigation
feat(apps): open outputs in one Desktop dialog from Apps and Assets #2008
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
Open
PabloWiedemann
wants to merge
17
commits into
PabloWiedemann/apps-catalog-gallery
from
PabloWiedemann/apps-output-modal
+994
−20
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2039528
feat(apps): open outputs in one Desktop dialog from apps and Generate…
PabloWiedemann 380b273
refactor(apps): keep the output dialog change to what it needs
PabloWiedemann 1ff4e6b
fix(apps): harden the output dialog after review
PabloWiedemann 774cb9e
Merge branch 'PabloWiedemann/apps-catalog-gallery' into PabloWiedeman…
PabloWiedemann 963985e
Merge branch 'PabloWiedemann/apps-catalog-gallery' into PabloWiedeman…
PabloWiedemann 2958b95
Merge the Apps and Assets pages and split the output dialog between them
PabloWiedemann 29a0762
Merge branch 'PabloWiedemann/apps-catalog-gallery' into PabloWiedeman…
PabloWiedemann 9917ce0
fix(apps): polish the output dialog after review
PabloWiedemann 751f901
fix(apps): harden the app output viewer after review
PabloWiedemann b6d9a25
Merge branch 'PabloWiedemann/apps-catalog-gallery' into PabloWiedeman…
PabloWiedemann 961143f
Merge branch 'PabloWiedemann/apps-catalog-gallery' into PabloWiedeman…
vqt123 c5bea76
Merge branch 'PabloWiedemann/apps-catalog-gallery' into PabloWiedeman…
PabloWiedemann 953e2f9
Merge branch 'PabloWiedemann/apps-catalog-gallery' into PabloWiedeman…
PabloWiedemann 4cdc9af
Merge PabloWiedemann/apps-catalog-gallery into PabloWiedemann/apps-ou…
PabloWiedemann b34e0bc
Merge fix for #1997 into PabloWiedemann/apps-output-modal
PabloWiedemann c306c27
fix(apps): drop outputs when the app hides during capture
PabloWiedemann 1851b6f
Merge PabloWiedemann/apps-catalog-gallery into PabloWiedemann/apps-ou…
PabloWiedemann 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
There are no files selected for viewing
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
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
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,75 @@ | ||
| // @vitest-environment node | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { MAX_OUTPUTS, MAX_OUTPUTS_BYTES, outputAction, outputRequest } from './outputs' | ||
|
|
||
| const picture = (extra: Record<string, unknown> = {}) => ({ | ||
| name: 'picture-1.png', | ||
| mimeType: 'image/png', | ||
| bytes: new Uint8Array([1, 2, 3]), | ||
| ...extra | ||
| }) | ||
|
|
||
| describe('outputRequest', () => { | ||
| it('keeps the outputs and the one to show first', () => { | ||
| const request = outputRequest({ | ||
| items: [ | ||
| picture({ tags: ['This computer', 7, ' '], workflow: true }), | ||
| picture({ name: 'clip.mp4', mimeType: 'video/mp4' }) | ||
| ], | ||
| index: 1 | ||
| }) | ||
| expect(request?.index).toBe(1) | ||
| expect(request?.items[0]).toMatchObject({ | ||
| name: 'picture-1.png', | ||
| tags: ['This computer'], | ||
| workflow: true | ||
| }) | ||
| expect(request?.items[1]).toMatchObject({ workflow: false, tags: [] }) | ||
| }) | ||
|
|
||
| it('refuses outputs it cannot show', () => { | ||
| expect(outputRequest(null)).toBeNull() | ||
| expect(outputRequest({ items: [], index: 0 })).toBeNull() | ||
| expect(outputRequest({ items: [picture()], index: 1 })).toBeNull() | ||
| expect(outputRequest({ items: [picture()], index: -1 })).toBeNull() | ||
| expect(outputRequest({ items: [picture({ mimeType: 'text/html' })], index: 0 })).toBeNull() | ||
| expect(outputRequest({ items: [picture({ mimeType: 'image/svg+xml' })], index: 0 })).toBeNull() | ||
| expect(outputRequest({ items: [picture({ bytes: 'abc' })], index: 0 })).toBeNull() | ||
| expect(outputRequest({ items: [picture({ name: ' ' })], index: 0 })).toBeNull() | ||
| expect( | ||
| outputRequest({ items: Array.from({ length: MAX_OUTPUTS + 1 }, () => picture()), index: 0 }) | ||
| ).toBeNull() | ||
| const half = new Uint8Array(MAX_OUTPUTS_BYTES / 2 + 1) | ||
| expect( | ||
| outputRequest({ items: [picture({ bytes: half }), picture({ bytes: half })], index: 0 }) | ||
| ).toBeNull() | ||
| }) | ||
|
|
||
| it('refuses an items list with holes', () => { | ||
| const items = [picture(), picture()] | ||
| delete items[0] | ||
| expect(outputRequest({ items, index: 1 })).toBeNull() | ||
| }) | ||
|
|
||
| it('counts the whole buffer behind each output', () => { | ||
| const view = new Uint8Array(new ArrayBuffer(MAX_OUTPUTS_BYTES + 1), 0, 1) | ||
| expect(outputRequest({ items: [picture({ bytes: view })], index: 0 })).toBeNull() | ||
| }) | ||
| }) | ||
|
|
||
| describe('outputAction', () => { | ||
| it('passes on a download or an open-workflow for one output', () => { | ||
| expect(outputAction({ action: 'download', index: 2 })).toEqual({ action: 'download', index: 2 }) | ||
| expect(outputAction({ action: 'open-workflow', index: 0 })).toEqual({ | ||
| action: 'open-workflow', | ||
| index: 0 | ||
| }) | ||
| }) | ||
|
|
||
| it('drops anything else', () => { | ||
| expect(outputAction({ action: 'delete', index: 0 })).toBeNull() | ||
| expect(outputAction({ action: 'download', index: 1.5 })).toBeNull() | ||
| expect(outputAction('download')).toBeNull() | ||
| }) | ||
| }) |
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,55 @@ | ||
| import type { AppOutputAction, AppOutputItem } from '../../types/ipc' | ||
|
|
||
| export const MAX_OUTPUTS = 40 | ||
| export const MAX_OUTPUTS_BYTES = 100_000_000 | ||
| const MAX_TAGS = 8 | ||
| const MEDIA_TYPE = | ||
| /^(image\/(png|jpeg|webp|gif|avif)|video\/(mp4|webm|quicktime)|audio\/(mpeg|mp4|wav|x-wav|ogg|webm|flac|aac))$/ | ||
|
|
||
| function text(value: unknown, max: number): string | null { | ||
| return typeof value === 'string' && value.trim() !== '' ? value.trim().slice(0, max) : null | ||
| } | ||
|
|
||
| function outputItem(value: unknown): AppOutputItem | null { | ||
| if (!value || typeof value !== 'object') return null | ||
| const item = value as Record<string, unknown> | ||
| const name = text(item['name'], 200) | ||
| const mimeType = item['mimeType'] | ||
| const bytes = item['bytes'] | ||
| if (!name || typeof mimeType !== 'string' || !MEDIA_TYPE.test(mimeType)) return null | ||
| if (!(bytes instanceof Uint8Array)) return null | ||
| const tags = Array.isArray(item['tags']) | ||
| ? item['tags'] | ||
| .slice(0, MAX_TAGS) | ||
| .map((tag) => text(tag, 40)) | ||
| .filter((tag): tag is string => tag !== null) | ||
| : [] | ||
| return { | ||
| name, | ||
| mimeType, | ||
| bytes: bytes as Uint8Array<ArrayBuffer>, | ||
| tags, | ||
| workflow: item['workflow'] === true | ||
| } | ||
| } | ||
|
|
||
| export function outputRequest(input: unknown): { items: AppOutputItem[]; index: number } | null { | ||
| if (!input || typeof input !== 'object') return null | ||
| const { items, index } = input as { items?: unknown; index?: unknown } | ||
| if (!Array.isArray(items) || items.length === 0 || items.length > MAX_OUTPUTS) return null | ||
| const parsed = Array.from(items, outputItem) | ||
| if (parsed.some((item) => item === null)) return null | ||
| const outputs = parsed as AppOutputItem[] | ||
| const total = outputs.reduce((sum, item) => sum + item.bytes.buffer.byteLength, 0) | ||
| if (total > MAX_OUTPUTS_BYTES) return null | ||
|
PabloWiedemann marked this conversation as resolved.
Resolved
|
||
| if (typeof index !== 'number' || !Number.isInteger(index) || index < 0) return null | ||
| return index < outputs.length ? { items: outputs, index } : null | ||
| } | ||
|
PabloWiedemann marked this conversation as resolved.
Resolved
|
||
|
|
||
| export function outputAction(input: unknown): AppOutputAction | null { | ||
| if (!input || typeof input !== 'object') return null | ||
| const { action, index } = input as { action?: unknown; index?: unknown } | ||
| if (action !== 'download' && action !== 'open-workflow') return null | ||
| if (typeof index !== 'number' || !Number.isInteger(index) || index < 0) return null | ||
|
PabloWiedemann marked this conversation as resolved.
Resolved
|
||
| return { action, index } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.