From f83b89ea0039d53537cce25afc029e89adc7d646 Mon Sep 17 00:00:00 2001 From: Wzp-2008 Date: Wed, 20 Nov 2024 20:30:00 +0800 Subject: [PATCH] feat: adding readme and auto table creator --- README.md | 4 + .../filemanager/FileManagerApplication.java | 13 +--- .../events/StartEventListener.java | 28 +++++++ .../mapper/InitializationMapper.java | 11 +++ src/main/resources/application.yaml | 14 ---- .../mapper/InitializationMapper.xml | 77 +++++++++++++++++++ src/main/resources/scheme.sql | 63 +++++++++++++++ 7 files changed, 186 insertions(+), 24 deletions(-) create mode 100644 README.md create mode 100644 src/main/java/cn/wzpmc/filemanager/events/StartEventListener.java create mode 100644 src/main/java/cn/wzpmc/filemanager/mapper/InitializationMapper.java create mode 100644 src/main/resources/cn/wzpmc/filemanager/mapper/InitializationMapper.xml create mode 100644 src/main/resources/scheme.sql diff --git a/README.md b/README.md new file mode 100644 index 0000000..4bfa8cb --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# File Manager +### A self-hosted file share and management system +___ +## How to Use diff --git a/src/main/java/cn/wzpmc/filemanager/FileManagerApplication.java b/src/main/java/cn/wzpmc/filemanager/FileManagerApplication.java index 81ee918..c8498eb 100644 --- a/src/main/java/cn/wzpmc/filemanager/FileManagerApplication.java +++ b/src/main/java/cn/wzpmc/filemanager/FileManagerApplication.java @@ -1,8 +1,5 @@ package cn.wzpmc.filemanager; -import com.mybatisflex.core.audit.AuditManager; -import com.mybatisflex.core.audit.ConsoleMessageCollector; -import com.mybatisflex.core.audit.MessageCollector; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -19,12 +16,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableAsync public class FileManagerApplication { - public static void main(String[] args) { - //开启审计功能 - AuditManager.setAuditEnable(true); - MessageCollector collector = new ConsoleMessageCollector(); - AuditManager.setMessageCollector(collector); - SpringApplication.run(FileManagerApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(FileManagerApplication.class, args); + } } \ No newline at end of file diff --git a/src/main/java/cn/wzpmc/filemanager/events/StartEventListener.java b/src/main/java/cn/wzpmc/filemanager/events/StartEventListener.java new file mode 100644 index 0000000..cbf9108 --- /dev/null +++ b/src/main/java/cn/wzpmc/filemanager/events/StartEventListener.java @@ -0,0 +1,28 @@ +package cn.wzpmc.filemanager.events; + +import cn.wzpmc.filemanager.mapper.InitializationMapper; +import com.mybatisflex.core.audit.AuditManager; +import com.mybatisflex.core.audit.ConsoleMessageCollector; +import com.mybatisflex.core.audit.MessageCollector; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.context.event.ApplicationStartedEvent; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class StartEventListener { + private final InitializationMapper initializationMapper; + + @EventListener + public void onStart(ApplicationStartedEvent ignored) { + initializationMapper.createUserTable(); + initializationMapper.createStatisticsTable(); + initializationMapper.createFolderTable(); + initializationMapper.createFileTable(); + //开启审计功能 + AuditManager.setAuditEnable(true); + MessageCollector collector = new ConsoleMessageCollector(); + AuditManager.setMessageCollector(collector); + } +} diff --git a/src/main/java/cn/wzpmc/filemanager/mapper/InitializationMapper.java b/src/main/java/cn/wzpmc/filemanager/mapper/InitializationMapper.java new file mode 100644 index 0000000..085f4d3 --- /dev/null +++ b/src/main/java/cn/wzpmc/filemanager/mapper/InitializationMapper.java @@ -0,0 +1,11 @@ +package cn.wzpmc.filemanager.mapper; + +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface InitializationMapper { + void createFileTable(); + void createFolderTable(); + void createStatisticsTable(); + void createUserTable(); +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 6c032d4..7d6f91f 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -3,22 +3,8 @@ server: spring: application: name: FileManager - datasource: - url: jdbc:mysql://server.wzpmc.cn:3306/fsv2 - username: "fsv2" - password: "JiGSnWrwpPFnrthM" - type: com.alibaba.druid.pool.DruidDataSource - data: - redis: - host: "server.wzpmc.cn" - database: 3 - password: "MyCraftAdmin123" servlet: multipart: max-file-size: 400GB max-request-size: 400GB resolve-lazily: true -wzp: - filemanager: - save-path: "./file" - hmac-key: "V(LWJ6D5*4%,Hk{1" \ No newline at end of file diff --git a/src/main/resources/cn/wzpmc/filemanager/mapper/InitializationMapper.xml b/src/main/resources/cn/wzpmc/filemanager/mapper/InitializationMapper.xml new file mode 100644 index 0000000..d5c5d54 --- /dev/null +++ b/src/main/resources/cn/wzpmc/filemanager/mapper/InitializationMapper.xml @@ -0,0 +1,77 @@ + + + + + CREATE TABLE IF NOT EXISTS `file` + ( + `id` int NOT NULL AUTO_INCREMENT COMMENT '文件ID', + `name` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件名', + `ext` varchar(40) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件扩展名', + `mime` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件的MIME类型', + `hash` char(128) COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件sha512', + `uploader` int NOT NULL COMMENT '文件上传者', + `folder` int DEFAULT NULL COMMENT '所属文件夹ID', + `size` bigint NOT NULL, + `upload_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '上传时间', + PRIMARY KEY (`id`), + UNIQUE KEY `path` (`name`, `ext`, `folder`), + KEY `ext` (`ext`), + KEY `sha1` (`hash`), + KEY `upload_time` (`upload_time`), + KEY `uploader` (`uploader`), + KEY `name` (`name`, `ext`) + ) ENGINE = InnoDB + AUTO_INCREMENT = 2845 + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='文件'; + + + CREATE TABLE IF NOT EXISTS `folder` + ( + `id` int NOT NULL AUTO_INCREMENT COMMENT '文件夹ID', + `name` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件夹名称', + `parent` int DEFAULT NULL COMMENT '父文件夹ID', + `creator` int DEFAULT NULL COMMENT '创建者ID', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`), + UNIQUE KEY `path` (`name`, `parent`), + KEY `name` (`name`) + ) ENGINE = InnoDB + AUTO_INCREMENT = 3118 + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='文件夹'; + + + CREATE TABLE IF NOT EXISTS `statistics` + ( + `actor` int DEFAULT NULL COMMENT '操作者', + `action` enum ('UPLOAD','DELETE','ACCESS','DOWNLOAD','SEARCH','LOGIN','INVITE','REGISTER') COLLATE utf8mb4_general_ci NOT NULL COMMENT '所做的操作', + `params` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '操作的参数(在ACCESS操作中为空)', + `time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '操作的时间', + KEY `action` (`action`) COMMENT '操作类型索引', + KEY `actor_index` (`actor`) COMMENT '操作者索引', + KEY `time` (`time`) COMMENT '时间索引' + ) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='统计信息'; + + + CREATE TABLE IF NOT EXISTS `user` + ( + `id` int NOT NULL AUTO_INCREMENT COMMENT '用户ID', + `name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户名', + `password` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户密码(MD5+SHA1)', + `auth` enum ('admin','user') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'user' COMMENT '用户类型', + `banned` tinyint(1) NOT NULL DEFAULT '0' COMMENT '用户是否被封禁', + PRIMARY KEY (`id`) COMMENT 'ID索引', + UNIQUE KEY `name_pk` (`name`), + UNIQUE KEY `login_index` (`name`, `password`) COMMENT '用户名密码索引', + UNIQUE KEY `id_index` (`id`) COMMENT 'ID索引' + ) ENGINE = InnoDB + AUTO_INCREMENT = 4 + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='用户表'; + + \ No newline at end of file diff --git a/src/main/resources/scheme.sql b/src/main/resources/scheme.sql new file mode 100644 index 0000000..e131798 --- /dev/null +++ b/src/main/resources/scheme.sql @@ -0,0 +1,63 @@ +CREATE TABLE IF NOT EXISTS `file` +( + `id` int NOT NULL AUTO_INCREMENT COMMENT '文件ID', + `name` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件名', + `ext` varchar(40) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件扩展名', + `mime` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件的MIME类型', + `hash` char(128) COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件sha512', + `uploader` int NOT NULL COMMENT '文件上传者', + `folder` int DEFAULT NULL COMMENT '所属文件夹ID', + `size` bigint NOT NULL, + `upload_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '上传时间', + PRIMARY KEY (`id`), + UNIQUE KEY `path` (`name`, `ext`, `folder`), + KEY `ext` (`ext`), + KEY `sha1` (`hash`), + KEY `upload_time` (`upload_time`), + KEY `uploader` (`uploader`), + KEY `name` (`name`, `ext`) +) ENGINE = InnoDB + AUTO_INCREMENT = 2845 + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='文件'; +CREATE TABLE IF NOT EXISTS `folder` +( + `id` int NOT NULL AUTO_INCREMENT COMMENT '文件夹ID', + `name` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件夹名称', + `parent` int DEFAULT NULL COMMENT '父文件夹ID', + `creator` int DEFAULT NULL COMMENT '创建者ID', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`), + UNIQUE KEY `path` (`name`, `parent`), + KEY `name` (`name`) +) ENGINE = InnoDB + AUTO_INCREMENT = 3118 + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='文件夹'; +CREATE TABLE IF NOT EXISTS `statistics` +( + `actor` int DEFAULT NULL COMMENT '操作者', + `action` enum ('UPLOAD','DELETE','ACCESS','DOWNLOAD','SEARCH','LOGIN','INVITE','REGISTER') COLLATE utf8mb4_general_ci NOT NULL COMMENT '所做的操作', + `params` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '操作的参数(在ACCESS操作中为空)', + `time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '操作的时间', + KEY `action` (`action`) COMMENT '操作类型索引', + KEY `actor_index` (`actor`) COMMENT '操作者索引', + KEY `time` (`time`) COMMENT '时间索引' +) ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='统计信息'; +CREATE TABLE IF NOT EXISTS `user` +( + `id` int NOT NULL AUTO_INCREMENT COMMENT '用户ID', + `name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户名', + `password` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户密码(MD5+SHA1)', + `auth` enum ('admin','user') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'user' COMMENT '用户类型', + `banned` tinyint(1) NOT NULL DEFAULT '0' COMMENT '用户是否被封禁', + PRIMARY KEY (`id`) COMMENT 'ID索引', + UNIQUE KEY `name_pk` (`name`), + UNIQUE KEY `login_index` (`name`, `password`) COMMENT '用户名密码索引', + UNIQUE KEY `id_index` (`id`) COMMENT 'ID索引' +) ENGINE = InnoDB + AUTO_INCREMENT = 4 + DEFAULT CHARSET = utf8mb4 + COLLATE = utf8mb4_general_ci COMMENT ='用户表'; \ No newline at end of file