From 18a1d0d4d35a8014a2412ddad4797573938ded5e Mon Sep 17 00:00:00 2001 From: Haoyu Xu Date: Thu, 10 Oct 2024 15:02:30 +0800 Subject: [PATCH] feat(aklive2d): updated downloader --- download_packs.sh | 4 ++-- libs/charword_table.js | 6 +++++- libs/downloader.js | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/download_packs.sh b/download_packs.sh index 2aee077..e742894 100755 --- a/download_packs.sh +++ b/download_packs.sh @@ -39,8 +39,8 @@ do done ASSET_FOLDER="assets" -FILES_TO_KEEP=("spritepack/ui_camp_logo_h2_0.ab" "spritepack/ui_camp_logo_h2_linkage_0.ab" "arts/dynchars" "chararts" "skinpack" "arts/ui/homebackground/wrapper" "arts/charportraits" "audio/sound_beta_2/music" "audio/sound_beta_2/voice*") -FILES_DESTS=("ui_camp_logo_h2_0.ab" "ui_camp_logo_h2_linkage_0.ab" "dynchars" "chararts" "skinpack" "homebackground" "charportraits" "music" ".") +FILES_TO_KEEP=("spritepack/ui_camp_logo_0.ab" "arts/dynchars" "chararts" "skinpack" "arts/ui/homebackground/wrapper" "arts/charportraits" "audio/sound_beta_2/music" "audio/sound_beta_2/voice*") +FILES_DESTS=("ui_camp_logo_0.ab" "dynchars" "chararts" "skinpack" "homebackground" "charportraits" "music" ".") mkdir -p ./$ASSET_FOLDER for i in "${!FILES_TO_KEEP[@]}"; do diff --git a/libs/charword_table.js b/libs/charword_table.js index 83b1665..60476d2 100644 --- a/libs/charword_table.js +++ b/libs/charword_table.js @@ -124,7 +124,11 @@ export default class CharwordTable { } async #download(region) { - return await (new Downloader()).github(`https://api.github.com/repos/${REGION_URLS[region]}/commits?path=${region}/gamedata/excel/charword_table.json`, `https://raw.githubusercontent.com/${REGION_URLS[region]}/master/${region}/gamedata/excel/charword_table.json`, path.join(this.#charwordTablePath, `charword_table_${region}.json`)) + return await (new Downloader()).github( + `https://api.github.com/repos/${REGION_URLS[region]}/commits?path=${region}/gamedata/excel/charword_table.json`, + `https://raw.githubusercontent.com/${REGION_URLS[region]}/master/${region}/gamedata/excel/charword_table.json`, + path.join(this.#charwordTablePath, `charword_table_${region}.json`) + ) } } diff --git a/libs/downloader.js b/libs/downloader.js index 0df3cef..3250850 100644 --- a/libs/downloader.js +++ b/libs/downloader.js @@ -10,10 +10,11 @@ export default class Downloader { const historyData = await historyResponse.json() const lastCommit = historyData[0] const lastCommitDate = new Date(lastCommit.commit.committer.date) - console.log(`Last commit date: ${lastCommitDate.getTime()}`) const ext = path.extname(filepath) const basename = path.basename(filepath).replace(ext, '') filepath = path.join(filepath, "..", `${basename}_${lastCommitDate.getTime()}${ext}`) + const dirpath = path.join(filepath, "..") + console.log(`Last ${basename} commit date: ${lastCommitDate.getTime()}`) if (exists(filepath)) { console.log(`${basename} is the latest version.`) @@ -25,10 +26,10 @@ export default class Downloader { console.log(`${basename} is updated.`) // remove old file - const files = readdirSync(path.join(__projectRoot, __config.folder.operator, __config.folder.share)) + const files = readdirSync(path.join(dirpath)) for (const file of files) { if (file.startsWith(basename) && file !== path.basename(filepath)) { - rm(path.join(__projectRoot, __config.folder.operator, __config.folder.share, file)) + rm(path.join(dirpath, file)) } } return data