fix: pdf cache

This commit is contained in:
Yanlong Wang 2024-05-31 18:26:05 +08:00
parent fd0b77285f
commit 1ba21da0c5
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -281,18 +281,21 @@ export class PDFExtractor extends AsyncService {
// Don't try again until the next day
const expireMixin = extracted ? {} : { expireAt: new Date(Date.now() + 1000 * 3600 * 24) };
const theID = randomUUID();
await this.firebaseObjectStorage.saveFile(`pdfs/${theID}`,
Buffer.from(JSON.stringify(extracted), 'utf-8'), { contentType: 'application/json' });
await PDFContent.COLLECTION.doc(theID).set(
{
PDFContent.save(
PDFContent.from({
_id: theID,
src: url.toString(),
meta: extracted?.meta || {},
urlDigest: digest,
createdAt: new Date(),
...expireMixin
}, { merge: true }
);
}).degradeForFireStore()
).catch((r) => {
this.logger.warn(`Unable to cache PDF content for ${url}`, { err: r });
});
return extracted;
}