V1.0正式版
This commit is contained in:
1 parent
d2fc7a83a8
commit
529ad70e11
13 files changed
+1052
-237
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* SecHub 搜索API
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
// 定义路径
|
||||
$jsonDir = __DIR__ . '/assets/json/';
|
||||
$dbDir = __DIR__ . '/assets/db/';
|
||||
$dbPath = $dbDir . 'sechub.db';
|
||||
|
||||
// 引入数据库类
|
||||
require_once __DIR__ . '/db.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
$keyword = $_GET['keyword'] ?? '';
|
||||
|
||||
if (empty($action) || empty($keyword)) {
|
||||
echo json_encode([]);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$database = new SecHubDatabase($dbPath, $jsonDir);
|
||||
|
||||
if ($action === 'global') {
|
||||
// 全局搜索
|
||||
$results = $database->globalSearch($keyword);
|
||||
echo json_encode($results, JSON_UNESCAPED_UNICODE);
|
||||
} elseif ($action === 'section') {
|
||||
// 栏目搜索
|
||||
$section = $_GET['section'] ?? '';
|
||||
$results = $database->searchBySection($section, $keyword);
|
||||
echo json_encode($results, JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
echo json_encode([]);
|
||||
}
|
||||
|
||||
$database->close();
|
||||
} catch (Exception $e) {
|
||||
error_log("搜索失败: " . $e->getMessage());
|
||||
echo json_encode(['error' => '搜索失败']);
|
||||
}
|
||||
Reference in new issue
Block a user