Spaces:
Build error
Build error
fix: pdf cache
Browse files
backend/functions/src/services/pdf-extract.ts
CHANGED
|
@@ -281,18 +281,21 @@ export class PDFExtractor extends AsyncService {
|
|
| 281 |
// Don't try again until the next day
|
| 282 |
const expireMixin = extracted ? {} : { expireAt: new Date(Date.now() + 1000 * 3600 * 24) };
|
| 283 |
const theID = randomUUID();
|
|
|
|
| 284 |
await this.firebaseObjectStorage.saveFile(`pdfs/${theID}`,
|
| 285 |
Buffer.from(JSON.stringify(extracted), 'utf-8'), { contentType: 'application/json' });
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
src: url.toString(),
|
| 290 |
meta: extracted?.meta || {},
|
| 291 |
urlDigest: digest,
|
| 292 |
createdAt: new Date(),
|
| 293 |
...expireMixin
|
| 294 |
-
}
|
| 295 |
-
)
|
|
|
|
|
|
|
| 296 |
|
| 297 |
return extracted;
|
| 298 |
}
|
|
|
|
| 281 |
// Don't try again until the next day
|
| 282 |
const expireMixin = extracted ? {} : { expireAt: new Date(Date.now() + 1000 * 3600 * 24) };
|
| 283 |
const theID = randomUUID();
|
| 284 |
+
|
| 285 |
await this.firebaseObjectStorage.saveFile(`pdfs/${theID}`,
|
| 286 |
Buffer.from(JSON.stringify(extracted), 'utf-8'), { contentType: 'application/json' });
|
| 287 |
+
PDFContent.save(
|
| 288 |
+
PDFContent.from({
|
| 289 |
+
_id: theID,
|
| 290 |
src: url.toString(),
|
| 291 |
meta: extracted?.meta || {},
|
| 292 |
urlDigest: digest,
|
| 293 |
createdAt: new Date(),
|
| 294 |
...expireMixin
|
| 295 |
+
}).degradeForFireStore()
|
| 296 |
+
).catch((r) => {
|
| 297 |
+
this.logger.warn(`Unable to cache PDF content for ${url}`, { err: r });
|
| 298 |
+
});
|
| 299 |
|
| 300 |
return extracted;
|
| 301 |
}
|