41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import type { EntityInfo } from "src/lib/entity";
|
|
import type { UpObject } from "upend";
|
|
import { GROUP_TYPE_ADDR } from "upend/constants";
|
|
|
|
export function getTypes(entity: UpObject, entityInfo: EntityInfo) {
|
|
const mimeType = String(entity?.get("FILE_MIME"));
|
|
|
|
const video =
|
|
["video", "application/x-matroska"].some((p) => mimeType.startsWith(p)) ||
|
|
entity?.identify().some((l) => l.endsWith(".avi"));
|
|
const audio =
|
|
(["audio", "application/x-riff"].some((p) => mimeType.startsWith(p)) &&
|
|
!video) ||
|
|
[".ogg", ".mp3", ".wav"].some((suffix) =>
|
|
entity?.identify().some((l) => l.toLowerCase().endsWith(suffix))
|
|
);
|
|
const image = mimeType.startsWith("image");
|
|
const text = mimeType.startsWith("text");
|
|
const pdf = mimeType.startsWith("application/pdf");
|
|
const model =
|
|
mimeType?.startsWith("model") ||
|
|
entity?.identify().some((l) => l.endsWith(".stl"));
|
|
const web = entityInfo?.t == "Url";
|
|
const fragment = Boolean(entity?.get("ANNOTATES"));
|
|
|
|
const group = entity?.get("IS") == GROUP_TYPE_ADDR;
|
|
|
|
return {
|
|
mimeType,
|
|
audio,
|
|
video,
|
|
image,
|
|
text,
|
|
pdf,
|
|
model,
|
|
web,
|
|
fragment,
|
|
group,
|
|
};
|
|
}
|