fix(remote): 上传路由修复

This commit is contained in:
2026-03-09 20:08:46 +08:00
parent 4273b3d43b
commit 88f265757c
3 changed files with 39 additions and 6 deletions

View File

@@ -27,6 +27,10 @@
"frpcPath": "./frp/frpc.exe",
"configPath": "./frp/frpc.toml"
},
"opencode": {
"enabled": true,
"port": 3002
},
"gitea": {
"enabled": true
}

View File

@@ -120,7 +120,12 @@ class App {
this.container.register('openCodeService', (c) => {
const OpenCodeService = require('../services/opencode/OpenCodeService');
return new OpenCodeService();
const config = c.resolve('config');
const opencodeConfig = config.getSection('opencode') || {};
return new OpenCodeService({
enabled: opencodeConfig.enabled !== false,
port: opencodeConfig.port || 3002
});
});
this.container.register('giteaService', (c) => {

View File

@@ -1,15 +1,30 @@
const { spawn } = require('child_process');
const { spawn, execSync } = require('child_process');
const path = require('path');
const config = require('../../config');
const logger = require('../../utils/logger');
class OpenCodeService {
constructor() {
constructor(options = {}) {
this.process = null;
this.isRunning = false;
this.port = 3002;
this.port = options.port || 3002;
this.enabled = options.enabled !== false;
try {
const result = execSync('where opencode', { encoding: 'utf8', windowsHide: true });
const firstLine = result.split('\n')[0].trim();
this.opencodePath = firstLine.endsWith('.cmd') ? firstLine : firstLine + '.cmd';
} catch (e) {
this.opencodePath = null;
}
}
start() {
if (!this.enabled) {
logger.info('OpenCode service is disabled');
return;
}
if (this.isRunning) {
logger.warn('OpenCode service is already running');
return;
@@ -21,15 +36,24 @@ class OpenCodeService {
return;
}
if (!this.opencodePath) {
logger.error('OpenCode command not found in PATH');
return;
}
try {
logger.info('Starting OpenCode service', { port: this.port });
logger.info('Starting OpenCode service', { port: this.port, opencodePath: this.opencodePath });
const env = {
...process.env,
OPENCODE_SERVER_PASSWORD: password
};
this.process = spawn('opencode', ['serve', '--port', this.port.toString()], {
this.process = spawn('powershell.exe', [
'-NoProfile',
'-Command',
`& '${this.opencodePath}' serve --port ${this.port}`
], {
stdio: ['ignore', 'pipe', 'pipe'],
env,
windowsHide: true