fix: error file too large

This commit is contained in:
Methapon Metanipat 2024-08-26 11:12:06 +07:00
parent 798fd4b37b
commit d1bdf89fd6

View file

@ -136,7 +136,15 @@ async function handleNotFoundRecord(
) { ) {
const path = stripLeadingSlash(pathname.split("/").slice(0, -1).join("/") + "/"); const path = stripLeadingSlash(pathname.split("/").slice(0, -1).join("/") + "/");
const filename = pathname.split("/").at(-1); const filename = pathname.split("/").at(-1);
const base64 = errorKey.includes(key) ? "" : Buffer.from(buffer).toString("base64"); let base64 = "";
if (!errorKey.includes(key)) {
try {
Buffer.from(buffer).toString("base64");
} catch (e) {
console.warn("[WARN] Cannot extract data from the file.", e);
}
}
const metadata = { const metadata = {
pathname, pathname,
@ -191,12 +199,22 @@ async function handleFoundRecord(
metadata.fileType = stat.type; metadata.fileType = stat.type;
metadata.upload = true; metadata.upload = true;
let base64 = "";
if (!errorKey.includes(key)) {
try {
Buffer.from(buffer).toString("base64");
} catch (e) {
console.warn("[WARN] Cannot extract data from the file.", e);
}
}
const result = await esClient const result = await esClient
.index({ .index({
pipeline: "attachment", pipeline: "attachment",
index: DEFAULT_INDEX!, index: DEFAULT_INDEX!,
document: { document: {
data: errorKey.includes(key) ? "" : Buffer.from(buffer).toString("base64"), data: base64,
...metadata, ...metadata,
}, },
refresh: "wait_for", refresh: "wait_for",