Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Add TSS Mirrorp
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirasawaSama committed Apr 24, 2020
1 parent c33d210 commit 0ff5baa
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 485 deletions.
4 changes: 2 additions & 2 deletions .github/actions/upload/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const github = require('@actions/github')
const core = require('@actions/core')
const COS = require('cos-nodejs-sdk-v5')
const Refresher = require('tencent-cdn-refresh/src/refresh')
const Refresher = require('tencent-cdn-refresh')
const { extname, basename } = require('path')
const { promises: fs } = require('fs')
const { createHash } = require('crypto')
Expand Down Expand Up @@ -86,7 +86,7 @@ const { promisify } = require('util')
Body: hashesData
})
try {
core.info(await new Refresher(options).flashDirs('https://dl.pl.apisium.cn/'))
core.info(await new Refresher(options).purgeDirsCache('https://dl.pl.apisium.cn/'))
} catch (e) {
core.warning(e)
}
Expand Down
8 changes: 7 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Shirasawa & CI010
Copyright (c) 2020 Apisium

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,3 +19,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Copyright (c) 2020 Apisium

Without permission by Apisium, do not use our logo and name outside this
project, modify the copyright, name, logo and author information is not
allowed too.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Use taobao registry:
set REGISTRY=https://registry.npm.taobao.org/
set dist-url=http://npm.taobao.org/mirrors/atom-shell
set ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/
set ELECTRON_CUSTOM_DIR=8.2.2
set ELECTRON_CUSTOM_DIR=8.2.3
```

### Development
Expand Down
743 changes: 311 additions & 432 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 12 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@
"@emotion/core": "^10.0.28",
"@emotion/styled": "^10.0.27",
"@types/fs-extra": "^8.1.0",
"@types/lodash": "^4.14.149",
"@types/lodash": "^4.14.150",
"@types/minimist": "^1.2.0",
"@types/node": "^13.11.1",
"@types/node": "^13.13.2",
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.6",
"@types/react-router-dom": "^5.1.4",
"@types/semver": "^7.1.0",
"@types/url-join": "^4.0.0",
"@types/yauzl": "^2.9.1",
"@types/yazl": "^2.4.2",
"@typescript-eslint/eslint-plugin": "^2.28.0",
"@typescript-eslint/parser": "^2.28.0",
"@xmcl/core": "^2.1.3",
"@xmcl/installer": "^2.6.8",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
"@xmcl/core": "^2.2.0",
"@xmcl/installer": "^2.7.3",
"@xmcl/nbt": "^2.0.3",
"@xmcl/resourcepack": "^1.0.12",
"@xmcl/task": "^2.1.6",
Expand All @@ -80,7 +80,7 @@
"babel-plugin-module-resolver": "^4.0.0",
"cos-nodejs-sdk-v5": "^2.5.20",
"del-cli": "^3.0.0",
"electron": "^8.2.2",
"electron": "^8.2.3",
"electron-builder": "^22.4.1",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
Expand Down Expand Up @@ -115,14 +115,14 @@
"react-router-cache-route": "^1.8.4",
"react-router-dom": "^5.1.2",
"react-slick": "^0.25.2",
"reqwq": "^0.2.4",
"reqwq": "^0.3.0",
"resolve-path": "^1.4.0",
"semver": "^7.3.2",
"shallowequal": "^1.1.0",
"skinview-utils": "^0.2.1",
"skinview3d": "^2.0.0-alpha.1",
"slick-carousel": "^1.8.1",
"tencent-cdn-refresh": "git+https://github.com/godruoyi/tencent-cdn-refresh.git",
"tencent-cdn-refresh": "^2.0.0",
"typescript": "^3.8.3",
"url-join": "^4.0.1",
"uuid-by-string": "^3.0.2",
Expand All @@ -145,7 +145,7 @@
"dependencies": {
"@xmcl/client": "^2.0.5",
"asar": "^3.0.3",
"bili": "^4.9.0",
"bili": "^4.9.1",
"chalk": "^4.0.0",
"fs-extra": "^9.0.0",
"globby": "^11.0.0",
Expand All @@ -169,12 +169,6 @@
"output": "release"
},
"extraFiles": "unpacked",
"publish": [
{
"provider": "generic",
"url": "https://xmcl.azurewebsites.net/api/pl/latest"
}
],
"files": [
"dist/**/*",
"!dist/report.html",
Expand Down Expand Up @@ -227,7 +221,8 @@
"oneClick": false,
"perMachine": true,
"allowToChangeInstallationDirectory": true,
"include": "build/installer.nsh"
"include": "build/installer.nsh",
"appPackageUrl": "https://nsis.pl.apisium.cn/release/pl-nsis-redirect"
},
"linux": {
"maintainer": "Shirasawa <764798966@qq.com>",
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ export const ALLOW_PLUGIN_EXTENSIONS = ['.js', '.mjs', '.asar']
export const DEFAULT_LOCATE = (navigator.languages[0] || 'zh-cn').toLowerCase()

export const LAUNCHING_IMAGE = join(APP_PATH, 'launching.webp')
export const DOWNLOAD_EXE_URL = 'https://dl.pl.apisium.cn/PureLauncher.exe'
export const DOWNLOAD_ASAR_URL = 'https://dl.pl.apisium.cn/app.asar'
export const LATEST_URL = 'https://dl.pl.apisium.cn/latest.json'
export const LAUNCHER_MANIFEST_URL = 'https://r.pl.apisium.cn/manifest.json'
export const NEWS_URL = 'https://s.pl.apisium.cn/news.json'
73 changes: 52 additions & 21 deletions src/plugin/DownloadProviders.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
import urlJoin from 'url-join'
import { DefaultDownloader, DownloadOption, Installer } from '@xmcl/installer/index'
import { HttpDownloader, DownloadOption, Installer } from '@xmcl/installer/index'
import { NOT_PROXY } from 'reqwq'

interface Version { id: string, url: string }
export interface DownloadProvider {
name (): string
locales?: string[]
launchermeta: string
launcher: string
resources: string
libraries: string
resources: string | string[]
libraries: string | string[]
forge: string
preference?: boolean
client?: (version: { id: string, url: string }) => string
json?: (version: Version) => string
client?: (version: Version) => string
optifine?: (mcVersion: string, type: string, version: string) => Promise<string> | string
}

export const optifine = (mcVersion: string, type: string, version: string) =>
`https://bmclapi2.bangbang93.com/optifine/${mcVersion}/${type}/${version}`

const MCBBSAPI: DownloadProvider & { [NOT_PROXY]: true } = {
[NOT_PROXY]: true,
preference: true,
name: () => 'MCBBSAPI',
locales: ['zh'],
launchermeta: 'https://download.mcbbs.net',
launcher: 'https://download.mcbbs.net',
resources: 'https://download.mcbbs.net/assets',
libraries: 'https://download.mcbbs.net/maven',
forge: 'https://download.mcbbs.net/maven',
json: ({ id }) => `https://download.mcbbs.net/version/${id}/json`,
client: ({ id }) => `https://download.mcbbs.net/version/${id}/client`,
optifine: (mcVersion: string, type: string, version: string) =>
`https://download.mcbbs.net/optifine/${mcVersion}/${type}/${version}`
}

const DownloadProviders = {
MCBBSAPI: {
[NOT_PROXY]: true,
preference: true,
name: () => 'MCBBSAPI',
locales: ['zh'],
launchermeta: 'https://download.mcbbs.net',
launcher: 'https://download.mcbbs.net',
resources: 'https://download.mcbbs.net/assets',
libraries: 'https://download.mcbbs.net/maven',
forge: 'https://download.mcbbs.net/maven',
client: ({ id }) => `https://download.mcbbs.net/version/${id}/client`,
optifine: (mcVersion: string, type: string, version: string) =>
`https://download.mcbbs.net/optifine/${mcVersion}/${type}/${version}`
},
MCBBSAPI,
BMCLAPI: {
[NOT_PROXY]: true,
name: () => 'BMCLAPI',
Expand All @@ -41,9 +47,23 @@ const DownloadProviders = {
resources: 'https://bmclapi2.bangbang93.com/assets',
libraries: 'https://bmclapi2.bangbang93.com/maven',
forge: 'https://bmclapi2.bangbang93.com/maven',
json: ({ id }) => `https://bmclapi2.bangbang93.com/version/${id}/json`,
client: ({ id }) => `https://bmclapi2.bangbang93.com/version/${id}/client`,
optifine
},
TSS_MIRROR: {
...MCBBSAPI,
preference: false,
name: () => 'TSS Mirror',
client: (c: any) => {
try { return 'https://mc.mirrors.tmysam.top' + new URL(c.url).pathname } catch (e) {
console.error(e)
return MCBBSAPI.client(c)
}
},
resources: 'https://mcres.mirrors.tmysam.top',
libraries: 'https://mclib.mirrors.tmysam.top'
},
OFFICIAL: {
[NOT_PROXY]: true,
name: () => $('OFFICIAL'),
Expand All @@ -66,8 +86,15 @@ const DownloadProviders = {
}
}

export class ProgressDownloader extends DefaultDownloader {
export class ProgressDownloader extends HttpDownloader {
public bytes = 0
public syncSockets = () => {
this.agents.http.maxSockets = this.agents.https.maxSockets = profilesStore.extraJson.downloadThreads
}
constructor () {
super()
pluginMaster.once('loaded', this.syncSockets)
}
public downloadFile (option: DownloadOption) {
const fn = option.progress
option.progress = (c, w, t, u) => {
Expand All @@ -88,11 +115,15 @@ export const getDownloaders = (client?: any): Installer.Option => {
if (!provider) isOffcical = true
return {
downloader,
jsonUrl: client && provider.json ? provider.json(client) : undefined,
client: client && provider.client ? provider.client(client) : undefined,
assetsDownloadConcurrency: profilesStore.extraJson.downloadThreads || 16,
maxConcurrency: profilesStore.extraJson.downloadThreads || 16,
assetsHost: isOffcical ? undefined : [provider.resources],
libraryHost: isOffcical && provider?.libraries ? undefined : lib => urlJoin(provider.libraries, lib.download.path)
assetsHost: isOffcical ? undefined : typeof provider.resources === 'string'
? [provider.resources] : provider.resources,
libraryHost: isOffcical && provider?.libraries ? undefined : lib => typeof provider.libraries === 'string'
? urlJoin(provider.libraries, lib.download.path)
: provider.libraries.map(it => urlJoin(it, lib.download.path))
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/protocol/check-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { remote, ipcRenderer, shell } from 'electron'
import { getJson, download, genId } from '../utils/index'
import { RESOURCES_VERSIONS_INDEX_PATH, RESOURCES_MODS_INDEX_FILE_NAME, ENTRY_POINT_PATH,
RESOURCES_VERSIONS_PATH, ASAR_PATH, RESOURCES_RESOURCE_PACKS_INDEX_PATH, RESOURCES_PLUGINS_INDEX,
LAUNCHER_MANIFEST_URL, TEMP_PATH, DEFAULT_LOCATE } from '../constants'
LATEST_URL, TEMP_PATH, DOWNLOAD_ASAR_URL, DOWNLOAD_EXE_URL } from '../constants'

export default async (version: string) => {
const json: T.ResourceVersion = (await fs.readJson(RESOURCES_VERSIONS_INDEX_PATH, { throws: false }) || { })[version]
Expand Down Expand Up @@ -43,15 +43,13 @@ export const updatePlugins = async () => {

let downloaded = ''
export const updateLauncher = async () => {
const data = await getJson(LAUNCHER_MANIFEST_URL)
const url: string = data.downloads[+(DEFAULT_LOCATE !== 'zh-cn')]
const json = await getJson(joinUrl(url, 'latest.json'))
const json = await getJson(joinUrl(LATEST_URL))
if (!gt(json.version, version)) return
if (major(json.version) === major(version)) {
const destination = join(TEMP_PATH, genId())
await download({
destination,
url: joinUrl(url, 'app.asar'),
url: DOWNLOAD_ASAR_URL,
checksum: { algorithm: 'sha1', hash: json.asar }
}, $('Update Package'), `PureLauncher-${json.version}.asar`)
await fs.ensureDir(ASAR_PATH)
Expand All @@ -66,7 +64,7 @@ export const updateLauncher = async () => {
downloaded = join(TEMP_PATH, `PureLauncher-${json.version}-${genId()}.exe`)
await download({
destination: downloaded,
url: joinUrl(url, 'PureLauncher.exe'),
url: DOWNLOAD_EXE_URL,
checksum: { algorithm: 'sha1', hash: json.exe }
}, $('Update Package'), `PureLauncher-${json.version}.exe`)
localStorage.removeItem('updateCheckTime')
Expand Down
7 changes: 2 additions & 5 deletions src/utils/hacks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { downloader } from '../plugin/DownloadProviders'

const { normailzeDownloader } = require('@xmcl/installer/util')
require('@xmcl/installer/util').normailzeDownloader = (a: any) => {
if (!a.downloader) a.downloader = downloader
normailzeDownloader(a)
}
require('@xmcl/installer/util').resolveDownloader = (opts: any, closure: any) =>
closure(opts.downloader ? opts : { ...opts, downloader })

const fs = require('fs-extra')
const installer = require('@xmcl/installer/index')
Expand Down

0 comments on commit 0ff5baa

Please sign in to comment.