
--- src/main/java/com/takensoft/cms/bbs/service/Impl/BbsCnServiceImpl.java
+++ src/main/java/com/takensoft/cms/bbs/service/Impl/BbsCnServiceImpl.java
... | ... | @@ -23,6 +23,8 @@ |
23 | 23 |
import org.springframework.web.multipart.MultipartFile; |
24 | 24 |
|
25 | 25 |
import java.io.IOException; |
26 |
+import java.net.URI; |
|
27 |
+import java.net.URISyntaxException; |
|
26 | 28 |
import java.nio.file.Path; |
27 | 29 |
import java.nio.file.Paths; |
28 | 30 |
import java.util.HashMap; |
... | ... | @@ -270,15 +272,17 @@ |
270 | 272 |
if (path.startsWith("file:///")) { |
271 | 273 |
// "file:///" 부분을 제거하고 경로를 반환 |
272 | 274 |
previewPath = path.replace("file:///", "") + fileUploadPath; |
273 |
- } else { |
|
274 |
- previewPath = locationPath + fileUploadPath; |
|
275 | 275 |
} |
276 |
+// else { |
|
277 |
+// previewPath = locationPath + fileUploadPath; |
|
278 |
+// } |
|
276 | 279 |
} |
277 | 280 |
if (filePath == null) return null; |
278 | 281 |
// 서버경로를 절대경로에서 상대경로로 변환 |
279 | 282 |
String basePath = previewPath; // 이 부분은 환경설정 파일에서 가져오는 것이 좋습니다. |
280 | 283 |
String relativePath = filePath.substring(basePath.length()); |
281 |
- return frontUrl + ":" + serverPort + fileUploadPath + relativePath; |
|
284 |
+ return fileUploadPath + relativePath; // 윈도우 상대 경로 |
|
285 |
+// return frontUrl + ":" + serverPort + fileUploadPath + relativePath; |
|
282 | 286 |
} |
283 | 287 |
|
284 | 288 |
/** |
... | ... | @@ -462,13 +466,44 @@ |
462 | 466 |
*/ |
463 | 467 |
private String vdoUrlCheck(String vdoUrl) { |
464 | 468 |
// youtube 링크가 있을 경우 |
465 |
- if (vdoUrl.contains("youtube.com") || vdoUrl.contains("youtu.be")) { |
|
466 |
- String[] url = vdoUrl.split("/"); |
|
467 |
- String videoId = url[url.length - 1]; |
|
468 |
- String videoUrl = "https://www.youtube.com/embed/" + videoId; |
|
469 |
+// if (vdoUrl.contains("youtube.com") || vdoUrl.contains("youtu.be")) { |
|
470 |
+// String[] url = vdoUrl.split("/"); |
|
471 |
+// String videoId = url[url.length - 1]; |
|
472 |
+// String videoUrl = "https://www.youtube.com/embed/" + videoId; |
|
473 |
+// return videoUrl; |
|
474 |
+// } else { |
|
475 |
+// return vdoUrl; |
|
476 |
+// } |
|
477 |
+ try { |
|
478 |
+ URI uri = new URI(vdoUrl); |
|
479 |
+ String host = uri.getHost(); |
|
480 |
+ String path = uri.getPath(); |
|
481 |
+ |
|
482 |
+ if (host == null) return vdoUrl; |
|
483 |
+ |
|
484 |
+ String videoUrl = "https://www.youtube.com/embed/"; |
|
485 |
+ |
|
486 |
+ if (host.contains("youtu.be")) { |
|
487 |
+ videoUrl += path.substring(1); |
|
488 |
+ } |
|
489 |
+ |
|
490 |
+ if (host.contains("youtube.com") || host.contains("m.youtube.com")) { |
|
491 |
+ String query = uri.getQuery(); |
|
492 |
+ if (query != null) { |
|
493 |
+ for (String param : query.split("&")) { |
|
494 |
+ if (param.startsWith("v=")) { |
|
495 |
+ videoUrl += param.substring(2); |
|
496 |
+ } |
|
497 |
+ } |
|
498 |
+ } |
|
499 |
+ |
|
500 |
+ if (path.contains("/embed/")) { |
|
501 |
+ videoUrl += path.substring(path.lastIndexOf("/embed/") + 7); |
|
502 |
+ } |
|
503 |
+ } |
|
469 | 504 |
return videoUrl; |
470 |
- } else { |
|
471 |
- return vdoUrl; |
|
505 |
+ } catch (URISyntaxException e) { |
|
506 |
+ throw new RuntimeException(e); |
|
472 | 507 |
} |
473 | 508 |
} |
474 | 509 |
|
--- src/main/java/com/takensoft/common/file/service/Impl/FileServiceImpl.java
+++ src/main/java/com/takensoft/common/file/service/Impl/FileServiceImpl.java
... | ... | @@ -288,7 +288,17 @@ |
288 | 288 |
String maskNm = UUID.randomUUID() + ext; // 랜덤으로 파일명 생성 |
289 | 289 |
// 파일 저장 경로 |
290 | 290 |
String uploadPath = null; |
291 |
- uploadPath = "/home/cloud-user/front-end/uploadFiles" + editPath; |
|
291 |
+ // 1. 윈도우 환경 |
|
292 |
+ String[] pathArray = locationPath.split("/, "); |
|
293 |
+ for (String path : pathArray) { |
|
294 |
+ if (path.startsWith("file:///")) { |
|
295 |
+ // "file:///" 부분을 제거하고 경로를 반환 |
|
296 |
+ uploadPath = path.replace("file:///", "") + editPath; |
|
297 |
+ break; // 루프를 종료하여 첫 번째 일치하는 경로만 사용 |
|
298 |
+ } |
|
299 |
+ } |
|
300 |
+ // 2. 리눅스 환경 |
|
301 |
+// uploadPath = "/home/cloud-user/front-end/uploadFiles" + editPath; |
|
292 | 302 |
String savePath = uploadPath + maskNm; |
293 | 303 |
// 파일 저장 |
294 | 304 |
try { |
... | ... | @@ -300,7 +310,8 @@ |
300 | 310 |
} catch (IOException ioe) { |
301 | 311 |
throw new CustomFileUploadFailException("파일 업로드에 실패했습니다.", ioe); |
302 | 312 |
} |
303 |
- String imgPath = frontUrl + "/uploadFiles" + editPath + maskNm; |
|
313 |
+ String imgPath = editPath + maskNm; // 윈도우 상대 경로 경로 |
|
314 |
+// String imgPath = frontUrl + "/uploadFiles" + editPath + maskNm; // 리눅스 경로 |
|
304 | 315 |
return imgPath; |
305 | 316 |
} catch (DataAccessException dae) { |
306 | 317 |
throw dae; |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?