🎨 Improved code quality of manifest parser
This commit is contained in:
parent
62ed08c6c3
commit
57c99b88fe
3 changed files with 25 additions and 6 deletions
16
src/interfaces/IManifest.ts
Normal file
16
src/interfaces/IManifest.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
/** A patch manifest, containing a list of releases, how to patch them, and which the current release is. */
|
||||
export default interface IManifest {
|
||||
/** Current release. */
|
||||
current: number;
|
||||
/** List of releases. */
|
||||
releases: {
|
||||
[s: string]: {
|
||||
/** SHA1 hash of this release. */
|
||||
sha1: string;
|
||||
/** List of releases from where we can patch to this release. */
|
||||
from: number[];
|
||||
/** List of releases that this release can be patched to. */
|
||||
to: number[];
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import { TextDecoder } from 'util';
|
||||
import * as xmlJs from 'xml-js';
|
||||
import getUrlContents from '../cdn/getUrlContents';
|
||||
import IManifest from '../interfaces/IManifest';
|
||||
import { Product } from '../interfaces/ISettings';
|
||||
import parsePatchmanifest from '../ssn/parsePatchmanifest';
|
||||
import verifyPatchmanifest from '../ssn/verifyPatchmanifest';
|
||||
|
@ -10,7 +11,7 @@ import readSsnFile from './readSsnFile';
|
|||
|
||||
const Decoder = new TextDecoder('utf-8');
|
||||
|
||||
export default async function getPatchmanifest(product: Product): Promise<any> {
|
||||
export default async function getPatchmanifest(product: Product): Promise<IManifest> {
|
||||
//Verify function arguments
|
||||
if (!verifyProductName(product)) {
|
||||
throw new Error(`"${product}" is not a valid product.`);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import IManifest from '../interfaces/IManifest';
|
||||
|
||||
/** Receives a JSON-converted version of the manifest.xml file, and returns an easier to read JSON file */
|
||||
export default function parsePatchManifest(manifestFile: any): any {
|
||||
const out: any = {};
|
||||
export default function parsePatchManifest(manifestFile: any): IManifest {
|
||||
const out: IManifest = { current: -1, releases: {} };
|
||||
|
||||
const PatchManifest = manifestFile.elements[0];
|
||||
|
||||
|
@ -11,21 +12,22 @@ export default function parsePatchManifest(manifestFile: any): any {
|
|||
|
||||
//<Releases><Release><Id>0</Id><SHA1>53678f8057e52896a8145dca5c188ab3f24fa55f</SHA1></Release></Releases>
|
||||
const Releases = PatchManifest.elements[7];
|
||||
out.releases = {};
|
||||
Releases.elements.forEach((Release: any) => {
|
||||
const id = Release.elements[0].elements[0].text;
|
||||
const sha1 = Release.elements[1].elements[0].text;
|
||||
out.releases[id] = { sha1, from: [], to: [] };
|
||||
});
|
||||
|
||||
//<ReleaseUpdatePaths><ReleaseUpdatePath><From>287</From><To>288</To><ExtraDataItem>...</ExtraDataItem></ReleaseUpdatePath></ReleaseUpdatePaths
|
||||
const ReleaseUpdatePaths = PatchManifest.elements[8];
|
||||
ReleaseUpdatePaths.elements.forEach((ReleaseUpdatePath: any) => {
|
||||
const from = ReleaseUpdatePath.elements[0].elements[0].text;
|
||||
const to = ReleaseUpdatePath.elements[1].elements[0].text;
|
||||
//Release -1 does not exist but is a valid "from", e.g. for -1to0
|
||||
if (from !== '-1') {
|
||||
out.releases[from].to.push(to);
|
||||
out.releases[from].to.push(Number(to));
|
||||
}
|
||||
out.releases[to].from.push(from);
|
||||
out.releases[to].from.push(Number(from));
|
||||
});
|
||||
|
||||
return out;
|
||||
|
|
Loading…
Reference in a new issue