Search in sources :

Example 6 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class FileController method createFile.

@Operation(summary = "创建文件", description = "目录(文件夹)的创建", tags = { "file" })
@RequestMapping(value = "/createfile", method = RequestMethod.POST)
@MyLog(operation = "创建文件", module = CURRENT_MODULE)
@ResponseBody
public RestResult<String> createFile(@Valid @RequestBody CreateFileDTO createFileDto) {
    JwtUser sessionUserBean = SessionUtil.getSession();
    boolean isDirExist = userFileService.isDirExist(createFileDto.getFileName(), createFileDto.getFilePath(), sessionUserBean.getUserId());
    if (isDirExist) {
        return RestResult.fail().message("同名文件已存在");
    }
    UserFile userFile = new UserFile();
    userFile.setUserId(sessionUserBean.getUserId());
    userFile.setFileName(createFileDto.getFileName());
    userFile.setFilePath(createFileDto.getFilePath());
    userFile.setDeleteFlag(0);
    userFile.setIsDir(1);
    userFile.setUploadTime(DateUtil.getCurrentTime());
    userFileService.save(userFile);
    fileDealComp.uploadESByUserFileId(userFile.getUserFileId());
    return RestResult.success();
}
Also used : UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 7 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class FileController method renameFile.

@Operation(summary = "文件重命名", description = "文件重命名", tags = { "file" })
@RequestMapping(value = "/renamefile", method = RequestMethod.POST)
@MyLog(operation = "文件重命名", module = CURRENT_MODULE)
@ResponseBody
public RestResult<String> renameFile(@RequestBody RenameFileDTO renameFileDto) {
    JwtUser sessionUserBean = SessionUtil.getSession();
    UserFile userFile = userFileService.getById(renameFileDto.getUserFileId());
    List<UserFile> userFiles = userFileService.selectUserFileByNameAndPath(renameFileDto.getFileName(), userFile.getFilePath(), sessionUserBean.getUserId());
    if (userFiles != null && !userFiles.isEmpty()) {
        return RestResult.fail().message("同名文件已存在");
    }
    LambdaUpdateWrapper<UserFile> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
    lambdaUpdateWrapper.set(UserFile::getFileName, renameFileDto.getFileName()).set(UserFile::getUploadTime, DateUtil.getCurrentTime()).eq(UserFile::getUserFileId, renameFileDto.getUserFileId());
    userFileService.update(lambdaUpdateWrapper);
    if (1 == userFile.getIsDir()) {
        List<UserFile> list = userFileService.selectFileListLikeRightFilePath(userFile.getFilePath() + userFile.getFileName() + "/", sessionUserBean.getUserId());
        for (UserFile newUserFile : list) {
            newUserFile.setFilePath(newUserFile.getFilePath().replaceFirst(userFile.getFilePath() + userFile.getFileName() + "/", userFile.getFilePath() + renameFileDto.getFileName() + "/"));
            userFileService.updateById(newUserFile);
        }
    }
    fileDealComp.uploadESByUserFileId(renameFileDto.getUserFileId());
    return RestResult.success();
}
Also used : LambdaUpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper) UserFile(com.qiwenshare.file.domain.UserFile) JwtUser(com.qiwenshare.common.util.security.JwtUser) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 8 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class FiletransferController method downloadFile.

@Operation(summary = "下载文件", description = "下载文件接口", tags = { "filetransfer" })
@MyLog(operation = "下载文件", module = CURRENT_MODULE)
@RequestMapping(value = "/downloadfile", method = RequestMethod.GET)
public void downloadFile(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, DownloadFileDTO downloadFileDTO) {
    Cookie[] cookieArr = httpServletRequest.getCookies();
    String token = "";
    if (cookieArr != null) {
        for (Cookie cookie : cookieArr) {
            if ("token".equals(cookie.getName())) {
                token = cookie.getValue();
            }
        }
    }
    boolean authResult = fileDealComp.checkAuthDownloadAndPreview(downloadFileDTO.getShareBatchNum(), downloadFileDTO.getExtractionCode(), token, downloadFileDTO.getUserFileId(), null);
    if (!authResult) {
        log.error("没有权限下载!!!");
        return;
    }
    // 设置强制下载不打开
    httpServletResponse.setContentType("application/force-download");
    UserFile userFile = userFileService.getById(downloadFileDTO.getUserFileId());
    String fileName = "";
    if (userFile.getIsDir() == 1) {
        fileName = userFile.getFileName() + ".zip";
    } else {
        fileName = userFile.getFileName() + "." + userFile.getExtendName();
    }
    try {
        fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    // 设置文件名
    httpServletResponse.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
    filetransferService.downloadFile(httpServletResponse, downloadFileDTO);
}
Also used : Cookie(javax.servlet.http.Cookie) UserFile(com.qiwenshare.file.domain.UserFile) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Operation(io.swagger.v3.oas.annotations.Operation) MyLog(com.qiwenshare.common.anno.MyLog)

Example 9 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class FiletransferController method preview.

@Operation(summary = "预览文件", description = "用于文件预览", tags = { "filetransfer" })
@GetMapping("/preview")
public void preview(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, PreviewDTO previewDTO) {
    if (previewDTO.getPlatform() != null && previewDTO.getPlatform() == 2) {
        filetransferService.previewPictureFile(httpServletResponse, previewDTO);
        return;
    }
    String token = "";
    if (StringUtils.isNotEmpty(previewDTO.getToken())) {
        token = previewDTO.getToken();
    } else {
        Cookie[] cookieArr = httpServletRequest.getCookies();
        for (Cookie cookie : cookieArr) {
            if ("token".equals(cookie.getName())) {
                token = cookie.getValue();
            }
        }
    }
    UserFile userFile = userFileService.getById(previewDTO.getUserFileId());
    boolean authResult = fileDealComp.checkAuthDownloadAndPreview(previewDTO.getShareBatchNum(), previewDTO.getExtractionCode(), token, previewDTO.getUserFileId(), previewDTO.getPlatform());
    if (!authResult) {
        log.error("没有权限预览!!!");
        return;
    }
    FileBean fileBean = fileService.getById(userFile.getFileId());
    String mime = MimeUtils.getMime(userFile.getExtendName());
    httpServletResponse.setHeader("Content-Type", mime);
    // 如果是video标签发起的请求就不会为null
    String rangeString = httpServletRequest.getHeader("Range");
    if (StringUtils.isNotEmpty(rangeString)) {
        long range = Long.valueOf(rangeString.substring(rangeString.indexOf("=") + 1, rangeString.indexOf("-")));
        httpServletResponse.setContentLength(Math.toIntExact(fileBean.getFileSize()));
        httpServletResponse.setHeader("Content-Range", String.valueOf(range + (Math.toIntExact(fileBean.getFileSize()) - 1)));
    }
    httpServletResponse.setHeader("Accept-Ranges", "bytes");
    String fileName = userFile.getFileName() + "." + userFile.getExtendName();
    try {
        fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    // 设置文件名
    httpServletResponse.addHeader("Content-Disposition", "fileName=" + fileName);
    filetransferService.previewFile(httpServletResponse, previewDTO);
}
Also used : Cookie(javax.servlet.http.Cookie) UserFile(com.qiwenshare.file.domain.UserFile) FileBean(com.qiwenshare.file.domain.FileBean) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Operation(io.swagger.v3.oas.annotations.Operation)

Example 10 with UserFile

use of com.qiwenshare.file.domain.UserFile in project qiwen-file by qiwenshare.

the class OfficeController method editOfficeFile.

@Operation(summary = "编辑office文件", description = "编辑office文件", tags = { "office" })
@ResponseBody
@RequestMapping(value = "/editofficefile", method = RequestMethod.POST)
public RestResult<Object> editOfficeFile(HttpServletRequest request, @RequestBody EditOfficeFileDTO editOfficeFileDTO, @RequestHeader("token") String token) {
    RestResult<Object> result = new RestResult<>();
    log.info("editOfficeFile");
    try {
        JwtUser loginUser = SessionUtil.getSession();
        UserFile userFile = userFileService.getById(editOfficeFileDTO.getUserFileId());
        String baseUrl = request.getScheme() + "://" + deploymentHost + ":" + port + request.getContextPath();
        log.info("回调地址baseUrl:" + baseUrl);
        FileModel file = new FileModel(userFile.getFileName() + "." + userFile.getExtendName(), editOfficeFileDTO.getPreviewUrl(), userFile.getUploadTime(), String.valueOf(loginUser.getUserId()), loginUser.getUsername(), "edit");
        file.changeType(request.getParameter("mode"), "edit");
        String query = "?type=edit&userFileId=" + userFile.getUserFileId() + "&token=" + token;
        file.editorConfig.callbackUrl = baseUrl + "/office/IndexServlet" + query;
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("file", file);
        jsonObject.put("docserviceApiUrl", ConfigManager.GetProperty("files.docservice.url.site") + ConfigManager.GetProperty("files.docservice.url.api"));
        jsonObject.put("reportName", userFile.getFileName());
        result.setData(jsonObject);
        result.setCode(200);
        result.setMessage("编辑报告成功!");
    } catch (Exception e) {
        log.error(e.getMessage());
        result.setCode(500);
        result.setMessage("服务器错误!");
    }
    return result;
}
Also used : FileModel(com.qiwenshare.file.util.FileModel) RestResult(com.qiwenshare.common.result.RestResult) JSONObject(com.alibaba.fastjson.JSONObject) UserFile(com.qiwenshare.file.domain.UserFile) JSONObject(com.alibaba.fastjson.JSONObject) JwtUser(com.qiwenshare.common.util.security.JwtUser) IOException(java.io.IOException) NotLoginException(com.qiwenshare.common.exception.NotLoginException) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

UserFile (com.qiwenshare.file.domain.UserFile)26 Operation (io.swagger.v3.oas.annotations.Operation)15 JwtUser (com.qiwenshare.common.util.security.JwtUser)14 MyLog (com.qiwenshare.common.anno.MyLog)8 IOException (java.io.IOException)8 FileBean (com.qiwenshare.file.domain.FileBean)7 LambdaUpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper)5 RestResult (com.qiwenshare.common.result.RestResult)5 JSONObject (com.alibaba.fastjson.JSONObject)4 NotLoginException (com.qiwenshare.common.exception.NotLoginException)4 FileListVo (com.qiwenshare.file.vo.file.FileListVo)4 IPage (com.baomidou.mybatisplus.core.metadata.IPage)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 QiwenException (com.qiwenshare.common.exception.QiwenException)3 DownloadFile (com.qiwenshare.ufop.operation.download.domain.DownloadFile)3 FileInputStream (java.io.FileInputStream)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 RecoveryFile (com.qiwenshare.file.domain.RecoveryFile)2 ShareFile (com.qiwenshare.file.domain.ShareFile)2 FileModel (com.qiwenshare.file.util.FileModel)2