author | ymh <ymh.work@gmail.com> |
Sun, 27 Nov 2016 15:12:30 +0100 | |
changeset 447 | 38d5789e30d0 |
parent 424 | feb0d3e0fef9 |
child 466 | a8effb60ccb6 |
permissions | -rw-r--r-- |
173 | 1 |
import ENV from 'app-client/config/environment'; |
2 |
import _ from 'lodash/lodash'; |
|
3 |
import * as constants from 'corpus-common-addon/utils/constants'; |
|
4 |
||
5 |
export default function() { |
|
6 |
||
7 |
// These comments are here to help you get started. Feel free to delete them. |
|
8 |
||
9 |
/* |
|
10 |
Config (with defaults). |
|
11 |
||
12 |
Note: these only affect routes defined *after* them! |
|
13 |
*/ |
|
14 |
// this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server |
|
15 |
// this.namespace = ''; // make this `api`, for example, if your API is namespaced |
|
319
78990a8a069b
Work on front and back integration, correct the expected data format
ymh <ymh.work@gmail.com>
parents:
318
diff
changeset
|
16 |
this.namespace = (ENV.APP.backRootURL || ENV.rootURL).replace(/\/$/,'')+'/api/v1'; |
173 | 17 |
// this.timing = 400; // delay for each request, automatically set to 0 during testing |
18 |
||
19 |
this.get('/documents', function({ documents }) { |
|
20 |
return this.serialize(documents.all(), 'sparse-document'); |
|
21 |
}); |
|
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
173
diff
changeset
|
22 |
|
173 | 23 |
this.get('/documents/:id', ({documents}, request) => { |
319
78990a8a069b
Work on front and back integration, correct the expected data format
ymh <ymh.work@gmail.com>
parents:
318
diff
changeset
|
24 |
let id = decodeURIComponent(decodeURIComponent(request.params.id)); |
173 | 25 |
return documents.find(id); |
26 |
}); |
|
27 |
||
28 |
this.get('/documents/:id/transcript', ({transcripts}, request) => { |
|
319
78990a8a069b
Work on front and back integration, correct the expected data format
ymh <ymh.work@gmail.com>
parents:
318
diff
changeset
|
29 |
let id = decodeURIComponent(decodeURIComponent(request.params.id)); |
173 | 30 |
return transcripts.find(id).transcript; |
31 |
}); |
|
32 |
||
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
33 |
this.get('/stats/languages', 'languages'); |
173 | 34 |
|
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
35 |
this.get('/stats/geostats', 'geostats'); |
274
53a6985443f8
geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents:
261
diff
changeset
|
36 |
|
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
37 |
this.get('/stats/themes', 'themes'); |
173 | 38 |
|
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
39 |
this.get('/stats/discourses', 'discourses'); |
173 | 40 |
|
307 | 41 |
this.get('/stats/datestats', 'datestats'); |
42 |
||
424
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
329
diff
changeset
|
43 |
this.get('/stats/dateminmax', 'dateminmax'); |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
329
diff
changeset
|
44 |
|
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
45 |
this.get('/resolvers/lexvo/:ids', ({lexvos}, request) => { |
173 | 46 |
var langIds = decodeURIComponent(request.params.ids); |
47 |
var resMap = _.reduce(langIds.split(','), function(res, id) { |
|
48 |
var fullId = id; |
|
329
0a2c2ad49d75
Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
49 |
if(!_.startsWith(fullId, constants.LEXVO_BASE_URL) && !_.startsWith(fullId, constants.LANGUAGES_NODE_PREFIX)) { |
173 | 50 |
fullId = constants.LEXVO_BASE_URL + id; |
51 |
} |
|
52 |
var lexvoRes = lexvos.find(fullId); |
|
53 |
res[id] = lexvoRes?lexvoRes.name:null; |
|
54 |
return res; |
|
55 |
}, {}); |
|
56 |
return { |
|
57 |
'lexvoids': resMap |
|
58 |
}; |
|
59 |
}); |
|
60 |
||
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
61 |
this.get('/resolvers/bnf/:ids', ({ bnfs }, request) => { |
173 | 62 |
var bnfIds = decodeURIComponent(request.params.ids); |
63 |
var resMap = _.reduce(bnfIds.split(','), function(res, id) { |
|
64 |
var fullId = id; |
|
65 |
if(_.startsWith(fullId, constants.BNF_BASE_URL)) { |
|
66 |
fullId = fullId.slice(constants.BNF_BASE_URL.length); |
|
67 |
} else if (_.startsWith(fullId, constants.BNF_ARK_BASE_URL)) { |
|
68 |
fullId = fullId.slice(constants.BNF_ARK_BASE_URL.length); |
|
69 |
} else if (!_.startsWith(fullId, constants.BNF_ARK_BASE_ID)) { |
|
70 |
fullId = constants.BNF_ARK_BASE_ID + fullId; |
|
71 |
} |
|
72 |
var bnfRes = bnfs.find(fullId); |
|
73 |
res[id] = bnfRes?bnfRes.label:null; |
|
74 |
return res; |
|
75 |
}, {}); |
|
76 |
return { |
|
77 |
'bnfids': resMap |
|
78 |
}; |
|
79 |
}); |
|
80 |
||
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
81 |
this.get('/resolvers/geonames/:ids', ({ geonames }, request) => { |
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
82 |
var geonamesIds = decodeURIComponent(request.params.ids); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
83 |
var resMap = _.reduce(geonamesIds.split(','), function(res, id) { |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
84 |
var code = id; |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
85 |
var m = code.match(constants.GEONAMES_BASE_URLS); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
86 |
if(m) { |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
87 |
code = code.slice(m[0].length); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
88 |
} |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
89 |
code = code.replace(/\/+$/, ''); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
90 |
var geonamesRes = geonames.find(code); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
91 |
res[id] = geonamesRes?geonamesRes.label:null; |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
92 |
return res; |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
93 |
}, {}); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
94 |
return { |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
95 |
'geonamesids': resMap |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
96 |
}; |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
97 |
}); |
173 | 98 |
|
447
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
99 |
this.get('/resolvers/viaf/:ids', ({viafs}, request) => { |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
100 |
var viafIds = decodeURIComponent(request.params.ids); |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
101 |
var resMap = _.reduce(viafIds.split(','), function(res, id) { |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
102 |
var fullId = id; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
103 |
if(!_.startsWith(fullId, constants.VIAF_BASE_URL)) { |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
104 |
fullId = constants.VIAF_BASE_URL + id; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
105 |
} |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
106 |
var viafRes = viafs.find(fullId); |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
107 |
res[id] = viafRes?viafRes.name:null; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
108 |
return res; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
109 |
}, {}); |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
110 |
return { |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
111 |
'viafids': resMap |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
112 |
}; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
113 |
}); |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
114 |
|
173 | 115 |
} |