-
Notifications
You must be signed in to change notification settings - Fork 3
/
entry.js
104 lines (92 loc) · 2.92 KB
/
entry.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
class Entry {
constructor(dataset, entry) {
this.dataset = dataset;
Object.assign(this, entry);
// Quick check
if (!this.hash) throw new Error("Not a valid file entry object");
}
buildUrl(path) {
let url = `${this.dataset.baseApi}/build/${this.hash}/${path}`;
return url;
}
async getEpt() {
const eptUrl = this.buildUrl("ept/ept.json");
if (await this.dataset.registry.headRequest(eptUrl)) return eptUrl;
else throw new Error(`${eptUrl} is not available`);
}
async getCog(){
const cogUrl = this.buildUrl("cog/cog.tif");
if (await this.dataset.registry.headRequest(cogUrl)) return cogUrl;
else throw new Error(`${cogUrl} is not available`);
}
async getNxz(){
const nxzUrl = this.buildUrl("nxs/model.nxz");
if (await this.dataset.registry.headRequest(nxzUrl)) return nxzUrl;
else throw new Error(`${nxzUrl} is not available`);
}
}
module.exports = {
Entry,
type: {
UNDEFINED: 0,
DIRECTORY: 1,
GENERIC: 2,
GEOIMAGE: 3,
GEORASTER: 4,
POINTCLOUD: 5,
IMAGE: 6,
DRONEDB: 7,
MARKDOWN: 8,
VIDEO: 9,
GEOVIDEO: 10,
MODEL: 11,
PANORAMA: 12,
GEOPANORAMA: 13
},
typeToHuman: function (t) {
switch (t) {
case this.type.UNDEFINED:
return "Undefined";
case this.type.DIRECTORY:
return "Directory";
case this.type.GENERIC:
return "Generic";
case this.type.GEOIMAGE:
return "GeoImage";
case this.type.GEORASTER:
return "GeoRaster";
case this.type.POINTCLOUD:
return "PointCloud";
case this.type.IMAGE:
return "Image";
case this.type.DRONEDB:
return "DroneDB";
case this.type.MARKDOWN:
return "Markdown";
case this.type.VIDEO:
return "Video";
case this.type.GEOVIDEO:
return "GeoVideo";
case this.type.MODEL:
return "Model";
case this.type.PANORAMA:
return "Panorama";
case this.type.GEOPANORAMA:
return "GeoPanorama";
default:
return "?";
}
},
hasGeometry: function (entry) {
if (!entry) return false;
return !!entry.point_geom || !!entry.polygon_geom;
},
isDirectory: function (entry) {
if (!entry) return false;
return entry.type === this.type.DIRECTORY ||
entry.type === this.type.DRONEDB;
}
};