38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import type { EntityInfo } from '@upnd/upend/types';
|
|
import type { UpObject } from '@upnd/upend';
|
|
import { ATTR_IN } from '@upnd/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?.backlinks.some((e) => e.attribute == ATTR_IN);
|
|
|
|
return {
|
|
mimeType,
|
|
audio,
|
|
video,
|
|
image,
|
|
text,
|
|
pdf,
|
|
model,
|
|
web,
|
|
fragment,
|
|
group
|
|
};
|
|
}
|