Files
orca/src/main/plugins/plugin-image-read.ts
T
Neil 14d29b8d24 feat(themes): background images for app themes (#36589)
An app theme may declare one validated raster image (png/jpeg/webp, <=2 MB, >=640x360, inside the plugin) served through orca-plugin-image, painted as one static body layer under translucent terminals. Older Orca ignores the field; a bad image drops only the image.
2026-10-31 19:45:04 -07:00

31 lines
994 B
TypeScript

import {
PLUGIN_IMAGE_MIME,
readPluginImageHeader
} from '../../shared/plugins/images/plugin-image-format'
import {
PLUGIN_IMAGE_RULES,
pluginImageRuleError,
type PluginImageKind
} from '../../shared/plugins/images/plugin-image-fields'
import { readContainedPluginArtifactBytes } from './plugin-artifact-validation'
export type CheckedPluginImage = { bytes: Buffer; mimeType: string }
/** Reads a plugin image inside its root and re-checks it against its kind's rules; null when it no longer fits. */
export async function readCheckedPluginImage(
rootDir: string,
kind: PluginImageKind,
path: string
): Promise<CheckedPluginImage | null> {
const bytes = await readContainedPluginArtifactBytes(
rootDir,
path,
PLUGIN_IMAGE_RULES[kind].maxBytes
)
const info = readPluginImageHeader(bytes)
if (typeof info === 'string' || pluginImageRuleError(kind, info, bytes.byteLength)) {
return null
}
return { bytes, mimeType: PLUGIN_IMAGE_MIME[info.format] }
}