fix:에디터 그림넣기 적용완료

TaehunPark 2022-11-15 14:40:10 +09:00
parent ae96b9da6a
commit 02e6f71607
4 changed files with 47 additions and 72 deletions

View File

@ -33,6 +33,9 @@ dependencies {
implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16'
runtimeOnly 'org.postgresql:postgresql:42.3.6'
implementation 'com.oracle.database.jdbc:ojdbc8:21.7.0.0'
// json
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
//

View File

@ -12,63 +12,62 @@ import com.dbnt.faisp.util.Utils;
import lombok.RequiredArgsConstructor;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.ui.Model;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@RestController
@RequiredArgsConstructor
public class EditorController {
private final CodeMgtService codeMgtService;
private final OrganConfigService organConfigService;
private final MenuMgtService menuMgtService;
private final UserInfoService userInfoService;
SimpleDateFormat sDate = new SimpleDateFormat("yyyyMM");
// 현재년월
String year = sDate.format(new Date()) + "/";
@Value("${site.domain}")
protected String siteDomain;
@Value("${file.dir}")
protected String fileDir;
@Value("${file.dir.editor}")
protected String editorPath;
@Autowired
private Environment env;
@Value("${editor.img.view}")
protected String imgView;
@PostMapping("/Crosseditor/uploadImg")
@ResponseBody
public ParamMap uploadImg(Model model, HttpServletRequest request, HttpServletResponse response, HttpSession session) {
ParamMap result = new ParamMap();
public @ResponseBody JSONObject uploadImg(Model model, HttpServletRequest request, HttpServletResponse response, HttpSession session) {
JSONObject jsonObject = new JSONObject();
JSONObject data = new JSONObject();
JSONArray req_array = new JSONArray();
try {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)request;
MultipartFile mFile = multipartRequest.getFile("imageFile");
if(!"".equals(mFile.getOriginalFilename())){
long attach_file_Size = mFile.getSize();
String attach_file_Name = mFile.getOriginalFilename();
String attach_save_Name = Utils.generationSaveName();
String imageKind = request.getParameter("imageKind");
String editorFrame = request.getParameter("editorFrame");
//파일 타입
String extNm = "." + attach_file_Name.substring( attach_file_Name.lastIndexOf( "." ) + 1, attach_file_Name.length());
@ -93,70 +92,35 @@ public class EditorController {
System.out.println("Directory already exists");
}
File file = new File(fileDir+File.separator+editorPath, attach_save_Name + extNm);
File file = new File(fileDir+File.separator+editorPath, attach_save_Name + extNm);
FileCopyUtils.copy(mFile.getBytes(), file);
String webPath = "http://localhost:8080/file/editorFileDisplay?fileNm=" + attach_save_Name + extNm;
result.set("result", "success");
List<ParamMap> addmsg = new ArrayList<>();
ParamMap imgInfo = new ParamMap();
imgInfo.set("imageURL", webPath);
imgInfo.set("imageTitle", "");
imgInfo.set("imageAlt", "");
imgInfo.set("imageWidth", "");
imgInfo.set("imageWidthUnit", "px");
imgInfo.set("imageHeight", "");
imgInfo.set("imageHeightUnit", "");
imgInfo.set("imageSize", attach_file_Size);
imgInfo.set("imageMarginLeft", "");
imgInfo.set("imageMarginLeftUnit", "px");
imgInfo.set("imageMarginRight", "");
imgInfo.set("imageMarginRightUnit", "px");
imgInfo.set("imageMarginTop", "");
imgInfo.set("imageMarginTopUnit", "px");
imgInfo.set("imageMarginBottom", "");
imgInfo.set("imageMarginBottomUnit", "px");
imgInfo.set("imageAlign", "imageAlign");
imgInfo.set("imageId", "");
imgInfo.set("imageClass", "");
imgInfo.set("imageBorder", 0);
imgInfo.set("imageKind", "image");
imgInfo.set("imageOrgPath", attach_save_Name + extNm+"|"+webPath);
imgInfo.set("imageOrgWidth", 1893);
imgInfo.set("imageOrgHeight", 857);
imgInfo.set("editorFrame", "NamoSE_editorframe_crosseditor4");
addmsg.add(imgInfo);
result.set("addmsg", addmsg);
String webPath = siteDomain+ imgView + attach_save_Name + extNm;
jsonObject.put("result","success");
data.put("imageURL",webPath);
data.put("imageKind", imageKind);
data.put("editorFrame", editorFrame);
req_array.add(data);
jsonObject.put("addmsg", req_array);
} else {
result.set("uploaded", 0);
ParamMap error = new ParamMap();
error.set("message", "Check File Extentions.");
result.set("error", error);
}
} else {
result.set("uploaded", 0);
ParamMap error = new ParamMap();
error.set("message", "Check File Extentions.");
result.set("error", error);
}
} catch (Exception e) {
result.set("uploaded", 0);
ParamMap error = new ParamMap();
error.set("message", "Check File Extentions.");
result.set("error", error);
}
return result;
return jsonObject;
}
private String getCurrentProfile() {
String[] profiles = env.getActiveProfiles();
if( profiles.length == 0 ) profiles = env.getDefaultProfiles();
return profiles[0];
}
}

View File

@ -6,6 +6,8 @@ spring.servlet.multipart.location=C:\\faispUploadFiles
spring.servlet.multipart.max-file-size=200MB
spring.servlet.multipart.max-request-size=500MB
site.domain=http://localhost:8080
#file
file.dir=C:\\faispUploadFiles
file.dir.vulnerable=/vulnerable
@ -15,6 +17,8 @@ file.dir.sailor=sailor
file.dir.affair=affair
file.dir.editor=editor
editor.img.view=/file/editorFileDisplay?fileNm=
#thymeleaf
spring.thymeleaf.prefix=classpath:templates/

View File

@ -5,6 +5,8 @@ spring.servlet.multipart.location=/uploadFiles
spring.servlet.multipart.max-file-size=200MB
spring.servlet.multipart.max-request-size=500MB
site.domain=http://118.219.150.34:50580
#file
file.dir=/uploadFiles
file.dir.vulnerable=/vulnerable
@ -14,6 +16,8 @@ file.dir.sailor=sailor
file.dir.affair=affair
file.dir.editor=editor
editor.img.view=/file/editorFileDisplay?fileNm=
#thymeleaf
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.check-template-location=true