- Deleted `http.ts` which contained custom HTTP routes for authentication and JWKS. - Removed `schema.ts` that defined database schemas for `github_starred`, `users`, and `sessions`. - Updated `package.json` to remove the Convex dependency and updated other dependencies. - Deleted SQL script `clear.sql` for removing constraints from tables. - Removed `update.sh` script for updating dependencies. - Deleted demo application routes and models in `app-demo` directory. - Cleaned up unused modules and imports across various files. - Removed Redis and common utility scripts that were not in use. - Deleted test scripts related to user and bucket management.
83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
import { sequelize } from '../../../modules/sequelize.ts';
|
|
import { DataTypes, Model } from 'sequelize';
|
|
export type DomainList = Partial<InstanceType<typeof AppDomainModel>>;
|
|
import { redis } from '../../../modules/redis.ts';
|
|
|
|
// 审核,通过,驳回
|
|
const appDomainStatus = ['audit', 'auditReject', 'auditPending', 'running', 'stop'] as const;
|
|
|
|
type AppDomainStatus = (typeof appDomainStatus)[number];
|
|
/**
|
|
* 应用域名管理
|
|
*/
|
|
export class AppDomainModel extends Model {
|
|
declare id: string;
|
|
declare domain: string;
|
|
declare appId: string;
|
|
// 状态,
|
|
declare status: AppDomainStatus;
|
|
declare uid: string;
|
|
declare data: Record<string, any>;
|
|
|
|
declare createdAt: Date;
|
|
declare updatedAt: Date;
|
|
|
|
checkCanUpdateStatus(newStatus: AppDomainStatus) {
|
|
// 原本是运行中,可以改为停止,原本是停止,可以改为运行。
|
|
if (this.status === 'running' || this.status === 'stop') {
|
|
return true;
|
|
}
|
|
// 原本是审核状态,不能修改。
|
|
return false;
|
|
}
|
|
async clearCache() {
|
|
// 清除缓存
|
|
const cacheKey = `domain:${this.domain}`;
|
|
const checkHas = async () => {
|
|
const has = await redis.get(cacheKey);
|
|
return has;
|
|
};
|
|
const has = await checkHas();
|
|
if (has) {
|
|
await redis.set(cacheKey, '', 'EX', 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
AppDomainModel.init(
|
|
{
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
primaryKey: true,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
comment: 'id',
|
|
},
|
|
domain: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
unique: true,
|
|
},
|
|
data: {
|
|
type: DataTypes.JSONB,
|
|
allowNull: true,
|
|
},
|
|
status: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
defaultValue: 'running',
|
|
},
|
|
appId: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
},
|
|
uid: {
|
|
type: DataTypes.STRING,
|
|
allowNull: true,
|
|
},
|
|
},
|
|
{
|
|
sequelize,
|
|
tableName: 'kv_app_domain',
|
|
paranoid: true,
|
|
},
|
|
); |