-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy.php
More file actions
129 lines (94 loc) · 3.26 KB
/
proxy.php
File metadata and controls
129 lines (94 loc) · 3.26 KB
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
<?php
error_reporting(E_ERROR);
define('CACHE_LOCATION', __DIR__ . '/.cache');
require_once(__DIR__ . '/includes/input.php');
require_once(__DIR__ . '/includes/http.php');
switch (strtolower(sanitize($_GET['action']))) {
case 'flag':
$countryCode = strtoupper(sanitize($_GET['country']));
$key = 'flag_of_' . $countryCode . '.png';
$cacheTtl = 365 * 24 * 60 * 60;
header('Content-Type: image/png');
header('Cache-Control: public, max-age: ' . $cacheTtl);
header('ETag: ' . fileTTL(resolveCachePath($key)));
echo cacheFetchURL(
$key,
'https://www.countryflags.io/' . $countryCode . '/flat/64.png',
$cacheTtl
);
break;
case 'geojson':
$key = 'geojson.json';
$cacheTtl = 365 * 24 * 60 * 60;
header('Content-Type: application/json');
header('Cache-Control: public, max-age: ' . $cacheTtl);
header('ETag: ' . fileTTL(resolveCachePath($key)));
echo cacheFetchURL(
$key,
'https://api.quarantine.country/geojson.json',
$cacheTtl
);
break;
case 'summary':
$key = 'summary.json';
$cacheTtl = 5 * 60;
header('Content-Type: application/json');
header('Cache-Control: private, max-age: ' . $cacheTtl);
header('ETag: ' . fileTTL(resolveCachePath($key)));
echo cacheFetchURL(
$key,
'https://api.quarantine.country/api/v1/summary/latest',
5 * 60
);
break;
case 'spots':
$key = 'spots.json';
$cacheTtl = 5 * 60;
header('Content-Type: application/json');
header('Cache-Control: private, max-age: ' . $cacheTtl);
header('ETag: ' . fileTTL(resolveCachePath($key)));
echo cacheFetchURL(
$key,
'https://api.quarantine.country/api/v1/spots/summary',
$cacheTtl
);
break;
case 'news':
$key = 'news.json';
$cacheTtl = 5 * 60;
header('Content-Type: application/json');
header('Cache-Control: private, max-age: ' . $cacheTtl);
header('ETag: ' . fileTTL(resolveCachePath($key)));
$response = json_decode(
cacheFetchURL(
$key,
'https://tools.cdc.gov/api/v2/resources/media/404952.json',
$cacheTtl
),
true
);
echo json_encode($response['results'][0]['children']);
break;
case 'metal-prices':
$key = 'gold-prices.json';
$cacheTtl = 5 * 60;
header('Content-Type: application/json');
header('Cache-Control: private, max-age: ' . $cacheTtl);
header('ETag: ' . fileTTL(resolveCachePath($key)));
echo json_encode([
'xau' => json_decode(cacheFetchURL(
$key,
'https://api.goldprice.pro/api/v1/symbols/4058?spot=1D',
$cacheTtl
), true),
'xag' => json_decode(cacheFetchURL(
'silver-prices.json',
'https://api.goldprice.pro/api/v1/symbols/4057?spot=1D',
$cacheTtl
), true)
]);
break;
default:
http_response_code(404);
break;
}