Replace axios with got, check for empty version in forgemod meta.

This commit is contained in:
Daniel Scalzi
2020-09-04 23:29:36 -04:00
parent f287388931
commit d2e317b4df
6 changed files with 528 additions and 161 deletions

View File

@@ -71,6 +71,11 @@ export class ForgeModStructure17 extends BaseForgeModStructure {
})
}
private isMalformedVersion(version: string): boolean {
// Ex. empty, @VERSION@, ${version}
return version.trim().length === 0 || version.indexOf('@') > -1 || version.indexOf('$') > -1
}
private processZip(zip: StreamZip, name: string, path: string): McModInfo {
// Optifine is a tweak that can be loaded as a forge mod. It does not
// appear to contain a mcmod.info class. This a special case we will
@@ -143,10 +148,9 @@ export class ForgeModStructure17 extends BaseForgeModStructure {
x.name = this.discernResult(claritasName, crudeInference.name)
}
// Ex. @VERSION@, ${version}
if(this.forgeModMetadata[name]!.version != null) {
const isVersionWildcard = this.forgeModMetadata[name]!.version.indexOf('@') > -1 || this.forgeModMetadata[name]!.version.indexOf('$') > -1
if(isVersionWildcard) {
const isMalformedVersion = this.isMalformedVersion(this.forgeModMetadata[name]!.version)
if(isMalformedVersion) {
x.version = this.discernResult(claritasVersion, crudeInference.version)
}
} else {

View File

@@ -1,4 +1,4 @@
import axios from 'axios'
import got from 'got'
import { createWriteStream, mkdirs, pathExists } from 'fs-extra'
import { dirname, join, resolve } from 'path'
import { resolve as resolveURL } from 'url'
@@ -58,15 +58,11 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
public async downloadArtifactDirect(url: string, path: string): Promise<void> {
BaseMavenRepo.logger.debug(`Downloading ${url}..`)
const response = await axios({
method: 'get',
url,
responseType: 'stream'
})
const request = await got.stream.get({ url })
const localPath = resolve(this.containerDirectory, path)
await mkdirs(dirname(localPath))
const writer = createWriteStream(localPath)
response.data.pipe(writer)
request.pipe(writer)
// tslint:disable-next-line: no-shadowed-variable
return new Promise((resolve, reject) => {
writer.on('finish', () => {
@@ -91,11 +87,10 @@ export abstract class BaseMavenRepo extends BaseFileStructure {
private async headArtifactBase(url: string, relative: string): Promise<boolean> {
const resolvedURL = resolveURL(url, relative).toString()
try {
const response = await axios({
method: 'head',
const response = await got.head({
url: resolvedURL
})
return response.status === 200
return response.statusCode === 200
} catch (ignored) {
return false
}

View File

@@ -1,8 +1,12 @@
import { createLogger, format, transports, Logger } from 'winston'
import { SPLAT } from 'triple-beam'
import { SPLAT as SPLAT_Symbol } from 'triple-beam'
import moment from 'moment'
import { inspect } from 'util'
// Workaround until fixed.
// https://github.com/winstonjs/logform/issues/111
const SPLAT = SPLAT_Symbol as unknown as string
export class LoggerUtil {
public static getLogger(label: string): Logger {

View File

@@ -1,4 +1,4 @@
import Axios from 'axios'
import got from 'got'
import { PromotionsSlim } from '../model/forge/promotionsslim'
import { MinecraftVersion } from './MinecraftVersion'
import { LoggerUtil } from './LoggerUtil'
@@ -39,12 +39,12 @@ export class VersionUtil {
}
public static async getPromotionIndex(): Promise<PromotionsSlim> {
const response = await Axios({
const response = await got.get<PromotionsSlim>({
method: 'get',
url: 'https://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json',
responseType: 'json'
})
return response.data as PromotionsSlim
return response.body
}
public static getPromotedVersionStrict(index: PromotionsSlim, minecraftVersion: MinecraftVersion, promotion: string): string {