fix: Enhance file handling and inspection method mapping

- Updated fileController to include Cross-Origin-Resource-Policy headers for improved security and file handling.
- Added error handling for file streams to ensure robust responses in case of read errors.
- Modified materialStatusController to correctly map material IDs to their respective codes for inventory stock queries.
- Enhanced moldController to include warranty shot count in mold creation and update processes.
- Improved item inspection page by adding inspection method category loading and mapping, ensuring accurate display of method labels in the UI.

These changes aim to enhance the overall functionality and user experience across multiple companies by ensuring proper file handling, data mapping, and error management.
This commit is contained in:
kjs
2026-04-10 15:59:38 +09:00
parent b8860e56e5
commit 2f50d7d809
24 changed files with 414 additions and 123 deletions

View File

@@ -924,12 +924,26 @@ export const previewFile = async (
);
res.setHeader("Access-Control-Allow-Credentials", "true");
// 캐시 헤더 설정
// Cross-Origin-Resource-Policy: cross-origin 설정
// helmet 기본값(same-origin)을 오버라이드하여 v1.vexplor.com에서 api.vexplor.com 이미지 로드 허용
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
// 파일 크기 및 캐시 헤더 설정
const stat = fs.statSync(finalPath);
res.setHeader("Content-Length", stat.size);
res.setHeader("Cache-Control", "public, max-age=3600");
res.setHeader("Content-Type", mimeType);
// 파일 스트림으로 전송
const fileStream = fs.createReadStream(finalPath);
fileStream.on("error", (err) => {
console.error("파일 스트림 오류:", err);
if (!res.headersSent) {
res.status(500).json({ success: false, message: "파일 읽기 오류" });
} else {
res.end();
}
});
fileStream.pipe(res);
} catch (error) {
console.error("파일 미리보기 오류:", error);
@@ -1031,9 +1045,20 @@ export const downloadFile = async (
`attachment; filename="${encodeURIComponent(fileRecord.real_file_name!)}"`
);
res.setHeader("Content-Type", "application/octet-stream");
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
const stat = fs.statSync(filePath);
res.setHeader("Content-Length", stat.size);
// 파일 스트림 전송
const fileStream = fs.createReadStream(filePath);
fileStream.on("error", (err) => {
console.error("파일 스트림 오류:", err);
if (!res.headersSent) {
res.status(500).json({ success: false, message: "파일 읽기 오류" });
} else {
res.end();
}
});
fileStream.pipe(res);
} catch (error) {
console.error("파일 다운로드 오류:", error);
@@ -1218,10 +1243,21 @@ export const getFileByToken = async (req: Request, res: Response) => {
"Content-Disposition",
`inline; filename="${encodeURIComponent(fileRecord.real_file_name!)}"`
);
res.setHeader("Cross-Origin-Resource-Policy", "cross-origin");
const stat = fs.statSync(filePath);
res.setHeader("Content-Length", stat.size);
res.setHeader("Cache-Control", "public, max-age=300"); // 5분 캐시
// 파일 스트림 전송
const fileStream = fs.createReadStream(filePath);
fileStream.on("error", (err) => {
console.error("파일 스트림 오류:", err);
if (!res.headersSent) {
res.status(500).json({ success: false, message: "파일 읽기 오류" });
} else {
res.end();
}
});
fileStream.pipe(res);
} catch (error) {
console.error("❌ 토큰 파일 접근 오류:", error);

View File

@@ -226,11 +226,12 @@ export async function getMaterialStatus(
return res.json({ success: true, data: [] });
}
// 4) 재고 조회 (창고/위치별)
const stockPlaceholders = materialIds
// 4) 재고 조회 (창고/위치별) — inventory_stock.item_code는 item_number 기준
const materialCodes = materialIds.map((id) => materialMap[id].materialCode);
const stockPlaceholders = materialCodes
.map((_, i) => `$${i + 1}`)
.join(",");
const stockParams: any[] = [...materialIds];
const stockParams: any[] = [...materialCodes];
let stockParamIdx = materialIds.length + 1;
const stockConditions: string[] = [

View File

@@ -94,7 +94,7 @@ export async function createMold(req: AuthenticatedRequest, res: Response): Prom
mold_code, mold_name, mold_type, category, manufacturer,
manufacturing_number, manufacturing_date, cavity_count,
shot_count, mold_quantity, base_input_qty, operation_status,
remarks, image_path, memo,
remarks, image_path, memo, warranty_shot_count,
} = req.body;
if (!mold_code || !mold_name) {
@@ -107,15 +107,16 @@ export async function createMold(req: AuthenticatedRequest, res: Response): Prom
id, company_code, mold_code, mold_name, mold_type, category,
manufacturer, manufacturing_number, manufacturing_date,
cavity_count, shot_count, mold_quantity, base_input_qty,
operation_status, remarks, image_path, memo, writer, created_date
) VALUES (gen_random_uuid()::text,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,NOW())
operation_status, remarks, image_path, memo, warranty_shot_count, writer, created_date
) VALUES (gen_random_uuid()::text,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,NOW())
RETURNING *
`;
const params = [
companyCode, mold_code, mold_name, mold_type || null, category || null,
manufacturer || null, manufacturing_number || null, manufacturing_date || null,
cavity_count || 0, shot_count || 0, mold_quantity || 1, base_input_qty || 0,
operation_status || "ACTIVE", remarks || null, image_path || null, memo || null, userId,
operation_status || "ACTIVE", remarks || null, image_path || null, memo || null,
warranty_shot_count || 0, userId,
];
const result = await query(sql, params);
@@ -139,7 +140,7 @@ export async function updateMold(req: AuthenticatedRequest, res: Response): Prom
mold_name, mold_type, category, manufacturer,
manufacturing_number, manufacturing_date, cavity_count,
shot_count, mold_quantity, base_input_qty, operation_status,
remarks, image_path, memo,
remarks, image_path, memo, warranty_shot_count,
} = req.body;
const sql = `
@@ -153,8 +154,9 @@ export async function updateMold(req: AuthenticatedRequest, res: Response): Prom
base_input_qty = COALESCE($10, base_input_qty),
operation_status = COALESCE($11, operation_status),
remarks = $12, image_path = $13, memo = $14,
warranty_shot_count = $15,
updated_date = NOW()
WHERE mold_code = $15 AND company_code = $16
WHERE mold_code = $16 AND company_code = $17
RETURNING *
`;
const params = [
@@ -162,7 +164,7 @@ export async function updateMold(req: AuthenticatedRequest, res: Response): Prom
manufacturing_number, manufacturing_date,
cavity_count, shot_count, mold_quantity, base_input_qty,
operation_status, remarks, image_path, memo,
moldCode, companyCode,
warranty_shot_count || 0, moldCode, companyCode,
];
const result = await query(sql, params);