-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathhungaricana.js
More file actions
75 lines (66 loc) · 2.88 KB
/
Copy pathhungaricana.js
File metadata and controls
75 lines (66 loc) · 2.88 KB
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
var hungaricana = (function () {
const utf8 = new TextEncoder();
const key = crypto.subtle.importKey("raw", utf8.encode("dGhpcyBpcyBubyBr"), { name: "AES-CBC" }, true, ["encrypt", "decrypt"]);
const algorithm = { name: "AES-CBC", iv: new Uint8Array(16) };
async function get_hash(x, y, z, base_path) {
const s = base_path.split('').map(x => x.charCodeAt(0)).reduce((a, b) => a + b);
const padded = `${s % 100}|${z}|${x}|${y}`.padEnd(16, '*');
const encrypted = await crypto.subtle.encrypt(algorithm, await key, utf8.encode(padded));
return Array.from(new Uint8Array(encrypted))
.slice(0, 16)
.map(x => x.toString(16).padStart(2, '0'))
.join('');
}
return {
name: 'Hungaricana',
description: 'Hungarian Cultural Heritage Portal (hungaricana.hu)',
urls: [
/hungaricana\.hu/,
/\.ecw$/
],
contents: [
/(imagepath|files ).*\.ecw/,
],
findFile: function getInfoFile(baseUrl, callback) {
if (baseUrl.endsWith(".ecw")) return callback(baseUrl);
ZoomManager.getFile(baseUrl, { type: "htmltext" }, function (text) {
var layerUrlMatch = text.match(/layer_?[uU]rl["']?\s*:\s*['"]([^'"]*)/);
if (!layerUrlMatch) throw new Error("Unable to find the layer base url");
var layerPathMatch = text.match(/\Wpath["']?\s*:\s*["']([^"']*)/);
var layerPath = layerPathMatch ? layerPathMatch[1] : '';
function foundLayerFile(layerFile) {
return callback(layerUrlMatch[1] + layerPath + layerFile);
}
function foundLayerFileJson(layerFileJson) {
var layerFileArray = JSON.parse(layerFileJson);
var idxMatch = baseUrl.match(/(?:img|pg)=(\d+)/);
var idx = idxMatch ? parseInt(idxMatch[1]) : 0;
return foundLayerFile(layerFileArray[idx]);
}
var layerFileMatch = text.match(/imagepath["']?\s*=\s*["']([^"']*)/);
if (layerFileMatch) return foundLayerFile(layerFileMatch[1]);
var layerFileArrayMatch = text.match(/(?:files|images)["']?\s*\:\s*(\[.*?\])/);
if (layerFileArrayMatch) return foundLayerFileJson(layerFileArrayMatch[1]);
var fileUrlMatch = text.match(/files_url["']?\s*\:\s*['"]([^'"]*)/);
if (fileUrlMatch) return ZoomManager.getFile(fileUrlMatch[1], { type: 'text' }, foundLayerFileJson);
throw new Error("Unable to find the layer file name");
});
},
open: function (url) {
ZoomManager.getFile(url, { type: 'json' }, function (data) {
const [base_url, path] = url.split('imagesize/');
ZoomManager.readyToRender({
origin: base_url + 'image/' + path + '/',
path: path,
width: data.width,
height: data.height,
tileSize: 512,
});
});
},
getTileURL: function (x, y, zoom, data) {
return get_hash(x, y, zoom, data.path);
},
};
})();
ZoomManager.addDezoomer(hungaricana);