Repository navigation
Expand file tree
/
Copy pathjson.php
More file actions
48 lines (43 loc) · 1.4 KB
/
Copy pathjson.php
File metadata and controls
48 lines (43 loc) · 1.4 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
<?php
$dirs = glob("dumps/*");
$a = [];
foreach ($dirs as $dir) {
$a = array_merge($a, glob($dir . "/*"));
}
rsort($a);
$dates = [];
$tables = [];
$files = [];
foreach ($a as $v) {
if (strstr($v, ".inprogress")) {
continue;
}
if (!preg_match("/pouetdatadump-(.*)-(.*).json/", $v, $m)) {
continue;
}
$tables[$m[1]] = true;
$dates[$m[2]] = true;
$files[$m[1] . $m[2]] = $v;
}
// Absolute, as outside tools read this; from the request so a local stack
// links to itself
$baseURL = (@$_SERVER["HTTPS"] == "on" ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . "/";
$output = ["dumps" => [], "latest" => null];
foreach ($dates as $date => $_true) {
foreach ($tables as $table => $_true2) {
$filename = @$files[ $table . $date ]; // "pouetdatadump-".$k2."-".$k.".json.gz";
if ($filename && file_exists($filename)) {
$output["dumps"][$date][$table]["filename"] = basename($filename);
$output["dumps"][$date][$table]["url"] = $baseURL . $filename;
$output["dumps"][$date][$table]["size_in_bytes"] = filesize($filename);
}
}
}
if ($output["dumps"]) {
arsort($output["dumps"]);
$output["latest"] = reset($output["dumps"]);
} else {
$output["dumps"] = new stdClass(); // {} like a non-empty list, not []
}
header("Content-type: application/json; charset=utf-8");
echo json_encode($output, JSON_PRETTY_PRINT);