feat: adding some feature
This commit is contained in:
parent
f83b89ea00
commit
137ad6b8c3
@ -1,3 +1,5 @@
|
||||
import java.net.URI
|
||||
|
||||
plugins {
|
||||
java
|
||||
id("org.springframework.boot") version "3.3.4"
|
||||
@ -23,6 +25,7 @@ configurations {
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = URI("https://oss.sonatype.org/content/repositories/snapshots") }
|
||||
}
|
||||
|
||||
extra["snippetsDir"] = file("build/generated-snippets")
|
||||
@ -39,12 +42,14 @@ dependencies {
|
||||
// https://mvnrepository.com/artifact/com.mybatis-flex/mybatis-flex-spring-boot3-starter
|
||||
implementation("com.mybatis-flex:mybatis-flex-spring-boot3-starter:1.9.7")
|
||||
annotationProcessor("com.mybatis-flex:mybatis-flex-processor:1.9.7")
|
||||
compileOnly("org.mybatis.spring.native:mybatis-spring-native-extensions:0.1.0-SNAPSHOT")
|
||||
compileOnly("org.mybatis.spring.native:mybatis-spring-native-core:0.1.0-SNAPSHOT")
|
||||
// https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2
|
||||
implementation("com.alibaba.fastjson2:fastjson2:2.0.53")
|
||||
implementation("com.alibaba.fastjson2:fastjson2:2.0.46")
|
||||
// https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2-extension
|
||||
implementation("com.alibaba.fastjson2:fastjson2-extension:2.0.53")
|
||||
implementation("com.alibaba.fastjson2:fastjson2-extension:2.0.46")
|
||||
// https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2-extension-spring6
|
||||
implementation("com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.53")
|
||||
implementation("com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.46")
|
||||
// https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter
|
||||
implementation("com.alibaba:druid-spring-boot-starter:1.2.23")
|
||||
// https://mvnrepository.com/artifact/com.auth0/java-jwt
|
||||
|
@ -2,7 +2,10 @@ package cn.wzpmc.filemanager.annotation;
|
||||
|
||||
import cn.wzpmc.filemanager.entities.user.enums.Auth;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -8,12 +8,12 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
public class CorsConfiguration implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**") //**匹配的是我们所有后台的路径,代表后台共享了什么资源
|
||||
.maxAge(300 * 1000)
|
||||
.allowedOrigins("https://localhost:5173", "https://127.0.0.1:5173", "http://localhost:5173", "http://127.0.0.1:5173", "http://192.168.31.12:5173", "https://192.168.31.12:5173")
|
||||
registry.addMapping("/**") //允许所有路径进行CORS
|
||||
// .maxAge(300 * 1000)
|
||||
// .allowedOrigins("https://localhost:5173", "https://127.0.0.1:5173", "http://localhost:5173", "http://127.0.0.1:5173", "http://192.168.31.12:5173", "https://192.168.31.12:5173", "https://local.wzpmc.cn:5173")
|
||||
.allowedHeaders("*")
|
||||
.exposedHeaders("Set-Authorization")
|
||||
.allowedMethods("*"); //允许的前台的请求方式
|
||||
.exposedHeaders("Add-Authorization")
|
||||
.allowedMethods("*"); //允许所有请求方式
|
||||
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import cn.wzpmc.filemanager.config.FFmpegConfiguration;
|
||||
import cn.wzpmc.filemanager.config.FileManagerProperties;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -4,8 +4,8 @@ import cn.wzpmc.filemanager.annotation.Address;
|
||||
import cn.wzpmc.filemanager.annotation.AuthorizationRequired;
|
||||
import cn.wzpmc.filemanager.entities.PageResult;
|
||||
import cn.wzpmc.filemanager.entities.Result;
|
||||
import cn.wzpmc.filemanager.entities.files.DeleteRequest;
|
||||
import cn.wzpmc.filemanager.entities.files.FolderCreateRequest;
|
||||
import cn.wzpmc.filemanager.entities.files.NamedRawFile;
|
||||
import cn.wzpmc.filemanager.entities.files.RawFileObject;
|
||||
import cn.wzpmc.filemanager.entities.files.enums.FileType;
|
||||
import cn.wzpmc.filemanager.entities.vo.FileVo;
|
||||
@ -32,8 +32,8 @@ public class FileController {
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
public Result<PageResult<RawFileObject>> getFilePager(@RequestParam long page, @RequestParam int num, @RequestParam long folder, @Address String address) {
|
||||
return fileService.getFilePager(page, num, folder, address);
|
||||
public Result<PageResult<NamedRawFile>> getFilePager(@RequestParam long page, @RequestParam int num, @RequestParam long folder) {
|
||||
return fileService.getFilePager(page, num, folder);
|
||||
}
|
||||
|
||||
@PostMapping("/mkdir")
|
||||
@ -41,14 +41,24 @@ public class FileController {
|
||||
return fileService.mkdir(request, user, address);
|
||||
}
|
||||
|
||||
@GetMapping("/detail")
|
||||
@GetMapping("/get/file")
|
||||
public Result<NamedRawFile> getFile(@RequestParam long id) {
|
||||
return fileService.getFile(id);
|
||||
}
|
||||
|
||||
@GetMapping("/get/folder")
|
||||
public Result<NamedRawFile> getFolder(@RequestParam long id) {
|
||||
return fileService.getFolder(id);
|
||||
}
|
||||
|
||||
@GetMapping("/detail/file")
|
||||
public Result<FileVo> getFileDetail(@RequestParam long id) {
|
||||
return fileService.getFileDetail(id);
|
||||
}
|
||||
|
||||
@DeleteMapping("/rm")
|
||||
public Result<Void> delete(@RequestBody DeleteRequest request, @AuthorizationRequired UserVo user, @Address String address) {
|
||||
return fileService.delete(request, user, address);
|
||||
public Result<Void> delete(@RequestParam long id, @RequestParam FileType type, @AuthorizationRequired UserVo user, @Address String address) {
|
||||
return fileService.delete(id, type, user, address);
|
||||
}
|
||||
|
||||
@GetMapping("/link")
|
||||
|
@ -38,4 +38,12 @@ public class UserController {
|
||||
public Result<String> invite(@AuthorizationRequired(level = Auth.admin) UserVo userVo, @Address String address) {
|
||||
return userService.invite(userVo, address);
|
||||
}
|
||||
@GetMapping("/info")
|
||||
public Result<UserVo> getUserInfo(@AuthorizationRequired UserVo user) {
|
||||
return Result.success(user);
|
||||
}
|
||||
@GetMapping("/info/{id}")
|
||||
public Result<UserVo> getUser(@PathVariable Long id) {
|
||||
return userService.getUserInformation(id);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package cn.wzpmc.filemanager.entities;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@ -7,6 +8,7 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@JSONCompiled
|
||||
public class PageResult<T> {
|
||||
private long total;
|
||||
private List<T> data;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.wzpmc.filemanager.entities;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.Data;
|
||||
@ -13,6 +14,7 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Slf4j
|
||||
@Data
|
||||
@JSONCompiled
|
||||
public class Result<T> {
|
||||
private int status;
|
||||
private String msg;
|
||||
|
@ -1,10 +0,0 @@
|
||||
package cn.wzpmc.filemanager.entities.files;
|
||||
|
||||
import cn.wzpmc.filemanager.entities.files.enums.FileType;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeleteRequest {
|
||||
private FileType type;
|
||||
private long id;
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package cn.wzpmc.filemanager.entities.files;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JSONCompiled
|
||||
public class FolderCreateRequest {
|
||||
private long parent;
|
||||
private String name;
|
||||
|
@ -0,0 +1,16 @@
|
||||
package cn.wzpmc.filemanager.entities.files;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JSONCompiled
|
||||
public class NamedRawFile extends RawFileObject {
|
||||
private String ownerName;
|
||||
}
|
@ -3,6 +3,7 @@ package cn.wzpmc.filemanager.entities.files;
|
||||
import cn.wzpmc.filemanager.entities.files.enums.FileType;
|
||||
import cn.wzpmc.filemanager.entities.vo.FileVo;
|
||||
import cn.wzpmc.filemanager.entities.vo.FolderVo;
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -12,6 +13,7 @@ import java.util.Date;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JSONCompiled
|
||||
public class RawFileObject {
|
||||
private long id;
|
||||
private String name;
|
||||
|
@ -1,5 +1,8 @@
|
||||
package cn.wzpmc.filemanager.entities.files.enums;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
|
||||
@JSONCompiled
|
||||
public enum FileType {
|
||||
FILE, FOLDER
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package cn.wzpmc.filemanager.entities.statistics.enums;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
|
||||
@JSONCompiled
|
||||
public enum Actions {
|
||||
UPLOAD, DELETE, ACCESS, DOWNLOAD, SEARCH, LOGIN, INVITE, REGISTER
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package cn.wzpmc.filemanager.entities.user;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JSONCompiled
|
||||
public class UserLoginRequest {
|
||||
private String username;
|
||||
private String password;
|
||||
|
@ -1,9 +1,11 @@
|
||||
package cn.wzpmc.filemanager.entities.user;
|
||||
|
||||
import cn.wzpmc.filemanager.entities.user.enums.Auth;
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JSONCompiled
|
||||
public class UserRegisterRequest {
|
||||
private String username;
|
||||
private String password;
|
||||
|
@ -1,9 +1,11 @@
|
||||
package cn.wzpmc.filemanager.entities.user.enums;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import com.mybatisflex.annotation.EnumValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@AllArgsConstructor
|
||||
@JSONCompiled
|
||||
public enum Auth {
|
||||
admin(1, "admin"), user(0, "user");
|
||||
public final int value;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.wzpmc.filemanager.entities.vo;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
@ -11,6 +12,7 @@ import java.util.Date;
|
||||
|
||||
@Table("file")
|
||||
@Data
|
||||
@JSONCompiled
|
||||
public class FileVo implements Serializable {
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private long id;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.wzpmc.filemanager.entities.vo;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
@ -10,6 +11,7 @@ import java.util.Date;
|
||||
|
||||
@Table("folder")
|
||||
@Data
|
||||
@JSONCompiled
|
||||
public class FolderVo {
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private long id;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.wzpmc.filemanager.entities.vo;
|
||||
|
||||
import cn.wzpmc.filemanager.entities.statistics.enums.Actions;
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
@ -11,6 +12,7 @@ import java.util.Date;
|
||||
@Table("statistics")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@JSONCompiled
|
||||
public class StatisticsVo {
|
||||
private Long actor;
|
||||
private Actions action;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.wzpmc.filemanager.entities.vo;
|
||||
|
||||
import cn.wzpmc.filemanager.entities.user.enums.Auth;
|
||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
@ -11,6 +12,7 @@ import lombok.Data;
|
||||
@Table("user")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@JSONCompiled
|
||||
public class UserVo {
|
||||
@Id(keyType = KeyType.Auto)
|
||||
private long id;
|
||||
@ -32,5 +34,8 @@ public class UserVo {
|
||||
public UserVo(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void clearPassword() {
|
||||
this.setPassword(null);
|
||||
}
|
||||
public static final UserVo CONSOLE = new UserVo(0L, "CONSOLE", Auth.admin);
|
||||
}
|
@ -8,7 +8,9 @@ import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.wzpmc.filemanager.entities.vo.table.FileVoTableDef.FILE_VO;
|
||||
import static cn.wzpmc.filemanager.entities.vo.table.FolderVoTableDef.FOLDER_VO;
|
||||
|
@ -42,7 +42,7 @@ public class SimpleResolver extends SimplePathResolver {
|
||||
if (file != null) {
|
||||
return RawFileObject.of(file);
|
||||
}
|
||||
return RawFileObject.of(folderMapper.selectOneById(FOLDER_VO.NAME.eq(name).and(FOLDER_VO.PARENT.eq(parentId))));
|
||||
return RawFileObject.of(folderMapper.selectOneByCondition(FOLDER_VO.NAME.eq(name).and(FOLDER_VO.PARENT.eq(parentId))));
|
||||
}
|
||||
FolderVo folderVo = folderMapper.selectOneByCondition(FOLDER_VO.NAME.eq(currentLayerName).and(FOLDER_VO.PARENT.eq(parentId)));
|
||||
if (folderVo == null) {
|
||||
|
@ -3,8 +3,8 @@ package cn.wzpmc.filemanager.service;
|
||||
import cn.wzpmc.filemanager.config.FileManagerProperties;
|
||||
import cn.wzpmc.filemanager.entities.PageResult;
|
||||
import cn.wzpmc.filemanager.entities.Result;
|
||||
import cn.wzpmc.filemanager.entities.files.DeleteRequest;
|
||||
import cn.wzpmc.filemanager.entities.files.FolderCreateRequest;
|
||||
import cn.wzpmc.filemanager.entities.files.NamedRawFile;
|
||||
import cn.wzpmc.filemanager.entities.files.RawFileObject;
|
||||
import cn.wzpmc.filemanager.entities.files.enums.FileType;
|
||||
import cn.wzpmc.filemanager.entities.statistics.enums.Actions;
|
||||
@ -36,20 +36,24 @@ import org.apache.tomcat.util.http.fileupload.impl.FileItemIteratorImpl;
|
||||
import org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static cn.wzpmc.filemanager.entities.vo.table.FileVoTableDef.FILE_VO;
|
||||
import static cn.wzpmc.filemanager.entities.vo.table.FolderVoTableDef.FOLDER_VO;
|
||||
import static cn.wzpmc.filemanager.entities.vo.table.UserVoTableDef.USER_VO;
|
||||
import static com.mybatisflex.core.query.QueryMethods.*;
|
||||
|
||||
@Slf4j
|
||||
@ -71,6 +75,34 @@ public class FileService {
|
||||
public static final char PATH_SEPARATOR_CHAR = '/';
|
||||
public static final String PATH_SEPARATOR = "" + PATH_SEPARATOR_CHAR;
|
||||
|
||||
protected static QueryWrapper queryRawFileWithOwnerName() {
|
||||
return select(
|
||||
FILE_VO.ID.as("id"),
|
||||
FILE_VO.NAME.as("name"),
|
||||
FILE_VO.EXT.as("ext"),
|
||||
FILE_VO.SIZE.as("size"),
|
||||
FILE_VO.FOLDER.as("parent"),
|
||||
FILE_VO.UPLOADER.as("owner"),
|
||||
USER_VO.NAME.as("ownerName"),
|
||||
FILE_VO.UPLOAD_TIME.as("time"),
|
||||
string("FILE").as("type")
|
||||
).from(FILE_VO).leftJoin(USER_VO).on(USER_VO.ID.eq(FILE_VO.UPLOADER));
|
||||
}
|
||||
|
||||
protected static QueryWrapper queryRawFolderWithOwnerName() {
|
||||
return select(
|
||||
FOLDER_VO.ID.as("id"),
|
||||
FOLDER_VO.NAME.as("name"),
|
||||
null_().as("ext"),
|
||||
number(-1).as("size"),
|
||||
FOLDER_VO.PARENT.as("parent"),
|
||||
FOLDER_VO.CREATOR.as("owner"),
|
||||
USER_VO.NAME.as("ownerName"),
|
||||
FOLDER_VO.CREATE_TIME.as("time"),
|
||||
string("FOLDER").as("type")
|
||||
).from(FOLDER_VO).leftJoin(USER_VO).on(USER_VO.ID.eq(FOLDER_VO.CREATOR));
|
||||
}
|
||||
|
||||
protected void tryDeleteOrDeleteOnExit(File tmpFile) {
|
||||
if (!tmpFile.delete()) {
|
||||
log.error("delete tmp file error");
|
||||
@ -165,39 +197,19 @@ public class FileService {
|
||||
return folderParams;
|
||||
}
|
||||
|
||||
public Result<PageResult<RawFileObject>> getFilePager(long page, int num, long folder, String address) {
|
||||
QueryWrapper queryWrapper = select(
|
||||
FILE_VO.ID.as("id"),
|
||||
FILE_VO.NAME.as("name"),
|
||||
FILE_VO.EXT.as("ext"),
|
||||
FILE_VO.SIZE.as("size"),
|
||||
FILE_VO.FOLDER.as("parent"),
|
||||
FILE_VO.UPLOADER.as("owner"),
|
||||
FILE_VO.UPLOAD_TIME.as("time"),
|
||||
string("FILE").as("type")
|
||||
).from(FILE_VO).
|
||||
where(FILE_VO.FOLDER.eq(folder)).
|
||||
unionAll(
|
||||
select(
|
||||
FOLDER_VO.ID.as("id"),
|
||||
FOLDER_VO.NAME.as("name"),
|
||||
null_().as("ext"),
|
||||
number(-1).as("size"),
|
||||
FOLDER_VO.PARENT.as("parent"),
|
||||
FOLDER_VO.CREATOR.as("owner"),
|
||||
FOLDER_VO.CREATE_TIME.as("time"),
|
||||
string("FOLDER").as("type")
|
||||
).from(FOLDER_VO).
|
||||
where(FOLDER_VO.PARENT.eq(folder))
|
||||
).
|
||||
orderBy(
|
||||
public Result<PageResult<NamedRawFile>> getFilePager(long page, int num, long folder) {
|
||||
QueryWrapper folderQueryWrapper = queryRawFolderWithOwnerName().where(FOLDER_VO.PARENT.eq(folder));
|
||||
QueryWrapper fileQueryWrapper = queryRawFileWithOwnerName().where(FILE_VO.FOLDER.eq(folder));
|
||||
QueryWrapper queryWrapper = fileQueryWrapper.unionAll(folderQueryWrapper)
|
||||
.orderBy(
|
||||
column("time").
|
||||
asc(),
|
||||
column("id").
|
||||
asc()
|
||||
);
|
||||
Page<RawFileObject> paginate = fileMapper.paginateAs(page, num, queryWrapper, RawFileObject.class);
|
||||
PageResult<RawFileObject> result = new PageResult<>(paginate.getTotalRow(), paginate.getRecords());
|
||||
long totalCount = fileMapper.selectCountByCondition(FILE_VO.FOLDER.eq(folder)) + folderMapper.selectCountByCondition(FOLDER_VO.PARENT.eq(folder));
|
||||
Page<NamedRawFile> paginate = fileMapper.paginateAs(page, num, totalCount, queryWrapper, NamedRawFile.class);
|
||||
PageResult<NamedRawFile> result = new PageResult<>(paginate.getTotalRow(), paginate.getRecords());
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@ -233,10 +245,15 @@ public class FileService {
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteFolder(long id) {
|
||||
fileMapper.selectListByCondition(FILE_VO.FOLDER.eq(id)).forEach(this::deleteFile);
|
||||
fileMapper.deleteByCondition(FILE_VO.FOLDER.eq(id));
|
||||
folderMapper.selectListByCondition(FOLDER_VO.PARENT.eq(id)).stream().map(FolderVo::getId).forEach(this::deleteFolder);
|
||||
folderMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Result<Void> delete(DeleteRequest request, UserVo user, String address) {
|
||||
long id = request.getId();
|
||||
FileType type = request.getType();
|
||||
public Result<Void> delete(long id, FileType type, UserVo user, String address) {
|
||||
long actorId = user.getId();
|
||||
if (type.equals(FileType.FILE)) {
|
||||
FileVo fileVo = fileMapper.selectOneById(id);
|
||||
@ -256,27 +273,14 @@ public class FileService {
|
||||
return Result.failed(HttpStatus.NOT_FOUND, "文件不存在!");
|
||||
}
|
||||
if (user.getAuth().equals(Auth.user)) {
|
||||
if (folderMapper.selectCountByCondition(FOLDER_VO.ID.eq(id).and(FOLDER_VO.CREATOR.eq(actorId))) <= 0) {
|
||||
return Result.failed(HttpStatus.UNAUTHORIZED, "权限不足!");
|
||||
}
|
||||
}
|
||||
fileMapper.deleteByCondition(FILE_VO.FOLDER.eq(id));
|
||||
for (FileVo fileVo : fileMapper.selectListByCondition(FILE_VO.FOLDER.eq(id))) {
|
||||
deleteFile(fileVo);
|
||||
}
|
||||
this.deleteFolder(folder.getId());
|
||||
}
|
||||
statisticsService.insertAction(user, Actions.DELETE, JSONObject.of("id", id, "type", type, "address", address));
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
public Result<FileVo> getFileDetail(long id) {
|
||||
FileVo fileVo = this.fileMapper.selectOneById(id);
|
||||
if (fileVo == null) {
|
||||
return Result.failed(HttpStatus.NOT_FOUND, "未知文件");
|
||||
}
|
||||
return Result.success(fileVo);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void downloadFile(String id, String range, HttpServletResponse response) {
|
||||
FileVo fileVo = linkMapper.opsForValue().get(id);
|
||||
@ -296,6 +300,10 @@ public class FileService {
|
||||
if (minMax.length > 1) {
|
||||
max = Long.parseLong(minMax[1]);
|
||||
}
|
||||
response.setStatus(206);
|
||||
response.addHeader("Content-Range", "bytes " + min + "-" + max + "/" + size);
|
||||
} else {
|
||||
response.setStatus(200);
|
||||
}
|
||||
String hash = fileVo.getHash();
|
||||
File file = new File(properties.getSavePath(), hash);
|
||||
@ -304,10 +312,10 @@ public class FileService {
|
||||
if (ext != null) {
|
||||
fullName += '.' + ext;
|
||||
}
|
||||
response.setStatus(206);
|
||||
|
||||
response.addHeader("Content-Length", String.valueOf(max - min));
|
||||
response.addHeader("Content-Range", "bytes " + min + "-" + max + "/" + size);
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fullName, StandardCharsets.UTF_8));
|
||||
ContentDisposition disposition = ContentDisposition.attachment().filename(fullName, StandardCharsets.UTF_8).build();
|
||||
response.addHeader("Content-Disposition", disposition.toString());
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
StreamUtils.copyRange(fis, outputStream, min, max);
|
||||
@ -369,4 +377,28 @@ public class FileService {
|
||||
}
|
||||
return Result.success("成功", pathService.getFilePath(RawFileObject.of(folderVo)));
|
||||
}
|
||||
|
||||
public Result<NamedRawFile> getFile(long id) {
|
||||
NamedRawFile fileVo = this.fileMapper.selectOneByQueryAs(queryRawFileWithOwnerName().where(FILE_VO.ID.eq(id)), NamedRawFile.class);
|
||||
if (fileVo == null) {
|
||||
return Result.failed(HttpStatus.NOT_FOUND, "未知文件");
|
||||
}
|
||||
return Result.success(fileVo);
|
||||
}
|
||||
|
||||
public Result<NamedRawFile> getFolder(long id) {
|
||||
NamedRawFile fileVo = this.folderMapper.selectOneByQueryAs(queryRawFolderWithOwnerName().where(FOLDER_VO.ID.eq(id)), NamedRawFile.class);
|
||||
if (fileVo == null) {
|
||||
return Result.failed(HttpStatus.NOT_FOUND, "未知文件");
|
||||
}
|
||||
return Result.success(fileVo);
|
||||
}
|
||||
|
||||
public Result<FileVo> getFileDetail(long id) {
|
||||
FileVo fileVo = this.fileMapper.selectOneById(id);
|
||||
if (fileVo == null) {
|
||||
return Result.failed(HttpStatus.NOT_FOUND, "未知文件");
|
||||
}
|
||||
return Result.success(fileVo);
|
||||
}
|
||||
}
|
@ -58,15 +58,17 @@ public class UserService {
|
||||
return;
|
||||
}
|
||||
UserVo userVo = this.userMapper.selectOneByCondition(findUserCondition);
|
||||
userVo.clearPassword();
|
||||
long id = userVo.getId();
|
||||
String token = this.jwtUtils.createToken(id);
|
||||
response.addHeader("Add-Authorization", token);
|
||||
this.statisticsService.insertAction(userVo, Actions.LOGIN, JSONObject.of("status", "success", "address", address));
|
||||
Result.success("登录成功").writeToResponse(response);
|
||||
Result.success("登录成功", userVo).writeToResponse(response);
|
||||
}
|
||||
public void register(UserRegisterRequest request, HttpServletResponse response, String address) {
|
||||
String username = request.getUsername();
|
||||
String password = request.getPassword();
|
||||
String sha1edPassword = DigestUtils.sha1Hex(password);
|
||||
Auth auth = request.getAuth();
|
||||
if (this.userMapper.selectCountByCondition(USER_VO.NAME.eq(username)) > 0) {
|
||||
this.statisticsService.insertAction(Actions.REGISTER, JSONObject.of("status", "error", "auth", auth, "msg", "用户名已存在", "address", address));
|
||||
@ -85,13 +87,14 @@ public class UserService {
|
||||
}
|
||||
statisticsData.put("inviteCode", inviteCode);
|
||||
}
|
||||
UserVo userVo = new UserVo(username, password, auth);
|
||||
UserVo userVo = new UserVo(username, sha1edPassword, auth);
|
||||
this.userMapper.insert(userVo);
|
||||
userVo.clearPassword();
|
||||
long id = userVo.getId();
|
||||
String token = this.jwtUtils.createToken(id);
|
||||
response.addHeader("Add-Authorization", token);
|
||||
this.statisticsService.insertAction(userVo, Actions.REGISTER, statisticsData);
|
||||
Result.success("注册成功!").writeToResponse(response);
|
||||
Result.success("注册成功!", userVo).writeToResponse(response);
|
||||
}
|
||||
|
||||
public Result<String> invite(UserVo userVo, String address) {
|
||||
@ -106,4 +109,13 @@ public class UserService {
|
||||
ops.set(s, "", 15, TimeUnit.MINUTES);
|
||||
return s;
|
||||
}
|
||||
|
||||
public Result<UserVo> getUserInformation(Long id) {
|
||||
UserVo userVo = userMapper.selectOneById(id);
|
||||
if (userVo == null){
|
||||
return Result.failed(HttpStatus.NOT_FOUND, "用户不存在!");
|
||||
}
|
||||
userVo.clearPassword();
|
||||
return Result.success(userVo);
|
||||
}
|
||||
}
|
@ -6,10 +6,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
@Slf4j
|
||||
|
@ -10,8 +10,6 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Component
|
||||
public class AuthorizationHandlerInterceptor implements HandlerInterceptor {
|
||||
private final AuthorizationUtils authorizationUtils;
|
||||
|
26
src/main/resources/META-INF/native-image/reflect-config.json
Normal file
26
src/main/resources/META-INF/native-image/reflect-config.json
Normal file
@ -0,0 +1,26 @@
|
||||
[
|
||||
{
|
||||
"name" : "com.alibaba.fastjson2.example.graalvm_native.vo.MediaContent$MediaContent_FASTJSONReader",
|
||||
"allPublicConstructors" : true
|
||||
},
|
||||
{
|
||||
"name" : "com.alibaba.fastjson2.example.graalvm_native.vo.MediaContent$MediaContent_FASTJSONWriter",
|
||||
"allPublicConstructors" : true
|
||||
},
|
||||
{
|
||||
"name" : "com.alibaba.fastjson2.example.graalvm_native.vo.Media$Media_FASTJSONReader",
|
||||
"allPublicConstructors" : true
|
||||
},
|
||||
{
|
||||
"name" : "com.alibaba.fastjson2.example.graalvm_native.vo.Media$Media_FASTJSONWriter",
|
||||
"allPublicConstructors" : true
|
||||
},
|
||||
{
|
||||
"name" : "com.alibaba.fastjson2.example.graalvm_native.vo.Image$Image_FASTJSONReader",
|
||||
"allPublicConstructors" : true
|
||||
},
|
||||
{
|
||||
"name" : "com.alibaba.fastjson2.example.graalvm_native.vo.Image$Image_FASTJSONWriter",
|
||||
"allPublicConstructors" : true
|
||||
}
|
||||
]
|
@ -1,5 +1,3 @@
|
||||
server:
|
||||
port: 8080
|
||||
spring:
|
||||
application:
|
||||
name: FileManager
|
||||
|
Loading…
x
Reference in New Issue
Block a user