This commit is contained in:
rgrgogu
2026-05-14 12:59:42 +08:00
parent 06c4286c4a
commit c3663572ae
12 changed files with 570 additions and 536 deletions
+43 -50
View File
@@ -1,84 +1,77 @@
// models/Asset.js
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const sequelize = require("../../config/db.config");
const mdl_Users = require("../users/users.mdl")
const Asset = sequelize.define("Asset", {
// ─── Identity ─────────────────────────────────────────────────────────────
asset_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false, unique: true },
asset_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true, label: "Asset ID", order: 0, hidden: true },
uuid: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, allowNull: false, unique: true, label: "UUID", order: 0, hidden: true },
// ─── File info ────────────────────────────────────────────────────────────
original_name: { type: DataTypes.STRING(255), allowNull: false },
display_name: { type: DataTypes.STRING(255), allowNull: false },
file_url: { type: DataTypes.STRING(512), allowNull: false },
file_size: { type: DataTypes.BIGINT, allowNull: false },
mime_type: { type: DataTypes.STRING(100), allowNull: false },
extension: { type: DataTypes.STRING(20) },
checksum: { type: DataTypes.STRING(64) },
original_name: { type: DataTypes.STRING(255), allowNull: false, label: "Original Name", order: 0, hidden: true },
display_name: { type: DataTypes.STRING(255), allowNull: false, label: "Name", order: 0 },
file_url: { type: DataTypes.STRING(512), allowNull: false, label: "File URL", order: 0, hidden: true },
file_size: { type: DataTypes.BIGINT, allowNull: false, label: "File Size", order: 0, hidden: true },
mime_type: { type: DataTypes.STRING(100), allowNull: false, label: "MIME Type", order: 0, hidden: true },
extension: { type: DataTypes.STRING(20), label: "File Type", order: 0 },
checksum: { type: DataTypes.STRING(64), label: "Checksum", order: 0, hidden: true },
// ─── Classification ───────────────────────────────────────────────────────
file_type: {
type: DataTypes.ENUM("image", "video", "document", "other"),
allowNull: false,
defaultValue: "other",
type: DataTypes.ENUM("avatar", "document", "video", "image"),
allowNull: false,
defaultValue: "image", label: "Classification", order: 0
},
// ─── Image & video dimensions ─────────────────────────────────────────────
width: { type: DataTypes.INTEGER },
height: { type: DataTypes.INTEGER },
width: { type: DataTypes.INTEGER, label: "", order: 0, hidden: true },
height: { type: DataTypes.INTEGER, label: "", order: 0, hidden: true },
// ─── Video-specific ───────────────────────────────────────────────────────
duration: { type: DataTypes.FLOAT }, // seconds
resolution: { type: DataTypes.STRING(20) }, // "1080p", "720p", "4K"
frame_rate: { type: DataTypes.FLOAT }, // fps
bitrate: { type: DataTypes.BIGINT }, // bps
video_codec: { type: DataTypes.STRING(50) }, // "H.264", "H.265"
audio_codec: { type: DataTypes.STRING(50) }, // "AAC", "MP3"
thumbnail_url: { type: DataTypes.STRING(512) }, // face of the video / doc preview
duration: { type: DataTypes.FLOAT, label: "", order: 0, hidden: true }, // seconds
resolution: { type: DataTypes.STRING(20), label: "", order: 0, hidden: true }, // "1080p", "720p", "4K"
frame_rate: { type: DataTypes.FLOAT, label: "", order: 0, hidden: true }, // fps
bitrate: { type: DataTypes.BIGINT, label: "", order: 0, hidden: true }, // bps
video_codec: { type: DataTypes.STRING(50), label: "", order: 0, hidden: true }, // "H.264", "H.265"
audio_codec: { type: DataTypes.STRING(50), label: "", order: 0, hidden: true }, // "AAC", "MP3"
thumbnail_url: { type: DataTypes.STRING(512), label: "", order: 0, hidden: true }, // face of the video / doc preview
// ─── Description ──────────────────────────────────────────────────────────
description: { type: DataTypes.TEXT },
description: { type: DataTypes.TEXT, label: "Description", hidden: true },
// ─── Storage ──────────────────────────────────────────────────────────────
storage_provider: {
type: DataTypes.ENUM("local", "s3", "gcs", "cloudinary", "chibisafe", "other"),
defaultValue: "local",
type: DataTypes.ENUM("local", "s3", "gcs", "cloudinary", "chibisafe", "other"),
defaultValue: "local", label: "Storage Provider", order: 0
},
storage_bucket: { type: DataTypes.STRING(255) },
storage_key: { type: DataTypes.STRING(512) },
storage_bucket: { type: DataTypes.STRING(255), label: "", order: 0, hidden: true },
storage_key: { type: DataTypes.STRING(512), label: "", order: 0, hidden: true },
// ─── Access control ───────────────────────────────────────────────────────
is_public: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
access_level: {
type: DataTypes.ENUM("public", "private", "restricted"),
defaultValue: "private",
type: DataTypes.BOOLEAN,
defaultValue: false, label: "Access Type", order: 0
},
// ─── Polymorphic ownership ────────────────────────────────────────────────
owner_type: { type: DataTypes.STRING(100) }, // avatar, document, video, image
owner_id: { type: DataTypes.BIGINT },
// ─── Who did what ─────────────────────────────────────────────────────────
uploadedBy: { type: DataTypes.BIGINT, allowNull: false },
deletedBy: { type: DataTypes.BIGINT, allowNull: true },
// ─── Soft delete ──────────────────────────────────────────────────────────
deletedAt: { type: DataTypes.DATE, allowNull: true, defaultValue: null },
// ── Audit trails ────────────────────────────────────────────────────────────
createdBy: { type: DataTypes.BIGINT, allowNull: true, label: "Created By" },
updatedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Modified By" },
deletedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Deleted By" },
}, {
tableName: "assets",
tableName: "assets",
timestamps: true, // createdAt, updatedAt
paranoid: false,
paranoid: true,
indexes: [
{ fields: ["uuid"] },
{ fields: ["owner_type", "owner_id"] },
{ fields: ["uploadedBy"] },
{ fields: ["file_type"] },
{ fields: ["deletedAt"] },
{ fields: ["uuid"] },
{ fields: ["createdBy"] },
{ fields: ["file_type"] },
{ fields: ["deletedAt"] },
],
});
Asset.belongsTo(mdl_Users, { as: "creator", foreignKey: "createdBy" });
Asset.belongsTo(mdl_Users, { as: "updater", foreignKey: "updatedBy" });
module.exports = Asset;