Skip to content

Commit

Permalink
Merge pull request #131 from jamebal/develop
Browse files Browse the repository at this point in the history
perf: 删除逻辑,删除时可选永久删除
  • Loading branch information
jamebal authored Jul 9, 2024
2 parents d2bae62 + 9d4baae commit 209268c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jmal.clouddisk.controller.rest;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.URLUtil;
import com.jmal.clouddisk.annotation.LogOperatingFun;
import com.jmal.clouddisk.annotation.Permission;
Expand Down Expand Up @@ -320,10 +321,10 @@ public ResponseResult<Object> unFavorite(@RequestParam String[] fileIds) {
@DeleteMapping("/delete")
@LogOperatingFun
@Permission("cloud:file:delete")
public ResponseResult<Object> delete(@RequestParam String username, @RequestParam String[] fileIds, @RequestParam String currentDirectory) {
public ResponseResult<Object> delete(@RequestParam String username, @RequestParam String[] fileIds, @RequestParam String currentDirectory, Boolean sweep) {
if (fileIds != null && fileIds.length > 0) {
List<String> list = Arrays.asList(fileIds);
return fileService.delete(username, currentDirectory, list, userLoginHolder.getUsername(), false);
return fileService.delete(username, currentDirectory, list, userLoginHolder.getUsername(), BooleanUtil.isTrue(sweep), true);
} else {
throw new CommonException(ExceptionType.MISSING_PARAMETERS.getCode(), ExceptionType.MISSING_PARAMETERS.getMsg());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jmal/clouddisk/service/IFileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public interface IFileService {
* @param sweep 是否彻底删除
* @return ResponseResult<Object>
*/
ResponseResult<Object> delete(String username, String currentDirectory, List<String> fileIds, String operator, boolean sweep);
ResponseResult<Object> delete(String username, String currentDirectory, List<String> fileIds, String operator, boolean sweep, boolean notify);

/**
* 显示缩略图
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public String createFile(String username, File file, String userId, Boolean isPu
if (lock != null) {
lock.lock();
}
UpdateResult updateResult;
UpdateResult updateResult = null;
ObjectId objectId = new ObjectId();
String fileId = objectId.toHexString();
try {
Expand Down Expand Up @@ -364,18 +364,32 @@ public String createFile(String username, File file, String userId, Boolean isPu
pushMessage(username, update.getUpdateObject(), Constants.CREATE_FILE);
// 添加文件索引
luceneService.pushCreateIndexQueue(fileId);
// 判断回收站是否存在该文件, 如果存在则删除
checkTrash(file, username);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
if (lock != null) {
lock.unlock();
uploadFileLockCache.invalidate(fileAbsolutePath);
}
}
if (null != updateResult.getUpsertedId()) {
if (updateResult != null && null != updateResult.getUpsertedId()) {
return updateResult.getUpsertedId().asObjectId().getValue().toHexString();
}
return fileId;
}

private void checkTrash(File file, String username) {
String userId = userService.getUserIdByUserName(username);
String relativePath = getRelativePath(username, String.valueOf(file.getAbsoluteFile()), file.getName());
Query query = new Query();
query.addCriteria(Criteria.where(IUserService.USER_ID).is(userId));
query.addCriteria(Criteria.where("path").is(relativePath));
query.addCriteria(Criteria.where("name").is(file.getName()));
mongoTemplate.remove(query, TRASH_COLLECTION_NAME);
}

private void updateOtherInfo(FileDocument fileExists, String contentType, Update update) {
if (!contentType.equals(fileExists.getContentType())) {
update.set(Constants.CONTENT_TYPE, contentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ public ResponseResult<Object> move(UploadApiParamDTO upload, List<String> froms,
getCopyResult(upload, froms, to, true);
String currentDirectory = getOssFileCurrentDirectory(upload, froms);
// 删除
delete(upload.getUsername(), currentDirectory, froms, upload.getUsername(), true);
delete(upload.getUsername(), currentDirectory, froms, upload.getUsername(), true, false);
} catch (CommonException e) {
pushMessageOperationFileError(upload.getUsername(), Convert.toStr(e.getMsg(), Constants.UNKNOWN_ERROR), "移动");
} catch (Exception e) {
Expand Down Expand Up @@ -1855,7 +1855,7 @@ public ResponseResult<Object> unFavorite(List<String> fileIds) {
}

@Override
public ResponseResult<Object> delete(String username, String currentDirectory, List<String> fileIds, String operator, boolean sweep) {
public ResponseResult<Object> delete(String username, String currentDirectory, List<String> fileIds, String operator, boolean sweep, boolean notify) {
FileDocument doc = getById(fileIds.get(0));
List<OperationPermission> operationPermissionList = null;
if (doc != null) {
Expand Down Expand Up @@ -1918,7 +1918,7 @@ public ResponseResult<Object> delete(String username, String currentDirectory, L
} else {
operationTips.setSuccess(false);
}
if (!sweep) {
if (notify) {
pushMessage(username, operationTips, Constants.OPERATION_TIPS);
}
return ResultUtil.success();
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/jmal/clouddisk/video/FFMPEGCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class FFMPEGCommand {
/**
* 缩略图宽度
*/
static final int thumbnailWidth = 128;

static final int thumbnailWidth = 192;
/**
* 获取视频的分辨率和码率信息
*
Expand Down Expand Up @@ -213,6 +212,10 @@ static ProcessBuilder useNvencCuda(String fileId, Path fileAbsolutePath, int bit
"-hwaccel_output_format", "cuda",
"-threads", "1",
"-i", fileAbsolutePath.toString(),
"-autoscale", "0",
"-map_metadata", "-1",
"-map_chapters", "-1",
"-autorotate", "0",
"-threads", "0",
"-map", "0:0",
"-map", "0:1",
Expand Down

0 comments on commit 209268c

Please sign in to comment.