"php_" . $filename, "name" => $filename . "(PHP)", "type" => 4, "api" => $baseUrl . "/" . $filename . ".php", "searchable" => 1, "quickSearch" => 1, "changeable" => 0 ]; if (strpos($filename, '[书]') !== false) { $site['类型'] = '小说'; } elseif (strpos($filename, '[画]') !== false) { $site['类型'] = '漫画'; } $sites[] = $site; } // ================== // 2. 尝试加载 index.json (同级) 或 ../drpy-node/index.json 或 ../../drpy-node/index.json // ================== $possiblePaths = [ $dir . '/config.json', $dir . '/index.json', $dir . '/../drpy-node/index.json', $dir . '/../../drpy-node/index.json' ]; $indexJsonPath = false; foreach ($possiblePaths as $path) { $realPath = realpath($path); if ($realPath && is_file($realPath)) { $indexJsonPath = $realPath; break; } } 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 | JSON_UNESCAPED_SLASHES ); exit; } } // ================== // 3. 找不到或失败,回退只返回 sites // ================== echo json_encode( ["sites" => $sites], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );