Files
orca/src/shared/github/image-attachment.ts
T
Brennan Bensonandlydiassssz 548ba48c32 Upload images before publishing GitHub drafts (#38928)
* Upload GitHub images when pasted or dropped

Keep image bytes out of issue and review bodies by uploading from the owning composer and inserting hosted attachment URLs.

Co-authored-by: lydiassssz <60514233+lydiassssz@users.noreply.github.com>

* Preserve GitHub image intake across editor and thread states

* Keep image placeholder boundaries and ordinary HTML paste intact

* Match the native replace overload in the image projection fixture

* Use typed element queries in the image intake fixture

* Narrow textarea elements at the fixture boundary

* Show failed GitHub draft images as filename links

* Keep GitHub draft attachment links current across updates

* Supply the repository address in the attachment preview fixture

---------

Co-authored-by: lydiassssz <60514233+lydiassssz@users.noreply.github.com>
2026-11-06 16:03:20 -08:00

25 lines
848 B
TypeScript

export const GITHUB_IMAGE_ATTACHMENT_CAPABILITY = 'github.image-attachments.v1' as const
export const GITHUB_IMAGE_MAX_BYTES = 10 * 1024 * 1024
export const GITHUB_IMAGE_TYPES = [
'image/png',
'image/jpeg',
'image/gif',
'image/webp',
'image/svg+xml'
] as const
export class GitHubImageValidationError extends Error {}
export function assertGitHubImage(contentType: string, size: number): void {
if (!GITHUB_IMAGE_TYPES.some((type) => type === contentType)) {
throw new GitHubImageValidationError(
'GitHub images must be PNG, JPEG, GIF, WebP, or SVG. Use an image URL for another format.'
)
}
if (!Number.isSafeInteger(size) || size <= 0 || size > GITHUB_IMAGE_MAX_BYTES) {
throw new GitHubImageValidationError(
'GitHub images must be nonempty and no larger than 10 MB. Choose a smaller image.'
)
}
}