feat: adding readme and auto table creator
This commit is contained in:
parent
5b01a66371
commit
f83b89ea00
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# File Manager
|
||||
### A self-hosted file share and management system
|
||||
___
|
||||
## How to Use
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
@ -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"
|
@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.wzpmc.filemanager.mapper.InitializationMapper">
|
||||
<insert id="createFileTable">
|
||||
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 ='文件';
|
||||
</insert>
|
||||
<insert id="createFolderTable">
|
||||
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 ='文件夹';
|
||||
</insert>
|
||||
<insert id="createStatisticsTable">
|
||||
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 ='统计信息';
|
||||
</insert>
|
||||
<insert id="createUserTable">
|
||||
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 ='用户表';
|
||||
</insert>
|
||||
</mapper>
|
63
src/main/resources/scheme.sql
Normal file
63
src/main/resources/scheme.sql
Normal file
@ -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 ='用户表';
|
Loading…
x
Reference in New Issue
Block a user