Update Harbor client and gateway integration workflows
This commit is contained in:
@@ -19,6 +19,23 @@ export function createSingboxRuntime({
|
||||
|
||||
const state = () => ({ running: Boolean(child), startedAt });
|
||||
|
||||
function checkConfig(config: unknown) {
|
||||
const directory = fs.mkdtempSync(`${configPath}.check-`);
|
||||
const candidatePath = `${directory}/config.json`;
|
||||
try {
|
||||
fs.writeFileSync(candidatePath, JSON.stringify(config));
|
||||
const check = spawnSync('sing-box', ['check', '-c', candidatePath], { encoding: 'utf8' });
|
||||
if (check.status !== 0) {
|
||||
throw new HarborError('CONFIG_INVALID', {
|
||||
cause: new Error((check.stderr || check.stdout || check.error?.message || 'sing-box check failed').trim()),
|
||||
});
|
||||
}
|
||||
return { valid: true };
|
||||
} finally {
|
||||
fs.rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
async function stop() {
|
||||
if (gateway) setGatewayInterception(false, tproxyChain);
|
||||
if (!child) {
|
||||
@@ -100,6 +117,7 @@ export function createSingboxRuntime({
|
||||
get running() { return Boolean(child); },
|
||||
get startedAt() { return startedAt; },
|
||||
refresh: async () => state(),
|
||||
checkConfig,
|
||||
apply,
|
||||
restart: () => apply({ force: true }),
|
||||
stop,
|
||||
|
||||
Reference in New Issue
Block a user