package com.jmal.clouddisk.service.impl;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.PathUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import com.jmal.clouddisk.exception.CommonException;
import com.jmal.clouddisk.exception.ExceptionType;
import com.jmal.clouddisk.interceptor.AuthInterceptor;
import com.jmal.clouddisk.model.*;
import com.jmal.clouddisk.model.rbac.ConsumerDO;
import com.jmal.clouddisk.oss.web.WebOssCommonService;
import com.jmal.clouddisk.oss.web.WebOssCopyFileService;
import com.jmal.clouddisk.oss.web.WebOssService;
import com.jmal.clouddisk.service.Constants;
import com.jmal.clouddisk.service.IFileService;
import com.jmal.clouddisk.service.IFileVersionService;
import com.jmal.clouddisk.service.video.VideoProcessService;
import com.jmal.clouddisk.util.*;
import com.jmal.clouddisk.webdav.MyWebdavServlet;
import com.mongodb.client.AggregateIterable;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.ClientAbortException;
import org.apache.commons.compress.utils.Lists;
import org.apache.tika.mime.MimeType;
import org.apache.tika.mime.MimeTypeException;
import org.apache.tika.mime.MimeTypes;
import org.bson.BsonNull;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import static com.jmal.clouddisk.service.IUserService.USER_ID;
import static com.mongodb.client.model.Accumulators.sum;
import static com.mongodb.client.model.Aggregates.group;
import static com.mongodb.client.model.Aggregates.match;
import static com.mongodb.client.model.Filters.*;
/**
* @author jmal
* @Description 文件管理
* @Author jmal
* @Date 2020-01-14 13:05
*/
@Service
@Slf4j
public class FileServiceImpl extends CommonFileService implements IFileService {
@Autowired
MultipartUpload multipartUpload;
@Autowired
WebOssService webOssService;
@Autowired
WebOssCopyFileService webOssCopyFileService;
@Autowired
VideoProcessService videoProcessService;
@Autowired
IFileVersionService fileVersionService;
/***
* 前端文件夹树的第一级的文件Id
*/
private static final String FIRST_FILE_TREE_ID = "0";
private static final AES aes = SecureUtil.aes();
@Override
public ResponseResult<Object> listFiles(UploadApiParamDTO upload) throws CommonException {
ResponseResult<Object> result = ResultUtil.genResult();
Path path = Paths.get(upload.getUsername(), upload.getCurrentDirectory());
String ossPath = CaffeineUtil.getOssPath(path);
if (ossPath != null) {
return webOssService.searchFileAndOpenOssFolder(path, upload);
}
String currentDirectory = getUserDirectory(upload.getCurrentDirectory());
if (!CharSequenceUtil.isBlank(upload.getFolder()) && checkMountParam(upload, currentDirectory)) {
return listFiles(upload);
}
Criteria criteria;
String queryFileType = upload.getQueryFileType();
if (!CharSequenceUtil.isBlank(queryFileType)) {
criteria = switch (upload.getQueryFileType()) {
case Constants.AUDIO -> Criteria.where(Constants.CONTENT_TYPE).regex("^" + Constants.AUDIO);
case Constants.VIDEO -> Criteria.where(Constants.CONTENT_TYPE).regex("^" + Constants.VIDEO);
case Constants.CONTENT_TYPE_IMAGE -> Criteria.where(Constants.CONTENT_TYPE).regex("^image");
case "text" -> Criteria.where(Constants.SUFFIX).in(Arrays.asList(fileProperties.getSimText()));
case "document" -> Criteria.where(Constants.SUFFIX).in(Arrays.asList(fileProperties.getDocument()));
default -> Criteria.where("path").is(currentDirectory);
};
} else {
criteria = Criteria.where("path").is(currentDirectory);
Boolean isFolder = upload.getIsFolder();
if (isFolder != null) {
criteria = Criteria.where(Constants.IS_FOLDER).is(isFolder);
}
Boolean isFavorite = upload.getIsFavorite();
if (isFavorite != null) {
criteria = Criteria.where(Constants.IS_FAVORITE).is(isFavorite);
}
}
List<FileIntroVO> list = getFileDocuments(upload, criteria);
result.setData(list);
result.setCount(getFileDocumentsCount(upload, criteria));
return result;
}
/**
* 查看是否有挂载文件
* @param upload 上传参数
* @param currentDirectory 当前目录
* @return 是否有挂载文件
*/
private boolean checkMountParam(UploadApiParamDTO upload, String currentDirectory) {
if (!CharSequenceUtil.isBlank(currentDirectory)) {
Path currentDirectoryPath = Paths.get(currentDirectory);
if (currentDirectoryPath.getFileName() == null) {
return false;
}
String fileId = upload.getFolder();
FileDocument fileDocument = getById(fileId);
if (fileDocument != null) {
upload.setUserId(fileDocument.getUserId());
upload.setUsername(userService.getUserNameById(fileDocument.getUserId()));
upload.setCurrentDirectory(fileDocument.getPath() + fileDocument.getName());
upload.setFolder(null);
return true;
}
}
return false;
}
@Override
public long takeUpSpace(String userId) throws CommonException {
return occupiedSpace(userId);
}
/***
* 通过查询条件获取文件数
* @param upload UploadApiParamDTO
* @param criteriaList criteriaList
* @return 文件数
*/
private long getFileDocumentsCount(UploadApiParamDTO upload, Criteria... criteriaList) {
Query query = new Query();
query.addCriteria(Criteria.where(USER_ID).is(upload.getUserId()));
for (Criteria criteria : criteriaList) {
query.addCriteria(criteria);
}
return mongoTemplate.count(query, COLLECTION_NAME);
}
private List<FileIntroVO> getFileDocuments(UploadApiParamDTO upload, Criteria... criteriaList) {
List<FileIntroVO> fileIntroVOList;
Query query = getQuery(upload, criteriaList);
String order = listByPage(upload, query);
if (!CharSequenceUtil.isBlank(order)) {
String sortableProp = upload.getSortableProp();
Sort.Direction direction = Sort.Direction.ASC;
if ("descending".equals(order)) {
direction = Sort.Direction.DESC;
}
query.with(Sort.by(direction, sortableProp));
} else {
没有合适的资源?快使用搜索试试~ 我知道了~
基于springboot的网盘服务端 私有云存储网盘项目,能够简单安全管理您的云端文件+源代码+文档说明
共698个文件
java:224个
ts:108个
js:100个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 147 浏览量
2023-11-28
16:17:44
上传
评论
收藏 21MB ZIP 举报
温馨提示
- ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
资源推荐
资源详情
资源评论
收起资源包目录
基于springboot的网盘服务端 私有云存储网盘项目,能够简单安全管理您的云端文件+源代码+文档说明 (698个子文件)
nginx.conf 10KB
all.min.css 100KB
layui.css 72KB
index.css 42KB
index-2.0.2.css 30KB
katex.min.css 23KB
katex.min.css 22KB
layer.css 14KB
layui.mobile.css 10KB
tango.css 8KB
viewer.min.css 8KB
colorful.css 8KB
pastie.css 8KB
ant-design.css 7KB
laydate.css 7KB
solarized-light.css 7KB
github.css 7KB
murphy.css 7KB
friendly.css 7KB
rainbow_dash.css 7KB
emacs.css 7KB
manni.css 7KB
monokailight.css 7KB
native.css 7KB
lovelace.css 7KB
pygments.css 7KB
trac.css 7KB
perldoc.css 6KB
autumn.css 6KB
xcode.css 6KB
index-2.0.2.css 6KB
abap.css 6KB
arduino.css 6KB
solarized-dark256.css 6KB
paraiso-light.css 6KB
paraiso-dark.css 6KB
borland.css 6KB
dracula.css 6KB
fruity.css 6KB
solarized-dark.css 6KB
bw.css 6KB
vim.css 6KB
swapoff.css 6KB
monokai.css 6KB
algol.css 5KB
rrt.css 5KB
ant-design.css 5KB
algol_nu.css 5KB
vs.css 4KB
igor.css 4KB
wechat.css 3KB
dark.css 3KB
light.css 3KB
prism.css 2KB
code.css 1KB
independent.css 53B
Dockerfile 902B
Dockerfile 151B
iconfont.eot 46KB
huaji.gif 13KB
59.gif 10KB
22.gif 10KB
24.gif 8KB
13.gif 7KB
16.gif 7KB
39.gif 6KB
64.gif 6KB
63.gif 6KB
50.gif 6KB
loading-0.gif 6KB
4.gif 6KB
1.gif 5KB
42.gif 5KB
71.gif 5KB
21.gif 5KB
20.gif 5KB
29.gif 5KB
70.gif 4KB
5.gif 4KB
17.gif 4KB
27.gif 4KB
9.gif 4KB
44.gif 4KB
11.gif 4KB
8.gif 4KB
3.gif 4KB
23.gif 4KB
34.gif 4KB
41.gif 4KB
38.gif 4KB
65.gif 3KB
32.gif 3KB
45.gif 3KB
7.gif 3KB
12.gif 3KB
26.gif 3KB
60.gif 3KB
2.gif 3KB
40.gif 3KB
25.gif 3KB
共 698 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
奋斗奋斗再奋斗的ajie
- 粉丝: 1193
- 资源: 2908
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功