feat(api): hidden folder and file
This commit is contained in:
parent
e73f5cc855
commit
c48e8c9873
8 changed files with 113 additions and 5 deletions
|
|
@ -27,6 +27,9 @@ export class SearchController extends Controller {
|
|||
should: search.OR?.map((v) => ({
|
||||
[type[search.exact || v.exact ? 1 : 0]]: { [v.field]: v.value },
|
||||
})),
|
||||
must_not: {
|
||||
match: { hidden: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
size: 10000,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ const PATH_ALREADY_EXIST = "ตำแหน่งดังกล่าวมี
|
|||
interface ListRequestBody {
|
||||
operation: "folder" | "file";
|
||||
path: string[];
|
||||
hidden?: boolean;
|
||||
}
|
||||
|
||||
interface FolderBody {
|
||||
|
|
@ -77,6 +78,8 @@ interface FileBody {
|
|||
category?: string[];
|
||||
/** @example ["การเงิน", "รายรับ", "รายจ่าย"] */
|
||||
keyword?: string[];
|
||||
/** @example false */
|
||||
hidden?: boolean;
|
||||
}
|
||||
|
||||
interface PutFileBody extends Omit<FileBody, "file" | "path"> {
|
||||
|
|
@ -111,7 +114,7 @@ interface DownloadFileBody {
|
|||
file: string;
|
||||
}
|
||||
|
||||
async function listFolder(path: string[]) {
|
||||
async function listFolder(path: string[], hidden: boolean = false) {
|
||||
const list = await new Promise<{ pathname: string; name: string }[]>((resolve, reject) => {
|
||||
const item: { pathname: string; name: string }[] = [];
|
||||
|
||||
|
|
@ -132,6 +135,8 @@ async function listFolder(path: string[]) {
|
|||
|
||||
const folder = await Promise.all(
|
||||
list.map(async (v) => {
|
||||
if (v.name.startsWith(".") && !hidden) return undefined;
|
||||
|
||||
// Get stat from hidden object that used to mark as folder as minio doesn't really have folder
|
||||
const stat = await minioClient
|
||||
.statObject(DEFAULT_BUCKET, `${v.pathname}.keep`)
|
||||
|
|
@ -152,12 +157,17 @@ async function listFolder(path: string[]) {
|
|||
return folder.filter((v: StorageFolder | undefined): v is StorageFolder => !!v);
|
||||
}
|
||||
|
||||
async function listFile(path: string[]) {
|
||||
async function listFile(path: string[], hidden: boolean = false) {
|
||||
const result = await esClient
|
||||
.search<StorageFile & { attachment: Record<string, string> }>({
|
||||
index: DEFAULT_INDEX,
|
||||
sort: [{ pathname: "asc" }],
|
||||
query: { match: { path: path.join("/") + "/" } },
|
||||
query: {
|
||||
bool: {
|
||||
must: { match: { path: path.join("/") + "/" } },
|
||||
must_not: !hidden ? { match: { hidden: true } } : undefined,
|
||||
},
|
||||
},
|
||||
size: 10000,
|
||||
})
|
||||
.then((r) => r.hits.hits);
|
||||
|
|
@ -229,7 +239,7 @@ export class StorageController extends Controller {
|
|||
public async getList(@Body() body: ListRequestBody) {
|
||||
const path = body.path.filter(Boolean);
|
||||
|
||||
if (body.operation === "folder") return await listFolder(path);
|
||||
if (body.operation === "folder") return await listFolder(path, body.hidden);
|
||||
if (body.operation === "file") return await listFile(path);
|
||||
}
|
||||
|
||||
|
|
@ -428,6 +438,7 @@ export class StorageController extends Controller {
|
|||
category: body.category ?? [],
|
||||
keyword: body.keyword ?? [],
|
||||
upload: false, // flag
|
||||
hidden: body.hidden ?? false,
|
||||
createdAt: new Date().toISOString(),
|
||||
createdBy: request.user.preferred_username,
|
||||
updatedAt: new Date().toISOString(),
|
||||
|
|
|
|||
11
Services/server/src/controllers/versionController.ts
Normal file
11
Services/server/src/controllers/versionController.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { Controller, Get, Route, Tags } from "tsoa";
|
||||
import version from "../ver.json";
|
||||
|
||||
@Route("version")
|
||||
export class VersionController extends Controller {
|
||||
@Get()
|
||||
@Tags("Version")
|
||||
public async getVersion() {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue