Skip to content

Commit

Permalink
prettier/eslint conflict fix
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Dec 21, 2023
1 parent 9299ccc commit 257252f
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 53 deletions.
48 changes: 24 additions & 24 deletions src/v2/controller/addon.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,40 @@ export class AddonController extends Controller {

private async getAddonProperty(id: number, property: AddonProperty): Promise<Addon | Files> {
switch (property) {
case "files":
return (await this.service.getFiles(id)).map((f) => {
if ((f.use === "header" || f.use === "screenshot") && f.source.startsWith("/"))
f.source = process.env.DB_IMAGE_ROOT + f.source;

if (
f.use === "download" &&
!f.source.startsWith("https://") &&
!f.source.startsWith("http://")
)
f.source = `http://${f.source}`;

return f;
});

case "all":
default:
return this.service.getAll(id).then((addon: AddonAll) => {
addon.files = addon.files.map((f) => {
case "files":
return (await this.service.getFiles(id)).map((f) => {
if ((f.use === "header" || f.use === "screenshot") && f.source.startsWith("/"))
f.source = process.env.DB_IMAGE_ROOT + f.source;

if (
f.use === "download" &&
!f.source.startsWith("https://") &&
!f.source.startsWith("http://")
!f.source.startsWith("https://") &&
!f.source.startsWith("http://")
)
f.source = `http://${f.source}`;

return f;
});

return addon;
});
case "all":
default:
return this.service.getAll(id).then((addon: AddonAll) => {
addon.files = addon.files.map((f) => {
if ((f.use === "header" || f.use === "screenshot") && f.source.startsWith("/"))
f.source = process.env.DB_IMAGE_ROOT + f.source;

if (
f.use === "download" &&
!f.source.startsWith("https://") &&
!f.source.startsWith("http://")
)
f.source = `http://${f.source}`;

return f;
});

return addon;
});
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ export class AddonController extends Controller {
@Get("{id_or_slug}/{property}")
public async getAddonPropertyById(
@Path() id_or_slug: string,
property: AddonProperty,
property: AddonProperty,
): Promise<Addon | Files> {
return this.service
.getAddonFromSlugOrId(id_or_slug)
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/modpacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Modpack {

export interface Modpacks extends Array<Modpack> {}

export interface FirestormModpack extends Modpack {};
export interface FirestormModpack extends Modpack {}

export interface ModpacksRepository {
getRaw(): Promise<Record<string, Modpack>>;
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/mods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Mod {

export interface Mods extends Array<Mod> {}

export interface FirestormMod extends Mod {};
export interface FirestormMod extends Mod {}

export interface ModsRepository {
getRaw(): Promise<Record<string, Mod>>;
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface WebsitePost extends CreateWebsitePost {
id: string;
}

export interface FirestormPost extends WebsitePost {};
export interface FirestormPost extends WebsitePost {}

export interface WebsitePostRepository {
getRaw(): Promise<Record<string, WebsitePost>>;
Expand Down
4 changes: 2 additions & 2 deletions src/v2/repository/firestorm/path.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export default class PathFirestormRepository implements PathRepository {

createPath(path: InputPath): Promise<Path> {
// breaks without structuredClone, not sure why
return paths.add(structuredClone(path)).then((id) => ({ ...structuredClone(path), id }) );
return paths.add(structuredClone(path)).then((id) => ({ ...structuredClone(path), id }));
}

createPathBulk(pathArray: InputPath[]): Promise<Path[]> {
return paths.addBulk(pathArray).then((ids) => paths.searchKeys(ids))
return paths.addBulk(pathArray).then((ids) => paths.searchKeys(ids));
}

removePathById(path_id: string): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/v2/repository/firestorm/use.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class UseFirestormRepository implements UseRepository {
}

setMultiple(useArray: Use[]): Promise<Use[]> {
const use_ids = useArray.map(u => u.id);
const use_ids = useArray.map((u) => u.id);
return uses.setBulk(use_ids, useArray).then(() => uses.searchKeys(use_ids));
}

Expand Down
37 changes: 20 additions & 17 deletions src/v2/service/texture.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,28 +97,31 @@ export default class TextureService {
const texture_id = created_texture.id;

// create uses
const [use_ids, full_uses_to_create]: [string[], Use[]] = input.uses.reduce((acc,u,ui) => {
const use_id = String(texture_id) + String.fromCharCode("a".charCodeAt(0) + ui);
const use = {
name: u.name,
edition: u.edition,
texture: Number.parseInt(texture_id, 10),
id: use_id,
}
acc[0].push(use_id)
acc[1].push(use)
return acc
}, [[],[]]);
const [use_ids, full_uses_to_create]: [string[], Use[]] = input.uses.reduce(
(acc, u, ui) => {
const use_id = String(texture_id) + String.fromCharCode("a".charCodeAt(0) + ui);
const use = {
name: u.name,
edition: u.edition,
texture: Number.parseInt(texture_id, 10),
id: use_id,
};
acc[0].push(use_id);
acc[1].push(use);
return acc;
},
[[], []],
);
await this.useService.createMultipleUses(full_uses_to_create);

// create paths
const paths_to_add = input.uses.reduce((acc, u, ui) => {
const paths: InputPath[] = u.paths.map(p => ({
const paths: InputPath[] = u.paths.map((p) => ({
...p,
use: use_ids[ui]
}))
return [ ...acc, ...paths ]
}, [] as InputPath[])
use: use_ids[ui],
}));
return [...acc, ...paths];
}, [] as InputPath[]);
await this.pathService.createMultiplePaths(paths_to_add);

return created_texture;
Expand Down
16 changes: 10 additions & 6 deletions src/v2/service/use.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ export default class UseService {
}

createMultipleUses(uses: Use[]): Promise<Use[]> {
return Promise.all(uses.map(u => new Promise((resolve, reject) => {
this.getUseByIdOrNameAndCatch(u.id)
.then(() => reject())
.catch(() => resolve(undefined))
})))
.then(() => this.useRepo.setMultiple(uses))
return Promise.all(
uses.map(
(u) =>
new Promise((resolve, reject) => {
this.getUseByIdOrNameAndCatch(u.id)
.then(() => reject())
.catch(() => resolve(undefined));
}),
),
).then(() => this.useRepo.setMultiple(uses));
}
}

0 comments on commit 257252f

Please sign in to comment.