mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
chore: relocate backend into apps/api ahead of monorepo merge
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// models/assets/assets.attributes.js
|
||||
|
||||
// ─── Exclude sets ─────────────────────────────────────────────────────────────
|
||||
|
||||
// Fields hidden from all roles (sensitive / internal storage details)
|
||||
const excludeAttributes = [
|
||||
"checksum", // internal integrity hash, not useful to clients
|
||||
"storage_bucket", // internal storage config
|
||||
"storage_key", // internal Chibisafe / S3 key
|
||||
];
|
||||
|
||||
// Admins see everything except the base excludes
|
||||
const adminExclude = [
|
||||
...excludeAttributes,
|
||||
];
|
||||
|
||||
// Regular users also cannot see audit trails or soft-delete info
|
||||
const userExclude = [
|
||||
...excludeAttributes,
|
||||
"uploadedBy",
|
||||
"deletedAt",
|
||||
];
|
||||
|
||||
// ─── No JSONB columns on assets ───────────────────────────────────────────────
|
||||
// Assets has no JSONB columns so jsonbSchemas stays empty.
|
||||
const jsonbSchemas = {};
|
||||
|
||||
// ─── Computed attributes ──────────────────────────────────────────────────────
|
||||
// Add any SQL-computed fields here (e.g. a view count join).
|
||||
// Format: { key, label, type, order, literal }
|
||||
const computedAttributes = [
|
||||
// Example:
|
||||
// {
|
||||
// key: "viewCount",
|
||||
// label: "Views",
|
||||
// type: "number",
|
||||
// order: 99,
|
||||
// literal: `(SELECT COUNT(*) FROM "asset_views" WHERE "asset_views"."asset_id" = "Asset"."asset_id")`,
|
||||
// },
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
excludeAttributes,
|
||||
adminExclude,
|
||||
userExclude,
|
||||
jsonbSchemas,
|
||||
computedAttributes,
|
||||
};
|
||||
@@ -0,0 +1,85 @@
|
||||
// models/Asset.js
|
||||
const { DataTypes } = require("sequelize");
|
||||
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, 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, label: "Original Name", order: 0, hidden: true },
|
||||
display_name: { type: DataTypes.STRING(255), allowNull: false, label: "Name", order: 0, filterable: true },
|
||||
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 },
|
||||
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, filterable: true },
|
||||
checksum: { type: DataTypes.STRING(64), label: "Checksum", order: 0, hidden: true },
|
||||
|
||||
// ─── Classification ───────────────────────────────────────────────────────
|
||||
file_type: {
|
||||
type: DataTypes.ENUM("avatar", "document", "video", "image", "audio"),
|
||||
allowNull: false,
|
||||
defaultValue: "image", label: "Classification", order: 0
|
||||
},
|
||||
|
||||
// ─── Image & video dimensions ─────────────────────────────────────────────
|
||||
width: { type: DataTypes.INTEGER, label: "", order: 0, hidden: true },
|
||||
height: { type: DataTypes.INTEGER, label: "", order: 0, hidden: true },
|
||||
|
||||
// ─── Video-specific ───────────────────────────────────────────────────────
|
||||
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 },
|
||||
thumbnail_storage_key: { type: DataTypes.STRING(512), label: "", order: 0, hidden: true },
|
||||
|
||||
// ─── Background remux (.mov/.mkv → faststart .mp4) ───────────────────────
|
||||
// "none" — asset never needed a remux (not video, or already a fast format).
|
||||
// STRING, not ENUM — matches the STRING+CHECK column (see migration
|
||||
// 20270101000076), not a real Postgres enum type.
|
||||
transcode_status: { type: DataTypes.STRING(20), defaultValue: "none", label: "", order: 0, hidden: true },
|
||||
transcode_error: { type: DataTypes.TEXT, label: "", order: 0, hidden: true },
|
||||
|
||||
// ─── Description ──────────────────────────────────────────────────────────
|
||||
description: { type: DataTypes.TEXT, label: "Description", hidden: true },
|
||||
|
||||
// ─── Storage ──────────────────────────────────────────────────────────────
|
||||
storage_provider: {
|
||||
type: DataTypes.ENUM("local", "s3", "gcs", "cloudinary", "chibisafe", "other"),
|
||||
defaultValue: "local", label: "Storage Provider", order: 0
|
||||
},
|
||||
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, label: "Access Type", order: 0
|
||||
},
|
||||
|
||||
// ── Audit trails ────────────────────────────────────────────────────────────
|
||||
createdBy: { type: DataTypes.BIGINT, allowNull: true, label: "Created By", filterable: true },
|
||||
updatedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Modified By", filterable: true },
|
||||
deletedBy: { type: DataTypes.BIGINT, allowNull: true, label: "Deleted By", filterable: true },
|
||||
}, {
|
||||
tableName: "assets",
|
||||
timestamps: true, // createdAt, updatedAt
|
||||
paranoid: true,
|
||||
indexes: [
|
||||
{ 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;
|
||||
Reference in New Issue
Block a user