Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
fix: 更换url全局替换位置
Browse files Browse the repository at this point in the history
  • Loading branch information
ChingCdesu committed May 22, 2023
1 parent 1b052a3 commit b896073
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
48 changes: 21 additions & 27 deletions packages/main/componentManager/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,21 @@ export default abstract class InstallerBase implements Installer {
}

async install() {
const update = await this.checkUpdate()
switch (update.msg) {
case 'failedAccessLatest':
this.notifier.onException()
return
case 'alreadyLatest':
logger.info(`[Component Installer | ${this.componentType}] No update available`)
this.notifier.onCompleted()
return
case 'haveUpdate': {
const dm = new DownloadManager()
const url = update.update.url
const urlMatches =
/^https:\/\/(.+)\/MaaAssistantArknights\/MaaAssistantArknights\/releases\/download\/(.+)\/(.+)$/.exec(
url
)
if (!urlMatches) {
logger.error(`[Component Installer | ${this.componentType}] Invalid update url: ${url}`)
try {
const info = await this.checkUpdate()
switch (info.msg) {
case 'failedAccessLatest':
this.notifier.onException()
return
}
const [, host, version, filename] = urlMatches
case 'alreadyLatest':
logger.info(`[Component Installer | ${this.componentType}] No update available`)
this.notifier.onCompleted()
return
case 'haveUpdate': {
const dm = new DownloadManager()
const { url, postUpgrade } = info.update

dm.download(
`https://s3.maa-org.net:25240/maa-release/MaaAssistantArknights/MaaAssistantArknights/releases/download/${filename}`,
{
dm.download(url, {
handleDownloadUpdate: task => {
this.notifier.onProgress(0.99 * (task.progress.percent ?? 0))
},
Expand All @@ -68,7 +57,7 @@ export default abstract class InstallerBase implements Installer {
extractFile(task.savePath, path.join(getAppBaseDir(), this.componentDir))
.then(() => {
this.status = 'done'
update.update.postUpgrade() // 更新版本信息
postUpgrade() // 更新版本信息
this.notifier.onCompleted()
})
.catch(() => {
Expand All @@ -82,10 +71,15 @@ export default abstract class InstallerBase implements Installer {
this.notifier.onException()
},
}
).then(() => {
this.status = 'downloading'
})
).then(() => {
this.status = 'downloading'
})
}
}
} catch (error) {
logger.error(`[Component Installer | ${this.componentType}] Failed to install: ${error}`)
this.status = 'exception'
this.notifier.onException()
}
}
}
13 changes: 11 additions & 2 deletions packages/main/componentManager/utils/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function createCheckUpdate(
} else {
logger.warn(
`[Component Installer | ${component}] ` +
'Unable to acquire OTA update asset, attempting to obtain full update asset'
'Unable to acquire OTA update asset, attempting to obtain full update asset'
)
}
}
Expand All @@ -106,10 +106,19 @@ export function createCheckUpdate(

fs.writeFileSync(infoPath.latestFile, item.name, 'utf-8')

const url = item.browser_download_url
const urlMatches =
/^https:\/\/(.+)\/MaaAssistantArknights\/MaaAssistantArknights\/releases\/download\/(.+)\/(.+)$/.exec(
url
)
if (!urlMatches) {
throw new Error(`Invalid update url: ${url}`)
}
const [, host, version, filename] = urlMatches
return {
msg: 'haveUpdate',
update: {
url: item.browser_download_url,
url: `https://s3.maa-org.net:25240/maa-release/MaaAssistantArknights/MaaAssistantArknights/releases/download/${filename}`,
version: latestVersion,
releaseDate: published_at,
postUpgrade: () => {
Expand Down

0 comments on commit b896073

Please sign in to comment.