- 登录/邮箱验证码/密码流程(controller/auth.js、lib/emailCode.js、middleware/jwt_auth.js) - 主体(principal)隔离与主体用户、对外接口配置模块及 principalCheck 中间件 - 菜单、用户、文件上传、快递公司字典(express_companies)等基础模块 - 通用工具:分页(lib/pagination.js)、缓存(service/cache.js) - 全量接口契约(contract/index.js)与路由注册(router.js)、config.default.js 配置 - 相关迁移:菜单组件调整与菜单种子、创建 files 表
36 lines
1.6 KiB
JavaScript
36 lines
1.6 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 文件资源模型,对应 files 表
|
||
* 同一主体下按内容 hash 去重(uk_files_principal_hash),磁盘路径按「主体ID/年/月/日」分层
|
||
* @param {Egg.Application} app egg application
|
||
* @return {object} file model
|
||
*/
|
||
module.exports = app => {
|
||
const { BIGINT, STRING, INTEGER, DATE } = app.Sequelize;
|
||
|
||
const File = app.model.define('file', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
principal_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' },
|
||
hash: { type: STRING(64), allowNull: false, comment: '文件内容 SHA256,用于去重' },
|
||
name: { type: STRING(255), allowNull: false, comment: '原始文件名' },
|
||
ext: { type: STRING(20), allowNull: false, comment: '扩展名(小写,含点,如 .png)' },
|
||
mime: { type: STRING(100), comment: 'MIME 类型' },
|
||
size: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '文件大小(字节)' },
|
||
path: { type: STRING(255), allowNull: false, comment: '相对存储路径:主体ID/年/月/日/hash.ext' },
|
||
url: { type: STRING(500), allowNull: false, comment: '访问地址' },
|
||
created_at: { type: DATE, comment: '创建时间' },
|
||
updated_at: { type: DATE, comment: '更新时间' },
|
||
deleted_at: { type: DATE, comment: '软删除时间' },
|
||
}, {
|
||
paranoid: true,
|
||
deletedAt: 'deleted_at',
|
||
});
|
||
|
||
File.associate = () => {
|
||
app.model.File.belongsTo(app.model.Principal, { foreignKey: 'principal_id', as: 'principal' });
|
||
};
|
||
|
||
return File;
|
||
};
|