feat: additional field

This commit is contained in:
Methapon2001 2023-12-26 14:52:02 +07:00
parent 2da9f91e4e
commit ae2e0edfd2
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
5 changed files with 110 additions and 1 deletions

View file

@ -75,10 +75,14 @@ interface FileBody {
title?: string; title?: string;
/** @example "การเงิน" */ /** @example "การเงิน" */
description?: string; description?: string;
/** @example "นายก" */
author?: string;
/** @example ["การเงิน", "รายงาน"] */ /** @example ["การเงิน", "รายงาน"] */
category?: string[]; category?: string[];
/** @example ["การเงิน", "รายรับ", "รายจ่าย"] */ /** @example ["การเงิน", "รายรับ", "รายจ่าย"] */
keyword?: string[]; keyword?: string[];
/** @example {} */
metadata?: { [key: string]: unknown };
/** @example false */ /** @example false */
hidden?: boolean; hidden?: boolean;
} }
@ -250,6 +254,7 @@ export class StorageController extends Controller {
path: "ตู้เอกสาร 1/ลิ้นชัก 1/แฟ้ม 1/", path: "ตู้เอกสาร 1/ลิ้นชัก 1/แฟ้ม 1/",
title: "เอกสาร", title: "เอกสาร",
description: "เอกสารการเงิน", description: "เอกสารการเงิน",
author: "นายก",
category: ["บัญชี"], category: ["บัญชี"],
keyword: ["เงิน", "บัญชี", "รายจ่าย", "รายรับ"], keyword: ["เงิน", "บัญชี", "รายจ่าย", "รายรับ"],
upload: false, upload: false,
@ -498,6 +503,7 @@ export class StorageController extends Controller {
path: "ตู้เอกสาร 1/ลิ้นชัก 1/แฟ้ม 1/", path: "ตู้เอกสาร 1/ลิ้นชัก 1/แฟ้ม 1/",
title: "เอกสาร", title: "เอกสาร",
description: "เอกสารการเงิน", description: "เอกสารการเงิน",
author: "นายก",
category: ["บัญชี"], category: ["บัญชี"],
keyword: ["เงิน", "บัญชี", "รายจ่าย", "รายรับ"], keyword: ["เงิน", "บัญชี", "รายจ่าย", "รายรับ"],
upload: false, upload: false,
@ -540,9 +546,11 @@ export class StorageController extends Controller {
fileSize: 0, // Will be get by minio object storage after file is uploaded fileSize: 0, // Will be get by minio object storage after file is uploaded
fileType: "", // Will be determined by minio object storage after file is uploaded fileType: "", // Will be determined by minio object storage after file is uploaded
title: body.title ?? validFileName, // default to same as filename title: body.title ?? validFileName, // default to same as filename
author: body.author ?? "",
description: body.description ?? "", description: body.description ?? "",
category: body.category ?? [], category: body.category ?? [],
keyword: body.keyword ?? [], keyword: body.keyword ?? [],
metadata: body.metadata ?? {},
upload: false, // flag upload: false, // flag
hidden: body.hidden ?? false, hidden: body.hidden ?? false,
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
@ -675,6 +683,12 @@ export class StorageController extends Controller {
id: id, id: id,
doc: { doc: {
...metadata, ...metadata,
metadata: metadata["metadata"]
? {
...source["metadata"], // keep old field
...metadata["metadata"], // replace some field that user update
}
: undefined,
path: stripLeadingSlash(`${to.path.join("/")}/`), path: stripLeadingSlash(`${to.path.join("/")}/`),
pathname: dst, pathname: dst,
fileName: to.file, fileName: to.file,
@ -786,6 +800,7 @@ export class StorageController extends Controller {
description: "เอกสารการเงิน", description: "เอกสารการเงิน",
category: ["บัญชี"], category: ["บัญชี"],
keyword: ["เงิน", "บัญชี", "รายจ่าย", "รายรับ"], keyword: ["เงิน", "บัญชี", "รายจ่าย", "รายรับ"],
author: "นายก",
upload: false, upload: false,
hidden: false, hidden: false,
fileName: "เอกสาร 1.pdf", fileName: "เอกสาร 1.pdf",

View file

@ -26,6 +26,8 @@ export interface StorageFile {
description: string; description: string;
category: string[]; category: string[];
keyword: string[]; keyword: string[];
author: string;
metadata: Record<string, unknown>;
path: string; path: string;
upload: boolean; upload: boolean;

View file

@ -3,6 +3,23 @@ import esClient from "../elasticsearch";
import minioClient from "../minio"; import minioClient from "../minio";
import * as io from "../lib/websocket"; import * as io from "../lib/websocket";
// const MINIO_ERROR_MESSAGE = "เกิดข้อผิดพลาดกับระบบจัดการไฟล์";
// async function checkPathExist(bucket: string, path: string[]) {
// if (path.filter(Boolean).length === 0) return true; // root does not contain any mark
// return await checkFileExist(bucket, `${path.filter(Boolean).join("/")}/.keep`);
// }
//
// async function checkFileExist(bucket: string, pathname: string) {
// return Boolean(
// await minioClient.statObject(bucket, stripLeadingSlash(pathname)).catch((e) => {
// if (e.code === "NotFound") return false;
// console.error(`Storage Error: ${e}`);
// throw new Error(MINIO_ERROR_MESSAGE);
// }),
// );
// }
const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX; const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX;
if (!DEFAULT_INDEX) throw Error("Default ElasticSearch index must be specified."); if (!DEFAULT_INDEX) throw Error("Default ElasticSearch index must be specified.");
@ -122,15 +139,17 @@ async function handleNotFoundRecord(
fileType: stat.type, fileType: stat.type,
title: "", title: "",
description: "", description: "",
author: "",
category: [], category: [],
keyword: [], keyword: [],
metadata: {},
upload: true, upload: true,
hidden: false, hidden: false,
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
createdBy: "n/a", createdBy: "n/a",
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
updatedBy: "n/a", updatedBy: "n/a",
} satisfies Partial<StorageFile>; } satisfies StorageFile;
const result = await esClient const result = await esClient
.index({ .index({

View file

@ -16,6 +16,11 @@ import type { RequestHandler, Router } from 'express';
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
const models: TsoaRoute.Models = { const models: TsoaRoute.Models = {
"Record_string.unknown_": {
"dataType": "refAlias",
"type": {"dataType":"nestedObjectLiteral","nestedProperties":{},"validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"StorageFile": { "StorageFile": {
"dataType": "refObject", "dataType": "refObject",
"properties": { "properties": {
@ -27,6 +32,8 @@ const models: TsoaRoute.Models = {
"description": {"dataType":"string","required":true}, "description": {"dataType":"string","required":true},
"category": {"dataType":"array","array":{"dataType":"string"},"required":true}, "category": {"dataType":"array","array":{"dataType":"string"},"required":true},
"keyword": {"dataType":"array","array":{"dataType":"string"},"required":true}, "keyword": {"dataType":"array","array":{"dataType":"string"},"required":true},
"author": {"dataType":"string","required":true},
"metadata": {"ref":"Record_string.unknown_","required":true},
"path": {"dataType":"string","required":true}, "path": {"dataType":"string","required":true},
"upload": {"dataType":"boolean","required":true}, "upload": {"dataType":"boolean","required":true},
"hidden": {"dataType":"boolean","required":true}, "hidden": {"dataType":"boolean","required":true},
@ -95,6 +102,11 @@ const models: TsoaRoute.Models = {
"additionalProperties": false, "additionalProperties": false,
}, },
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"Record_string.any_": {
"dataType": "refAlias",
"type": {"dataType":"nestedObjectLiteral","nestedProperties":{},"validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"FileBody": { "FileBody": {
"dataType": "refObject", "dataType": "refObject",
"properties": { "properties": {
@ -102,8 +114,10 @@ const models: TsoaRoute.Models = {
"file": {"dataType":"string","required":true}, "file": {"dataType":"string","required":true},
"title": {"dataType":"string"}, "title": {"dataType":"string"},
"description": {"dataType":"string"}, "description": {"dataType":"string"},
"author": {"dataType":"string"},
"category": {"dataType":"array","array":{"dataType":"string"}}, "category": {"dataType":"array","array":{"dataType":"string"}},
"keyword": {"dataType":"array","array":{"dataType":"string"}}, "keyword": {"dataType":"array","array":{"dataType":"string"}},
"metadata": {"dataType":"nestedObjectLiteral","nestedProperties":{},"additionalProperties":{"dataType":"any"}},
"hidden": {"dataType":"boolean"}, "hidden": {"dataType":"boolean"},
}, },
"additionalProperties": false, "additionalProperties": false,
@ -117,6 +131,8 @@ const models: TsoaRoute.Models = {
"title": {"dataType":"string"}, "title": {"dataType":"string"},
"description": {"dataType":"string"}, "description": {"dataType":"string"},
"category": {"dataType":"array","array":{"dataType":"string"}}, "category": {"dataType":"array","array":{"dataType":"string"}},
"author": {"dataType":"string"},
"metadata": {"dataType":"nestedObjectLiteral","nestedProperties":{},"additionalProperties":{"dataType":"any"}},
"from": {"dataType":"nestedObjectLiteral","nestedProperties":{"file":{"dataType":"string","required":true},"path":{"dataType":"array","array":{"dataType":"string"},"required":true}},"required":true}, "from": {"dataType":"nestedObjectLiteral","nestedProperties":{"file":{"dataType":"string","required":true},"path":{"dataType":"array","array":{"dataType":"string"},"required":true}},"required":true},
"to": {"dataType":"nestedObjectLiteral","nestedProperties":{"file":{"dataType":"string","required":true},"path":{"dataType":"array","array":{"dataType":"string"},"required":true}}}, "to": {"dataType":"nestedObjectLiteral","nestedProperties":{"file":{"dataType":"string","required":true},"path":{"dataType":"array","array":{"dataType":"string"},"required":true}}},
"upload": {"dataType":"boolean"}, "upload": {"dataType":"boolean"},

View file

@ -6,6 +6,11 @@
"requestBodies": {}, "requestBodies": {},
"responses": {}, "responses": {},
"schemas": { "schemas": {
"Record_string.unknown_": {
"properties": {},
"type": "object",
"description": "Construct a type with a set of properties K of type T"
},
"StorageFile": { "StorageFile": {
"properties": { "properties": {
"pathname": { "pathname": {
@ -39,6 +44,12 @@
}, },
"type": "array" "type": "array"
}, },
"author": {
"type": "string"
},
"metadata": {
"$ref": "#/components/schemas/Record_string.unknown_"
},
"path": { "path": {
"type": "string" "type": "string"
}, },
@ -86,6 +97,8 @@
"description", "description",
"category", "category",
"keyword", "keyword",
"author",
"metadata",
"path", "path",
"upload", "upload",
"hidden", "hidden",
@ -314,6 +327,11 @@
"type": "object", "type": "object",
"additionalProperties": false "additionalProperties": false
}, },
"Record_string.any_": {
"properties": {},
"type": "object",
"description": "Construct a type with a set of properties K of type T"
},
"FileBody": { "FileBody": {
"properties": { "properties": {
"path": { "path": {
@ -339,6 +357,10 @@
"type": "string", "type": "string",
"example": "การเงิน" "example": "การเงิน"
}, },
"author": {
"type": "string",
"example": "นายก"
},
"category": { "category": {
"items": { "items": {
"type": "string" "type": "string"
@ -360,6 +382,12 @@
"รายจ่าย" "รายจ่าย"
] ]
}, },
"metadata": {
"properties": {},
"additionalProperties": {},
"type": "object",
"example": {}
},
"hidden": { "hidden": {
"type": "boolean", "type": "boolean",
"example": false "example": false
@ -407,6 +435,16 @@
"รายงาน" "รายงาน"
] ]
}, },
"author": {
"type": "string",
"example": "นายก"
},
"metadata": {
"properties": {},
"additionalProperties": {},
"type": "object",
"example": {}
},
"from": { "from": {
"properties": { "properties": {
"file": { "file": {
@ -625,6 +663,7 @@
"path": "ตู้เอกสาร 1/ลิ้นชัก 1/แฟ้ม 1/", "path": "ตู้เอกสาร 1/ลิ้นชัก 1/แฟ้ม 1/",
"title": "เอกสาร", "title": "เอกสาร",
"description": "เอกสารการเงิน", "description": "เอกสารการเงิน",
"author": "นายก",
"category": [ "category": [
"บัญชี" "บัญชี"
], ],
@ -874,6 +913,12 @@
"path": { "path": {
"type": "string" "type": "string"
}, },
"metadata": {
"$ref": "#/components/schemas/Record_string.any_"
},
"author": {
"type": "string"
},
"keyword": { "keyword": {
"items": { "items": {
"type": "string" "type": "string"
@ -917,6 +962,8 @@
"hidden", "hidden",
"upload", "upload",
"path", "path",
"metadata",
"author",
"keyword", "keyword",
"category", "category",
"description", "description",
@ -936,6 +983,7 @@
"path": "ตู้เอกสาร 1/ลิ้นชัก 1/แฟ้ม 1/", "path": "ตู้เอกสาร 1/ลิ้นชัก 1/แฟ้ม 1/",
"title": "เอกสาร", "title": "เอกสาร",
"description": "เอกสารการเงิน", "description": "เอกสารการเงิน",
"author": "นายก",
"category": [ "category": [
"บัญชี" "บัญชี"
], ],
@ -1127,6 +1175,12 @@
"path": { "path": {
"type": "string" "type": "string"
}, },
"metadata": {
"$ref": "#/components/schemas/Record_string.any_"
},
"author": {
"type": "string"
},
"keyword": { "keyword": {
"items": { "items": {
"type": "string" "type": "string"
@ -1170,6 +1224,8 @@
"hidden", "hidden",
"upload", "upload",
"path", "path",
"metadata",
"author",
"keyword", "keyword",
"category", "category",
"description", "description",
@ -1198,6 +1254,7 @@
"รายจ่าย", "รายจ่าย",
"รายรับ" "รายรับ"
], ],
"author": "นายก",
"upload": false, "upload": false,
"hidden": false, "hidden": false,
"fileName": "เอกสาร 1.pdf", "fileName": "เอกสาร 1.pdf",