mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-28 17:43:05 +00:00
34 lines
1001 B
TypeScript
34 lines
1001 B
TypeScript
export type MediaPayloadInput = {
|
|
path: string;
|
|
contentType?: string;
|
|
};
|
|
|
|
export type MediaPayload = {
|
|
MediaPath?: string;
|
|
MediaType?: string;
|
|
MediaUrl?: string;
|
|
MediaPaths?: string[];
|
|
MediaUrls?: string[];
|
|
MediaTypes?: string[];
|
|
};
|
|
|
|
export function buildMediaPayload(
|
|
mediaList: MediaPayloadInput[],
|
|
opts?: { preserveMediaTypeCardinality?: boolean },
|
|
): MediaPayload {
|
|
const first = mediaList[0];
|
|
const mediaPaths = mediaList.map((media) => media.path);
|
|
const rawMediaTypes = mediaList.map((media) => media.contentType ?? "");
|
|
const mediaTypes = opts?.preserveMediaTypeCardinality
|
|
? rawMediaTypes
|
|
: rawMediaTypes.filter((value): value is string => Boolean(value));
|
|
return {
|
|
MediaPath: first?.path,
|
|
MediaType: first?.contentType,
|
|
MediaUrl: first?.path,
|
|
MediaPaths: mediaPaths.length > 0 ? mediaPaths : undefined,
|
|
MediaUrls: mediaPaths.length > 0 ? mediaPaths : undefined,
|
|
MediaTypes: mediaTypes.length > 0 ? mediaTypes : undefined,
|
|
};
|
|
}
|