-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathconfig.php
More file actions
63 lines (53 loc) · 1.49 KB
/
config.php
File metadata and controls
63 lines (53 loc) · 1.49 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
<?php
header('Content-Type: application/json; charset=utf-8');
// http://127.0.0.1:9980/config.php
// ==================
// 1. 生成 sites
// ==================
$dir = __DIR__;
$self = basename(__FILE__);
$files = scandir($dir);
$sites = [];
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) !== 'php') {
continue;
}
if ($file === $self || $file === 'index.php') {
continue;
}
$filename = pathinfo($file, PATHINFO_FILENAME);
$sites[] = [
"key" => "php_" . $filename,
"name" => $filename . "(PHP)",
"type" => 4,
"api" => "http://127.0.0.1:9980/" . $filename . ".php",
"searchable" => 1,
"quickSearch" => 1,
"changeable" => 0
];
}
// ==================
// 2. 尝试加载 ../drpy-node/index.json
// ==================
$indexJsonPath = realpath($dir . '/../drpy-node/index.json');
if ($indexJsonPath && is_file($indexJsonPath)) {
$content = file_get_contents($indexJsonPath);
$json = json_decode($content, true);
// JSON 合法并且是数组
if (is_array($json)) {
// 替换 sites
$json['sites'] = $sites;
echo json_encode(
$json,
JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
);
exit;
}
}
// ==================
// 3. 找不到或失败,回退只返回 sites
// ==================
echo json_encode(
["sites" => $sites],
JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT
);