Skip to content

Commit

Permalink
extension blacklist (+attempted socket fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Oct 14, 2023
1 parent a92a54c commit 439ae22
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
1 change: 1 addition & 0 deletions json/blacklisted_textures.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"allowed_extensions": ["png", "tga", "mcmeta"],
"java": [
"environment/end_sky",
"gui/title/mojangstudios",
Expand Down
45 changes: 20 additions & 25 deletions src/helpers/functions/missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { existsSync, readdirSync, statSync } from "fs";
import { mkdir } from "fs/promises";
import formatName from "@utility/formatName";
import { Client } from "@client";
import { ChannelType, VoiceChannel } from "discord.js";
import { ChannelType } from "discord.js";
import { join, normalize } from "path";

import os from "os";
Expand All @@ -30,9 +30,9 @@ export const computeAll = async (
const editions: string[] = (await axios.get(`${client.tokens.apiUrl}textures/editions`)).data;

return Promise.all(
editions.map(async (edition: string) => {
return await compute(client, pack, edition, version, callback);
}),
editions.map(
async (edition: string) => await compute(client, pack, edition, version, callback),
),
);
};

Expand All @@ -45,9 +45,9 @@ export const computeAndUpdateAll = async (
const editions: string[] = (await axios.get(`${client.tokens.apiUrl}textures/editions`)).data;

return Promise.all(
editions.map(async (edition: string) => {
return await computeAndUpdate(client, pack, edition, version, callback);
}),
editions.map(
async (edition: string) => await computeAndUpdate(client, pack, edition, version, callback),
),
);
};

Expand Down Expand Up @@ -77,7 +77,7 @@ export const computeAndUpdate = async (
if (channel.name.match(pattern)?.[0] == results[2].completion.toString()) break;

const updatedName = channel.name.replace(pattern, results[2].completion.toString());
await (channel as VoiceChannel).setName(updatedName);
channel.setName(updatedName).catch(console.error);
break;
}

Expand Down Expand Up @@ -114,16 +114,14 @@ export const compute = async (

// CLONE REPO IF NOT ALREADY CLONED
if (!existsSync(tmpDirPathDefault)) {
await callback(`Downloading default ${edition} pack...`).catch((err: any) =>
Promise.reject(err),
);
await callback(`Downloading default ${edition} pack...`).catch(Promise.reject);
mkdir(tmpDirPathDefault);
await exec(`git clone ${repoDefault} .`, { cwd: tmpDirPathDefault });
}

if (!existsSync(tmpDirPathRequest)) {
await callback(`Downloading \`${formatName(pack)[0]}\` (${edition}) pack...`).catch(
(err: any) => Promise.reject(err),
Promise.reject,
);
mkdir(tmpDirPathRequest);
await exec(`git clone ${repoRequest} .`, { cwd: tmpDirPathRequest });
Expand All @@ -135,7 +133,7 @@ export const compute = async (
// latest version if versions doesn't include version (unexisting/unsupported)
if (!versions.includes(version)) version = versions[0];
await callback(`Updating packs with latest version of \`${version}\` known...`).catch(
(err: any) => Promise.reject(err),
Promise.reject,
);

// for some reason specifying the steps in a variable and loading it here breaks?
Expand All @@ -146,9 +144,9 @@ export const compute = async (
series(["git stash", "git remote update", "git fetch", `git checkout ${version}`, `git pull`], {
cwd: tmpDirPathRequest,
}),
]).catch((err) => Promise.reject(err));
]).catch(Promise.reject);

await callback("Searching for differences...").catch((err: any) => Promise.reject(err));
await callback("Searching for differences...").catch(Promise.reject);

const editionFilter = blacklistedTextures[edition].map(normalize);

Expand Down Expand Up @@ -197,16 +195,13 @@ export const getAllFilesFromDir = (dir: string, filter: string[] = []): string[]
file = normalize(join(dir, file));
const stat = statSync(file);

if (!file.includes(".git")) {
if (stat.isDirectory()) fileList.push(...getAllFilesFromDir(file, filter));
else {
if (
(file.endsWith(".png") || file.endsWith(".tga")) &&
!filter.some((i) => file.includes(i))
)
fileList.push(file);
}
}
if (file.includes(".git")) return;
if (stat.isDirectory()) return fileList.push(...getAllFilesFromDir(file, filter));
if (
blacklistedTextures.allowed_extensions.some((ex) => file.endsWith(`.${ex}`)) &&
!filter.some((i) => file.includes(i))
)
fileList.push(file);
});

return fileList;
Expand Down
7 changes: 4 additions & 3 deletions src/interfaces/submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ export interface Pack {
time_to_council?: number; // not used if council disabled
contributor_role?: string;
github: {
[edition: string]: { // java and bedrock
// java and bedrock
[edition: string]: {
repo: string;
org: string;
}
}
};
};
}

// just the channels
Expand Down

0 comments on commit 439ae22

Please sign in to comment.