blob: 9bd92a316aa90876708354e3a9a19512e12cae0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import { Doc } from "../../../fields/Doc";
import { ImageField } from "../../../fields/URLField";
import { Cast, StrCast, NumCast } from "../../../fields/Types";
import { Networking } from "../../Network";
import { Id } from "../../../fields/FieldSymbols";
import { Utils } from "../../../Utils";
export namespace ImageUtils {
export const ExtractExif = async (document: Doc): Promise<boolean> => {
const field = Cast(document.data, ImageField);
if (!field) {
return false;
}
const source = field.url.href;
const {
contentSize,
nativeWidth,
nativeHeight,
exifData: { error, data }
} = await Networking.PostToServer("/inspectImage", { source });
document.exif = error || Doc.Get.FromJson({ data });
const proto = Doc.GetProto(document);
nativeWidth && (document._height = NumCast(document._width) * nativeHeight / nativeWidth);
proto["data-nativeWidth"] = nativeWidth;
proto["data-nativeHeight"] = nativeHeight;
proto["data-path"] = source;
proto.contentSize = contentSize ? contentSize : undefined;
return data !== undefined;
};
export const ExportHierarchyToFileSystem = async (collection: Doc): Promise<void> => {
const a = document.createElement("a");
a.href = Utils.prepend(`/imageHierarchyExport/${collection[Id]}`);
a.download = `Dash Export [${StrCast(collection.title)}].zip`;
a.click();
};
}
|