mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 11:24:37 +00:00
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.
31 lines
994 B
TypeScript
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] }
|
|
}
|