This commit is contained in:
rgrgogu
2026-05-12 00:09:09 +08:00
parent 4e6017c79b
commit d3ff140688
9 changed files with 1350 additions and 509 deletions
+49
View File
@@ -0,0 +1,49 @@
// 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
"deletedBy", // exposed via audit subquery as a name instead
];
// 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,
};
+1 -1
View File
@@ -59,7 +59,7 @@ const Asset = sequelize.define("Asset", {
},
// ─── Polymorphic ownership ────────────────────────────────────────────────
owner_type: { type: DataTypes.STRING(100) }, // e.g. "Course", "Channel", "Post", "User"
owner_type: { type: DataTypes.STRING(100) }, // avatar, document, video, image
owner_id: { type: DataTypes.BIGINT },
// ─── Who did what ─────────────────────────────────────────────────────────