summaryrefslogtreecommitdiff
path: root/packages/backend/src/queue
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-02-03 11:37:20 +0000
committerdakkar <dakkar@thenautilus.net>2024-02-03 11:37:20 +0000
commita981bca7a3d8c5f44c24728f8c8b20134d311869 (patch)
treeaa12763214c9a30b8b227a841538acb8a9f9be8b /packages/backend/src/queue
parentmake almost all fs ops async (diff)
downloadsharkey-a981bca7a3d8c5f44c24728f8c8b20134d311869.tar.gz
sharkey-a981bca7a3d8c5f44c24728f8c8b20134d311869.tar.bz2
sharkey-a981bca7a3d8c5f44c24728f8c8b20134d311869.zip
simpler logic
thanks Alina
Diffstat (limited to 'packages/backend/src/queue')
-rw-r--r--packages/backend/src/queue/processors/ImportNotesProcessorService.ts15
1 files changed, 6 insertions, 9 deletions
diff --git a/packages/backend/src/queue/processors/ImportNotesProcessorService.ts b/packages/backend/src/queue/processors/ImportNotesProcessorService.ts
index 7664c282df..2476f94359 100644
--- a/packages/backend/src/queue/processors/ImportNotesProcessorService.ts
+++ b/packages/backend/src/queue/processors/ImportNotesProcessorService.ts
@@ -130,6 +130,7 @@ export class ImportNotesProcessorService {
return typeof obj[Symbol.iterator] === 'function';
}
+ @bindThis
private parseTwitterFile(str : string) : null | { tweet: object }[] {
const jsonStr = str.replace(/^\s*window\.YTD\.tweets\.part0\s*=\s*/, '');
@@ -137,7 +138,8 @@ export class ImportNotesProcessorService {
return JSON.parse(jsonStr);
} catch (error) {
//The format is not what we expected. Either this file was tampered with or twitters exports changed
- return null;
+ this.logger.warn('Failed to import twitter notes due to malformed file');
+ throw error;
}
}
@@ -189,14 +191,9 @@ export class ImportNotesProcessorService {
const unprocessedTweets = this.parseTwitterFile(await fs.promises.readFile(outputPath + '/data/tweets.js', 'utf-8'));
- //Make sure that it isnt null (because if something went wrong in parseTwitterFile it returns null)
- if (unprocessedTweetJson) {
- const tweets = unprocessedTweets.map(e=>e.tweet);
- const processedTweets = await this.recreateChain(['id_str'], ['in_reply_to_status_id_str'], tweets, false);
- this.queueService.createImportTweetsToDbJob(job.data.user, processedTweets, null);
- } else {
- this.logger.warn('Failed to import twitter notes due to malformed file');
- }
+ const tweets = unprocessedTweets.map(e=>e.tweet);
+ const processedTweets = await this.recreateChain(['id_str'], ['in_reply_to_status_id_str'], tweets, false);
+ this.queueService.createImportTweetsToDbJob(job.data.user, processedTweets, null);
} finally {
cleanup();
}