Coder Social home page Coder Social logo

crazymryan / upload-file-service Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 323 KB

使用 Nodejs + Koa + Sequelize 实现文件上传服务,可图片压缩、生成缩略图、添加水印、防盗链

License: MIT License

JavaScript 74.00% HTML 26.00%
file-upload file-upload-server file-upload-service image-thumbnails mysql2 nodejs sharp tinify upload-file-service sequelize

upload-file-service's Introduction

upload-file-service

nodejs 实现文件上传功能

注意此项目不在更新(作为基础项目存档),新开了一个组织,有兴趣的小伙伴可以参考 diskcloud/service,欢迎提ISSUES、PR等,一起建设此项目,

支持功能

目前均为免费版本,Plus 版本还在规划中,Lite 和 Full 版本永久免费。

功能 Lite(缩减版) Full(全量版) Plus(增强版)
数据出入库
缩略图
图片压缩
返回 md 格式
保留原始文件
文件水印
自动定时备份
公开失效时间
高级搜索功能

YouTube

使用方法

yarn install

yarn dev

启动完成之后,会自动创建 resource 作为资源文件夹,而 provisional 会作为临时文件夹。后续会考虑开启定时任务进行清理。

目录结构

├── LICENSE
├── README.md
├── constants
│   └── file.js
├── index.js
├── models # 表模型
│   └── files.js
├── package.json
├── public
│   ├── icons
│   │   ├── doc.png
│   │   ├── document.png
│   │   ├── folders.png
│   │   ├── pdf.png
│   │   ├── psd.png
│   │   ├── shared_folders.png
│   │   ├── unknown_file_types.png
│   │   ├── video.png
│   │   ├── xlsx.png
│   │   └── zip.png
│   └── index.html
├── routers # 路由
│   └── files.js
├── utils
│   ├── createPath.js
│   ├── dbInstance.js
│   ├── detectFileType.js
│   └── responseFormatter.js
└── yarn.lock

环境变量

创建一个 .env.local 文件,在里面配置对应的环境变量

TINIFY_KEY= #Tinify 压缩图片的key。如果不需要图片压缩则可以不写
INTERNAL_NETWORK_DOMAIN=http://localhost:3000
PUBLIC_NETWORK_DOMAIN=http://localhost:3000
SERVER_PORT=3000
DIALECT=mysql
MYSQL_DATABASE=
MYSQL_HOST=
MYSQL_USER=root
MYSQL_PASSWORD=
MYSQL_PORT=3306

创建表的字段说明

启动项目则会,自动创建创建 files 表结构

CREATE TABLE files (
    id VARCHAR(50) DEFAULT NULL,
    filename VARCHAR(255) NOT NULL,
    file_size BIGINT(20) NOT NULL,
    file_location VARCHAR(255) NOT NULL,
    created_by VARCHAR(255) NOT NULL,
    created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
    updated_by VARCHAR(255) DEFAULT NULL,
    updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    is_public TINYINT(1) DEFAULT '0',
    public_expiration TIMESTAMP NULL DEFAULT NULL,
    public_by VARCHAR(255) DEFAULT NULL,
    is_thumb TINYINT(1) DEFAULT NULL,
    thumb_location VARCHAR(255) DEFAULT NULL,
    is_delete TINYINT(1) NOT NULL DEFAULT '0',
    real_file_location VARCHAR(255) DEFAULT NULL,
    real_file_thumb_location VARCHAR(255) DEFAULT NULL,
    mime VARCHAR(255) DEFAULT NULL,
    ext VARCHAR(50) DEFAULT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
列名 数据类型 是否为空 默认值 注释
id int(11) NOT NULL 文件的唯一标识
filename varchar(255) NOT NULL 文件名
file_size bigint(20) NOT NULL 文件大小(以字节为单位)
file_location varchar(255) NOT NULL 文件存储的位置
created_by varchar(255) NOT NULL 创建该文件的用户
created_at timestamp NULL CURRENT_TIMESTAMP 文件的创建时间,默认当前时间
updated_by varchar(255) NULL NULL 最近更新该文件的用户
updated_at timestamp NULL CURRENT_TIMESTAMP 最近更新的时间,默认当前时间,更新时自动修改
is_public tinyint(1) NULL '0' 是否公开,默认值为0(不公开)
public_expiration timestamp NULL NULL 公开访问的截止时间
public_by varchar(255) NULL NULL 设置公开的用户
is_thumb tinyint(1) NULL '0' 是否为缩略图,默认值为0(不是缩略图)
thumb_location varchar(255) NULL NULL 缩略图存储的位置
is_delete tinyint(1) NOT NULL '0' 是否被删除,默认值为0(未删除)

upload-file-service's People

Contributors

crazymryan avatar

Stargazers

 avatar

Watchers

 avatar  avatar

upload-file-service's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.