feat(workshop): 프로젝트 파일 탭에 출력/ 폴더를 항상 표시(없으면 생성) + 슬라이서 저장 기본 이름의 시각을 UTC가 아닌 로컬 시각으로
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d19a6b6b06
commit
a0884881e1
4 files changed
+35
-1
No files matched your search
@@ -24,6 +24,7 @@ import { renderStlPng, dropStlToFloor, convertAsciiStlToBinary } from '../../too
|
||||
import { scanScadModules, unassignedParts } from './workshop-assembly';
|
||||
import { renderAssemblyManual, readManifest, resolveScadPath, currentAssemblyHash, assemblyOutDir, ASSEMBLY_DIR_NAME, draftAssembly } from '../../tools/workshop-assembly-render';
|
||||
import { clearHistory } from '../session';
|
||||
import { ensureOutputFolder } from './workshop-layout';
|
||||
import { caseFilesDir, resolveUploadPath, sanitizePathSegment, walkCaseFiles, fileCategory } from './case-storage';
|
||||
|
||||
const APP_TYPE = 'workshop';
|
||||
@@ -382,6 +383,11 @@ export function registerWorkshopRoutes(
|
||||
const projectId = String(req.query.projectId || '');
|
||||
if (!/^[a-zA-Z0-9_-]+$/.test(projectId)) return res.status(400).json({ error: 'invalid projectId' });
|
||||
const dir = caseFilesDir(session.username, APP_TYPE, projectId);
|
||||
// 등록된 프로젝트에만 — 임의 id 요청으로 빈 폴더가 생기지 않게 한다.
|
||||
const workspace = getUserWorkspace(session.username);
|
||||
if (loadWorkshop(workspace).projects.some(p => p.id === projectId)) {
|
||||
try { ensureOutputFolder(workspace, projectId); } catch { /* 폴더 생성 실패는 목록 조회를 막지 않는다 */ }
|
||||
}
|
||||
const files = walkCaseFiles(dir).map(e => {
|
||||
const segs = e.relPath.split('/');
|
||||
return {
|
||||
|
||||
@@ -174,6 +174,17 @@ export function planPrint3dMoves(workspace: string): { from: string; to: string
|
||||
}
|
||||
|
||||
// 도구가 파일을 저장할 폴더를 정하는 단일 지점(print3d_model / model_download / K2 웹 슬라이서가 공유).
|
||||
/**
|
||||
* 출력/ 폴더를 프로젝트에 항상 만들어 둔다(2026-09-30). 슬라이싱 결과(gcode)를 저장하는 자리인데,
|
||||
* 폴더가 없으면 파일 탭에 아예 안 보여서 어디에 저장되는지 알 수 없었다. 빈 폴더도 파일 탭에는
|
||||
* "(빈 폴더)"로 보이므로(listCaseFolders), 만들어 두기만 하면 보인다. 이미 있으면 아무것도 안 한다.
|
||||
*/
|
||||
export function ensureOutputFolder(workspace: string, projectId: string): string {
|
||||
const dir = path.join(projectDir(workspace, projectId), LAYOUT.out);
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
return dir;
|
||||
}
|
||||
|
||||
export function saveDirs(workspace: string, projectId?: string): { modelDir: string; outDir: string; downloadDir: string } {
|
||||
if (projectId) {
|
||||
const root = projectDir(workspace, projectId);
|
||||
|
||||
@@ -83,3 +83,17 @@ describe('saveGcodeToProject — 슬라이싱 결과를 프로젝트 출력/ 폴
|
||||
const d = saveGcodeToProject(ws, '../k2ui_10.gcode', 'proj_abc', 'x'); assert.equal(!d.ok && d.status, 400);
|
||||
});
|
||||
});
|
||||
|
||||
import { ensureOutputFolder } from '../src/gateway/routes/workshop-layout';
|
||||
describe('ensureOutputFolder — 출력/ 폴더가 파일 탭에 보이게 항상 만든다', () => {
|
||||
test('없으면 만들고, 있으면 파일을 건드리지 않는다', () => {
|
||||
const w = fs.mkdtempSync(path.join(os.tmpdir(), 'k2out-'));
|
||||
fs.mkdirSync(path.join(w, 'workshop', 'proj_z'), { recursive: true });
|
||||
const d = ensureOutputFolder(w, 'proj_z');
|
||||
assert.equal(d, path.join(w, 'workshop', 'proj_z', '출력'));
|
||||
assert.equal(fs.statSync(d).isDirectory(), true);
|
||||
fs.writeFileSync(path.join(d, 'keep.gcode'), 'x');
|
||||
assert.equal(ensureOutputFolder(w, 'proj_z'), d);
|
||||
assert.equal(fs.readFileSync(path.join(d, 'keep.gcode'), 'utf8'), 'x');
|
||||
});
|
||||
});
|
||||
@@ -936,7 +936,10 @@
|
||||
async function saveGcodeToProject() {
|
||||
if (!curGcodeFile || !workshopProjectId) return;
|
||||
setErr('');
|
||||
const stamp = new Date().toISOString().slice(0, 16).replace('T', '_').replace(':', '');
|
||||
// toISOString은 UTC라 한국 시각과 9시간 어긋난다(13:18에 저장했는데 이름이 0418) — 로컬 시각으로 만든다.
|
||||
const d0 = new Date();
|
||||
const p2 = (n) => String(n).padStart(2, '0');
|
||||
const stamp = `${d0.getFullYear()}-${p2(d0.getMonth() + 1)}-${p2(d0.getDate())}_${p2(d0.getHours())}${p2(d0.getMinutes())}`;
|
||||
const base = loadedModelNames.length > 1 ? `${loadedModelNames[0]}_외${loadedModelNames.length - 1}` : (loadedModelNames[0] || 'plate');
|
||||
const name = prompt('프로젝트 출력 폴더에 저장할 G-code 이름 (.gcode는 자동)', `${base}_${stamp}`);
|
||||
if (name === null) return;
|
||||
|
||||
Reference in new issue
Block a user