-
Notifications
You must be signed in to change notification settings - Fork 5
/
smithsonian.js
80 lines (68 loc) · 2.56 KB
/
smithsonian.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
const axios = require('axios');
const turf = require('@turf/turf');
const BASE_URL = "https://api.si.edu/openaccess/api/v1.0/search";
if (process.env.SMITHSONIAN_API_KEY == undefined) {
console.log("Set environment variable SMITHSONIAN_API_KEY to your Smithsonian API key.");
}
module.exports = {
async getImagesSmithsonianTextsearch(topic,language) {
//let query = '"' + JSON.parse(topic).join('" OR "') + '"';
let query = JSON.parse(topic)[0];
const requestConfig = {
baseURL: BASE_URL + "/",
params: {
api_key: process.env.SMITHSONIAN_API_KEY,
q: query,
rows: 50,
sort: 'relevancy'
//include: 'tags'
}
}
const response = await axios.request(requestConfig);
let images = [];
if (!response.data.response || !response.data.response.rows.length) {
return [];
}
//format response
for (var i = 0; i < response.data.response.rows.length; i++) {
var item = response.data.response.rows[i];
var image = {
//download_url: result.detail,
//legacy_tags: result.legacy_tags,
//license_version: result.license_version,
actors: item.content.indexedStructured.object_type.name,
collection: '',
creators: '',
datecreated: item.content.indexedStructured.date,
description: '',
formats: item.content.indexedStructured.object_type,
geoLocations: '',
id: item.content.descriptiveNonRepeating.record_ID,
imageRights: '',
imageURL: '',
infoURL: item.content.descriptiveNonRepeating.record_link,
inscriptions: '',
institutions: item.content.descriptiveNonRepeating.data_source,
inventoryNumber: '',
language: '',
license_id: '',
license_link: '',
license: '',
measurements: '',
places: item.content.indexedStructured.place,
publisher: '',
rightsstatement: '',
source: 'Smithsonian',
subjects: '',
thumbURL: '',
title: [],
year: ''
}
if (item.title) {
image.title.push(item.title);
}
images.push(image);
}
return images;
}
};