From 5e004db47cfd88627786966e6bd445022e96f0e1 Mon Sep 17 00:00:00 2001 From: Pierce Date: Sun, 18 Jun 2023 17:37:33 -0700 Subject: [PATCH] extract library download logic into its own function Enforcing the DRY principle here. --- components/handler.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/components/handler.js b/components/handler.js index 21209a5..94be656 100644 --- a/components/handler.js +++ b/components/handler.js @@ -509,9 +509,7 @@ class Handler { jarPath = path.join(directory, `${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}`) } - // Fix no artifact property when downloading a library - if (!fs.existsSync(path.join(jarPath, name))) { - // Simple lib support, forgot which addon needed this but here you go, Mr special. + const downloadLibrary = async library => { if (library.url) { const url = `${library.url}${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}/${name}` await this.downloadAsync(url, jarPath, name, true, eventName) @@ -520,16 +518,9 @@ class Handler { } } - if(library.downloads){ - if(!this.checkSum(library.downloads.artifact.sha1, path.join(jarPath, name))){ - // Simple lib support, forgot which addon needed this but here you go, Mr special. - if (library.url) { - const url = `${library.url}${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}/${name}` - await this.downloadAsync(url, jarPath, name, true, eventName) - } else if (library.downloads && library.downloads.artifact) { - await this.downloadAsync(library.downloads.artifact.url, jarPath, name, true, eventName) - } - } + if (!fs.existsSync(path.join(jarPath, name))) downloadLibrary(library) + else if (library.downloads && library.downloads.artifact) { + if (!this.checkSum(library.downloads.artifact.sha1, path.join(jarPath, name))) downloadLibrary(library) } counter++