Selaa lähdekoodia

添加 netdisk 模块, 作为网盘后端

reghao 3 vuotta sitten
vanhempi
commit
9729aa46ce

+ 6 - 0
pom.xml

@@ -159,6 +159,12 @@
             <artifactId>rocksdbjni</artifactId>
             <version>6.6.4</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.thoughtworks.xstream</groupId>
+            <artifactId>xstream</artifactId>
+            <version>1.4.11.1</version>
+        </dependency>
     </dependencies>
 
     <profiles>

+ 2 - 2
src/main/java/cn/reghao/dfs/store/config/WebConfig.java

@@ -43,7 +43,7 @@ public class WebConfig extends WebMvcConfigurationSupport {
     }*/
 
     // TODO 若 dfs-gw 中处理了跨域, 那么这里需要注释
-    /*@Override
+    @Override
     public void addCorsMappings(CorsRegistry registry) {
         registry.addMapping("/**")
                 .allowedOrigins("*")
@@ -51,7 +51,7 @@ public class WebConfig extends WebMvcConfigurationSupport {
                 .allowCredentials(true)
                 .maxAge(3600)
                 .allowedHeaders("*");
-    }*/
+    }
 
     /*@Bean
     public FilterRegistrationBean<Filter> jwtTokenFilter() {

+ 242 - 0
src/main/java/cn/reghao/dfs/store/netdisk/controller/NetDiskController.java

@@ -0,0 +1,242 @@
+package cn.reghao.dfs.store.netdisk.controller;
+
+import cn.reghao.dfs.store.netdisk.db.mapper.FileListMapper;
+import cn.reghao.dfs.store.netdisk.model.po.FileListBean;
+import cn.reghao.dfs.store.netdisk.model.po.MenuBean;
+import cn.reghao.dfs.store.netdisk.model.po.TreeJson;
+import cn.reghao.jutil.jdk.db.PageList;
+import cn.reghao.jutil.jdk.result.WebBody;
+import com.thoughtworks.xstream.XStream;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2022-12-26 10:16:28
+ */
+@Api(tags = "网盘接口")
+@RestController
+@RequestMapping("/api/file")
+public class NetDiskController {
+    private final FileListMapper fileListMapper;
+
+    public NetDiskController(FileListMapper fileListMapper) {
+        this.fileListMapper = fileListMapper;
+    }
+
+    @ApiOperation("返回文件分类列表列表")
+    @PostMapping(value = "/menu/findList", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String fileMenus() throws IOException {
+        XStream stream=new XStream();
+        stream.alias("menu", MenuBean.class);
+        stream.alias("menus", List.class);
+
+        ClassPathResource resource = new ClassPathResource("menu-user.xml");
+        InputStream input =resource.getInputStream();
+        List<MenuBean> lists=(List<MenuBean>)stream.fromXML(input);
+        return WebBody.success(lists);
+    }
+
+    @ApiOperation("返回列表模式文件列表")
+    @PostMapping(value = "/disk/file/findList", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String fileList() {
+        List<FileListBean> list = fileListMapper.findAll1();
+        PageList<FileListBean> pageList = PageList.pageList(list);
+        return WebBody.success(pageList);
+    }
+
+    @ApiOperation("返回卡片模式文件列表")
+    @PostMapping(value = "/disk/file/findListCard", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String findListCard() {
+        List<FileListBean> list = fileListMapper.findAll2();
+        PageList<FileListBean> pageList = PageList.pageList(list);
+        return WebBody.success(pageList);
+    }
+
+    @ApiOperation("获取图片文件的缩略图")
+    @GetMapping(value = "/disk/fileopen/previewThumbnail")
+    public ResponseEntity<InputStreamResource> previewThumbnail() throws FileNotFoundException {
+        InputStream in = new FileInputStream("/home/reghao/Downloads/file/010.jpeg");
+        InputStreamResource inputStreamResource = new InputStreamResource(in);
+
+        HttpHeaders httpHeaders = new HttpHeaders();
+        httpHeaders.set("Pragma", "No-cache");
+        httpHeaders.set("Cache-Control", "no-cache");
+        return ResponseEntity.status(HttpStatus.OK).headers(httpHeaders).contentType(MediaType.IMAGE_JPEG)
+                .body(inputStreamResource);
+    }
+
+    @ApiOperation("检查待上传文件的 MD5")
+    @PostMapping(value = "/disk/fileupload/checkFile", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String checkFile() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("上传文件")
+    @PostMapping(value = "/disk/fileupload/uploadChunk", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String uploadChunk() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("合并上传的文件分片")
+    @PostMapping(value = "/disk/fileupload/mergeChunk", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String mergeChunk() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("获取文件属性")
+    @PostMapping(value = "/disk/filecommon/findOne", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String findOne() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("获取 Album 属性")
+    @PostMapping(value = "/disk/filealbum/findOne", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String findOneFileAlbum() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("获取当前用户的好友列表")
+    @PostMapping(value = "/disk/filecommon/findUserTree", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String findUserTree() {
+        String type = "position";
+        String pid = "3";
+
+        List<TreeJson> trees = new ArrayList<>();
+        if("root".equals(type)){
+            if("0".equals(pid)){
+                TreeJson tree=new TreeJson();
+                tree.setId("1");
+                tree.setLabel("测试部门");
+                tree.setType("org");
+                tree.setDisabled(true);
+                trees.add(tree);
+            }
+
+        }else if("org".equals(type)){
+            if("1".equals(pid)){
+                TreeJson tree1=new TreeJson();
+                tree1.setId("2");
+                tree1.setLabel("项目经理");
+                tree1.setType("position");
+                tree1.setDisabled(true);
+                trees.add(tree1);
+
+                TreeJson tree2=new TreeJson();
+                tree2.setId("3");
+                tree2.setLabel("开发人员");
+                tree2.setType("position");
+                tree2.setDisabled(true);
+                trees.add(tree2);
+            }
+        }else if("position".equals(type)){
+            if("2".equals(pid)){
+                TreeJson tree=new TreeJson();
+                tree.setId("1");
+                tree.setLabel("超级管理员");
+                tree.setType("user");
+                tree.setDisabled(false);
+                trees.add(tree);
+
+            }else if("3".equals(pid)){
+                TreeJson tree=new TreeJson();
+                tree.setId("2");
+                tree.setLabel("测试账号");
+                tree.setType("user");
+                tree.setDisabled(false);
+                trees.add(tree);
+            }
+        }
+
+        return WebBody.success(trees);
+    }
+
+    @ApiOperation("分享给好友")
+    @PostMapping(value = "/disk/filecommon/shareFriends", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String shareFriends() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("私密链接分享")
+    @PostMapping(value = "/disk/filecommon/shareSecret", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String shareSecret() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("获取本人分享的文件列表")
+    @PostMapping(value = "/disk/sharebyself/findList", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String shareBySelf() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("获取好友分享的文件列表")
+    @PostMapping(value = "/disk/sharebyfriends/findList", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String shareByFriend() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("获取文件下载信息")
+    @PostMapping(value = "/disk/filedownload/getDownloadInfo", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String getDownloadInfo() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("文件批量下载")
+    @PostMapping(value = "/disk/filedownload/mergeFiles", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String mergeFiles() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("获取目录列表")
+    @PostMapping(value = "/disk/filecommon/findFolderList", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String findFolderList() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("新建目录")
+    @PostMapping(value = "/disk/filecommon/addFolder", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String addFolder() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("新增文件")
+    @PostMapping(value = "/disk/fileedit/addFile", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String addFile() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("文件重命名")
+    @PostMapping(value = "/disk/filecommon/rename", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String rename() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("回收站文件列表")
+    @PostMapping(value = "/disk/rubbish/findList", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String rubbishList() {
+        return WebBody.success();
+    }
+
+    @ApiOperation("通知列表")
+    @PostMapping(value = "/disk/notice/findList", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String noticeList() {
+        return WebBody.success();
+    }
+}

+ 17 - 0
src/main/java/cn/reghao/dfs/store/netdisk/db/mapper/FileListMapper.java

@@ -0,0 +1,17 @@
+package cn.reghao.dfs.store.netdisk.db.mapper;
+
+import cn.reghao.dfs.store.netdisk.model.po.FileListBean;
+import cn.reghao.jutil.jdk.db.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2022-11-24 11:11:06
+ */
+@Mapper
+public interface FileListMapper extends BaseMapper<FileListBean> {
+    List<FileListBean> findAll1();
+    List<FileListBean> findAll2();
+}

+ 18 - 0
src/main/java/cn/reghao/dfs/store/netdisk/model/po/DownloadBean.java

@@ -0,0 +1,18 @@
+package cn.reghao.dfs.store.netdisk.model.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author reghao
+ * @date 2022-12-26 16:58:51
+ */
+@Data
+public class DownloadBean implements Serializable {
+    private Integer filenum;
+    private Integer foldernum;
+    private Long totalsize;
+    private String totalsizename;
+    private Integer isbig;
+}

+ 32 - 0
src/main/java/cn/reghao/dfs/store/netdisk/model/po/FileListBean.java

@@ -0,0 +1,32 @@
+package cn.reghao.dfs.store.netdisk.model.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author reghao
+ * @date 2022-12-26 10:41:23
+ */
+@Data
+public class FileListBean implements Serializable {
+    private String id;
+    private String pid;
+    private String pname;
+
+    private String filename;
+    private long filesize;
+    private String filesizename;
+    private String filesuffix;
+    private String fileicon;//base64
+    private String typecode;//document/picture/video/music/other
+    private String filemd5;
+    private Integer filetype;//0文件夹,1文件
+    private String createuserid;
+    private String createusername;
+    private String createtime;
+
+    //////////////////////////////////图片的扩展属性///////////////////////////////////////////
+    private String thumbnailurl;//图片属性:缩略图
+    private String imgsize;//图片属性:尺寸
+}

+ 15 - 0
src/main/java/cn/reghao/dfs/store/netdisk/model/po/MenuBean.java

@@ -0,0 +1,15 @@
+package cn.reghao.dfs.store.netdisk.model.po;
+
+import lombok.Data;
+
+/**
+ * @author reghao
+ * @date 2022-12-26 10:18:40
+ */
+@Data
+public class MenuBean {
+    private String id;
+    private String name;
+    private String icon;
+    private String url;
+}

+ 20 - 0
src/main/java/cn/reghao/dfs/store/netdisk/model/po/TreeJson.java

@@ -0,0 +1,20 @@
+package cn.reghao.dfs.store.netdisk.model.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2022-12-26 15:19:01
+ */
+@Data
+public class TreeJson implements Serializable {
+    private String id;
+    private String label;
+    private String type;//org,position,user
+    private boolean disabled=false;//true表示checkbox可以禁用,false表示启用
+    private List<TreeJson> children=new ArrayList<>();
+}

+ 1 - 1
src/main/resources/application-dev.yml

@@ -8,6 +8,6 @@ dfs:
   group: 0
   node: 0
   baseDirs:
-    - /opt/oss/disk/c42796cb-496e-4621-8e11-cb080bdd474d/
+    - /opt/oss/disk/00b989fc-991b-4d4e-959e-9b6e19299b72/
   encryptKey: 5JCdi68CulSDu0TqD4jR
   metaDir: /opt/oss/meta

+ 1 - 1
src/main/resources/application-test.yml

@@ -8,6 +8,6 @@ dfs:
   group: 0
   node: 0
   baseDirs:
-    - /opt/oss/disk/13f654c8-af87-4710-aac9-7aa086c99aec/
+    - /opt/oss/disk/4b4a03cf-cb23-44e5-ac1b-bb810392c327/
   encryptKey: 5JCdi68CulSDu0TqD4jR
   metaDir: /opt/oss/meta

+ 14 - 0
src/main/resources/mapper/netdisk/FileListMapper.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="cn.reghao.dfs.store.netdisk.db.mapper.FileListMapper">
+    <select id="findAll1" resultType="cn.reghao.dfs.store.netdisk.model.po.FileListBean">
+        select id,filename,filesize,filetype,filemd5,filesuffix,date_format(createtime,'%Y-%m-%d %H:%i:%S') as createtime, (select icon from disk_type_suffix where suffix=df.filesuffix and typecode=df.typecode) as fileicon
+        from disk_file df
+    </select>
+
+    <select id="findAll2" resultType="cn.reghao.dfs.store.netdisk.model.po.FileListBean">
+        select id,filename,filesize,filetype,filemd5,filesuffix,typecode,thumbnailurl,date_format(createtime,'%Y-%m-%d %H:%i:%S') as createtime,  (select iconbig from disk_type_suffix where suffix=df.filesuffix and typecode=df.typecode) as fileicon
+        from disk_file df
+    </select>
+</mapper>

+ 45 - 0
src/main/resources/menu-admin.xml

@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<menus>
+	<menu>
+		<id>0</id>
+		<name>应用管理</name>
+		<icon>el-icon-document</icon>
+		<url><![CDATA[/main/app/index]]></url>
+	</menu>
+	<menu>
+		<id>1</id>
+		<name>文件管理</name>
+		<icon>el-icon-document</icon>
+		<url><![CDATA[/main/file/index]]></url>
+	</menu>
+	<menu>
+		<id>2</id>
+		<name>组件管理</name>
+		<icon>el-icon-document</icon>
+		<url><![CDATA[/main/typecomponent/index]]></url>
+	</menu>
+	<menu>
+		<id>3</id>
+		<name>文件类型</name>
+		<icon>el-icon-document</icon>
+		<url><![CDATA[/main/type/index]]></url>
+	</menu>
+	<menu>
+		<id>4</id>
+		<name>容量管理</name>
+		<icon>el-icon-document</icon>
+		<url><![CDATA[/main/user/index]]></url>
+	</menu>
+	<menu>
+		<id>5</id>
+		<name>日志追踪</name>
+		<icon>el-icon-document</icon>
+		<url><![CDATA[/main/logtrace/index]]></url>
+	</menu>
+<!-- 	<menu>
+		<id>6</id>
+		<name>统计分析</name>
+		<icon>el-icon-document</icon>
+		<url><![CDATA[/main/analy/index]]></url>
+	</menu> -->
+</menus>

+ 57 - 0
src/main/resources/menu-user.xml

@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<menus>
+	<menu>
+		<id>0</id>
+		<name>全部文件</name>
+		<icon>el-icon-files</icon>
+		<url><![CDATA[/main/fileall/index]]></url>
+	</menu>
+	<menu>
+		<id>1</id>
+		<name>文档</name>
+		<icon>el-icon-document-copy</icon>
+		<url><![CDATA[/main/filedocument/index]]></url>
+	</menu>
+	<menu>
+		<id>2</id>
+		<name>图片</name>
+		<icon>el-icon-picture-outline</icon>
+		<url><![CDATA[/main/filepicture/index]]></url>
+	</menu>
+	<menu>
+		<id>3</id>
+		<name>视频</name>
+		<icon>el-icon-video-camera</icon>
+		<url><![CDATA[/main/filevideo/index]]></url>
+	</menu>
+	<menu>
+		<id>4</id>
+		<name>音乐</name>
+		<icon>el-icon-headset</icon>
+		<url><![CDATA[/main/filemusic/index]]></url>
+	</menu>
+	<menu>
+		<id>5</id>
+		<name>其他</name>
+		<icon>el-icon-s-promotion</icon>
+		<url><![CDATA[/main/fileother/index]]></url>
+	</menu>
+	<menu>
+		<id>6</id>
+		<name>我的分享</name>
+		<icon>el-icon-share</icon>
+		<url><![CDATA[/main/sharebyself/index]]></url>
+	</menu>
+	<menu>
+		<id>7</id>
+		<name>好友分享</name>
+		<icon>el-icon-link</icon>
+		<url><![CDATA[/main/sharebyfriends/index]]></url>
+	</menu>
+	<menu>
+		<id>8</id>
+		<name>回收站</name>
+		<icon>el-icon-delete</icon>
+		<url><![CDATA[/main/rubbish/index]]></url>
+	</menu>
+</menus>