-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
53 lines (51 loc) · 1.89 KB
/
index.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
42
43
44
45
46
47
48
49
50
51
52
53
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET");
header("Content-Type: application/json; charset=UTF-8");
if (PHP_SAPI === 'cli') {
exec('cd ' . __DIR__ . '/../idrinth-thalui && git pull');
function scan(array &$out, string $root, string $path): void {
foreach (scandir(rtrim($root . '/' . $path, '/')) as $file) {
if ($file[0] === '.' || $file[0] === '_') {
//ignore hidden files
} elseif (is_dir($root . '/' . $path . '/' . $file) && $file !== '.' && $file !== '..') {
$out[$file] = [];
scan($out[$file], rtrim($root . '/' . $path, '/'), $file);
if (count($out[$file]) === 0) {
unset($out[$file]);
}
} elseif (is_file(rtrim($root . '/' . $path, '/'). '/' . $file) && str_ends_with($file, '.md')) {
$out[$file] = [
'content' => file_get_contents(rtrim($root . '/' . $path, '/') . '/' . $file),
'last' => filemtime(rtrim($root . '/' . $path, '/') . '/' . $file),
];
}
}
}
$out = [];
scan($out, __DIR__ . '/../idrinth-thalui', '');
file_put_contents(__DIR__ . '/../data.json', json_encode($out));
exit;
}
$data = is_file(__DIR__ . '/../data.json') ? json_decode(file_get_contents(__DIR__ . '/../data.json') ?: '[]', true): [];
if (isset($_GET['last'])) {
foreach ($data as $item) {
if ($item['last'] > $_GET['last']) {
die('true');
}
}
die('false');
}
function simplify(array $data): array
{
$return = [];
foreach ($data as $pos => $item) {
if (is_array($item) && !isset($item['content'])) {
$return[$pos] = simplify($item);
} else {
$return[$pos] = $item['content'];
}
}
return $return;
}
echo json_encode(simplify($data));