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 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 = {
pathname,
@ -191,12 +199,22 @@ async function handleFoundRecord(
metadata.fileType = stat.type;
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
.index({
pipeline: "attachment",
index: DEFAULT_INDEX!,
document: {
data: errorKey.includes(key) ? "" : Buffer.from(buffer).toString("base64"),
data: base64,
...metadata,
},
refresh: "wait_for",