Skip to content

Commit

Permalink
you no longer have to update settings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Dec 29, 2023
1 parent c4e0dca commit 170fad6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/v2/service/gallery.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
/* eslint-disable no-await-in-loop */

import { textures } from "../firestorm";
import { AcceptedRes, GalleryResult, Path, TextureMCMETA, Textures, Use, Uses } from "../interfaces";
import {
AcceptedRes,
GalleryResult,
Path,
TextureMCMETA,
Textures,
Use,
Uses,
} from "../interfaces";
import PathFirestormRepository from "../repository/firestorm/path.repository";
import { SettingsService } from "./settings.service";
import TextureService from "./texture.service";
Expand Down
22 changes: 19 additions & 3 deletions src/v2/service/path.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ export default class PathService {
.then(() => this.repository.updatePath(id, path));
}

modifyVersion(old_version: string, new_version: string): void | PromiseLike<void> {
async modifyVersion(old_version: string, new_version: string): Promise<void> {
const allVersions = await settings.get("versions");
const edition = Object.entries(allVersions).find(([_, v]) => v.includes(old_version))?.[0];

settings.editField({
id: "versions",
field: edition,
operation: "set",
// map old version to new version, keep the rest the same
value: allVersions[edition].map((v: string) => (v == old_version ? new_version : v)),
});

return this.repository.modifyVersion(old_version, new_version);
}

Expand All @@ -62,11 +73,16 @@ export default class PathService {
if (!versions.includes(body.version))
return Promise.reject(new BadRequestError("Incorrect input path version provided"));

const versionArray: string[] = (await settings.get("versions"))[body.edition];

// add to start of array, array-push would add to end and mess up ordering otherwise
versionArray.unshift(body.newVersion);

settings.editField({
id: "versions",
field: body.edition,
operation: "array-push",
value: body.newVersion,
operation: "set",
value: versionArray,
});

return this.repository.addNewVersionToVersion(body.version, body.newVersion);
Expand Down

0 comments on commit 170fad6

Please sign in to comment.