Skip to content

Commit e144360

Browse files
committed
docs: #15 Docs - Supplementary documents
1 parent 947a51c commit e144360

3 files changed

Lines changed: 27 additions & 82 deletions

File tree

README.md

Lines changed: 23 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1-
# upload-file-service
2-
nodejs 实现文件上传功能
1+
<p align="center">
2+
<a href="https://github.com/diskcloud/service">
3+
<img width="150" src="./public/logo.png">
4+
</a>
5+
</p>
6+
7+
<p align="center">
8+
<img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/diskcloud/service">
9+
<img alt="GitHub Issues or Pull Requests" src="https://img.shields.io/github/issues-pr/diskcloud/service">
10+
<img alt="GitHub Issues or Pull Requests" src="https://img.shields.io/github/issues/diskcloud/service">
11+
</p>
12+
13+
## Example
14+
15+
[![YouTube](https://img.youtube.com/vi/5w1dCYBrf2k/0.jpg)](https://youtu.be/5w1dCYBrf2k)
316

417
### 支持功能
518
> 目前均为免费版本,Plus 版本还在规划中,Lite 和 Full 版本永久免费。
@@ -16,8 +29,6 @@ nodejs 实现文件上传功能
1629
| 公开失效时间 ||||
1730
| 高级搜索功能 ||||
1831

19-
[![YouTube](https://img.youtube.com/vi/5w1dCYBrf2k/0.jpg)](https://youtu.be/5w1dCYBrf2k)
20-
2132
### 使用方法
2233

2334
```shell
@@ -28,41 +39,9 @@ yarn dev
2839

2940
> 启动完成之后,会自动创建 resource 作为资源文件夹,而 provisional 会作为临时文件夹。后续会考虑开启定时任务进行清理。
3041
31-
### 目录结构
32-
33-
```shell
34-
├── LICENSE
35-
├── README.md
36-
├── constants
37-
│ └── file.js
38-
├── index.js
39-
├── models # 表模型
40-
│ └── files.js
41-
├── package.json
42-
├── public
43-
│ ├── icons
44-
│ │ ├── doc.png
45-
│ │ ├── document.png
46-
│ │ ├── folders.png
47-
│ │ ├── pdf.png
48-
│ │ ├── psd.png
49-
│ │ ├── shared_folders.png
50-
│ │ ├── unknown_file_types.png
51-
│ │ ├── video.png
52-
│ │ ├── xlsx.png
53-
│ │ └── zip.png
54-
│ └── index.html
55-
├── routers # 路由
56-
│ └── files.js
57-
├── utils
58-
│ ├── createPath.js
59-
│ ├── dbInstance.js
60-
│ ├── detectFileType.js
61-
│ └── responseFormatter.js
62-
└── yarn.lock
63-
```
6442

6543
### 环境变量
44+
6645
创建一个 `.env.local` 文件,在里面配置对应的环境变量
6746

6847
```env
@@ -76,49 +55,13 @@ MYSQL_HOST=
7655
MYSQL_USER=root
7756
MYSQL_PASSWORD=
7857
MYSQL_PORT=3306
58+
REDIS_HOST=127.0.0.1
59+
REDIS_PORT=6379
60+
USER_LOGIN_TOKEN_EXPIRE_TIME=3600
61+
JWT_EXPIRES_IN=1h
62+
JWT_SECRET=
7963
```
8064

81-
### 创建表的字段说明
82-
83-
> 启动项目则会,自动创建创建 `files` 表结构
84-
85-
```sql
86-
CREATE TABLE files (
87-
id VARCHAR(50) DEFAULT NULL,
88-
filename VARCHAR(255) NOT NULL,
89-
file_size BIGINT(20) NOT NULL,
90-
file_location VARCHAR(255) NOT NULL,
91-
created_by VARCHAR(255) NOT NULL,
92-
created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
93-
updated_by VARCHAR(255) DEFAULT NULL,
94-
updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
95-
is_public TINYINT(1) DEFAULT '0',
96-
public_expiration TIMESTAMP NULL DEFAULT NULL,
97-
public_by VARCHAR(255) DEFAULT NULL,
98-
is_thumb TINYINT(1) DEFAULT NULL,
99-
thumb_location VARCHAR(255) DEFAULT NULL,
100-
is_delete TINYINT(1) NOT NULL DEFAULT '0',
101-
real_file_location VARCHAR(255) DEFAULT NULL,
102-
real_file_thumb_location VARCHAR(255) DEFAULT NULL,
103-
mime VARCHAR(255) DEFAULT NULL,
104-
ext VARCHAR(50) DEFAULT NULL,
105-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
106-
```
107-
108-
| 列名 | 数据类型 | 是否为空 | 默认值 | 注释 |
109-
|------------------|----------------|----------|----------------------|----------------------------------------------|
110-
| `id` | int(11) | NOT NULL | | 文件的唯一标识 |
111-
| `filename` | varchar(255) | NOT NULL | | 文件名 |
112-
| `file_size` | bigint(20) | NOT NULL | | 文件大小(以字节为单位) |
113-
| `file_location` | varchar(255) | NOT NULL | | 文件存储的位置 |
114-
| `created_by` | varchar(255) | NOT NULL | | 创建该文件的用户 |
115-
| `created_at` | timestamp | NULL | CURRENT_TIMESTAMP | 文件的创建时间,默认当前时间 |
116-
| `updated_by` | varchar(255) | NULL | NULL | 最近更新该文件的用户 |
117-
| `updated_at` | timestamp | NULL | CURRENT_TIMESTAMP | 最近更新的时间,默认当前时间,更新时自动修改 |
118-
| `is_public` | tinyint(1) | NULL | '0' | 是否公开,默认值为0(不公开) |
119-
| `public_expiration` | timestamp | NULL | NULL | 公开访问的截止时间 |
120-
| `public_by` | varchar(255) | NULL | NULL | 设置公开的用户 |
121-
| `is_thumb` | tinyint(1) | NULL | '0' | 是否为缩略图,默认值为0(不是缩略图) |
122-
| `thumb_location` | varchar(255) | NULL | NULL | 缩略图存储的位置 |
123-
| `is_delete` | tinyint(1) | NOT NULL | '0' | 是否被删除,默认值为0(未删除) |
65+
## Contributors 💪
12466

67+
<a href="https://github.com/diskcloud/service/graphs/contributors"><img src="https://opencollective.com/diskcloud/contributors.svg?width=890" /></a>

middleware/authenticateToken.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ const isWhitelisted = (url, method) => {
2323
};
2424

2525
const authenticateToken = async (ctx, next) => {
26-
if (isWhitelisted(ctx.path, ctx.method)) {
26+
// token 不存在并且在白名单类,免除校验
27+
const token = ctx.headers["authorization"]?.replace("Bearer ", "");
28+
29+
if (isWhitelisted(ctx.path, ctx.method) && !token) {
2730
await next();
2831
return;
2932
}
3033

3134
try {
32-
const token = ctx.headers["authorization"]?.replace("Bearer ", "");
3335
if (!token) {
3436
ctx.status = 403;
3537
ctx.body = { message: "Not Logged In" };

public/logo.png

14 KB
Loading

0 commit comments

Comments
 (0)