From 52930e22e71fdc2b05878206f1a5834a314dc426 Mon Sep 17 00:00:00 2001 From: Elton Chou Date: Sun, 2 Jan 2022 02:35:38 +0800 Subject: [PATCH] refine: sort out code --- src/background.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/background.js b/src/background.js index 3835e6a9..cc47b54a 100644 --- a/src/background.js +++ b/src/background.js @@ -128,9 +128,6 @@ async function processRequest(request) { const ct0Value = await fetchTwitterCt0Cookie() const twitterMedia = new MediaTweet(tweetInfo.tweetId, ct0Value) - const downloadMedia = mediasDownloader(tweetInfo) - const downloadInfoRecorder = downloadItemRecorder(tweetInfo) - let { mediaList, errorReason } = await twitterMedia.fetchMediaList() if (errorReason) { @@ -138,6 +135,9 @@ async function processRequest(request) { return false } + const downloadMedia = mediasDownloader(tweetInfo) + const downloadInfoRecorder = downloadItemRecorder(tweetInfo) + downloadMedia(mediaList, downloadInfoRecorder) } @@ -156,10 +156,11 @@ function mediasDownloader(tweetInfo) { for (const [index, value] of mediaList.entries()) { const mediaFile = new TwitterMediaFile(tweetInfo, value, index) const config = mediaFile.makeDownloadConfigBySetting(setting, mode) - const downloadRecorder = infoRecorder(config) + + const downloadCallback = infoRecorder(config) isPassToAria2 ? chrome.runtime.sendMessage(ARIA2_ID, config) - : chrome.downloads.download(config, downloadRecorder) + : chrome.downloads.download(config, downloadCallback) } } }