-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtrove.js
81 lines (69 loc) · 2.41 KB
/
trove.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
const axios = require('axios');
const turf = require('@turf/turf');
const BASE_URL = "https://api.trove.nla.gov.au/v2/result";
if (process.env.TROVE_API_KEY == undefined) {
console.log("Set environment variable TROVE_API_KEY to your TROVE API key.");
}
module.exports = {
async getImagesTroveTextsearch(topic,language) {
let query = '"' + JSON.parse(topic).join('" OR "') + '"';
const requestConfig = {
baseURL: BASE_URL + "/",
params: {
key: process.env.TROVE_API_KEY,
zone: 'picture',
q: query,
n: 50,
sortby: 'relevance',
encoding: 'json',
include: 'links'
}
}
const response = await axios.request(requestConfig);
let images = [];
if (!response.data.response || !response.data.response.zone.length || !response.data.response.zone[0].records.work) {
return [];
}
//format response
for (var i = 0; i < response.data.response.zone[0].records.work.length; i++) {
var item = response.data.response.zone[0].records.work[i];
var image = {
//download_url: result.detail,
//legacy_tags: result.legacy_tags,
//license_version: result.license_version,
actors: [],
collection: '',
creators: item.contributor,
datecreated: '',
description: item.snippet,
formats: item.type,
geoLocations: '',
id: item.id,
imageRights: item.rights,
imageURL: '',
infoURL: item.troveUrl,
inscriptions: '',
institutions: [],
inventoryNumber: '',
language: item.language,
license_id: '',
license_link: '',
license: '',
measurements: '',
places: '',
publisher: '',
rightsstatement: '',
source: 'Trove',
subjects: item.subject,
thumbURL: '',
title: [],
year: item.issued
}
if (item.title) {
image.title.push(item.title);
}
images.push(image);
}
return images;
}
};