nomagick commited on
Commit
908157b
·
unverified ·
1 Parent(s): 9c60b4b

fix: pdf cache

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