Files
aklive2d/packages/assets/libs/download.js
Haoyu Xu d6e7bc20d3 feat: migrate to turbo (#22)
* feat: migrate top turbo

* ci: ci test

* fix: fix codeql issues

* feat: ci test

* chore: lint

* chore: misc changes

* feat: rename vite helpers

* feat: use fetch to handle assets

* feat: update directory

* feat: fetch charword table

* feat: migrate download game data and detect missing voice files

* feat: symlink relative path

* feat: finish wrangler upload

* feat: migrate wrangler download

* feat: finish

* chore: auto update

* ci: update ci

* ci: update ci

---------

Co-authored-by: Halyul <Halyul@users.noreply.github.com>
2025-02-22 15:11:30 +08:00

58 lines
2.0 KiB
JavaScript

import path from 'node:path'
import { file } from '@aklive2d/libs'
import { unzipDownload } from '@aklive2d/downloader'
import { getOperatorId, getOperatorAlternativeId } from '@aklive2d/operator'
import { mapping } from '@aklive2d/music'
import config from '../index.js'
export default async (dataDir) => {
const pidSet = new Set()
const versionRes = await fetch(
'https://ak-conf.hypergryph.com/config/prod/official/Android/version'
)
const version = (await versionRes.json()).resVersion
const lpacksRes = await fetch(
`https://ak.hycdn.cn/assetbundle/official/Android/assets/${version}/hot_update_list.json`
)
const updateList = await lpacksRes.json()
const itemToDownload = new Set(config.item_to_download)
updateList.abInfos.map((item) => {
if (item.name.includes(config.dynchars)) {
const id = getOperatorId(item.name).replace('.ab', '')
itemToDownload.add(id)
itemToDownload.add(getOperatorAlternativeId(id))
}
})
mapping.musicFiles.map((item) => {
if (!file.exists(path.join(item.source, item.filename))) {
const filename = item.filename.replace('.ogg', '')
itemToDownload.add(filename)
}
})
const itemToDownloadRegExp = new RegExp(
`(.*)(${Array.from(itemToDownload).join('|')})(.*)`
)
updateList.abInfos.map((item) => {
if (itemToDownloadRegExp.test(item.name)) {
item.pid && pidSet.add(item.pid)
}
})
const lpacksToDownload = []
pidSet.forEach((item) => {
lpacksToDownload.push({
name: item,
url: `https://ak.hycdn.cn/assetbundle/official/Android/assets/${version}/${item}.dat`,
})
})
const regexs = []
if (config.additional_regex.length > 0) {
for (const item of config.additional_regex) {
regexs.push(new RegExp(item))
}
}
await unzipDownload(lpacksToDownload, dataDir, {
matchRegExps: regexs,
defaultRegex: itemToDownloadRegExp,
})
}