-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathparser.js
executable file
·61 lines (54 loc) · 2.59 KB
/
parser.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
#!/usr/bin/env node
'use strict';
let Parser = require('../.lib/parser.js');
/**
* Recognizes the accesses to the platform Archives Direct - Adam Matthew Digital
* @param {Object} parsedUrl an object representing the URL to analyze
* main attributes: pathname, query, hostname
* @param {Object} ec an object representing the EC whose URL is being analyzed
* @return {Object} the result
*/
module.exports = new Parser(function analyseEC(parsedUrl, ec) {
let result = {};
let path = parsedUrl.pathname;
// uncomment this line if you need parameters
let param = parsedUrl.query || {};
let match;
// http://www.archivesdirect.amdigital.co.uk/CP_Africa
// http://www.archivesdirect.amdigital.co.uk/CP_MiddleEast
if (param && param.searchId) {
// http://www.archivesdirect.amdigital.co.uk/Documents/Search?searchId=bf194253-5f69-42d6-8eae-594905b30720&referrer=&keepFilters=true
result.rtype = 'SEARCH';
result.mime = 'MISC';
result.unitid = param.searchId;
} else if (param && param.documentid) {
// http://www.archivesdirect.amdigital.co.uk/Download/FullDownload?file=FO_401_11\FO_401_11.pdf&documentid=FO_401_11
// http://www.archivesdirect.amdigital.co.uk/Download?type=DocumentDetails&documentid=FO_401_11
// http://www.archivesdirect.amdigital.co.uk/Download/FullDownload?file=FO 407_134\FO 407_134.pdf&documentid=FO 407_134
// http://www.archivesdirect.amdigital.co.uk/Download?type=DocumentDetails&documentid=FO%20407_134&indexStart=0&indexEnd=0
result.rtype = 'BOOK';
result.mime = 'PDF';
result.unitid = param.documentid;
let titleID = param.documentid;
if (titleID) {
titleID = titleID.replace('%20', ' ');
titleID = titleID.substring(0, 2) + ' ' + titleID.substring(3, titleID.length).replace('_', '/');
result.title_id = titleID;
}
} else if ((match = /^\/Documents\/(Details|SearchDetails)\/(.*)$/i.exec(path)) !== null) {
// http://www.archivesdirect.amdigital.co.uk/Documents/SearchDetails/CO_879_167
// http://www.archivesdirect.amdigital.co.uk/Documents/Details/FO_401_2
// http://www.archivesdirect.amdigital.co.uk/Documents/SearchDetails/FO 407_117
// http://www.archivesdirect.amdigital.co.uk/Documents/Details/FO 481_15
result.rtype = 'BOOK';
result.mime = 'HTML';
result.unitid = match[2];
let titleID = match[2];
if (titleID) {
titleID = titleID.replace('%20', ' ');
titleID = titleID.substring(0, 2) + ' ' + titleID.substring(3, titleID.length).replace('_', '/');
result.title_id = titleID;
}
}
return result;
});