2025-03-08 22:44:23 +08:00

118 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { sequelize } from '../../../modules/sequelize.ts';
import { DataTypes, Model } from 'sequelize';
type AppPermissionType = 'public' | 'private' | 'protected';
export interface AppData {
files: { name: string; path: string }[];
permission?: {
// 访问权限
type: AppPermissionType; // public, private(Only Self), protected(protected, 通过配置访问)
users?: string[];
orgs?: string[];
};
}
export type AppType = 'web-single' | 'web-module'; // 可以做到网页代理
export enum AppStatus {
running = 'running',
stop = 'stop',
}
export type App = Partial<InstanceType<typeof AppModel>>;
/**
* APP 管理
*/
export class AppModel extends Model {
declare id: string;
declare data: AppData;
declare title: string;
declare description: string;
declare version: string;
declare domain: string;
declare appType: string;
declare key: string;
declare type: string;
declare uid: string;
declare pid: string;
// 是否是history路由代理模式。静态的直接转minio而不需要缓存下来。
declare proxy: boolean;
declare user: string;
declare status: string;
}
AppModel.init(
{
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: DataTypes.UUIDV4,
comment: 'id',
},
title: {
type: DataTypes.STRING,
defaultValue: '',
},
description: {
type: DataTypes.STRING,
defaultValue: '',
},
data: {
type: DataTypes.JSONB,
defaultValue: {},
},
version: {
type: DataTypes.STRING,
defaultValue: '',
},
domain: {
type: DataTypes.STRING,
defaultValue: '',
},
appType: {
type: DataTypes.STRING,
defaultValue: '',
},
key: {
type: DataTypes.STRING,
// 和 uid 组合唯一
},
type: {
type: DataTypes.STRING,
defaultValue: '',
},
uid: {
type: DataTypes.UUID,
allowNull: true,
},
pid: {
type: DataTypes.UUID,
allowNull: true,
},
proxy: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
user: {
type: DataTypes.STRING,
allowNull: true,
},
status: {
type: DataTypes.STRING,
defaultValue: 'running', // stop, running
},
},
{
sequelize,
tableName: 'kv_app',
paranoid: true,
indexes: [
{
unique: true,
fields: ['key', 'uid'],
},
],
},
);
AppModel.sync({ alter: true, logging: false }).catch((e) => {
console.error('AppModel sync', e);
});