fix: socket should not notify hidden folder or file

fix: socket should not notify hidden folder
This commit is contained in:
Methapon2001 2023-12-15 16:18:40 +07:00
parent 7a0727927b
commit 7eada9e0dd
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
2 changed files with 41 additions and 35 deletions

View file

@ -309,13 +309,14 @@ export class StorageController extends Controller {
if (!created) throw new Error(MINIO_ERROR_MESSAGE);
io.getInstance()?.emit("FolderCreate", {
pathname: stripLeadingSlash(
`${path.join("/")}/${name.replace(/[/\\?%*:|"<>#]/g, "-").trim()}/`,
),
name: name.replace(/[/\\?%*:|"<>#]/g, "-").trim(),
...meta,
});
!name.startsWith(".") &&
io.getInstance()?.emit("FolderCreate", {
pathname: stripLeadingSlash(
`${path.join("/")}/${name.replace(/[/\\?%*:|"<>#]/g, "-").trim()}/`,
),
name: name.replace(/[/\\?%*:|"<>#]/g, "-").trim(),
...meta,
});
return this.setStatus(HttpStatusCode.NO_CONTENT);
}
@ -550,7 +551,7 @@ export class StorageController extends Controller {
refresh: "wait_for", // Must have or else it doesn't wait for updated index resulted in data not found on fetch
});
io.getInstance()?.emit("FileUploadRequest", metadata);
!metadata.hidden && io.getInstance()?.emit("FileUploadRequest", metadata);
const presignedUrl = await minioClient.presignedPutObject(DEFAULT_BUCKET, metadata.pathname);
@ -664,17 +665,19 @@ export class StorageController extends Controller {
)
.catch((e) => console.error(`ElasticSearch Error: ${e}`));
io.getInstance()?.emit("FileMove", {
from: source,
to: {
...source,
...metadata,
path: stripLeadingSlash(`${to.path.join("/")}/`),
pathname: dst,
fileName: to.file,
...dateMeta,
},
});
if (!source.hidden && !metadata.hidden) {
io.getInstance()?.emit("FileMove", {
from: source,
to: {
...source,
...metadata,
path: stripLeadingSlash(`${to.path.join("/")}/`),
pathname: dst,
fileName: to.file,
...dateMeta,
},
});
}
if (upload) {
const presignedUrl = await minioClient.presignedPutObject(DEFAULT_BUCKET, dst);
@ -697,14 +700,16 @@ export class StorageController extends Controller {
})
.catch((e) => console.error(`ElasticSearch Error: ${e}`));
io.getInstance()?.emit("FileMove", {
from: source,
to: {
...source,
...metadata,
...dateMeta,
},
});
if (!source.hidden && !metadata.hidden) {
io.getInstance()?.emit("FileMove", {
from: source,
to: {
...source,
...metadata,
...dateMeta,
},
});
}
if (upload) {
const src = stripLeadingSlash(`${from.path.join("/")}/${from.file}`);

View file

@ -1,7 +1,7 @@
import { StorageFile } from "../interfaces/storage-fs";
import esClient from "../elasticsearch";
import minioClient from "../minio";
import { getInstance } from "../lib/websocket";
import * as io from "../lib/websocket";
const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX;
@ -44,7 +44,7 @@ export async function handler(key: string, event: string): Promise<boolean> {
const rec = await popInfo(pathname);
console.info(`[AMQ] Key: ${key} - ${rec ?? "Not Found."}`);
console.info(`[AMQ] Key: ${key} - ${JSON.stringify(rec, null, 2) ?? "Not Found."}`);
const result = rec
? await handleFoundRecord(rec, cachedBuffer[key], cachedMetadata[key])
@ -96,8 +96,7 @@ async function ensureDelete(pathname: string) {
})
.catch((e) => console.error(e));
const io = getInstance();
io?.emit("FileDelete", { pathname });
io.getInstance()?.emit("FileDelete", { pathname });
return true;
}
@ -144,8 +143,9 @@ async function handleNotFoundRecord(
if (!result) return false;
const io = getInstance();
io?.emit("FileUpload", metadata);
if (!metadata.hidden) {
io.getInstance()?.emit("FileUpload", metadata);
}
return true;
}
@ -170,8 +170,9 @@ async function handleFoundRecord(
if (!result) return false;
const io = getInstance();
io?.emit("FileUpload", metadata);
if (!metadata.hidden) {
io.getInstance()?.emit("FileUpload", metadata);
}
return true;
}