|
|
|
|
@ -58,9 +58,9 @@ app.get('/dashboard', (req, res) => {
|
|
|
|
|
res.sendFile(path.join(__dirname, 'public', 'dashboard.html'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 6. 모델 변경 API 엔드포인트
|
|
|
|
|
// 6. 모델 변경 API 엔드포인트 (*** 수정된 부분 ***)
|
|
|
|
|
app.post('/set-model', (req, res) => {
|
|
|
|
|
const { model } = req.body; // app.js에서 보낸 { model: "..." }
|
|
|
|
|
const { model } = req.body; // app.js에서 보낸 { model: "OBJDET" } 등
|
|
|
|
|
|
|
|
|
|
if (!model) {
|
|
|
|
|
return res.status(400).json({ status: 'error', message: '모델 값이 없습니다.' });
|
|
|
|
|
@ -68,40 +68,42 @@ app.post('/set-model', (req, res) => {
|
|
|
|
|
|
|
|
|
|
console.log(`[서버] 모델 변경 명령 수신: ${model}`);
|
|
|
|
|
|
|
|
|
|
// --- 요청하신 파이썬 스크립트 실행 ---
|
|
|
|
|
const pythonCommand = 'python3';
|
|
|
|
|
const scriptPath = '/mnt/user_data/ctrl_cli.py';
|
|
|
|
|
const combinedArg = `"ON ${model}"`;
|
|
|
|
|
const args = [scriptPath, combinedArg];
|
|
|
|
|
// --- 요청하신 쉘 스크립트 실행으로 변경 ---
|
|
|
|
|
const scriptCommand = '/mnt/user_data/feat_control/feat_on.sh';
|
|
|
|
|
const args = [model]; // OBJDET, ABNORM, CROWD 등
|
|
|
|
|
|
|
|
|
|
console.log(`[서버] 실행: ${pythonCommand} ${args.join(' ')}`);
|
|
|
|
|
console.log(`[서버] 실행: ${scriptCommand} ${args.join(' ')}`);
|
|
|
|
|
|
|
|
|
|
const py = spawn(pythonCommand, args);
|
|
|
|
|
// 스크립트 파일에 실행 권한(chmod +x)이 있다고 가정합니다.
|
|
|
|
|
const scriptProcess = spawn(scriptCommand, args);
|
|
|
|
|
|
|
|
|
|
let stdoutData = '';
|
|
|
|
|
let stderrData = '';
|
|
|
|
|
|
|
|
|
|
py.stdout.on('data', (data) => {
|
|
|
|
|
console.log(`Python stdout: ${data}`);
|
|
|
|
|
scriptProcess.stdout.on('data', (data) => {
|
|
|
|
|
console.log(`Script stdout: ${data}`);
|
|
|
|
|
stdoutData += data.toString();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
py.stderr.on('data', (data) => {
|
|
|
|
|
console.error(`Python stderr: ${data}`);
|
|
|
|
|
scriptProcess.stderr.on('data', (data) => {
|
|
|
|
|
console.error(`Script stderr: ${data}`);
|
|
|
|
|
stderrData += data.toString();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
py.on('close', (code) => {
|
|
|
|
|
console.log(`Python process exited with code ${code}`);
|
|
|
|
|
scriptProcess.on('close', (code) => {
|
|
|
|
|
console.log(`Script process exited with code ${code}`);
|
|
|
|
|
if (code === 0) {
|
|
|
|
|
res.json({ status: 'success', message: `모델이 ${model}(으)로 변경됨`, output: stdoutData });
|
|
|
|
|
} else {
|
|
|
|
|
res.status(500).json({ status: 'error', message: '파이썬 스크립트 실행 실패', error: stderrData });
|
|
|
|
|
res.status(500).json({ status: 'error', message: '쉘 스크립트 실행 실패', error: stderrData });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
py.on('error', (err) => {
|
|
|
|
|
console.error('[서버] 파이썬 프로세스 시작 실패:', err);
|
|
|
|
|
scriptProcess.on('error', (err) => {
|
|
|
|
|
console.error('[서버] 쉘 프로세스 시작 실패:', err);
|
|
|
|
|
// "ENOENT" 오류는
|
|
|
|
|
// 1) 스크립트 경로가 잘못되었거나,
|
|
|
|
|
// 2) 스크립트 파일에 실행 권한이 없을 때 자주 발생합니다.
|
|
|
|
|
res.status(500).json({ status: 'error', message: '프로세스 시작 실패', error: err.message });
|
|
|
|
|
});
|
|
|
|
|
// --- 스크립트 실행 끝 ---
|
|
|
|
|
@ -244,4 +246,4 @@ app.post('/delete-model', (req, res) => {
|
|
|
|
|
app.listen(port, () => {
|
|
|
|
|
console.log(`Server running on http://localhost:${port}`);
|
|
|
|
|
});
|
|
|
|
|
//```
|
|
|
|
|
//
|