From beb5fd2e15580feb70e2494a8318f8c563c69d58 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Fri, 18 Mar 2022 12:14:55 +0400 Subject: [PATCH] fix image upload --- data/db.mv.db | Bin 57344 -> 0 bytes src/main/java/ru/ulstu/news/NewsService.java | 9 ++++++--- src/main/resources/templates/editNews.html | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) delete mode 100644 data/db.mv.db diff --git a/data/db.mv.db b/data/db.mv.db deleted file mode 100644 index 52ce82b99f5670716827ca5ffb5182b47bb39a90..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 57344 zcmeHwdvqk#d1p)Lf-{4F8DN+h7%0SGW`eBL`ypVVo-<-J(u|~eVT`EmF3q$fspVGp zgv}p&z{Vko@nhGqcak{gEGN#x-jicsmjK2ve&sk$Aa3C`*~G_>#OsZ-IR>)!CSGUP z?C;)N)m`0EKX}EEEe+i2TXpNZ-~GPte)qe#s(yF>xICI)EEj%$+~UXC(l18ik|>I! zg;TZVpC6ax2tOC2aCuxBEmWeg8WqPSV?htia3RvI(S>qlDXik+>8P?=Dx(;^V_`9> z7EVQ#am&<-rdB9y%4L6<1TqO^638TwNg$IzCV@->nFKNkWD>|EkVznuz)wj6`?LA~ zPf7AwwV4Dm31kw;B#=oUlRzecOahq%G6`f7$RvSH#if=&mZ>5m*UNMypsesFcgqaW!ug@TPz$Dx#{4R!d9KxFTt$7>R1? zZ2*v7DJ{F@+H!SV6kg*$`dY!>twwHOAUE{rXLGsnkK%YsZtF9b?ASZJ94vsZ?Y+g{3M>wR7neEk5WxXYhl`4;DX! z{E+8|0zX9ju)t{XyLFLec=1qU8Gch!Hdvb52~(&^|R6s0M$ z$TEkRnxuS-8Z}Fc^$3md0>y?RRj5&t45N@%WN|?qtu5D9qoQ3s+IYRASWIiTn9}Zl zY_b@|ESj-BB`l`-6I4 z^=fvuwp=VvmQRi)ue>xHUx?0UC8}Y5F&Yy$v&>>Se=uBW{GN#xu1poO;`e3}B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?11RX~Yde8%%>N^??MX>`{@=v^$5g&;<2bhJv+mJI z>kfb*{(9{INaz1oZ_P3M|Htr~;{VfQ8~*=;Z#w+{N{0Ur{C_jU|4(nTwh>5vjGxyE zw%-*>G{gS~%6PnwL5BaIMq17G|KocvX7m5neIc{?e>VSb+bT4h|FhVi0r+P7|FPL( zw*TKNn=5Y!NKS=R0+0 z`2UTqUN_t`qRSov8U8;u$xZO?*KeMj;s4X!;r~VA|6kr8{=b;v|6erlFAM*FZ+HCv z^Ulri|1+t`7u_OL}*ct!-Uf2~F^&I!e}?~0QS2qUqdU>B?_xs%;WPaI9%!a)Ak6Up8#{4Oqsj39 zGyMMy|3Ab3PoiUfTpuIDRb=@8J>YcN_>$rOw{Bqu!^!afGyMOq`2SyG`2SesWBC6# zzFhqOdo%q1#_l*7{(rKqMuz{NY=e^F|0kRFzG3nIU&`?R8@vBz`2WeqR~i0)vNdUj z|DS9T{Tkx`Z)51F2)G#jKaN}LzqSE7>iFSjThLL9O-R(J`E%iokN^J%OT+~fb$nqR)(r!FUWawlg#G8+08s3k+H!3*Dz*UZFQftXizz^y6i8|l1c
    ;B14wd!qz4jx zlH87;f+UyW|K}3?zZCvn6aNn<8~A^wtZ3LCS$d7}|Nb8m C(Z99; diff --git a/src/main/java/ru/ulstu/news/NewsService.java b/src/main/java/ru/ulstu/news/NewsService.java index b108a3a..8c3d016 100644 --- a/src/main/java/ru/ulstu/news/NewsService.java +++ b/src/main/java/ru/ulstu/news/NewsService.java @@ -39,15 +39,18 @@ public class NewsService { public void save(News news) throws IOException { String fileName = System.currentTimeMillis() + ""; - news.setImageFileName(fileName); + if (!news.getImageFile().isEmpty()) { + news.setImageFileName(fileName); + FileUtil.saveFile(FileSystemStorageService.UPLOAD_DIR, fileName, news.getImageFile()); + } else { + news.setImageFileName(news.getImageFileName().isEmpty() ? "logo.png" : news.getImageFileName()); + } if (news.getId() != null && (news.getId() != 0)) { newsRepository.save(news); } else { create(news); } - - FileUtil.saveFile(FileSystemStorageService.UPLOAD_DIR, fileName, news.getImageFile()); } public News getById(@NotNull Integer id) { diff --git a/src/main/resources/templates/editNews.html b/src/main/resources/templates/editNews.html index d448036..3a4eade 100644 --- a/src/main/resources/templates/editNews.html +++ b/src/main/resources/templates/editNews.html @@ -14,6 +14,7 @@ +