260115_01_ENH : Front 연동 테스트 완료 및 대량발송 결과 다운로드 구현 완료
This commit is contained in:
@@ -68,13 +68,11 @@ public class FileService {
|
||||
* 2) Asset 디렉토리에서 더 이상 사용되지 않는 파일 삭제
|
||||
* 3) 정리된 HTML 반환
|
||||
*/
|
||||
public String syncOnSave(String prjctCd, String rawHtml) {
|
||||
public String syncOnSave(String prjctCd, Long tmplatIdx, String rawHtml) {
|
||||
if (rawHtml == null) rawHtml = "";
|
||||
|
||||
String returnHtml = rawHtml;
|
||||
try{
|
||||
|
||||
|
||||
// body fragment로 파싱 (KriEditor가 body 없이 <p>...</p> 형태 저장하므로)
|
||||
Document doc = Jsoup.parseBodyFragment(rawHtml);
|
||||
Elements imgs = doc.select("img[src]");
|
||||
@@ -86,23 +84,33 @@ public class FileService {
|
||||
if (src == null || src.isBlank()) continue;
|
||||
if (!src.contains("/" + prjctCd + "/")) continue;
|
||||
|
||||
String fileName = FileUtil.extractFileNameFromPath(src);
|
||||
|
||||
if (src.contains("/" + prjctCd + "/Temp/")) {
|
||||
// Temp → Asset 이동
|
||||
String fileName = FileUtil.extractFileNameFromPath(src);
|
||||
moveTempToAsset(prjctCd, fileName);
|
||||
moveTempToAsset(prjctCd, tmplatIdx, fileName);
|
||||
|
||||
String assetSrc = src.replace("/Temp/", "/Asset/");
|
||||
String assetSrc = src.replace("/Temp/", "/Asset/" + tmplatIdx + "/");
|
||||
img.attr("src", assetSrc);
|
||||
|
||||
assetFileNamesToKeep.add(fileName);
|
||||
} else if (src.contains("/" + prjctCd + "/Asset/")) {
|
||||
String fileName = FileUtil.extractFileNameFromPath(src);
|
||||
if (!src.contains("/" + prjctCd + "/Asset/" + tmplatIdx + "/")){
|
||||
String[] srcArr = src.split("/" + prjctCd + "/Asset/");
|
||||
String fromTmplatIdx = srcArr[1].split("/")[0].replace(fileName, "");
|
||||
|
||||
copyAssetToAsset(prjctCd, fromTmplatIdx, tmplatIdx, fileName);
|
||||
|
||||
String assetSrc = src.replace("/Asset/" + fromTmplatIdx + "/", "/Asset/" + tmplatIdx + "/");
|
||||
img.attr("src", assetSrc);
|
||||
}
|
||||
|
||||
assetFileNamesToKeep.add(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
// Asset 디렉토리 정리 (본문에 없는 파일 삭제)
|
||||
cleanupAssetDir(prjctCd, assetFileNamesToKeep);
|
||||
cleanupAssetDir(prjctCd, tmplatIdx, assetFileNamesToKeep);
|
||||
|
||||
// body 안의 HTML만 반환 (불필요한 <html><body> wrapper 제거)
|
||||
returnHtml = doc.body().html();
|
||||
@@ -126,15 +134,36 @@ public class FileService {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Temp");
|
||||
}
|
||||
|
||||
private Path getAssetDir(String prjctCd) {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Asset");
|
||||
private Path getAssetDir(String prjctCd, String tmplatIdx) {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Asset").resolve(tmplatIdx);
|
||||
}
|
||||
|
||||
private void moveTempToAsset(String prjctCd, String fileName) throws IOException {
|
||||
private Path getAssetDir(String prjctCd, Long tmplatIdx) {
|
||||
return uploadBaseDir.resolve(prjctCd).resolve("Asset").resolve(tmplatIdx.toString());
|
||||
}
|
||||
|
||||
private void copyAssetToAsset(String prjctCd, String fromTmplatIdx, Long toTmplatIdx, String fileName) throws IOException {
|
||||
if (fileName == null || fileName.isBlank()) return;
|
||||
Path fromDir = getAssetDir(prjctCd, fromTmplatIdx);
|
||||
Path toDir = getAssetDir(prjctCd, toTmplatIdx);
|
||||
|
||||
Path src = fromDir.resolve(fileName).normalize();
|
||||
Path dst = toDir.resolve(fileName).normalize();
|
||||
|
||||
Files.createDirectories(toDir);
|
||||
|
||||
if (!Files.exists(src)) {
|
||||
throw new NoSuchFileException("Source asset not found: " + src);
|
||||
}
|
||||
|
||||
Files.copy(src, dst, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
private void moveTempToAsset(String prjctCd, Long tmplatIdx, String fileName) throws IOException {
|
||||
if (fileName == null || fileName.isBlank()) return;
|
||||
|
||||
Path tempDir = getTempDir(prjctCd);
|
||||
Path assetDir = getAssetDir(prjctCd);
|
||||
Path assetDir = getAssetDir(prjctCd, tmplatIdx);
|
||||
Files.createDirectories(assetDir);
|
||||
|
||||
Path source = tempDir.resolve(fileName).normalize();
|
||||
@@ -151,8 +180,8 @@ public class FileService {
|
||||
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
private void cleanupAssetDir(String prjctCd, Set<String> keepFileNames) throws IOException {
|
||||
Path assetDir = getAssetDir(prjctCd);
|
||||
private void cleanupAssetDir(String prjctCd, Long tmplatIdx, Set<String> keepFileNames) throws IOException {
|
||||
Path assetDir = getAssetDir(prjctCd, tmplatIdx);
|
||||
if (!Files.exists(assetDir)) return;
|
||||
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(assetDir)) {
|
||||
|
||||
Reference in New Issue
Block a user