-
Notifications
You must be signed in to change notification settings - Fork 3
/
thumbs.js
35 lines (33 loc) · 1.49 KB
/
thumbs.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
/* 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/. */
const entry = require('./entry');
const { parseUri, isDDBUri } = require('./utils');
const Registry = require('./registry');
module.exports = {
supportedForType: function (entryType) {
entryType = parseInt(entryType);
return entryType === entry.type.GEOIMAGE ||
entryType === entry.type.GEORASTER ||
entryType === entry.type.IMAGE ||
entryType === entry.type.POINTCLOUD ||
entryType === entry.type.PANORAMA ||
entryType === entry.type.GEOPANORAMA;
},
fetch: function (uri, thumbSize = 256) {
if (isDDBUri(uri)) {
const { registryUrl, org, ds, path } = parseUri(uri);
const dataset = new Registry(registryUrl).Organization(org).Dataset(ds);
return dataset.thumbUrl(path, thumbSize);
} else if (uri.startsWith("file://")) {
// Local file, use getFromUserCache (if available)
if (this.getFromUserCache) {
return this.getFromUserCache(uri.substring("file://".length), { thumbSize });
} else {
throw new Error("ddb.thumbs.getFromUserCache is only available in NodeJS. Did you call registerNativeBindings?");
}
} else {
throw new Error(`Unsupported URI: ${uri}`);
}
}
}