mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 01:13:08 +02:00
simpler logic
thanks Alina
This commit is contained in:
parent
3a3a051bb5
commit
a981bca7a3
1 changed files with 6 additions and 9 deletions
|
@ -130,6 +130,7 @@ export class ImportNotesProcessorService {
|
||||||
return typeof obj[Symbol.iterator] === 'function';
|
return typeof obj[Symbol.iterator] === 'function';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@bindThis
|
||||||
private parseTwitterFile(str : string) : null | { tweet: object }[] {
|
private parseTwitterFile(str : string) : null | { tweet: object }[] {
|
||||||
const jsonStr = str.replace(/^\s*window\.YTD\.tweets\.part0\s*=\s*/, '');
|
const jsonStr = str.replace(/^\s*window\.YTD\.tweets\.part0\s*=\s*/, '');
|
||||||
|
|
||||||
|
@ -137,7 +138,8 @@ export class ImportNotesProcessorService {
|
||||||
return JSON.parse(jsonStr);
|
return JSON.parse(jsonStr);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//The format is not what we expected. Either this file was tampered with or twitters exports changed
|
//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'));
|
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)
|
const tweets = unprocessedTweets.map(e=>e.tweet);
|
||||||
if (unprocessedTweetJson) {
|
const processedTweets = await this.recreateChain(['id_str'], ['in_reply_to_status_id_str'], tweets, false);
|
||||||
const tweets = unprocessedTweets.map(e=>e.tweet);
|
this.queueService.createImportTweetsToDbJob(job.data.user, processedTweets, null);
|
||||||
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');
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue