From 0ac62f1f8c3d25384b46268b891ed8099ff6e7b9 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Thu, 2 May 2024 00:36:32 -0400 Subject: [PATCH] Shared function --- bin/download-flash-cn.mjs | 10 ++-------- bin/download-harman-air-runtime.mjs | 9 ++------- bin/download-harman-air-sdk.mjs | 9 ++------- util/ia.mjs | 9 +++++++++ 4 files changed, 15 insertions(+), 22 deletions(-) create mode 100644 util/ia.mjs diff --git a/bin/download-flash-cn.mjs b/bin/download-flash-cn.mjs index 02721ed5..dbcb56dd 100755 --- a/bin/download-flash-cn.mjs +++ b/bin/download-flash-cn.mjs @@ -9,6 +9,7 @@ import {file as hashFile} from '../util/hash.mjs'; import {read as packaged} from '../util/packages.mjs'; import {walk} from '../util/util.mjs'; import {download} from '../util/download.mjs'; +import {packageUrl} from '../util/ia.mjs'; async function main() { // eslint-disable-next-line no-process-env @@ -133,7 +134,6 @@ async function main() { size, hashes: {sha256, sha1, md5} } of changed) { - console.log(name); doc.push({ name, file, @@ -141,13 +141,7 @@ async function main() { sha256, sha1, md5, - source: [ - `https://archive.org/download/shockpkg_packages_${sha256[0]}`, - sha256.substr(0, 2), - sha256.substr(2, 2), - sha256.substr(4), - file - ].join('/'), + source: packageUrl(sha256, file), metadata: { date } diff --git a/bin/download-harman-air-runtime.mjs b/bin/download-harman-air-runtime.mjs index d7ce82be..46436879 100755 --- a/bin/download-harman-air-runtime.mjs +++ b/bin/download-harman-air-runtime.mjs @@ -7,6 +7,7 @@ import {mkdir, stat} from 'node:fs/promises'; import {file as hashFile} from '../util/hash.mjs'; import {runtimes, userAgent} from '../util/harman.mjs'; import {download} from '../util/download.mjs'; +import {packageUrl} from '../util/ia.mjs'; async function main() { // eslint-disable-next-line no-process-env @@ -116,13 +117,7 @@ async function main() { sha256, sha1, md5, - source: [ - `https://archive.org/download/shockpkg_packages_${sha256[0]}`, - sha256.substr(0, 2), - sha256.substr(2, 2), - sha256.substr(4), - file - ].join('/') + source: packageUrl(sha256, file) }); } console.log(JSON.stringify(doc, null, '\t')); diff --git a/bin/download-harman-air-sdk.mjs b/bin/download-harman-air-sdk.mjs index e6bcd6b3..7918d318 100755 --- a/bin/download-harman-air-sdk.mjs +++ b/bin/download-harman-air-sdk.mjs @@ -7,6 +7,7 @@ import {mkdir, stat} from 'node:fs/promises'; import {file as hashFile} from '../util/hash.mjs'; import {sdks, cookies, userAgent} from '../util/harman.mjs'; import {download} from '../util/download.mjs'; +import {packageUrl} from '../util/ia.mjs'; async function main() { // eslint-disable-next-line no-process-env @@ -120,13 +121,7 @@ async function main() { sha256, sha1, md5, - source: [ - `https://archive.org/download/shockpkg_packages_${sha256[0]}`, - sha256.substr(0, 2), - sha256.substr(2, 2), - sha256.substr(4), - file - ].join('/') + source: packageUrl(sha256, file) }); } console.log(JSON.stringify(doc, null, '\t')); diff --git a/util/ia.mjs b/util/ia.mjs new file mode 100644 index 00000000..849a8c02 --- /dev/null +++ b/util/ia.mjs @@ -0,0 +1,9 @@ +export function packageUrl(sha256, file) { + return [ + `https://archive.org/download/shockpkg_packages_${sha256[0]}`, + sha256.substr(0, 2), + sha256.substr(2, 2), + sha256.substr(4), + encodeURIComponent(file) + ].join('/'); +}