-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcc.js
142 lines (126 loc) · 6.52 KB
/
cc.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
const axios = require('axios');
const turf = require('@turf/turf');
const BASE_URL = "https://api.creativecommons.engineering";
module.exports = {
async getImagesCC(topic) {
const requestConfig = {
baseURL: BASE_URL + "/",
url: "image/search/",
method: "get",
params: {
format: 'json',
q: topic,
lt: 'all',
provider: ['wikimedia', 'thorvaldsensmuseum', 'thingiverse', 'svgsilh', 'sciencemuseum', 'rijksmuseum', 'rawpixel', 'phylopic', 'nypl', 'museumsvictoria', 'met', 'mccordmuseum', 'iha', 'geographorguk', 'floraon', 'flickr', 'eol', 'digitaltmuseum', 'deviantart', 'clevelandmuseum', 'brooklynmuseum', 'behance', 'animaldiversity', 'WoRMS', 'CAPL', '500px'],
page: 1,
pagesize: 30,
filter_dead: true
}
}
const response = await axios.request(requestConfig);
let images = [];
if (!response.data.results) {
return [];
}
//format response
for (var i = 0; i < response.data.results.length; i++) {
var result = response.data.results[i];
var subjects = [];
if (result.tags != undefined) {
for (let tag of result.tags) {
subjects.push(tag.name);
}
}
var image = {
id: result.id,
source: "CC Search",
title: [],
imageURL: result.url,
thumbURL: result.thumbnail,
download_url: result.detail,
creators: [],//creator_url
institutions: [],
subjects: subjects,
legacy_tags: result.legacy_tags,
license: result.license,
license_id: result.license,
license_version: result.license_version,
license_link: '',
infoURL: result.foreign_landing_url,
inventoryNumber: '',
geoLocations: '',
measurements: '',
formats: '',
year: '',
publisher: '',
actors: '',
places: '',
collection: '',
imageRights: '',
description: '',
inscriptions: '',
datecreated: ''
}
if (result.title) {
image.title.push(result.title);
}
if (result.creator) {
image.creators.push(result.creator);
}
for (var j = 0; j < CCLicenses.length; j++) {
if (CCLicenses[j].id == result.license) {
image.license = CCLicenses[j].short;
image.license_link = CCLicenses[j].url;
break;
}
}
for (var k = 0; k < glams.length; k++) {
if (glams[k].id == result.provider) {
image.institutions.push(glams[k].defaultname);
}
// if (glams[k].id == result.source) {
// image.source.push(glams[k].defaultname);
// break;
// }
}
images.push(image);
}
return images;
}
};
const CCLicenses = [
{ "id": 'by', "short": "CC BY", "qid": "xxx", "url": "xxx", "icon": "xxx" },
{ "id": 'cc0', "short": "CC0", "qid": "xxx", "url": "xxx", "icon": "xxx" },
{ "id": 'by-nc-nd', "short": "CC BY-NC-ND", "qid": "xxx", "url": "xxx", "icon": "xxx" },
{ "id": 'by-nc-sa', "short": "CC BY-NC-SA", "qid": "xxx", "url": "xxx", "icon": "xxx" },
{ "id": 'by-nd', "short": "CC BY-ND", "qid": "xxx", "url": "xxx", "icon": "xxx" },
{ "id": 'pdm', "short": "PD", "qid": "xxx", "url": "xxx", "icon": "xxx" },
{ "id": 'by-sa', "short": "CC BY-SA", "qid": "xxx", "url": "xxx", "icon": "xxx" },
{ "id": 'by-nc', "short": "CC BY-NC", "qid": "xxx", "url": "xxx", "icon": "xxx" }
];
const glams = [
{ "id": "thorvaldsensmuseum", "defaultname": "Thorvaldsens Museum", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "thingiverse", "defaultname": "Thingiverse", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "svgsilh", "defaultname": "SVG Silh", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "sciencemuseum", "defaultname": "Science Museum – UK", "qid": "xxx", "url": "xxx", "included": true },
{ "id": "rijksmuseum", "defaultname": "Rijksmuseum", "qid": "xxx", "url": "xxx", "included": true },
{ "id": "rawpixel", "defaultname": "Rawpixel", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "nypl", "defaultname": "NYPL", "qid": "xxx", "url": "xxx", "included": true },
{ "id": "museumsvictoria", "defaultname": "Museums Victoria", "qid": "xxx", "url": "xxx", "included": true },
{ "id": "met", "defaultname": "Metropolitan Museum of Art", "qid": "xxx", "url": "xxx", "included": true },
{ "id": "mccordmuseum", "defaultname": "xxx", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "iha", "defaultname": "iha", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "floraon", "defaultname": "xxx", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "geographorguk", "defaultname": "Geograph Britain and Ireland", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "flickr", "defaultname": "Flickr", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "eol", "defaultname": "xxx", "qid": "xxx", "url": "xxx", "included": true },
{ "id": "digitaltmuseum", "defaultname": "Digitalt Museum", "qid": "xxx", "url": "xxx", "included": true },
{ "id": "deviantart", "defaultname": "DeviantArt", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "clevelandmuseum", "defaultname": "Cleveland Museum of Art", "qid": "xxx", "url": "xxx", "included": true },
{ "id": "brooklynmuseum", "defaultname": "Brooklyn Museum", "qid": "xxx", "url": "xxx", "included": true },
{ "id": "behance", "defaultname": "Bēhance", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "animaldiversity", "defaultname": "Animal Diversity Web", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "WoRMS", "defaultname": "World Register of Marine Species", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "CAPL", "defaultname": "CAPL", "qid": "xxx", "url": "xxx", "included": false },
{ "id": "500px", "defaultname": "500px", "qid": "xxx", "url": "xxx", "included": false }
];