* fix(app): preserve image attachment MIME types Image intake discarded clipboard and desktop path metadata, then guessed JPEG when a later file object had no type. Resolve MIME once at the platform boundary and require it downstream. * fix(app): honor native picker MIME metadata
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { ImageManipulator, SaveFormat } from "expo-image-manipulator";
|
|
import {
|
|
normalizePickedImageAssetsWith,
|
|
type ExpoImagePickerAssetLike,
|
|
type PickedImageAttachmentInput,
|
|
} from "./picked-image-normalizer";
|
|
|
|
export type {
|
|
ExportPickedImageAsPng,
|
|
ExpoImagePickerAssetLike,
|
|
PickedImageAttachmentInput,
|
|
PickedImageSource,
|
|
} from "./picked-image-normalizer";
|
|
|
|
async function exportPickedImageAsPng(uri: string): Promise<string> {
|
|
const context = ImageManipulator.manipulate(uri);
|
|
let image: Awaited<ReturnType<typeof context.renderAsync>> | null = null;
|
|
|
|
try {
|
|
image = await context.renderAsync();
|
|
const result = await image.saveAsync({
|
|
format: SaveFormat.PNG,
|
|
});
|
|
return result.uri;
|
|
} finally {
|
|
image?.release();
|
|
context.release();
|
|
}
|
|
}
|
|
|
|
export async function normalizePickedImageAssets(
|
|
assets: readonly ExpoImagePickerAssetLike[],
|
|
): Promise<PickedImageAttachmentInput[]> {
|
|
return normalizePickedImageAssetsWith(assets, exportPickedImageAsPng);
|
|
}
|
|
|
|
export async function pickImagesWithDesktopDialog(
|
|
_dialog?: unknown,
|
|
): Promise<PickedImageAttachmentInput[]> {
|
|
throw new Error("Desktop dialog API is not available on native.");
|
|
}
|