fix(k2): 웹 슬라이서 gcode 미리보기·프린터 전송이 404 — 저장 위치가 print3d/K2웹슬라이서/로 바뀌었는데(09-25) 조회는 옛 위치만 봤음. 새 위치 우선 + 옛 위치 폴백
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5bc60d1320
commit
a35f811d36
2 files changed
+61
-6
No files matched your search
@@ -36,14 +36,22 @@ function profilePath(workspacePath: string, name: string): string {
|
||||
function validProfileName(name: string): boolean {
|
||||
return PROFILE_NAME_RE.test(name) && name !== '__current';
|
||||
}
|
||||
// 슬라이싱 결과 gcode 파일명 검증 — print3d/ 디렉토리 안의 단일 파일명만 허용(슬래시/.. 거부).
|
||||
// 슬라이싱 결과 gcode 파일명 검증 — 파일명 하나만 허용(슬래시/.. 거부).
|
||||
//
|
||||
// 위치 규칙(2026-09-30 수정). 웹 슬라이서는 결과를 print3d/K2웹슬라이서/ 에 저장한다(09-25 작업실 폴더
|
||||
// 규칙 통일, ba193ee). 그런데 조회 쪽은 옛 위치(print3d/ 바로 아래)만 봐서, 슬라이싱은 성공하는데
|
||||
// 미리보기가 "gcode 불러오기 실패: HTTP 404"로 죽고 프린터 전송도 막혔다. 새 위치를 먼저 보고, 규칙 통일
|
||||
// 전에 만든 파일을 위해 옛 위치도 폴백으로 본다.
|
||||
const GCODE_NAME_RE = /^[A-Za-z0-9_\-]+\.gcode$/;
|
||||
function gcodePath(workspacePath: string, filename: string): string {
|
||||
export function gcodePath(workspacePath: string, filename: string): string {
|
||||
if (!GCODE_NAME_RE.test(filename)) throw new Error('잘못된 gcode 파일명.');
|
||||
const p = path.join(workspacePath, 'print3d', filename);
|
||||
const dir = path.join(workspacePath, 'print3d');
|
||||
if (!isPathInsideDir(dir, p)) throw new Error('경로가 print3d 디렉토리 밖입니다.');
|
||||
return p;
|
||||
const root = path.join(workspacePath, PRINT3D_DIRS.root);
|
||||
const candidates = [path.join(workspacePath, PRINT3D_DIRS.k2Web, filename), path.join(root, filename)];
|
||||
for (const c of candidates) {
|
||||
if (!isPathInsideDir(root, c)) throw new Error('경로가 print3d 디렉토리 밖입니다.');
|
||||
if (fs.existsSync(c)) return c;
|
||||
}
|
||||
return candidates[0];
|
||||
}
|
||||
|
||||
export function registerK2Routes(app: Express): void {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* gcodePath — 웹 슬라이서 결과 gcode 조회 위치
|
||||
*
|
||||
* 사건(2026-09-30): 슬라이싱은 성공하는데 미리보기가 "gcode 불러오기 실패: HTTP 404". 저장은
|
||||
* print3d/K2웹슬라이서/ 로 바뀌었는데(09-25 폴더 규칙 통일) 조회는 print3d/ 바로 아래만 봤다.
|
||||
*/
|
||||
import { test, describe } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { gcodePath } from '../src/gateway/routes/routes-k2';
|
||||
|
||||
const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'k2gcode-'));
|
||||
const newDir = path.join(ws, 'print3d', 'K2웹슬라이서');
|
||||
const oldDir = path.join(ws, 'print3d');
|
||||
fs.mkdirSync(newDir, { recursive: true });
|
||||
|
||||
describe('gcodePath', () => {
|
||||
test('새 위치(print3d/K2웹슬라이서/)의 파일을 찾는다 — 사건의 본체', () => {
|
||||
fs.writeFileSync(path.join(newDir, 'k2ui_1.gcode'), 'x');
|
||||
assert.equal(gcodePath(ws, 'k2ui_1.gcode'), path.join(newDir, 'k2ui_1.gcode'));
|
||||
});
|
||||
|
||||
test('옛 위치(print3d/ 바로 아래)에만 있는 파일도 찾는다(폴더 규칙 통일 전 파일)', () => {
|
||||
fs.writeFileSync(path.join(oldDir, 'k2ui_2.gcode'), 'x');
|
||||
assert.equal(gcodePath(ws, 'k2ui_2.gcode'), path.join(oldDir, 'k2ui_2.gcode'));
|
||||
});
|
||||
|
||||
test('두 곳에 모두 있으면 새 위치가 우선한다', () => {
|
||||
fs.writeFileSync(path.join(newDir, 'k2ui_3.gcode'), 'new');
|
||||
fs.writeFileSync(path.join(oldDir, 'k2ui_3.gcode'), 'old');
|
||||
assert.equal(gcodePath(ws, 'k2ui_3.gcode'), path.join(newDir, 'k2ui_3.gcode'));
|
||||
});
|
||||
|
||||
test('어디에도 없으면 새 위치 경로를 돌려준다(호출부가 existsSync로 404 처리)', () => {
|
||||
const p = gcodePath(ws, 'k2ui_nope.gcode');
|
||||
assert.equal(p, path.join(newDir, 'k2ui_nope.gcode'));
|
||||
assert.equal(fs.existsSync(p), false);
|
||||
});
|
||||
|
||||
test('경로 이탈·잘못된 이름은 거부한다', () => {
|
||||
assert.throws(() => gcodePath(ws, '../secret.gcode'), /잘못된 gcode 파일명/);
|
||||
assert.throws(() => gcodePath(ws, 'a/b.gcode'), /잘못된 gcode 파일명/);
|
||||
assert.throws(() => gcodePath(ws, 'x.txt'), /잘못된 gcode 파일명/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user