Skip to content

Commit

Permalink
use shorthand array syntax everywhere
Browse files Browse the repository at this point in the history
the power of regex
  • Loading branch information
3vorp committed Sep 29, 2024
1 parent a66c508 commit a8ed71d
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/v2/controller/addon.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class AddonController extends Controller {
@Response<PermissionError>(403)
@Security("discord", ["addon:approved", "administrator"])
@Get("{id_or_slug}/files/screenshots")
public async getScreenshots(@Path() id_or_slug: string): Promise<Array<string>> {
public async getScreenshots(@Path() id_or_slug: string): Promise<string[]> {
const [addonID] = await this.service.getAddonFromSlugOrId(id_or_slug);
const screens = await this.service.getScreenshots(addonID);
return screens.map((s) => (s.startsWith("/") ? process.env.DB_IMAGE_ROOT + s : s));
Expand All @@ -193,7 +193,7 @@ export class AddonController extends Controller {
@Response<PermissionError>(403)
@Security("discord", ["addon:own", "administrator"])
@Get("{id_or_slug}/files/screenshots-ids")
public async getScreenshotsIds(@Path() id_or_slug: string): Promise<Array<string>> {
public async getScreenshotsIds(@Path() id_or_slug: string): Promise<string[]> {
const [addonID] = await this.service.getAddonFromSlugOrId(id_or_slug);
return this.service.getScreenshotsIds(addonID);
}
Expand All @@ -206,7 +206,7 @@ export class AddonController extends Controller {
@Response<PermissionError>(403)
@Security("discord", ["addon:approved", "administrator"])
@Get("{id_or_slug}/files/downloads")
public async getDownloads(@Path() id_or_slug: string): Promise<Array<AddonDownload>> {
public async getDownloads(@Path() id_or_slug: string): Promise<AddonDownload[]> {
const [addonID] = await this.service.getAddonFromSlugOrId(id_or_slug);
const files = await this.service.getFiles(addonID);
return Object.values(
Expand Down
10 changes: 5 additions & 5 deletions src/v2/controller/texture.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export class TextureController extends Controller {
* Get Minecraft editions supported by the database
*/
@Get("editions")
public getEditions(): Promise<Array<string>> {
public getEditions(): Promise<string[]> {
return this.service.getEditions();
}

/**
* Get all the tags from all textures (Block, UI, etc)
*/
@Get("tags")
public getTags(): Promise<Array<string>> {
public getTags(): Promise<string[]> {
return this.service.getTags();
}

Expand All @@ -68,15 +68,15 @@ export class TextureController extends Controller {
* @returns array of integers
*/
@Get("resolutions")
public getResolutions(): Promise<Array<number>> {
public getResolutions(): Promise<number[]> {
return this.service.getResolutions();
}

/**
* Get all existing Minecraft versions supported in the database
*/
@Get("versions")
public getVersions(): Promise<Array<string>> {
public getVersions(): Promise<string[]> {
return this.service.getVersions();
}

Expand All @@ -85,7 +85,7 @@ export class TextureController extends Controller {
* @param edition Existing edition inside the settings collection
*/
@Get("versions/{edition}")
public getVersionByEdition(@Path() edition: Edition): Promise<Array<string>> {
public getVersionByEdition(@Path() edition: Edition): Promise<string[]> {
return this.service.getVersionByEdition(edition);
}

Expand Down
4 changes: 2 additions & 2 deletions src/v2/controller/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class UserController extends Controller {
* Get all discord roles the database has
*/
@Get("roles")
public getRoles(): Promise<Array<string>> {
public getRoles(): Promise<string[]> {
return this.userService.getRoles();
}

Expand Down Expand Up @@ -243,7 +243,7 @@ export class UserController extends Controller {
@Put("{id}/roles")
@Security("discord", ["administrator"])
@Security("bot")
public setRoles(@Path() id: string, @Body() roles: Array<string>): Promise<User> {
public setRoles(@Path() id: string, @Body() roles: string[]): Promise<User> {
return this.userService.setRoles(id, roles);
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface Addon {
name: string; // addon name (> 5 && < 30)
slug: string; // used in link (ex: 'www.faithfulpack.net/addons/Faithful3D')
description: string; // addon description (> 256 && < 4096)
authors: Array<string>; // discord users IDs
authors: string[]; // discord users IDs
options: {
optifine: boolean; // true if the pack require optifine to work properly
tags: string[]; // Editions + Resolutions
Expand Down
10 changes: 5 additions & 5 deletions src/v2/interfaces/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PackID } from "./packs";
export interface ContributionCreationParams {
date: number; // unix timestamp
pack: PackID; // resource pack name
authors: Array<string>; // discord user ids
authors: string[]; // discord user ids
texture: string; // texture id
}

Expand Down Expand Up @@ -62,9 +62,9 @@ export interface ContributionsRepository {
getAuthors(): Promise<ContributionsAuthors>;
getPacks(): Promise<PackID[]>;
searchByIdAndPacks(
textureIDs: Array<string>,
packs: Array<string>,
users?: Array<string>,
textureIDs: string[],
packs: string[],
users?: string[],
): Promise<Contributions>;
searchContributionsFrom(users: Array<string>, packs: Array<string>): Promise<Contributions>;
searchContributionsFrom(users: string[], packs: string[]): Promise<Contributions>;
}
2 changes: 1 addition & 1 deletion src/v2/interfaces/modpacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Mods } from "./mods";
export interface Modpack {
id: string; // modpack id (curseforge project id)
name: string; // modpack name
authors: Array<string>; // modpacks authors
authors: string[]; // modpacks authors
versions: Array<{
id: string; // modpack version
minecraft: string; // minecraft version (ex: "1.18")
Expand Down
6 changes: 3 additions & 3 deletions src/v2/interfaces/mods.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export interface Mod {
id: string; // mod id (curseforge project id) (custom if not curseforge)
name: string; // mod name (ex: Industrial Craft 2)
aliases: Array<string>; // mod aliases (ex: IC2)
aliases: string[]; // mod aliases (ex: IC2)
curse_url: string; // curseforge project url (if not: undefined)
resource_pack: {
blacklist: Array<string>; // mc versions without textures
versions: Array<string>; // mc versions supported
blacklist: string[]; // mc versions without textures
versions: string[]; // mc versions supported
git_repository: string; // github repository link
};
blacklisted: boolean; // if true, the mod is fully blacklisted
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Edition } from "./textures";

export interface CreationPath {
name: string; // texture path ('textures/block/stone.png')
versions: Array<string>; // MC versions
versions: string[]; // MC versions
mcmeta: boolean; // true if animated
}

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 @@ -4,7 +4,7 @@ export interface Post {
id: string; // post unique id
name: string; // post name (> 5 && < 30)
description: string; // post description (> 256 && < 4096)
authors: Array<string>; // discord users IDs
authors: string[]; // discord users IDs
slug: string; // used in link (ex: 'www.faithfulpack.net/faithful32x/R2')
}
export type Posts = Post[];
Expand Down
14 changes: 7 additions & 7 deletions src/v2/interfaces/textures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PackID } from "./packs";

export interface TextureCreationParam {
name: string | number; // texture name
tags: Array<string>; // texture tags (block, item...)
tags: string[]; // texture tags (block, item...)
}
export interface Texture extends TextureCreationParam {
id: string; // texture unique id
Expand All @@ -17,7 +17,7 @@ export interface MCMETA {
animation?: {
interpolate?: boolean;
frametime?: number;
frames?: Array<number | { index: number; time: number }>;
frames?: (number | { index: number; time: number })[];
};
}

Expand Down Expand Up @@ -70,11 +70,11 @@ export interface TextureRepository {
forcePartial?: boolean,
): Promise<Textures>;
getTextureById(id: number, property: TextureProperty): Promise<PropertyToOutput<TextureProperty>>;
getVersions(): Promise<Array<string>>;
getEditions(): Promise<Array<string>>;
getResolutions(): Promise<Array<number>>;
getTags(): Promise<Array<string>>;
getVersionByEdition(edition: Edition): Promise<Array<string>>;
getVersions(): Promise<string[]>;
getEditions(): Promise<string[]>;
getResolutions(): Promise<number[]>;
getTags(): Promise<string[]>;
getVersionByEdition(edition: Edition): Promise<string[]>;
searchTexturePropertyByNameOrId(
nameOrID: string | number,
property: TextureProperty,
Expand Down
2 changes: 1 addition & 1 deletion src/v2/interfaces/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface UserCreationParams {
username: string; // username displayed online
uuid: string; // minecraft profile UUID
anonymous: boolean; // true if the user is anonymous
roles: Array<string>; // discord roles the user has, that can be modified by admin only
roles: string[]; // discord roles the user has, that can be modified by admin only
}

export interface Username {
Expand Down
5 changes: 1 addition & 4 deletions src/v2/repository/contribution.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ export default class ContributionFirestormRepository implements ContributionsRep
return contributions.values({ field: "pack" });
}

async searchContributionsFrom(
authors: Array<string>,
packs: Array<string>,
): Promise<Contributions> {
async searchContributionsFrom(authors: string[], packs: string[]): Promise<Contributions> {
const options: SearchOption<Contribution>[] = authors.map((author) => ({
field: "authors",
criteria: "array-contains",
Expand Down
8 changes: 4 additions & 4 deletions src/v2/repository/texture.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ export default class TextureFirestormRepository implements TextureRepository {
return uses.values({ field: "edition" }).then((res) => res.sort());
}

public getResolutions(): Promise<Array<number>> {
public getResolutions(): Promise<number[]> {
return packs.values({ field: "resolution" }).then((res) => res.sort());
}

public async getTags(): Promise<Array<string>> {
public async getTags(): Promise<string[]> {
const res = await textures.values({ field: "tags", flatten: true });
return res.sort();
}

public async getVersions(): Promise<Array<string>> {
public async getVersions(): Promise<string[]> {
const s = await settings.readRaw(true);
return Object.values(s.versions).flat().sort(MinecraftSorter).reverse();
}

public async getVersionByEdition(edition: Edition): Promise<Array<string>> {
public async getVersionByEdition(edition: Edition): Promise<string[]> {
const versions = await settings.get("versions");
if (!versions[edition]) throw new NotFoundError("edition not found");
return versions[edition];
Expand Down
2 changes: 1 addition & 1 deletion src/v2/repository/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default class UserFirestormRepository implements UserRepository {
return users.remove(oldID);
}

getRoles(): Promise<Array<string>> {
getRoles(): Promise<string[]> {
return users.values({ field: "roles", flatten: true });
}

Expand Down
6 changes: 3 additions & 3 deletions src/v2/service/addon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class AddonService {
return this.addonRepo.getAddonById(id);
}

async getAddonAuthors(id: number): Promise<Array<string>> {
async getAddonAuthors(id: number): Promise<string[]> {
const addon = await this.getAddon(id);
return addon.authors;
}
Expand Down Expand Up @@ -150,12 +150,12 @@ export default class AddonService {
return files.filter((f) => ["screenshot", "carousel"].includes(f.use));
}

async getScreenshotsIds(id: number): Promise<Array<string>> {
async getScreenshotsIds(id: number): Promise<string[]> {
const files = await this.getScreenshotsFiles(id);
return Object.values(files).map((f) => f.id);
}

async getScreenshots(id: number): Promise<Array<string>> {
async getScreenshots(id: number): Promise<string[]> {
const files = await this.getScreenshotsFiles(id);
return Object.values(files).map((f) => f.source);
}
Expand Down
2 changes: 1 addition & 1 deletion src/v2/service/contribution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class ContributionService {
return this.contributionRepo.getAuthors();
}

searchContributionsFrom(users: Array<string>, packs: Array<string>): Promise<Contributions> {
searchContributionsFrom(users: string[], packs: string[]): Promise<Contributions> {
return this.contributionRepo.searchContributionsFrom(users, packs);
}

Expand Down
10 changes: 5 additions & 5 deletions src/v2/service/texture.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ export default class TextureService {
return this.textureRepo.getByNameIdAndTag(tag, search, true);
}

getVersions(): Promise<Array<string>> {
getVersions(): Promise<string[]> {
return this.textureRepo.getVersions();
}

getVersionByEdition(edition: Edition): Promise<Array<string>> {
getVersionByEdition(edition: Edition): Promise<string[]> {
return this.textureRepo.getVersionByEdition(edition);
}

getEditions(): Promise<Array<string>> {
getEditions(): Promise<string[]> {
return this.textureRepo.getEditions();
}

getTags(): Promise<Array<string>> {
getTags(): Promise<string[]> {
return this.textureRepo.getTags();
}

getResolutions(): Promise<Array<number>> {
getResolutions(): Promise<number[]> {
return this.textureRepo.getResolutions();
}

Expand Down
2 changes: 1 addition & 1 deletion src/v2/service/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class UserService {
return this.repo.getNameById(id);
}

public getRoles(): Promise<Array<string>> {
public getRoles(): Promise<string[]> {
return this.repo.getRoles();
}

Expand Down
4 changes: 2 additions & 2 deletions src/v2/tools/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export async function expressAuthentication(
"id_or_slug" in request.params
) {
const { id_or_slug: idOrSlug } = request.params;
if ((AddonStatusValues as ReadonlyArray<string>).includes(idOrSlug)) {
if (!(AddonStatusNotApproved as ReadonlyArray<string>).includes(idOrSlug))
if ((AddonStatusValues as readonly string[]).includes(idOrSlug)) {
if (!(AddonStatusNotApproved as readonly string[]).includes(idOrSlug))
return Promise.resolve(discordID);
//* check if D: admin or roles, uses the rest of authentication with roles
} else {
Expand Down

0 comments on commit a8ed71d

Please sign in to comment.