Compare commits
No commits in common. "deb01bc7a59628d73a8b60a19e24f24ec979c158" and "096838adab9d8c5a134d640e2780ab6827be5407" have entirely different histories.
deb01bc7a5
...
096838adab
|
|
@ -172,20 +172,7 @@ router.get(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 회사별 폴더 구조를 고려하여 파일 경로 찾기
|
const filePath = path.join(UPLOAD_PATH, serverFilename as string);
|
||||||
const user = req.user;
|
|
||||||
const companyCode = user?.companyCode || "default";
|
|
||||||
|
|
||||||
// 먼저 회사별 폴더에서 찾기
|
|
||||||
let filePath = FileSystemManager.findFileInCompanyFolders(
|
|
||||||
companyCode,
|
|
||||||
serverFilename as string
|
|
||||||
);
|
|
||||||
|
|
||||||
// 찾지 못하면 기본 uploads 폴더에서 찾기 (하위 호환성)
|
|
||||||
if (!filePath) {
|
|
||||||
filePath = path.join(UPLOAD_PATH, serverFilename as string);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 파일 존재 확인
|
// 파일 존재 확인
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
|
|
@ -193,8 +180,7 @@ router.get(
|
||||||
fileId,
|
fileId,
|
||||||
serverFilename,
|
serverFilename,
|
||||||
filePath,
|
filePath,
|
||||||
companyCode,
|
userId: req.user?.userId,
|
||||||
userId: user?.userId,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(404).json({
|
res.status(404).json({
|
||||||
|
|
@ -271,37 +257,15 @@ router.delete(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 회사별 폴더 구조를 고려하여 파일 경로 찾기
|
const filePath = path.join(UPLOAD_PATH, serverFilename);
|
||||||
const user = req.user;
|
|
||||||
const companyCode = user?.companyCode || "default";
|
|
||||||
|
|
||||||
// 먼저 회사별 폴더에서 찾기
|
// 파일 존재 확인
|
||||||
let filePath = FileSystemManager.findFileInCompanyFolders(
|
|
||||||
companyCode,
|
|
||||||
serverFilename
|
|
||||||
);
|
|
||||||
|
|
||||||
// 찾지 못하면 기본 uploads 폴더에서 찾기 (하위 호환성)
|
|
||||||
if (!filePath) {
|
|
||||||
filePath = path.join(UPLOAD_PATH, serverFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 파일 존재 확인 및 삭제
|
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
fs.unlinkSync(filePath);
|
fs.unlinkSync(filePath);
|
||||||
logger.info("파일 삭제 완료", {
|
logger.info("파일 삭제 완료", {
|
||||||
fileId,
|
fileId,
|
||||||
serverFilename,
|
serverFilename,
|
||||||
filePath,
|
userId: req.user?.userId,
|
||||||
companyCode,
|
|
||||||
userId: user?.userId,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
logger.warn("삭제할 파일을 찾을 수 없음", {
|
|
||||||
fileId,
|
|
||||||
serverFilename,
|
|
||||||
companyCode,
|
|
||||||
userId: user?.userId,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,52 +132,6 @@ export class FileSystemManager {
|
||||||
return sharedPath;
|
return sharedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 회사별 폴더 구조에서 파일 찾기
|
|
||||||
* @param companyCode 회사 코드
|
|
||||||
* @param serverFilename 서버 파일명
|
|
||||||
* @returns 찾은 파일의 전체 경로 또는 null
|
|
||||||
*/
|
|
||||||
static findFileInCompanyFolders(
|
|
||||||
companyCode: string,
|
|
||||||
serverFilename: string
|
|
||||||
): string | null {
|
|
||||||
try {
|
|
||||||
const companyBasePath = path.join(
|
|
||||||
this.BASE_UPLOAD_PATH,
|
|
||||||
`company_${companyCode}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!fs.existsSync(companyBasePath)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 회사 폴더 내의 모든 하위 폴더를 재귀적으로 검색
|
|
||||||
const findFileRecursively = (dirPath: string): string | null => {
|
|
||||||
const items = fs.readdirSync(dirPath);
|
|
||||||
|
|
||||||
for (const item of items) {
|
|
||||||
const itemPath = path.join(dirPath, item);
|
|
||||||
const stats = fs.statSync(itemPath);
|
|
||||||
|
|
||||||
if (stats.isFile() && item === serverFilename) {
|
|
||||||
return itemPath;
|
|
||||||
} else if (stats.isDirectory()) {
|
|
||||||
const found = findFileRecursively(itemPath);
|
|
||||||
if (found) return found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
return findFileRecursively(companyBasePath);
|
|
||||||
} catch (error) {
|
|
||||||
logger.error(`파일 검색 실패: ${companyCode}/${serverFilename}`, error);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 회사별 디스크 사용량 조회
|
* 회사별 디스크 사용량 조회
|
||||||
* @param companyCode 회사 코드
|
* @param companyCode 회사 코드
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue