-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions-routes.php
41 lines (33 loc) · 1.1 KB
/
functions-routes.php
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
<?php
add_route('/upload', function () {
////return pr($_FILES, 'files??');
if (empty($_FILES)) {
error_header(401, 'No File');
}
$file_meta = $_FILES['file'];
$src = $file_meta['tmp_name'];
$res = organize_file($src, $file_meta); //[error, result] format
//Q: should this return an error_header if the error is populated?
//Q: or should it just consistently return a 200 with
// an [error, result] JSON payload for the API caller to sort out?
header('Content-Type: application/json');
echo json_encode($res);
});
add_route('/solr-search', function () {
$opts = $_GET;
//FIXME: change solr to the ENV variable for the solr host?
$base_url = 'http://solr:8983/solr/mycore';
$query_string = urlencode($opts['q']);
$full = "${base_url}/select?q=${query_string}";
$json = file_get_contents($full);
header('Content-Type: application/json');
echo $json;
});
//attachment
add_route('/asset/{sha256}', function ($sha256) {
serve_asset($sha256, ['attachment' => true]);
});
//inline
add_route('/inline/{sha256}', function ($sha256) {
serve_asset($sha256, ['attachment' => false]);
});