|
@@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.GsonBuilder;
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
|
+import com.lc.ibps.base.web.context.ContextUtil;
|
|
|
import com.onlyoffice.integration.documentserver.callbacks.CallbackHandler;
|
|
import com.onlyoffice.integration.documentserver.callbacks.CallbackHandler;
|
|
|
import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
|
|
import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
|
|
|
import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
|
|
import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
|
|
@@ -52,7 +53,6 @@ import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.ui.Model;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.util.UriComponents;
|
|
import org.springframework.web.util.UriComponents;
|
|
@@ -63,8 +63,6 @@ import java.io.*;
|
|
|
import java.net.InetAddress;
|
|
import java.net.InetAddress;
|
|
|
import java.net.MalformedURLException;
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
|
-import java.net.URLEncoder;
|
|
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.nio.file.FileSystems;
|
|
import java.nio.file.FileSystems;
|
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
@@ -89,6 +87,8 @@ public class FileController {
|
|
|
@Value("${files.docservice.url.command}")
|
|
@Value("${files.docservice.url.command}")
|
|
|
private String docserviceUrlCommand;
|
|
private String docserviceUrlCommand;
|
|
|
|
|
|
|
|
|
|
+ @Value("${files.docservice.url.business}")
|
|
|
|
|
+ private String docserviceUrlBusiness;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private FileUtility fileUtility;
|
|
private FileUtility fileUtility;
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -115,14 +115,10 @@ public class FileController {
|
|
|
private FileConfigurer<DefaultFileWrapper> fileConfigurer;
|
|
private FileConfigurer<DefaultFileWrapper> fileConfigurer;
|
|
|
|
|
|
|
|
// create user metadata
|
|
// create user metadata
|
|
|
- private String createUserMetadata(final String uid, final String fullFileName) {
|
|
|
|
|
- Optional<User> optionalUser = userService.findUserById(Integer.parseInt(uid)); // find a user by their ID
|
|
|
|
|
|
|
+ private String createUserMetadata(final User user, final String fullFileName) {
|
|
|
String documentType = fileUtility.getDocumentType(fullFileName).toString().toLowerCase(); // get document type
|
|
String documentType = fileUtility.getDocumentType(fullFileName).toString().toLowerCase(); // get document type
|
|
|
- if (optionalUser.isPresent()) {
|
|
|
|
|
- User user = optionalUser.get();
|
|
|
|
|
- storageMutator.createMeta(fullFileName, // create meta information with the user ID and name specified
|
|
|
|
|
- String.valueOf(user.getId()), user.getName());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ storageMutator.createMeta(fullFileName, // create meta information with the user ID and name specified
|
|
|
|
|
+ String.valueOf(user.getId()), user.getName());
|
|
|
return "{ \"filename\": \"" + fullFileName + "\", \"documentType\": \"" + documentType + "\" }";
|
|
return "{ \"filename\": \"" + fullFileName + "\", \"documentType\": \"" + documentType + "\" }";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -139,27 +135,6 @@ public class FileController {
|
|
|
.body(resource);
|
|
.body(resource);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private ResponseEntity<Resource> downloadSample(final String fileName) {
|
|
|
|
|
- String serverPath = System.getProperty("user.dir");
|
|
|
|
|
- String contentType = "application/octet-stream";
|
|
|
|
|
- String[] fileLocation = new String[] {serverPath, "src", "main", "resources", "assets", "document-templates",
|
|
|
|
|
- "sample", fileName};
|
|
|
|
|
- Path filePath = Paths.get(String.join(File.separator, fileLocation));
|
|
|
|
|
- Resource resource;
|
|
|
|
|
- try {
|
|
|
|
|
- resource = new UrlResource(filePath.toUri());
|
|
|
|
|
- if (resource.exists()) {
|
|
|
|
|
- return ResponseEntity.ok()
|
|
|
|
|
- .contentType(MediaType.parseMediaType(contentType))
|
|
|
|
|
- .header(HttpHeaders.CONTENT_DISPOSITION,
|
|
|
|
|
- "attachment; filename=\"" + resource.getFilename() + "\"")
|
|
|
|
|
- .body(resource);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (MalformedURLException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
// download data from the specified history file
|
|
// download data from the specified history file
|
|
|
private ResponseEntity<Resource> downloadFileHistory(final String fileName,
|
|
private ResponseEntity<Resource> downloadFileHistory(final String fileName,
|
|
@@ -180,9 +155,10 @@ public class FileController {
|
|
|
|
|
|
|
|
@PostMapping("/upload")
|
|
@PostMapping("/upload")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
- public String upload(@RequestParam("file") final MultipartFile file, // upload a file
|
|
|
|
|
- @CookieValue("uid") final String uid) {
|
|
|
|
|
|
|
+ public String upload(@RequestParam("file") final MultipartFile file) {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ String userId = ContextUtil.getCurrentUserId();
|
|
|
|
|
+
|
|
|
String fullFileName = file.getOriginalFilename(); // get file name
|
|
String fullFileName = file.getOriginalFilename(); // get file name
|
|
|
String fileExtension = fileUtility.getFileExtension(fullFileName); // get file extension
|
|
String fileExtension = fileUtility.getFileExtension(fullFileName); // get file extension
|
|
|
long fileSize = file.getSize(); // get file size
|
|
long fileSize = file.getSize(); // get file size
|
|
@@ -208,7 +184,7 @@ public class FileController {
|
|
|
fullFileName = fileUtility.getFileNameWithoutExtension(fileNamePath)
|
|
fullFileName = fileUtility.getFileNameWithoutExtension(fileNamePath)
|
|
|
+ "." + fileExtension; // get full file name
|
|
+ "." + fileExtension; // get full file name
|
|
|
|
|
|
|
|
- return createUserMetadata(uid, fullFileName); // create user metadata and return it
|
|
|
|
|
|
|
+ return createUserMetadata(userService.getUser(), fullFileName); // create user metadata and return it
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
@@ -219,8 +195,7 @@ public class FileController {
|
|
|
|
|
|
|
|
@PostMapping(path = "${url.converter}")
|
|
@PostMapping(path = "${url.converter}")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
- public String convert(@RequestBody final Converter body, // convert a file
|
|
|
|
|
- @CookieValue("uid") final String uid, @CookieValue("ulang") final String lang) {
|
|
|
|
|
|
|
+ public String convert(@RequestBody final Converter body) {
|
|
|
// get file name
|
|
// get file name
|
|
|
String fileName = body.getFileName();
|
|
String fileName = body.getFileName();
|
|
|
|
|
|
|
@@ -244,7 +219,7 @@ public class FileController {
|
|
|
if (fileUtility.getConvertExts().contains(fileExt)) {
|
|
if (fileUtility.getConvertExts().contains(fileExt)) {
|
|
|
String key = serviceConverter.generateRevisionId(fileUri); // generate document key
|
|
String key = serviceConverter.generateRevisionId(fileUri); // generate document key
|
|
|
ConvertedData response = serviceConverter // get the URL to the converted file
|
|
ConvertedData response = serviceConverter // get the URL to the converted file
|
|
|
- .getConvertedData(fileUri, fileExt, internalFileExt, key, filePass, true, lang);
|
|
|
|
|
|
|
+ .getConvertedData(fileUri, fileExt, internalFileExt, key, filePass, true, "zh");
|
|
|
|
|
|
|
|
String newFileUri = response.getUri();
|
|
String newFileUri = response.getUri();
|
|
|
String newFileType = "." + response.getFileType();
|
|
String newFileType = "." + response.getFileType();
|
|
@@ -276,7 +251,7 @@ public class FileController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// create meta information about the converted file with the user ID and name specified
|
|
// create meta information about the converted file with the user ID and name specified
|
|
|
- return createUserMetadata(uid, fileName);
|
|
|
|
|
|
|
+ return createUserMetadata(userService.getUser(), fileName);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
}
|
|
}
|
|
@@ -288,7 +263,7 @@ public class FileController {
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public String delete(@RequestBody final Converter body) { // delete a file
|
|
public String delete(@RequestBody final Converter body) { // delete a file
|
|
|
try {
|
|
try {
|
|
|
- String fullFileName = fileUtility.getFileName(body.getFileName()); // get full file name
|
|
|
|
|
|
|
+ String fullFileName = body.getFileName(); // get full file name
|
|
|
|
|
|
|
|
// delete a file from the storage and return the status of this operation (true or false)
|
|
// delete a file from the storage and return the status of this operation (true or false)
|
|
|
boolean fileSuccess = storageMutator.deleteFile(fullFileName);
|
|
boolean fileSuccess = storageMutator.deleteFile(fullFileName);
|
|
@@ -329,12 +304,10 @@ public class FileController {
|
|
|
|
|
|
|
|
@GetMapping(path = "${url.download}")
|
|
@GetMapping(path = "${url.download}")
|
|
|
public ResponseEntity<Resource> download(final HttpServletRequest request, // download a file
|
|
public ResponseEntity<Resource> download(final HttpServletRequest request, // download a file
|
|
|
- @RequestParam("fileName") final String fileName,
|
|
|
|
|
- @RequestParam(value = "userAddress", required = false)
|
|
|
|
|
- final String userAddress) {
|
|
|
|
|
|
|
+ @RequestParam("fileName") final String fileName) {
|
|
|
try {
|
|
try {
|
|
|
// check if a token is enabled or not
|
|
// check if a token is enabled or not
|
|
|
- if (jwtManager.tokenEnabled() && userAddress != null && jwtManager.tokenUseForRequest()) {
|
|
|
|
|
|
|
+ if (jwtManager.tokenEnabled() && jwtManager.tokenUseForRequest()) {
|
|
|
String header = request.getHeader(documentJwtHeader == null // get the document JWT header
|
|
String header = request.getHeader(documentJwtHeader == null // get the document JWT header
|
|
|
|| documentJwtHeader.isEmpty() ? "Authorization" : documentJwtHeader);
|
|
|| documentJwtHeader.isEmpty() ? "Authorization" : documentJwtHeader);
|
|
|
if (header != null && !header.isEmpty()) {
|
|
if (header != null && !header.isEmpty()) {
|
|
@@ -359,8 +332,7 @@ public class FileController {
|
|
|
@RequestParam(value = "type", required = false) final String typeParam,
|
|
@RequestParam(value = "type", required = false) final String typeParam,
|
|
|
@RequestParam(value = "actionLink", required = false) final String actionLink,
|
|
@RequestParam(value = "actionLink", required = false) final String actionLink,
|
|
|
@RequestParam(value = "directUrl", required = false,
|
|
@RequestParam(value = "directUrl", required = false,
|
|
|
- defaultValue = "false") final Boolean directUrl,
|
|
|
|
|
- @RequestParam(value = "uid") final String uid) throws JsonProcessingException {
|
|
|
|
|
|
|
+ defaultValue = "false") final Boolean directUrl) throws JsonProcessingException {
|
|
|
com.onlyoffice.integration.documentserver.models.enums.Action action = com.onlyoffice.integration.documentserver.models.enums.Action.edit;
|
|
com.onlyoffice.integration.documentserver.models.enums.Action action = com.onlyoffice.integration.documentserver.models.enums.Action.edit;
|
|
|
Type type = Type.desktop;
|
|
Type type = Type.desktop;
|
|
|
Locale locale = Locale.CHINA;
|
|
Locale locale = Locale.CHINA;
|
|
@@ -372,12 +344,6 @@ public class FileController {
|
|
|
type = Type.valueOf(typeParam);
|
|
type = Type.valueOf(typeParam);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Optional<User> optionalUser = userService.findUserById(Integer.parseInt(uid));
|
|
|
|
|
-
|
|
|
|
|
- User user = optionalUser.get();
|
|
|
|
|
- user.setImage(user.getAvatar() ? storagePathBuilder.getServerUrl(true) + "/css/img/uid-"
|
|
|
|
|
- + user.getId() + ".png" : null);
|
|
|
|
|
-
|
|
|
|
|
// get file model with the default file parameters
|
|
// get file model with the default file parameters
|
|
|
FileModel fileModel = fileConfigurer.getFileModel(
|
|
FileModel fileModel = fileConfigurer.getFileModel(
|
|
|
DefaultFileWrapper
|
|
DefaultFileWrapper
|
|
@@ -386,7 +352,7 @@ public class FileController {
|
|
|
.type(type)
|
|
.type(type)
|
|
|
.lang(locale.toLanguageTag())
|
|
.lang(locale.toLanguageTag())
|
|
|
.action(action)
|
|
.action(action)
|
|
|
- .user(user)
|
|
|
|
|
|
|
+ .user(userService.getUser())
|
|
|
.actionData(actionLink)
|
|
.actionData(actionLink)
|
|
|
.isEnableDirectUrl(directUrl)
|
|
.isEnableDirectUrl(directUrl)
|
|
|
.build()
|
|
.build()
|
|
@@ -395,54 +361,44 @@ public class FileController {
|
|
|
return objectMapper.writeValueAsString(fileModel);
|
|
return objectMapper.writeValueAsString(fileModel);
|
|
|
}
|
|
}
|
|
|
@GetMapping("/create")
|
|
@GetMapping("/create")
|
|
|
- public String create(@RequestParam("fileExt")
|
|
|
|
|
- final String fileExt, // create a sample file of the specified extension
|
|
|
|
|
- @RequestParam(value = "sample", required = false) final Optional<Boolean> isSample,
|
|
|
|
|
- @CookieValue(value = "uid", required = false) final String uid,
|
|
|
|
|
- final Model model) {
|
|
|
|
|
- // specify if the sample data exists or not
|
|
|
|
|
- Boolean sampleData = isSample.isPresent() && isSample.get();
|
|
|
|
|
- if (fileExt != null) {
|
|
|
|
|
- try {
|
|
|
|
|
- Optional<User> user = userService.findUserById(Integer.parseInt(uid)); // find a user by their ID
|
|
|
|
|
- if (!user.isPresent()) {
|
|
|
|
|
- // if the user with the specified ID doesn't exist, an error occurs
|
|
|
|
|
- throw new RuntimeException("Could not fine any user with id = " + uid);
|
|
|
|
|
- }
|
|
|
|
|
- String fileName = documentManager.createDemo(fileExt,
|
|
|
|
|
- sampleData,
|
|
|
|
|
- uid,
|
|
|
|
|
- user.get().getName()); // create a demo document with the sample data
|
|
|
|
|
- if (StringUtils.isBlank(fileName) || fileName == null) {
|
|
|
|
|
- throw new RuntimeException("You must have forgotten to add asset files");
|
|
|
|
|
- }
|
|
|
|
|
- return "redirect:editor?fileName=" + URLEncoder
|
|
|
|
|
- .encode(fileName, "UTF-8"); // redirect the request
|
|
|
|
|
- } catch (Exception ex) {
|
|
|
|
|
- model.addAttribute("error", ex.getMessage());
|
|
|
|
|
- return "error.html";
|
|
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String create(@RequestParam("templateName") final String templateName,
|
|
|
|
|
+ @RequestParam("fileName") final String fileName) throws JsonProcessingException {
|
|
|
|
|
+
|
|
|
|
|
+ User user = userService.getUser();
|
|
|
|
|
+ try {
|
|
|
|
|
+ Resource resource = storageMutator.loadFileAsResource(templateName);
|
|
|
|
|
+
|
|
|
|
|
+ InputStream stream = resource.getInputStream();
|
|
|
|
|
+ if (Integer.parseInt(filesizeMax) < stream.available() || stream.available() <= 0) {
|
|
|
|
|
+ return "{\"error\":\"File size is incorrect\"}";
|
|
|
}
|
|
}
|
|
|
|
|
+ storageMutator.createFile(FileSystems.getDefault().getPath(storagePathBuilder.getFileLocation(fileName)), stream);
|
|
|
|
|
+ createUserMetadata(user, fileName);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
|
|
|
}
|
|
}
|
|
|
- return "redirect:/";
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- @GetMapping("/assets")
|
|
|
|
|
- public ResponseEntity<Resource> assets(@RequestParam("name")
|
|
|
|
|
- final String name) { // get sample files from the assests
|
|
|
|
|
- return downloadSample(name);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ com.onlyoffice.integration.documentserver.models.enums.Action action = com.onlyoffice.integration.documentserver.models.enums.Action.edit;
|
|
|
|
|
+ Type type = Type.desktop;
|
|
|
|
|
+ Locale locale = Locale.CHINA;
|
|
|
|
|
+ // get file model with the default file parameters
|
|
|
|
|
+ FileModel fileModel = fileConfigurer.getFileModel(
|
|
|
|
|
+ DefaultFileWrapper
|
|
|
|
|
+ .builder()
|
|
|
|
|
+ .fileName(fileName)
|
|
|
|
|
+ .type(type)
|
|
|
|
|
+ .lang(locale.toLanguageTag())
|
|
|
|
|
+ .action(action)
|
|
|
|
|
+ .user(user)
|
|
|
|
|
+ .isEnableDirectUrl(false)
|
|
|
|
|
+ .build()
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- @GetMapping("/csv")
|
|
|
|
|
- public ResponseEntity<Resource> csv() { // download a csv file
|
|
|
|
|
- return downloadSample("csv.csv");
|
|
|
|
|
|
|
+ return objectMapper.writeValueAsString(fileModel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @GetMapping("/files")
|
|
|
|
|
- @ResponseBody
|
|
|
|
|
- public ArrayList<Map<String, Object>> files(@RequestParam(value = "fileId", required = false)
|
|
|
|
|
- final String fileId) { // get files information
|
|
|
|
|
- return fileId == null ? documentManager.getFilesInfo() : documentManager.getFilesInfo(fileId);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
@PostMapping(path = "${url.track}")
|
|
@PostMapping(path = "${url.track}")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@@ -475,7 +431,7 @@ public class FileController {
|
|
|
|
|
|
|
|
@PostMapping("/saveas")
|
|
@PostMapping("/saveas")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
- public String saveAs(@RequestBody final SaveAs body, @CookieValue("uid") final String uid) {
|
|
|
|
|
|
|
+ public String saveAs(@RequestBody final SaveAs body) {
|
|
|
try {
|
|
try {
|
|
|
String fileName = documentManager.getCorrectName(body.getTitle());
|
|
String fileName = documentManager.getCorrectName(body.getTitle());
|
|
|
String curExt = fileUtility.getFileExtension(fileName);
|
|
String curExt = fileUtility.getFileExtension(fileName);
|
|
@@ -492,7 +448,7 @@ public class FileController {
|
|
|
return "{\"error\":\"File size is incorrect\"}";
|
|
return "{\"error\":\"File size is incorrect\"}";
|
|
|
}
|
|
}
|
|
|
storageMutator.createFile(FileSystems.getDefault().getPath(storagePathBuilder.getFileLocation(fileName)), stream);
|
|
storageMutator.createFile(FileSystems.getDefault().getPath(storagePathBuilder.getFileLocation(fileName)), stream);
|
|
|
- createUserMetadata(uid, fileName);
|
|
|
|
|
|
|
+ createUserMetadata(userService.getUser(), fileName);
|
|
|
|
|
|
|
|
return "{\"file\": \"" + fileName + "\"}";
|
|
return "{\"file\": \"" + fileName + "\"}";
|
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
@@ -622,7 +578,7 @@ public class FileController {
|
|
|
|
|
|
|
|
@PutMapping("/restore")
|
|
@PutMapping("/restore")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
- public String restore(@RequestBody final Restore body, @CookieValue("uid") final Integer uid) {
|
|
|
|
|
|
|
+ public String restore(@RequestBody final Restore body) {
|
|
|
try {
|
|
try {
|
|
|
String sourceStringFile = storagePathBuilder.getFileLocation(body.getFileName());
|
|
String sourceStringFile = storagePathBuilder.getFileLocation(body.getFileName());
|
|
|
File sourceFile = new File(sourceStringFile);
|
|
File sourceFile = new File(sourceStringFile);
|
|
@@ -650,7 +606,7 @@ public class FileController {
|
|
|
bumpedKeyFileWriter.write(bumpedKey);
|
|
bumpedKeyFileWriter.write(bumpedKey);
|
|
|
bumpedKeyFileWriter.close();
|
|
bumpedKeyFileWriter.close();
|
|
|
|
|
|
|
|
- User user = userService.findUserById(uid).get();
|
|
|
|
|
|
|
+ User user = userService.getUser();
|
|
|
|
|
|
|
|
Path bumpedChangesPathFile = Paths.get(bumpedVersionStringDirectory, "changes.json");
|
|
Path bumpedChangesPathFile = Paths.get(bumpedVersionStringDirectory, "changes.json");
|
|
|
String bumpedChangesStringFile = bumpedChangesPathFile.toString();
|
|
String bumpedChangesStringFile = bumpedChangesPathFile.toString();
|