Skip to content

Commit

Permalink
refine: sort out code
Browse files Browse the repository at this point in the history
  • Loading branch information
EltonChou committed Jan 1, 2022
1 parent 6c96f52 commit 52930e2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ 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) {
fetchErrorHandler(tweetInfo, errorReason)
return false
}

const downloadMedia = mediasDownloader(tweetInfo)
const downloadInfoRecorder = downloadItemRecorder(tweetInfo)

downloadMedia(mediaList, downloadInfoRecorder)
}

Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit 52930e2

Please sign in to comment.