You've already forked AstralRinth
forked from didirus/AstralRinth
refactor: migrate to common eslint+prettier configs (#4168)
* refactor: migrate to common eslint+prettier configs * fix: prettier frontend * feat: config changes * fix: lint issues * fix: lint * fix: type imports * fix: cyclical import issue * fix: lockfile * fix: missing dep * fix: switch to tabs * fix: continue switch to tabs * fix: rustfmt parity * fix: moderation lint issue * fix: lint issues * fix: ui intl * fix: lint issues * Revert "fix: rustfmt parity" This reverts commit cb99d2376c321d813d4b7fc7e2a213bb30a54711. * feat: revert last rs
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* @returns Whether any of the modifier keys is pressed.
|
||||
*/
|
||||
export function isModifierKeyDown(
|
||||
e: Pick<KeyboardEvent, "ctrlKey" | "altKey" | "metaKey" | "shiftKey">,
|
||||
e: Pick<KeyboardEvent, 'ctrlKey' | 'altKey' | 'metaKey' | 'shiftKey'>,
|
||||
) {
|
||||
return e.ctrlKey || e.altKey || e.metaKey || e.shiftKey;
|
||||
return e.ctrlKey || e.altKey || e.metaKey || e.shiftKey
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
import { formatBytes } from "@modrinth/utils";
|
||||
import { formatBytes } from '@modrinth/utils'
|
||||
|
||||
export const fileIsValid = (file, validationOptions) => {
|
||||
const { maxSize, alertOnInvalid } = validationOptions;
|
||||
if (maxSize !== null && maxSize !== undefined && file.size > maxSize) {
|
||||
if (alertOnInvalid) {
|
||||
alert(`File ${file.name} is too big! Must be less than ${formatBytes(maxSize)}`);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const { maxSize, alertOnInvalid } = validationOptions
|
||||
if (maxSize !== null && maxSize !== undefined && file.size > maxSize) {
|
||||
if (alertOnInvalid) {
|
||||
alert(`File ${file.name} is too big! Must be less than ${formatBytes(maxSize)}`)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
return true
|
||||
}
|
||||
|
||||
export const acceptFileFromProjectType = (projectType) => {
|
||||
switch (projectType) {
|
||||
case "mod":
|
||||
return ".jar,.zip,.litemod,application/java-archive,application/x-java-archive,application/zip";
|
||||
case "plugin":
|
||||
return ".jar,.zip,application/java-archive,application/x-java-archive,application/zip";
|
||||
case "resourcepack":
|
||||
return ".zip,application/zip";
|
||||
case "shader":
|
||||
return ".zip,application/zip";
|
||||
case "datapack":
|
||||
return ".zip,application/zip";
|
||||
case "modpack":
|
||||
return ".mrpack,application/x-modrinth-modpack+zip,application/zip";
|
||||
default:
|
||||
return "*";
|
||||
}
|
||||
};
|
||||
switch (projectType) {
|
||||
case 'mod':
|
||||
return '.jar,.zip,.litemod,application/java-archive,application/x-java-archive,application/zip'
|
||||
case 'plugin':
|
||||
return '.jar,.zip,application/java-archive,application/x-java-archive,application/zip'
|
||||
case 'resourcepack':
|
||||
return '.zip,application/zip'
|
||||
case 'shader':
|
||||
return '.zip,application/zip'
|
||||
case 'datapack':
|
||||
return '.zip,application/zip'
|
||||
case 'modpack':
|
||||
return '.mrpack,application/x-modrinth-modpack+zip,application/zip'
|
||||
default:
|
||||
return '*'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
import hljs from "highlight.js/lib/core";
|
||||
// Scripting
|
||||
import javascript from "highlight.js/lib/languages/javascript";
|
||||
import lua from "highlight.js/lib/languages/lua";
|
||||
import python from "highlight.js/lib/languages/python";
|
||||
// Coding
|
||||
import groovy from "highlight.js/lib/languages/groovy";
|
||||
import java from "highlight.js/lib/languages/java";
|
||||
import kotlin from "highlight.js/lib/languages/kotlin";
|
||||
import scala from "highlight.js/lib/languages/scala";
|
||||
// Configs
|
||||
import { configuredXss, md } from "@modrinth/utils";
|
||||
import gradle from "highlight.js/lib/languages/gradle";
|
||||
import ini from "highlight.js/lib/languages/ini";
|
||||
import json from "highlight.js/lib/languages/json";
|
||||
import properties from "highlight.js/lib/languages/properties";
|
||||
import xml from "highlight.js/lib/languages/xml";
|
||||
import yaml from "highlight.js/lib/languages/yaml";
|
||||
import { configuredXss, md } from '@modrinth/utils'
|
||||
import hljs from 'highlight.js/lib/core'
|
||||
import gradle from 'highlight.js/lib/languages/gradle'
|
||||
// Coding
|
||||
import groovy from 'highlight.js/lib/languages/groovy'
|
||||
import ini from 'highlight.js/lib/languages/ini'
|
||||
import java from 'highlight.js/lib/languages/java'
|
||||
// Scripting
|
||||
import javascript from 'highlight.js/lib/languages/javascript'
|
||||
import json from 'highlight.js/lib/languages/json'
|
||||
import kotlin from 'highlight.js/lib/languages/kotlin'
|
||||
import lua from 'highlight.js/lib/languages/lua'
|
||||
import properties from 'highlight.js/lib/languages/properties'
|
||||
import python from 'highlight.js/lib/languages/python'
|
||||
import scala from 'highlight.js/lib/languages/scala'
|
||||
import xml from 'highlight.js/lib/languages/xml'
|
||||
import yaml from 'highlight.js/lib/languages/yaml'
|
||||
|
||||
/* REGISTRATION */
|
||||
// Scripting
|
||||
hljs.registerLanguage("javascript", javascript);
|
||||
hljs.registerLanguage("python", python);
|
||||
hljs.registerLanguage("lua", lua);
|
||||
hljs.registerLanguage('javascript', javascript)
|
||||
hljs.registerLanguage('python', python)
|
||||
hljs.registerLanguage('lua', lua)
|
||||
// Coding
|
||||
hljs.registerLanguage("java", java);
|
||||
hljs.registerLanguage("kotlin", kotlin);
|
||||
hljs.registerLanguage("scala", scala);
|
||||
hljs.registerLanguage("groovy", groovy);
|
||||
hljs.registerLanguage('java', java)
|
||||
hljs.registerLanguage('kotlin', kotlin)
|
||||
hljs.registerLanguage('scala', scala)
|
||||
hljs.registerLanguage('groovy', groovy)
|
||||
// Configs
|
||||
hljs.registerLanguage("gradle", gradle);
|
||||
hljs.registerLanguage("json", json);
|
||||
hljs.registerLanguage("ini", ini);
|
||||
hljs.registerLanguage("yaml", yaml);
|
||||
hljs.registerLanguage("xml", xml);
|
||||
hljs.registerLanguage("properties", properties);
|
||||
hljs.registerLanguage('gradle', gradle)
|
||||
hljs.registerLanguage('json', json)
|
||||
hljs.registerLanguage('ini', ini)
|
||||
hljs.registerLanguage('yaml', yaml)
|
||||
hljs.registerLanguage('xml', xml)
|
||||
hljs.registerLanguage('properties', properties)
|
||||
|
||||
/* ALIASES */
|
||||
// Scripting
|
||||
hljs.registerAliases(["js"], { languageName: "javascript" });
|
||||
hljs.registerAliases(["py"], { languageName: "python" });
|
||||
hljs.registerAliases(['js'], { languageName: 'javascript' })
|
||||
hljs.registerAliases(['py'], { languageName: 'python' })
|
||||
// Coding
|
||||
hljs.registerAliases(["kt"], { languageName: "kotlin" });
|
||||
hljs.registerAliases(['kt'], { languageName: 'kotlin' })
|
||||
// Configs
|
||||
hljs.registerAliases(["json5"], { languageName: "json" });
|
||||
hljs.registerAliases(["toml"], { languageName: "ini" });
|
||||
hljs.registerAliases(["yml"], { languageName: "yaml" });
|
||||
hljs.registerAliases(["html", "htm", "xhtml", "mcui", "fxml"], { languageName: "xml" });
|
||||
hljs.registerAliases(['json5'], { languageName: 'json' })
|
||||
hljs.registerAliases(['toml'], { languageName: 'ini' })
|
||||
hljs.registerAliases(['yml'], { languageName: 'yaml' })
|
||||
hljs.registerAliases(['html', 'htm', 'xhtml', 'mcui', 'fxml'], { languageName: 'xml' })
|
||||
|
||||
export const renderHighlightedString = (string) =>
|
||||
configuredXss.process(
|
||||
md({
|
||||
highlight: function (str, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
return hljs.highlight(str, { language: lang }).value;
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
}
|
||||
configuredXss.process(
|
||||
md({
|
||||
highlight: function (str, lang) {
|
||||
if (lang && hljs.getLanguage(lang)) {
|
||||
try {
|
||||
return hljs.highlight(str, { language: lang }).value
|
||||
} catch {
|
||||
/* empty */
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
}).render(string),
|
||||
);
|
||||
return ''
|
||||
},
|
||||
}).render(string),
|
||||
)
|
||||
|
||||
@@ -1,522 +1,514 @@
|
||||
import { parse as parseTOML } from "@ltd/j-toml";
|
||||
import JSZip from "jszip";
|
||||
import yaml from "js-yaml";
|
||||
import { satisfies } from "semver";
|
||||
import { parse as parseTOML } from '@ltd/j-toml'
|
||||
import yaml from 'js-yaml'
|
||||
import JSZip from 'jszip'
|
||||
import { satisfies } from 'semver'
|
||||
|
||||
export const inferVersionInfo = async function (rawFile, project, gameVersions) {
|
||||
function versionType(number) {
|
||||
if (number.includes("alpha")) {
|
||||
return "alpha";
|
||||
} else if (
|
||||
number.includes("beta") ||
|
||||
number.match(/[^A-z](rc)[^A-z]/) || // includes `rc`
|
||||
number.match(/[^A-z](pre)[^A-z]/) // includes `pre`
|
||||
) {
|
||||
return "beta";
|
||||
} else {
|
||||
return "release";
|
||||
}
|
||||
}
|
||||
function versionType(number) {
|
||||
if (number.includes('alpha')) {
|
||||
return 'alpha'
|
||||
} else if (
|
||||
number.includes('beta') ||
|
||||
number.match(/[^A-z](rc)[^A-z]/) || // includes `rc`
|
||||
number.match(/[^A-z](pre)[^A-z]/) // includes `pre`
|
||||
) {
|
||||
return 'beta'
|
||||
} else {
|
||||
return 'release'
|
||||
}
|
||||
}
|
||||
|
||||
function getGameVersionsMatchingSemverRange(range, gameVersions) {
|
||||
if (!range) {
|
||||
return [];
|
||||
}
|
||||
const ranges = Array.isArray(range) ? range : [range];
|
||||
return gameVersions.filter((version) => {
|
||||
const semverVersion = version.split(".").length === 2 ? `${version}.0` : version; // add patch version if missing (e.g. 1.16 -> 1.16.0)
|
||||
return ranges.some((v) => satisfies(semverVersion, v));
|
||||
});
|
||||
}
|
||||
function getGameVersionsMatchingSemverRange(range, gameVersions) {
|
||||
if (!range) {
|
||||
return []
|
||||
}
|
||||
const ranges = Array.isArray(range) ? range : [range]
|
||||
return gameVersions.filter((version) => {
|
||||
const semverVersion = version.split('.').length === 2 ? `${version}.0` : version // add patch version if missing (e.g. 1.16 -> 1.16.0)
|
||||
return ranges.some((v) => satisfies(semverVersion, v))
|
||||
})
|
||||
}
|
||||
|
||||
function getGameVersionsMatchingMavenRange(range, gameVersions) {
|
||||
if (!range) {
|
||||
return [];
|
||||
}
|
||||
const ranges = [];
|
||||
function getGameVersionsMatchingMavenRange(range, gameVersions) {
|
||||
if (!range) {
|
||||
return []
|
||||
}
|
||||
const ranges = []
|
||||
|
||||
while (range.startsWith("[") || range.startsWith("(")) {
|
||||
let index = range.indexOf(")");
|
||||
const index2 = range.indexOf("]");
|
||||
if (index === -1 || (index2 !== -1 && index2 < index)) {
|
||||
index = index2;
|
||||
}
|
||||
if (index === -1) break;
|
||||
ranges.push(range.substring(0, index + 1));
|
||||
range = range.substring(index + 1).trim();
|
||||
if (range.startsWith(",")) {
|
||||
range = range.substring(1).trim();
|
||||
}
|
||||
}
|
||||
while (range.startsWith('[') || range.startsWith('(')) {
|
||||
let index = range.indexOf(')')
|
||||
const index2 = range.indexOf(']')
|
||||
if (index === -1 || (index2 !== -1 && index2 < index)) {
|
||||
index = index2
|
||||
}
|
||||
if (index === -1) break
|
||||
ranges.push(range.substring(0, index + 1))
|
||||
range = range.substring(index + 1).trim()
|
||||
if (range.startsWith(',')) {
|
||||
range = range.substring(1).trim()
|
||||
}
|
||||
}
|
||||
|
||||
if (range) {
|
||||
ranges.push(range);
|
||||
}
|
||||
if (range) {
|
||||
ranges.push(range)
|
||||
}
|
||||
|
||||
const LESS_THAN_EQUAL = /^\(,(.*)]$/;
|
||||
const LESS_THAN = /^\(,(.*)\)$/;
|
||||
const EQUAL = /^\[(.*)]$/;
|
||||
const GREATER_THAN_EQUAL = /^\[(.*),\)$/;
|
||||
const GREATER_THAN = /^\((.*),\)$/;
|
||||
const BETWEEN = /^\((.*),(.*)\)$/;
|
||||
const BETWEEN_EQUAL = /^\[(.*),(.*)]$/;
|
||||
const BETWEEN_LESS_THAN_EQUAL = /^\((.*),(.*)]$/;
|
||||
const BETWEEN_GREATER_THAN_EQUAL = /^\[(.*),(.*)\)$/;
|
||||
const LESS_THAN_EQUAL = /^\(,(.*)]$/
|
||||
const LESS_THAN = /^\(,(.*)\)$/
|
||||
const EQUAL = /^\[(.*)]$/
|
||||
const GREATER_THAN_EQUAL = /^\[(.*),\)$/
|
||||
const GREATER_THAN = /^\((.*),\)$/
|
||||
const BETWEEN = /^\((.*),(.*)\)$/
|
||||
const BETWEEN_EQUAL = /^\[(.*),(.*)]$/
|
||||
const BETWEEN_LESS_THAN_EQUAL = /^\((.*),(.*)]$/
|
||||
const BETWEEN_GREATER_THAN_EQUAL = /^\[(.*),(.*)\)$/
|
||||
|
||||
const semverRanges = [];
|
||||
const semverRanges = []
|
||||
|
||||
for (const range of ranges) {
|
||||
let result;
|
||||
if ((result = range.match(LESS_THAN_EQUAL))) {
|
||||
semverRanges.push(`<=${result[1]}`);
|
||||
} else if ((result = range.match(LESS_THAN))) {
|
||||
semverRanges.push(`<${result[1]}`);
|
||||
} else if ((result = range.match(EQUAL))) {
|
||||
semverRanges.push(`${result[1]}`);
|
||||
} else if ((result = range.match(GREATER_THAN_EQUAL))) {
|
||||
semverRanges.push(`>=${result[1]}`);
|
||||
} else if ((result = range.match(GREATER_THAN))) {
|
||||
semverRanges.push(`>${result[1]}`);
|
||||
} else if ((result = range.match(BETWEEN))) {
|
||||
semverRanges.push(`>${result[1]} <${result[2]}`);
|
||||
} else if ((result = range.match(BETWEEN_EQUAL))) {
|
||||
semverRanges.push(`>=${result[1]} <=${result[2]}`);
|
||||
} else if ((result = range.match(BETWEEN_LESS_THAN_EQUAL))) {
|
||||
semverRanges.push(`>${result[1]} <=${result[2]}`);
|
||||
} else if ((result = range.match(BETWEEN_GREATER_THAN_EQUAL))) {
|
||||
semverRanges.push(`>=${result[1]} <${result[2]}`);
|
||||
}
|
||||
}
|
||||
return getGameVersionsMatchingSemverRange(semverRanges, gameVersions);
|
||||
}
|
||||
for (const range of ranges) {
|
||||
let result
|
||||
if ((result = range.match(LESS_THAN_EQUAL))) {
|
||||
semverRanges.push(`<=${result[1]}`)
|
||||
} else if ((result = range.match(LESS_THAN))) {
|
||||
semverRanges.push(`<${result[1]}`)
|
||||
} else if ((result = range.match(EQUAL))) {
|
||||
semverRanges.push(`${result[1]}`)
|
||||
} else if ((result = range.match(GREATER_THAN_EQUAL))) {
|
||||
semverRanges.push(`>=${result[1]}`)
|
||||
} else if ((result = range.match(GREATER_THAN))) {
|
||||
semverRanges.push(`>${result[1]}`)
|
||||
} else if ((result = range.match(BETWEEN))) {
|
||||
semverRanges.push(`>${result[1]} <${result[2]}`)
|
||||
} else if ((result = range.match(BETWEEN_EQUAL))) {
|
||||
semverRanges.push(`>=${result[1]} <=${result[2]}`)
|
||||
} else if ((result = range.match(BETWEEN_LESS_THAN_EQUAL))) {
|
||||
semverRanges.push(`>${result[1]} <=${result[2]}`)
|
||||
} else if ((result = range.match(BETWEEN_GREATER_THAN_EQUAL))) {
|
||||
semverRanges.push(`>=${result[1]} <${result[2]}`)
|
||||
}
|
||||
}
|
||||
return getGameVersionsMatchingSemverRange(semverRanges, gameVersions)
|
||||
}
|
||||
|
||||
const simplifiedGameVersions = gameVersions
|
||||
.filter((it) => it.version_type === "release")
|
||||
.map((it) => it.version);
|
||||
const simplifiedGameVersions = gameVersions
|
||||
.filter((it) => it.version_type === 'release')
|
||||
.map((it) => it.version)
|
||||
|
||||
const inferFunctions = {
|
||||
// NeoForge
|
||||
"META-INF/neoforge.mods.toml": (file) => {
|
||||
const metadata = parseTOML(file, { joiner: "\n" });
|
||||
if (!metadata.mods || metadata.mods.length === 0) {
|
||||
return {};
|
||||
}
|
||||
const inferFunctions = {
|
||||
// NeoForge
|
||||
'META-INF/neoforge.mods.toml': (file) => {
|
||||
const metadata = parseTOML(file, { joiner: '\n' })
|
||||
if (!metadata.mods || metadata.mods.length === 0) {
|
||||
return {}
|
||||
}
|
||||
|
||||
const neoForgeDependency = Object.values(metadata.dependencies)
|
||||
.flat()
|
||||
.find((dependency) => dependency.modId === "neoforge");
|
||||
if (!neoForgeDependency) {
|
||||
return {};
|
||||
}
|
||||
const neoForgeDependency = Object.values(metadata.dependencies)
|
||||
.flat()
|
||||
.find((dependency) => dependency.modId === 'neoforge')
|
||||
if (!neoForgeDependency) {
|
||||
return {}
|
||||
}
|
||||
|
||||
// https://docs.neoforged.net/docs/gettingstarted/versioning/#neoforge
|
||||
const mcVersionRange = neoForgeDependency.versionRange
|
||||
.replace("-beta", "")
|
||||
.replace(/(\d+)(?:\.(\d+))?(?:\.(\d+)?)?/g, (_match, major, minor) => {
|
||||
return `1.${major}${minor ? "." + minor : ""}`;
|
||||
});
|
||||
const gameVersions = getGameVersionsMatchingMavenRange(
|
||||
mcVersionRange,
|
||||
simplifiedGameVersions,
|
||||
);
|
||||
// https://docs.neoforged.net/docs/gettingstarted/versioning/#neoforge
|
||||
const mcVersionRange = neoForgeDependency.versionRange
|
||||
.replace('-beta', '')
|
||||
.replace(/(\d+)(?:\.(\d+))?(?:\.(\d+)?)?/g, (_match, major, minor) => {
|
||||
return `1.${major}${minor ? '.' + minor : ''}`
|
||||
})
|
||||
const gameVersions = getGameVersionsMatchingMavenRange(mcVersionRange, simplifiedGameVersions)
|
||||
|
||||
const versionNum = metadata.mods[0].version;
|
||||
return {
|
||||
name: `${project.title} ${versionNum}`,
|
||||
version_number: versionNum,
|
||||
loaders: ["neoforge"],
|
||||
version_type: versionType(versionNum),
|
||||
game_versions: gameVersions,
|
||||
};
|
||||
},
|
||||
// Forge 1.13+
|
||||
"META-INF/mods.toml": async (file, zip) => {
|
||||
const metadata = parseTOML(file, { joiner: "\n" });
|
||||
const versionNum = metadata.mods[0].version
|
||||
return {
|
||||
name: `${project.title} ${versionNum}`,
|
||||
version_number: versionNum,
|
||||
loaders: ['neoforge'],
|
||||
version_type: versionType(versionNum),
|
||||
game_versions: gameVersions,
|
||||
}
|
||||
},
|
||||
// Forge 1.13+
|
||||
'META-INF/mods.toml': async (file, zip) => {
|
||||
const metadata = parseTOML(file, { joiner: '\n' })
|
||||
|
||||
if (metadata.mods && metadata.mods.length > 0) {
|
||||
let versionNum = metadata.mods[0].version;
|
||||
if (metadata.mods && metadata.mods.length > 0) {
|
||||
let versionNum = metadata.mods[0].version
|
||||
|
||||
// ${file.jarVersion} -> Implementation-Version from manifest
|
||||
const manifestFile = zip.file("META-INF/MANIFEST.MF");
|
||||
if (
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
metadata.mods[0].version.includes("${file.jarVersion}") &&
|
||||
manifestFile !== null
|
||||
) {
|
||||
const manifestText = await manifestFile.async("text");
|
||||
const regex = /Implementation-Version: (.*)$/m;
|
||||
const match = manifestText.match(regex);
|
||||
if (match) {
|
||||
// eslint-disable-next-line no-template-curly-in-string
|
||||
versionNum = versionNum.replace("${file.jarVersion}", match[1]);
|
||||
}
|
||||
}
|
||||
// ${file.jarVersion} -> Implementation-Version from manifest
|
||||
const manifestFile = zip.file('META-INF/MANIFEST.MF')
|
||||
if (metadata.mods[0].version.includes('${file.jarVersion}') && manifestFile !== null) {
|
||||
const manifestText = await manifestFile.async('text')
|
||||
const regex = /Implementation-Version: (.*)$/m
|
||||
const match = manifestText.match(regex)
|
||||
if (match) {
|
||||
versionNum = versionNum.replace('${file.jarVersion}', match[1])
|
||||
}
|
||||
}
|
||||
|
||||
let gameVersions = [];
|
||||
const mcDependencies = Object.values(metadata.dependencies)
|
||||
.flat()
|
||||
.filter((dependency) => dependency.modId === "minecraft");
|
||||
let gameVersions = []
|
||||
const mcDependencies = Object.values(metadata.dependencies)
|
||||
.flat()
|
||||
.filter((dependency) => dependency.modId === 'minecraft')
|
||||
|
||||
if (mcDependencies.length > 0) {
|
||||
gameVersions = getGameVersionsMatchingMavenRange(
|
||||
mcDependencies[0].versionRange,
|
||||
simplifiedGameVersions,
|
||||
);
|
||||
}
|
||||
if (mcDependencies.length > 0) {
|
||||
gameVersions = getGameVersionsMatchingMavenRange(
|
||||
mcDependencies[0].versionRange,
|
||||
simplifiedGameVersions,
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
name: `${project.title} ${versionNum}`,
|
||||
version_number: versionNum,
|
||||
version_type: versionType(versionNum),
|
||||
loaders: ["forge"],
|
||||
game_versions: gameVersions,
|
||||
};
|
||||
} else {
|
||||
return {};
|
||||
}
|
||||
},
|
||||
// Old Forge
|
||||
"mcmod.info": (file) => {
|
||||
const metadata = JSON.parse(file);
|
||||
return {
|
||||
name: `${project.title} ${versionNum}`,
|
||||
version_number: versionNum,
|
||||
version_type: versionType(versionNum),
|
||||
loaders: ['forge'],
|
||||
game_versions: gameVersions,
|
||||
}
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
// Old Forge
|
||||
'mcmod.info': (file) => {
|
||||
const metadata = JSON.parse(file)
|
||||
|
||||
return {
|
||||
name: metadata.version ? `${project.title} ${metadata.version}` : "",
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
loaders: ["forge"],
|
||||
game_versions: simplifiedGameVersions.filter((version) =>
|
||||
version.startsWith(metadata.mcversion),
|
||||
),
|
||||
};
|
||||
},
|
||||
// Fabric
|
||||
"fabric.mod.json": (file) => {
|
||||
const metadata = JSON.parse(file);
|
||||
return {
|
||||
name: metadata.version ? `${project.title} ${metadata.version}` : '',
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
loaders: ['forge'],
|
||||
game_versions: simplifiedGameVersions.filter((version) =>
|
||||
version.startsWith(metadata.mcversion),
|
||||
),
|
||||
}
|
||||
},
|
||||
// Fabric
|
||||
'fabric.mod.json': (file) => {
|
||||
const metadata = JSON.parse(file)
|
||||
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
loaders: ["fabric"],
|
||||
version_type: versionType(metadata.version),
|
||||
game_versions: metadata.depends
|
||||
? getGameVersionsMatchingSemverRange(metadata.depends.minecraft, simplifiedGameVersions)
|
||||
: [],
|
||||
};
|
||||
},
|
||||
// Quilt
|
||||
"quilt.mod.json": (file) => {
|
||||
const metadata = JSON.parse(file);
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
loaders: ['fabric'],
|
||||
version_type: versionType(metadata.version),
|
||||
game_versions: metadata.depends
|
||||
? getGameVersionsMatchingSemverRange(metadata.depends.minecraft, simplifiedGameVersions)
|
||||
: [],
|
||||
}
|
||||
},
|
||||
// Quilt
|
||||
'quilt.mod.json': (file) => {
|
||||
const metadata = JSON.parse(file)
|
||||
|
||||
return {
|
||||
name: `${project.title} ${metadata.quilt_loader.version}`,
|
||||
version_number: metadata.quilt_loader.version,
|
||||
loaders: ["quilt"],
|
||||
version_type: versionType(metadata.quilt_loader.version),
|
||||
game_versions: metadata.quilt_loader.depends
|
||||
? getGameVersionsMatchingSemverRange(
|
||||
metadata.quilt_loader.depends.find((x) => x.id === "minecraft")
|
||||
? metadata.quilt_loader.depends.find((x) => x.id === "minecraft").versions
|
||||
: [],
|
||||
simplifiedGameVersions,
|
||||
)
|
||||
: [],
|
||||
};
|
||||
},
|
||||
// Bukkit + Other Forks
|
||||
"plugin.yml": (file) => {
|
||||
const metadata = yaml.load(file);
|
||||
return {
|
||||
name: `${project.title} ${metadata.quilt_loader.version}`,
|
||||
version_number: metadata.quilt_loader.version,
|
||||
loaders: ['quilt'],
|
||||
version_type: versionType(metadata.quilt_loader.version),
|
||||
game_versions: metadata.quilt_loader.depends
|
||||
? getGameVersionsMatchingSemverRange(
|
||||
metadata.quilt_loader.depends.find((x) => x.id === 'minecraft')
|
||||
? metadata.quilt_loader.depends.find((x) => x.id === 'minecraft').versions
|
||||
: [],
|
||||
simplifiedGameVersions,
|
||||
)
|
||||
: [],
|
||||
}
|
||||
},
|
||||
// Bukkit + Other Forks
|
||||
'plugin.yml': (file) => {
|
||||
const metadata = yaml.load(file)
|
||||
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
// We don't know which fork of Bukkit users are using
|
||||
loaders: [],
|
||||
game_versions: gameVersions
|
||||
.filter(
|
||||
(x) => x.version.startsWith(metadata["api-version"]) && x.version_type === "release",
|
||||
)
|
||||
.map((x) => x.version),
|
||||
};
|
||||
},
|
||||
// Paper 1.19.3+
|
||||
"paper-plugin.yml": (file) => {
|
||||
const metadata = yaml.load(file);
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
// We don't know which fork of Bukkit users are using
|
||||
loaders: [],
|
||||
game_versions: gameVersions
|
||||
.filter(
|
||||
(x) => x.version.startsWith(metadata['api-version']) && x.version_type === 'release',
|
||||
)
|
||||
.map((x) => x.version),
|
||||
}
|
||||
},
|
||||
// Paper 1.19.3+
|
||||
'paper-plugin.yml': (file) => {
|
||||
const metadata = yaml.load(file)
|
||||
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
loaders: ["paper"],
|
||||
game_versions: gameVersions
|
||||
.filter(
|
||||
(x) => x.version.startsWith(metadata["api-version"]) && x.version_type === "release",
|
||||
)
|
||||
.map((x) => x.version),
|
||||
};
|
||||
},
|
||||
// Bungeecord + Waterfall
|
||||
"bungee.yml": (file) => {
|
||||
const metadata = yaml.load(file);
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
loaders: ['paper'],
|
||||
game_versions: gameVersions
|
||||
.filter(
|
||||
(x) => x.version.startsWith(metadata['api-version']) && x.version_type === 'release',
|
||||
)
|
||||
.map((x) => x.version),
|
||||
}
|
||||
},
|
||||
// Bungeecord + Waterfall
|
||||
'bungee.yml': (file) => {
|
||||
const metadata = yaml.load(file)
|
||||
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
loaders: ["bungeecord"],
|
||||
};
|
||||
},
|
||||
// Velocity
|
||||
"velocity-plugin.json": (file) => {
|
||||
const metadata = JSON.parse(file);
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
loaders: ['bungeecord'],
|
||||
}
|
||||
},
|
||||
// Velocity
|
||||
'velocity-plugin.json': (file) => {
|
||||
const metadata = JSON.parse(file)
|
||||
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
loaders: ["velocity"],
|
||||
};
|
||||
},
|
||||
// Modpacks
|
||||
"modrinth.index.json": (file) => {
|
||||
const metadata = JSON.parse(file);
|
||||
return {
|
||||
name: `${project.title} ${metadata.version}`,
|
||||
version_number: metadata.version,
|
||||
version_type: versionType(metadata.version),
|
||||
loaders: ['velocity'],
|
||||
}
|
||||
},
|
||||
// Modpacks
|
||||
'modrinth.index.json': (file) => {
|
||||
const metadata = JSON.parse(file)
|
||||
|
||||
const loaders = [];
|
||||
if ("forge" in metadata.dependencies) {
|
||||
loaders.push("forge");
|
||||
}
|
||||
if ("neoforge" in metadata.dependencies) {
|
||||
loaders.push("neoforge");
|
||||
}
|
||||
if ("fabric-loader" in metadata.dependencies) {
|
||||
loaders.push("fabric");
|
||||
}
|
||||
if ("quilt-loader" in metadata.dependencies) {
|
||||
loaders.push("quilt");
|
||||
}
|
||||
const loaders = []
|
||||
if ('forge' in metadata.dependencies) {
|
||||
loaders.push('forge')
|
||||
}
|
||||
if ('neoforge' in metadata.dependencies) {
|
||||
loaders.push('neoforge')
|
||||
}
|
||||
if ('fabric-loader' in metadata.dependencies) {
|
||||
loaders.push('fabric')
|
||||
}
|
||||
if ('quilt-loader' in metadata.dependencies) {
|
||||
loaders.push('quilt')
|
||||
}
|
||||
|
||||
return {
|
||||
name: `${project.title} ${metadata.versionId}`,
|
||||
version_number: metadata.versionId,
|
||||
version_type: versionType(metadata.versionId),
|
||||
loaders,
|
||||
game_versions: gameVersions
|
||||
.filter((x) => x.version === metadata.dependencies.minecraft)
|
||||
.map((x) => x.version),
|
||||
};
|
||||
},
|
||||
// Resource Packs + Data Packs
|
||||
"pack.mcmeta": (file) => {
|
||||
const metadata = JSON.parse(file);
|
||||
return {
|
||||
name: `${project.title} ${metadata.versionId}`,
|
||||
version_number: metadata.versionId,
|
||||
version_type: versionType(metadata.versionId),
|
||||
loaders,
|
||||
game_versions: gameVersions
|
||||
.filter((x) => x.version === metadata.dependencies.minecraft)
|
||||
.map((x) => x.version),
|
||||
}
|
||||
},
|
||||
// Resource Packs + Data Packs
|
||||
'pack.mcmeta': (file) => {
|
||||
const metadata = JSON.parse(file)
|
||||
|
||||
function getRange(versionA, versionB) {
|
||||
const startingIndex = gameVersions.findIndex((x) => x.version === versionA);
|
||||
const endingIndex = gameVersions.findIndex((x) => x.version === versionB);
|
||||
function getRange(versionA, versionB) {
|
||||
const startingIndex = gameVersions.findIndex((x) => x.version === versionA)
|
||||
const endingIndex = gameVersions.findIndex((x) => x.version === versionB)
|
||||
|
||||
const final = [];
|
||||
const filterOnlyRelease = gameVersions[startingIndex].version_type === "release";
|
||||
const final = []
|
||||
const filterOnlyRelease = gameVersions[startingIndex].version_type === 'release'
|
||||
|
||||
for (let i = startingIndex; i >= endingIndex; i--) {
|
||||
if (gameVersions[i].version_type === "release" || !filterOnlyRelease) {
|
||||
final.push(gameVersions[i].version);
|
||||
}
|
||||
}
|
||||
for (let i = startingIndex; i >= endingIndex; i--) {
|
||||
if (gameVersions[i].version_type === 'release' || !filterOnlyRelease) {
|
||||
final.push(gameVersions[i].version)
|
||||
}
|
||||
}
|
||||
|
||||
return final;
|
||||
}
|
||||
return final
|
||||
}
|
||||
|
||||
const loaders = [];
|
||||
let newGameVersions = [];
|
||||
const loaders = []
|
||||
let newGameVersions = []
|
||||
|
||||
if (project.actualProjectType === "mod") {
|
||||
loaders.push("datapack");
|
||||
if (project.actualProjectType === 'mod') {
|
||||
loaders.push('datapack')
|
||||
|
||||
switch (metadata.pack.pack_format) {
|
||||
case 4:
|
||||
newGameVersions = getRange("1.13", "1.14.4");
|
||||
break;
|
||||
case 5:
|
||||
newGameVersions = getRange("1.15", "1.16.1");
|
||||
break;
|
||||
case 6:
|
||||
newGameVersions = getRange("1.16.2", "1.16.5");
|
||||
break;
|
||||
case 7:
|
||||
newGameVersions = getRange("1.17", "1.17.1");
|
||||
break;
|
||||
case 8:
|
||||
newGameVersions = getRange("1.18", "1.18.1");
|
||||
break;
|
||||
case 9:
|
||||
newGameVersions.push("1.18.2");
|
||||
break;
|
||||
case 10:
|
||||
newGameVersions = getRange("1.19", "1.19.3");
|
||||
break;
|
||||
case 11:
|
||||
newGameVersions = getRange("23w03a", "23w05a");
|
||||
break;
|
||||
case 12:
|
||||
newGameVersions.push("1.19.4");
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
switch (metadata.pack.pack_format) {
|
||||
case 4:
|
||||
newGameVersions = getRange('1.13', '1.14.4')
|
||||
break
|
||||
case 5:
|
||||
newGameVersions = getRange('1.15', '1.16.1')
|
||||
break
|
||||
case 6:
|
||||
newGameVersions = getRange('1.16.2', '1.16.5')
|
||||
break
|
||||
case 7:
|
||||
newGameVersions = getRange('1.17', '1.17.1')
|
||||
break
|
||||
case 8:
|
||||
newGameVersions = getRange('1.18', '1.18.1')
|
||||
break
|
||||
case 9:
|
||||
newGameVersions.push('1.18.2')
|
||||
break
|
||||
case 10:
|
||||
newGameVersions = getRange('1.19', '1.19.3')
|
||||
break
|
||||
case 11:
|
||||
newGameVersions = getRange('23w03a', '23w05a')
|
||||
break
|
||||
case 12:
|
||||
newGameVersions.push('1.19.4')
|
||||
break
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
if (project.actualProjectType === "resourcepack") {
|
||||
loaders.push("minecraft");
|
||||
if (project.actualProjectType === 'resourcepack') {
|
||||
loaders.push('minecraft')
|
||||
|
||||
switch (metadata.pack.pack_format) {
|
||||
case 1:
|
||||
newGameVersions = getRange("1.6.1", "1.8.9");
|
||||
break;
|
||||
case 2:
|
||||
newGameVersions = getRange("1.9", "1.10.2");
|
||||
break;
|
||||
case 3:
|
||||
newGameVersions = getRange("1.11", "1.12.2");
|
||||
break;
|
||||
case 4:
|
||||
newGameVersions = getRange("1.13", "1.14.4");
|
||||
break;
|
||||
case 5:
|
||||
newGameVersions = getRange("1.15", "1.16.1");
|
||||
break;
|
||||
case 6:
|
||||
newGameVersions = getRange("1.16.2", "1.16.5");
|
||||
break;
|
||||
case 7:
|
||||
newGameVersions = getRange("1.17", "1.17.1");
|
||||
break;
|
||||
case 8:
|
||||
newGameVersions = getRange("1.18", "1.18.2");
|
||||
break;
|
||||
case 9:
|
||||
newGameVersions = getRange("1.19", "1.19.2");
|
||||
break;
|
||||
case 11:
|
||||
newGameVersions = getRange("22w42a", "22w44a");
|
||||
break;
|
||||
case 12:
|
||||
newGameVersions.push("1.19.3");
|
||||
break;
|
||||
case 13:
|
||||
newGameVersions.push("1.19.4");
|
||||
break;
|
||||
case 14:
|
||||
newGameVersions = getRange("23w14a", "23w16a");
|
||||
break;
|
||||
case 15:
|
||||
newGameVersions = getRange("1.20", "1.20.1");
|
||||
break;
|
||||
case 16:
|
||||
newGameVersions.push("23w31a");
|
||||
break;
|
||||
case 17:
|
||||
newGameVersions = getRange("23w32a", "1.20.2-pre1");
|
||||
break;
|
||||
case 18:
|
||||
newGameVersions.push("1.20.2");
|
||||
break;
|
||||
case 19:
|
||||
newGameVersions.push("23w42a");
|
||||
break;
|
||||
case 20:
|
||||
newGameVersions = getRange("23w43a", "23w44a");
|
||||
break;
|
||||
case 21:
|
||||
newGameVersions = getRange("23w45a", "23w46a");
|
||||
break;
|
||||
case 22:
|
||||
newGameVersions = getRange("1.20.3", "1.20.4");
|
||||
break;
|
||||
case 24:
|
||||
newGameVersions = getRange("24w03a", "24w04a");
|
||||
break;
|
||||
case 25:
|
||||
newGameVersions = getRange("24w05a", "24w05b");
|
||||
break;
|
||||
case 26:
|
||||
newGameVersions = getRange("24w06a", "24w07a");
|
||||
break;
|
||||
case 28:
|
||||
newGameVersions = getRange("24w09a", "24w10a");
|
||||
break;
|
||||
case 29:
|
||||
newGameVersions.push("24w11a");
|
||||
break;
|
||||
case 30:
|
||||
newGameVersions.push("24w12a");
|
||||
break;
|
||||
case 31:
|
||||
newGameVersions = getRange("24w13a", "1.20.5-pre3");
|
||||
break;
|
||||
case 32:
|
||||
newGameVersions = getRange("1.20.5", "1.20.6");
|
||||
break;
|
||||
case 33:
|
||||
newGameVersions = getRange("24w18a", "24w20a");
|
||||
break;
|
||||
case 34:
|
||||
newGameVersions = getRange("1.21", "1.21.1");
|
||||
break;
|
||||
case 35:
|
||||
newGameVersions.push("24w33a");
|
||||
break;
|
||||
case 36:
|
||||
newGameVersions = getRange("24w34a", "24w35a");
|
||||
break;
|
||||
case 37:
|
||||
newGameVersions.push("24w36a");
|
||||
break;
|
||||
case 38:
|
||||
newGameVersions.push("24w37a");
|
||||
break;
|
||||
case 39:
|
||||
newGameVersions = getRange("24w38a", "24w39a");
|
||||
break;
|
||||
case 40:
|
||||
newGameVersions.push("24w40a");
|
||||
break;
|
||||
case 41:
|
||||
newGameVersions = getRange("1.21.2-pre1", "1.21.2-pre2");
|
||||
break;
|
||||
case 42:
|
||||
newGameVersions = getRange("1.21.2", "1.21.3");
|
||||
break;
|
||||
case 43:
|
||||
newGameVersions.push("24w44a");
|
||||
break;
|
||||
case 44:
|
||||
newGameVersions.push("24w45a");
|
||||
break;
|
||||
case 45:
|
||||
newGameVersions.push("24w46a");
|
||||
break;
|
||||
case 46:
|
||||
newGameVersions.push("1.21.4");
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
switch (metadata.pack.pack_format) {
|
||||
case 1:
|
||||
newGameVersions = getRange('1.6.1', '1.8.9')
|
||||
break
|
||||
case 2:
|
||||
newGameVersions = getRange('1.9', '1.10.2')
|
||||
break
|
||||
case 3:
|
||||
newGameVersions = getRange('1.11', '1.12.2')
|
||||
break
|
||||
case 4:
|
||||
newGameVersions = getRange('1.13', '1.14.4')
|
||||
break
|
||||
case 5:
|
||||
newGameVersions = getRange('1.15', '1.16.1')
|
||||
break
|
||||
case 6:
|
||||
newGameVersions = getRange('1.16.2', '1.16.5')
|
||||
break
|
||||
case 7:
|
||||
newGameVersions = getRange('1.17', '1.17.1')
|
||||
break
|
||||
case 8:
|
||||
newGameVersions = getRange('1.18', '1.18.2')
|
||||
break
|
||||
case 9:
|
||||
newGameVersions = getRange('1.19', '1.19.2')
|
||||
break
|
||||
case 11:
|
||||
newGameVersions = getRange('22w42a', '22w44a')
|
||||
break
|
||||
case 12:
|
||||
newGameVersions.push('1.19.3')
|
||||
break
|
||||
case 13:
|
||||
newGameVersions.push('1.19.4')
|
||||
break
|
||||
case 14:
|
||||
newGameVersions = getRange('23w14a', '23w16a')
|
||||
break
|
||||
case 15:
|
||||
newGameVersions = getRange('1.20', '1.20.1')
|
||||
break
|
||||
case 16:
|
||||
newGameVersions.push('23w31a')
|
||||
break
|
||||
case 17:
|
||||
newGameVersions = getRange('23w32a', '1.20.2-pre1')
|
||||
break
|
||||
case 18:
|
||||
newGameVersions.push('1.20.2')
|
||||
break
|
||||
case 19:
|
||||
newGameVersions.push('23w42a')
|
||||
break
|
||||
case 20:
|
||||
newGameVersions = getRange('23w43a', '23w44a')
|
||||
break
|
||||
case 21:
|
||||
newGameVersions = getRange('23w45a', '23w46a')
|
||||
break
|
||||
case 22:
|
||||
newGameVersions = getRange('1.20.3', '1.20.4')
|
||||
break
|
||||
case 24:
|
||||
newGameVersions = getRange('24w03a', '24w04a')
|
||||
break
|
||||
case 25:
|
||||
newGameVersions = getRange('24w05a', '24w05b')
|
||||
break
|
||||
case 26:
|
||||
newGameVersions = getRange('24w06a', '24w07a')
|
||||
break
|
||||
case 28:
|
||||
newGameVersions = getRange('24w09a', '24w10a')
|
||||
break
|
||||
case 29:
|
||||
newGameVersions.push('24w11a')
|
||||
break
|
||||
case 30:
|
||||
newGameVersions.push('24w12a')
|
||||
break
|
||||
case 31:
|
||||
newGameVersions = getRange('24w13a', '1.20.5-pre3')
|
||||
break
|
||||
case 32:
|
||||
newGameVersions = getRange('1.20.5', '1.20.6')
|
||||
break
|
||||
case 33:
|
||||
newGameVersions = getRange('24w18a', '24w20a')
|
||||
break
|
||||
case 34:
|
||||
newGameVersions = getRange('1.21', '1.21.1')
|
||||
break
|
||||
case 35:
|
||||
newGameVersions.push('24w33a')
|
||||
break
|
||||
case 36:
|
||||
newGameVersions = getRange('24w34a', '24w35a')
|
||||
break
|
||||
case 37:
|
||||
newGameVersions.push('24w36a')
|
||||
break
|
||||
case 38:
|
||||
newGameVersions.push('24w37a')
|
||||
break
|
||||
case 39:
|
||||
newGameVersions = getRange('24w38a', '24w39a')
|
||||
break
|
||||
case 40:
|
||||
newGameVersions.push('24w40a')
|
||||
break
|
||||
case 41:
|
||||
newGameVersions = getRange('1.21.2-pre1', '1.21.2-pre2')
|
||||
break
|
||||
case 42:
|
||||
newGameVersions = getRange('1.21.2', '1.21.3')
|
||||
break
|
||||
case 43:
|
||||
newGameVersions.push('24w44a')
|
||||
break
|
||||
case 44:
|
||||
newGameVersions.push('24w45a')
|
||||
break
|
||||
case 45:
|
||||
newGameVersions.push('24w46a')
|
||||
break
|
||||
case 46:
|
||||
newGameVersions.push('1.21.4')
|
||||
break
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
loaders,
|
||||
game_versions: newGameVersions,
|
||||
};
|
||||
},
|
||||
};
|
||||
return {
|
||||
loaders,
|
||||
game_versions: newGameVersions,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
const zipReader = new JSZip();
|
||||
const zipReader = new JSZip()
|
||||
|
||||
const zip = await zipReader.loadAsync(rawFile);
|
||||
const zip = await zipReader.loadAsync(rawFile)
|
||||
|
||||
for (const fileName in inferFunctions) {
|
||||
const file = zip.file(fileName);
|
||||
for (const fileName in inferFunctions) {
|
||||
const file = zip.file(fileName)
|
||||
|
||||
if (file !== null) {
|
||||
const text = await file.async("text");
|
||||
return inferFunctions[fileName](text, zip);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (file !== null) {
|
||||
const text = await file.async('text')
|
||||
return inferFunctions[fileName](text, zip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,236 +1,236 @@
|
||||
import type { ExtendedReport, OwnershipTarget } from "@modrinth/moderation";
|
||||
import type { ExtendedReport, OwnershipTarget } from '@modrinth/moderation'
|
||||
import type {
|
||||
Thread,
|
||||
Version,
|
||||
User,
|
||||
Project,
|
||||
TeamMember,
|
||||
Organization,
|
||||
Report,
|
||||
} from "@modrinth/utils";
|
||||
Organization,
|
||||
Project,
|
||||
Report,
|
||||
TeamMember,
|
||||
Thread,
|
||||
User,
|
||||
Version,
|
||||
} from '@modrinth/utils'
|
||||
|
||||
export const useModerationCache = () => ({
|
||||
threads: useState<Map<string, Thread>>("moderation-report-cache-threads", () => new Map()),
|
||||
users: useState<Map<string, User>>("moderation-report-cache-users", () => new Map()),
|
||||
projects: useState<Map<string, Project>>("moderation-report-cache-projects", () => new Map()),
|
||||
versions: useState<Map<string, Version>>("moderation-report-cache-versions", () => new Map()),
|
||||
teams: useState<Map<string, TeamMember[]>>("moderation-report-cache-teams", () => new Map()),
|
||||
orgs: useState<Map<string, Organization>>("moderation-report-cache-orgs", () => new Map()),
|
||||
});
|
||||
threads: useState<Map<string, Thread>>('moderation-report-cache-threads', () => new Map()),
|
||||
users: useState<Map<string, User>>('moderation-report-cache-users', () => new Map()),
|
||||
projects: useState<Map<string, Project>>('moderation-report-cache-projects', () => new Map()),
|
||||
versions: useState<Map<string, Version>>('moderation-report-cache-versions', () => new Map()),
|
||||
teams: useState<Map<string, TeamMember[]>>('moderation-report-cache-teams', () => new Map()),
|
||||
orgs: useState<Map<string, Organization>>('moderation-report-cache-orgs', () => new Map()),
|
||||
})
|
||||
|
||||
// TODO: @AlexTMjugador - backend should do all of these functions.
|
||||
export async function enrichReportBatch(reports: Report[]): Promise<ExtendedReport[]> {
|
||||
if (reports.length === 0) return [];
|
||||
if (reports.length === 0) return []
|
||||
|
||||
const cache = useModerationCache();
|
||||
const cache = useModerationCache()
|
||||
|
||||
const threadIDs = reports
|
||||
.map((r) => r.thread_id)
|
||||
.filter(Boolean)
|
||||
.filter((id) => !cache.threads.value.has(id));
|
||||
const userIDs = [
|
||||
...reports.filter((r) => r.item_type === "user").map((r) => r.item_id),
|
||||
...reports.map((r) => r.reporter),
|
||||
].filter((id) => !cache.users.value.has(id));
|
||||
const versionIDs = reports
|
||||
.filter((r) => r.item_type === "version")
|
||||
.map((r) => r.item_id)
|
||||
.filter((id) => !cache.versions.value.has(id));
|
||||
const projectIDs = reports
|
||||
.filter((r) => r.item_type === "project")
|
||||
.map((r) => r.item_id)
|
||||
.filter((id) => !cache.projects.value.has(id));
|
||||
const threadIDs = reports
|
||||
.map((r) => r.thread_id)
|
||||
.filter(Boolean)
|
||||
.filter((id) => !cache.threads.value.has(id))
|
||||
const userIDs = [
|
||||
...reports.filter((r) => r.item_type === 'user').map((r) => r.item_id),
|
||||
...reports.map((r) => r.reporter),
|
||||
].filter((id) => !cache.users.value.has(id))
|
||||
const versionIDs = reports
|
||||
.filter((r) => r.item_type === 'version')
|
||||
.map((r) => r.item_id)
|
||||
.filter((id) => !cache.versions.value.has(id))
|
||||
const projectIDs = reports
|
||||
.filter((r) => r.item_type === 'project')
|
||||
.map((r) => r.item_id)
|
||||
.filter((id) => !cache.projects.value.has(id))
|
||||
|
||||
const [newThreads, newVersions, newUsers] = await Promise.all([
|
||||
threadIDs.length > 0
|
||||
? (fetchSegmented(threadIDs, (ids) => `threads?ids=${asEncodedJsonArray(ids)}`) as Promise<
|
||||
Thread[]
|
||||
>)
|
||||
: Promise.resolve([]),
|
||||
versionIDs.length > 0
|
||||
? (fetchSegmented(versionIDs, (ids) => `versions?ids=${asEncodedJsonArray(ids)}`) as Promise<
|
||||
Version[]
|
||||
>)
|
||||
: Promise.resolve([]),
|
||||
[...new Set(userIDs)].length > 0
|
||||
? (fetchSegmented(
|
||||
[...new Set(userIDs)],
|
||||
(ids) => `users?ids=${asEncodedJsonArray(ids)}`,
|
||||
) as Promise<User[]>)
|
||||
: Promise.resolve([]),
|
||||
]);
|
||||
const [newThreads, newVersions, newUsers] = await Promise.all([
|
||||
threadIDs.length > 0
|
||||
? (fetchSegmented(threadIDs, (ids) => `threads?ids=${asEncodedJsonArray(ids)}`) as Promise<
|
||||
Thread[]
|
||||
>)
|
||||
: Promise.resolve([]),
|
||||
versionIDs.length > 0
|
||||
? (fetchSegmented(versionIDs, (ids) => `versions?ids=${asEncodedJsonArray(ids)}`) as Promise<
|
||||
Version[]
|
||||
>)
|
||||
: Promise.resolve([]),
|
||||
[...new Set(userIDs)].length > 0
|
||||
? (fetchSegmented(
|
||||
[...new Set(userIDs)],
|
||||
(ids) => `users?ids=${asEncodedJsonArray(ids)}`,
|
||||
) as Promise<User[]>)
|
||||
: Promise.resolve([]),
|
||||
])
|
||||
|
||||
newThreads.forEach((t) => cache.threads.value.set(t.id, t));
|
||||
newVersions.forEach((v) => cache.versions.value.set(v.id, v));
|
||||
newUsers.forEach((u) => cache.users.value.set(u.id, u));
|
||||
newThreads.forEach((t) => cache.threads.value.set(t.id, t))
|
||||
newVersions.forEach((v) => cache.versions.value.set(v.id, v))
|
||||
newUsers.forEach((u) => cache.users.value.set(u.id, u))
|
||||
|
||||
const allVersions = [...newVersions, ...Array.from(cache.versions.value.values())];
|
||||
const fullProjectIds = new Set([
|
||||
...projectIDs,
|
||||
...allVersions
|
||||
.filter((v) => versionIDs.includes(v.id))
|
||||
.map((v) => v.project_id)
|
||||
.filter(Boolean),
|
||||
]);
|
||||
const allVersions = [...newVersions, ...Array.from(cache.versions.value.values())]
|
||||
const fullProjectIds = new Set([
|
||||
...projectIDs,
|
||||
...allVersions
|
||||
.filter((v) => versionIDs.includes(v.id))
|
||||
.map((v) => v.project_id)
|
||||
.filter(Boolean),
|
||||
])
|
||||
|
||||
const uncachedProjectIds = Array.from(fullProjectIds).filter(
|
||||
(id) => !cache.projects.value.has(id),
|
||||
);
|
||||
const newProjects =
|
||||
uncachedProjectIds.length > 0
|
||||
? ((await fetchSegmented(
|
||||
uncachedProjectIds,
|
||||
(ids) => `projects?ids=${asEncodedJsonArray(ids)}`,
|
||||
)) as Project[])
|
||||
: [];
|
||||
const uncachedProjectIds = Array.from(fullProjectIds).filter(
|
||||
(id) => !cache.projects.value.has(id),
|
||||
)
|
||||
const newProjects =
|
||||
uncachedProjectIds.length > 0
|
||||
? ((await fetchSegmented(
|
||||
uncachedProjectIds,
|
||||
(ids) => `projects?ids=${asEncodedJsonArray(ids)}`,
|
||||
)) as Project[])
|
||||
: []
|
||||
|
||||
newProjects.forEach((p) => cache.projects.value.set(p.id, p));
|
||||
newProjects.forEach((p) => cache.projects.value.set(p.id, p))
|
||||
|
||||
const allProjects = [...newProjects, ...Array.from(cache.projects.value.values())];
|
||||
const teamIds = [...new Set(allProjects.map((p) => p.team).filter(Boolean))].filter(
|
||||
(id) => !cache.teams.value.has(id || "invalid team id"),
|
||||
);
|
||||
const orgIds = [...new Set(allProjects.map((p) => p.organization).filter(Boolean))].filter(
|
||||
(id) => !cache.orgs.value.has(id),
|
||||
);
|
||||
const allProjects = [...newProjects, ...Array.from(cache.projects.value.values())]
|
||||
const teamIds = [...new Set(allProjects.map((p) => p.team).filter(Boolean))].filter(
|
||||
(id) => !cache.teams.value.has(id || 'invalid team id'),
|
||||
)
|
||||
const orgIds = [...new Set(allProjects.map((p) => p.organization).filter(Boolean))].filter(
|
||||
(id) => !cache.orgs.value.has(id),
|
||||
)
|
||||
|
||||
const [newTeams, newOrgs] = await Promise.all([
|
||||
teamIds.length > 0
|
||||
? (fetchSegmented(teamIds, (ids) => `teams?ids=${asEncodedJsonArray(ids)}`) as Promise<
|
||||
TeamMember[][]
|
||||
>)
|
||||
: Promise.resolve([]),
|
||||
orgIds.length > 0
|
||||
? (fetchSegmented(orgIds, (ids) => `organizations?ids=${asEncodedJsonArray(ids)}`, {
|
||||
apiVersion: 3,
|
||||
}) as Promise<Organization[]>)
|
||||
: Promise.resolve([]),
|
||||
]);
|
||||
const [newTeams, newOrgs] = await Promise.all([
|
||||
teamIds.length > 0
|
||||
? (fetchSegmented(teamIds, (ids) => `teams?ids=${asEncodedJsonArray(ids)}`) as Promise<
|
||||
TeamMember[][]
|
||||
>)
|
||||
: Promise.resolve([]),
|
||||
orgIds.length > 0
|
||||
? (fetchSegmented(orgIds, (ids) => `organizations?ids=${asEncodedJsonArray(ids)}`, {
|
||||
apiVersion: 3,
|
||||
}) as Promise<Organization[]>)
|
||||
: Promise.resolve([]),
|
||||
])
|
||||
|
||||
newTeams.forEach((team) => {
|
||||
if (team.length > 0) cache.teams.value.set(team[0].team_id, team);
|
||||
});
|
||||
newOrgs.forEach((org) => cache.orgs.value.set(org.id, org));
|
||||
newTeams.forEach((team) => {
|
||||
if (team.length > 0) cache.teams.value.set(team[0].team_id, team)
|
||||
})
|
||||
newOrgs.forEach((org) => cache.orgs.value.set(org.id, org))
|
||||
|
||||
return reports.map((report) => {
|
||||
const thread = cache.threads.value.get(report.thread_id) || ({} as Thread);
|
||||
const version =
|
||||
report.item_type === "version" ? cache.versions.value.get(report.item_id) : undefined;
|
||||
return reports.map((report) => {
|
||||
const thread = cache.threads.value.get(report.thread_id) || ({} as Thread)
|
||||
const version =
|
||||
report.item_type === 'version' ? cache.versions.value.get(report.item_id) : undefined
|
||||
|
||||
const project =
|
||||
report.item_type === "project"
|
||||
? cache.projects.value.get(report.item_id)
|
||||
: report.item_type === "version" && version
|
||||
? cache.projects.value.get(version.project_id)
|
||||
: undefined;
|
||||
const project =
|
||||
report.item_type === 'project'
|
||||
? cache.projects.value.get(report.item_id)
|
||||
: report.item_type === 'version' && version
|
||||
? cache.projects.value.get(version.project_id)
|
||||
: undefined
|
||||
|
||||
let target: OwnershipTarget | undefined;
|
||||
let target: OwnershipTarget | undefined
|
||||
|
||||
if (report.item_type === "user") {
|
||||
const targetUser = cache.users.value.get(report.item_id);
|
||||
if (targetUser) {
|
||||
target = {
|
||||
name: targetUser.username,
|
||||
slug: targetUser.username,
|
||||
avatar_url: targetUser.avatar_url,
|
||||
type: "user",
|
||||
};
|
||||
}
|
||||
} else if (project) {
|
||||
let owner: TeamMember | null = null;
|
||||
let org: Organization | null = null;
|
||||
if (report.item_type === 'user') {
|
||||
const targetUser = cache.users.value.get(report.item_id)
|
||||
if (targetUser) {
|
||||
target = {
|
||||
name: targetUser.username,
|
||||
slug: targetUser.username,
|
||||
avatar_url: targetUser.avatar_url,
|
||||
type: 'user',
|
||||
}
|
||||
}
|
||||
} else if (project) {
|
||||
let owner: TeamMember | null = null
|
||||
let org: Organization | null = null
|
||||
|
||||
if (project.team) {
|
||||
const teamMembers = cache.teams.value.get(project.team);
|
||||
if (teamMembers) {
|
||||
owner = teamMembers.find((member) => member.role === "Owner") || null;
|
||||
}
|
||||
}
|
||||
if (project.team) {
|
||||
const teamMembers = cache.teams.value.get(project.team)
|
||||
if (teamMembers) {
|
||||
owner = teamMembers.find((member) => member.role === 'Owner') || null
|
||||
}
|
||||
}
|
||||
|
||||
if (project.organization) {
|
||||
org = cache.orgs.value.get(project.organization) || null;
|
||||
}
|
||||
if (project.organization) {
|
||||
org = cache.orgs.value.get(project.organization) || null
|
||||
}
|
||||
|
||||
if (org) {
|
||||
target = {
|
||||
name: org.name,
|
||||
avatar_url: org.icon_url,
|
||||
type: "organization",
|
||||
slug: org.slug,
|
||||
};
|
||||
} else if (owner) {
|
||||
target = {
|
||||
name: owner.user.username,
|
||||
avatar_url: owner.user.avatar_url,
|
||||
type: "user",
|
||||
slug: owner.user.username,
|
||||
};
|
||||
}
|
||||
}
|
||||
if (org) {
|
||||
target = {
|
||||
name: org.name,
|
||||
avatar_url: org.icon_url,
|
||||
type: 'organization',
|
||||
slug: org.slug,
|
||||
}
|
||||
} else if (owner) {
|
||||
target = {
|
||||
name: owner.user.username,
|
||||
avatar_url: owner.user.avatar_url,
|
||||
type: 'user',
|
||||
slug: owner.user.username,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...report,
|
||||
thread,
|
||||
reporter_user: cache.users.value.get(report.reporter) || ({} as User),
|
||||
project,
|
||||
user: report.item_type === "user" ? cache.users.value.get(report.item_id) : undefined,
|
||||
version,
|
||||
target,
|
||||
};
|
||||
});
|
||||
return {
|
||||
...report,
|
||||
thread,
|
||||
reporter_user: cache.users.value.get(report.reporter) || ({} as User),
|
||||
project,
|
||||
user: report.item_type === 'user' ? cache.users.value.get(report.item_id) : undefined,
|
||||
version,
|
||||
target,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Doesn't need to be in @modrinth/moderation because it is specific to the frontend.
|
||||
export interface ModerationProject {
|
||||
project: any;
|
||||
owner: TeamMember | null;
|
||||
org: Organization | null;
|
||||
project: any
|
||||
owner: TeamMember | null
|
||||
org: Organization | null
|
||||
}
|
||||
|
||||
export async function enrichProjectBatch(projects: any[]): Promise<ModerationProject[]> {
|
||||
const teamIds = [...new Set(projects.map((p) => p.team_id).filter(Boolean))];
|
||||
const orgIds = [...new Set(projects.map((p) => p.organization).filter(Boolean))];
|
||||
const teamIds = [...new Set(projects.map((p) => p.team_id).filter(Boolean))]
|
||||
const orgIds = [...new Set(projects.map((p) => p.organization).filter(Boolean))]
|
||||
|
||||
const [teamsData, orgsData]: [TeamMember[][], Organization[]] = await Promise.all([
|
||||
teamIds.length > 0
|
||||
? fetchSegmented(teamIds, (ids) => `teams?ids=${asEncodedJsonArray(ids)}`)
|
||||
: Promise.resolve([]),
|
||||
orgIds.length > 0
|
||||
? fetchSegmented(orgIds, (ids) => `organizations?ids=${asEncodedJsonArray(ids)}`, {
|
||||
apiVersion: 3,
|
||||
})
|
||||
: Promise.resolve([]),
|
||||
]);
|
||||
const [teamsData, orgsData]: [TeamMember[][], Organization[]] = await Promise.all([
|
||||
teamIds.length > 0
|
||||
? fetchSegmented(teamIds, (ids) => `teams?ids=${asEncodedJsonArray(ids)}`)
|
||||
: Promise.resolve([]),
|
||||
orgIds.length > 0
|
||||
? fetchSegmented(orgIds, (ids) => `organizations?ids=${asEncodedJsonArray(ids)}`, {
|
||||
apiVersion: 3,
|
||||
})
|
||||
: Promise.resolve([]),
|
||||
])
|
||||
|
||||
const cache = useModerationCache();
|
||||
const cache = useModerationCache()
|
||||
|
||||
teamsData.forEach((team) => {
|
||||
if (team.length > 0) cache.teams.value.set(team[0].team_id, team);
|
||||
});
|
||||
teamsData.forEach((team) => {
|
||||
if (team.length > 0) cache.teams.value.set(team[0].team_id, team)
|
||||
})
|
||||
|
||||
orgsData.forEach((org: Organization) => {
|
||||
cache.orgs.value.set(org.id, org);
|
||||
});
|
||||
orgsData.forEach((org: Organization) => {
|
||||
cache.orgs.value.set(org.id, org)
|
||||
})
|
||||
|
||||
return projects.map((project) => {
|
||||
let owner: TeamMember | null = null;
|
||||
let org: Organization | null = null;
|
||||
return projects.map((project) => {
|
||||
let owner: TeamMember | null = null
|
||||
let org: Organization | null = null
|
||||
|
||||
if (project.team_id) {
|
||||
const teamMembers = cache.teams.value.get(project.team_id);
|
||||
if (teamMembers) {
|
||||
owner = teamMembers.find((member) => member.role === "Owner") || null;
|
||||
}
|
||||
}
|
||||
if (project.team_id) {
|
||||
const teamMembers = cache.teams.value.get(project.team_id)
|
||||
if (teamMembers) {
|
||||
owner = teamMembers.find((member) => member.role === 'Owner') || null
|
||||
}
|
||||
}
|
||||
|
||||
if (project.organization) {
|
||||
org = cache.orgs.value.get(project.organization) || null;
|
||||
}
|
||||
if (project.organization) {
|
||||
org = cache.orgs.value.get(project.organization) || null
|
||||
}
|
||||
|
||||
return {
|
||||
project,
|
||||
owner,
|
||||
org,
|
||||
} as ModerationProject;
|
||||
});
|
||||
return {
|
||||
project,
|
||||
owner,
|
||||
org,
|
||||
} as ModerationProject
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,214 +1,214 @@
|
||||
import JSZip from "jszip";
|
||||
import TOML from "@ltd/j-toml";
|
||||
import TOML from '@ltd/j-toml'
|
||||
import JSZip from 'jszip'
|
||||
|
||||
export const createDataPackVersion = async function (
|
||||
project,
|
||||
version,
|
||||
primaryFile,
|
||||
members,
|
||||
allGameVersions,
|
||||
loaders,
|
||||
project,
|
||||
version,
|
||||
primaryFile,
|
||||
members,
|
||||
allGameVersions,
|
||||
loaders,
|
||||
) {
|
||||
// force version to start with number, as required by FML
|
||||
const newVersionNumber = version.version_number.match(/^\d/)
|
||||
? version.version_number
|
||||
: `1-${version.version_number}`;
|
||||
// force version to start with number, as required by FML
|
||||
const newVersionNumber = version.version_number.match(/^\d/)
|
||||
? version.version_number
|
||||
: `1-${version.version_number}`
|
||||
|
||||
const newSlug = `mr_${project.slug.replace("-", "_").replace(/\W/g, "")}`.substring(0, 63);
|
||||
const newSlug = `mr_${project.slug.replace('-', '_').replace(/\W/g, '')}`.substring(0, 63)
|
||||
|
||||
const iconPath = `${project.slug}_pack.png`;
|
||||
const iconPath = `${project.slug}_pack.png`
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
const fabricModJson = {
|
||||
schemaVersion: 1,
|
||||
id: newSlug,
|
||||
version: newVersionNumber,
|
||||
name: project.title,
|
||||
description: project.description,
|
||||
authors: members.map((x) => x.name),
|
||||
contact: {
|
||||
homepage: `${config.public.siteUrl}/${project.project_type}/${project.slug ?? project.id}`,
|
||||
},
|
||||
license: project.license.id,
|
||||
icon: iconPath,
|
||||
environment: "*",
|
||||
depends: {
|
||||
"fabric-resource-loader-v0": "*",
|
||||
},
|
||||
};
|
||||
const fabricModJson = {
|
||||
schemaVersion: 1,
|
||||
id: newSlug,
|
||||
version: newVersionNumber,
|
||||
name: project.title,
|
||||
description: project.description,
|
||||
authors: members.map((x) => x.name),
|
||||
contact: {
|
||||
homepage: `${config.public.siteUrl}/${project.project_type}/${project.slug ?? project.id}`,
|
||||
},
|
||||
license: project.license.id,
|
||||
icon: iconPath,
|
||||
environment: '*',
|
||||
depends: {
|
||||
'fabric-resource-loader-v0': '*',
|
||||
},
|
||||
}
|
||||
|
||||
const quiltModJson = {
|
||||
schema_version: 1,
|
||||
quilt_loader: {
|
||||
group: "com.modrinth",
|
||||
id: newSlug,
|
||||
version: newVersionNumber,
|
||||
metadata: {
|
||||
name: project.title,
|
||||
description: project.description,
|
||||
contributors: members.reduce(
|
||||
(acc, x) => ({
|
||||
...acc,
|
||||
[x.name]: x.role,
|
||||
}),
|
||||
{},
|
||||
),
|
||||
contact: {
|
||||
homepage: `${config.public.siteUrl}/${project.project_type}/${
|
||||
project.slug ?? project.id
|
||||
}`,
|
||||
},
|
||||
icon: iconPath,
|
||||
},
|
||||
intermediate_mappings: "net.fabricmc:intermediary",
|
||||
depends: [
|
||||
{
|
||||
id: "quilt_resource_loader",
|
||||
versions: "*",
|
||||
unless: "fabric-resource-loader-v0",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const quiltModJson = {
|
||||
schema_version: 1,
|
||||
quilt_loader: {
|
||||
group: 'com.modrinth',
|
||||
id: newSlug,
|
||||
version: newVersionNumber,
|
||||
metadata: {
|
||||
name: project.title,
|
||||
description: project.description,
|
||||
contributors: members.reduce(
|
||||
(acc, x) => ({
|
||||
...acc,
|
||||
[x.name]: x.role,
|
||||
}),
|
||||
{},
|
||||
),
|
||||
contact: {
|
||||
homepage: `${config.public.siteUrl}/${project.project_type}/${
|
||||
project.slug ?? project.id
|
||||
}`,
|
||||
},
|
||||
icon: iconPath,
|
||||
},
|
||||
intermediate_mappings: 'net.fabricmc:intermediary',
|
||||
depends: [
|
||||
{
|
||||
id: 'quilt_resource_loader',
|
||||
versions: '*',
|
||||
unless: 'fabric-resource-loader-v0',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
const cutoffIndex = allGameVersions.findIndex((x) => x.version === "1.18.2");
|
||||
const cutoffIndex = allGameVersions.findIndex((x) => x.version === '1.18.2')
|
||||
|
||||
let maximumIndex = Number.MIN_VALUE;
|
||||
for (const val of version.game_versions) {
|
||||
const index = allGameVersions.findIndex((x) => x.version === val);
|
||||
if (index > maximumIndex) {
|
||||
maximumIndex = index;
|
||||
}
|
||||
}
|
||||
let maximumIndex = Number.MIN_VALUE
|
||||
for (const val of version.game_versions) {
|
||||
const index = allGameVersions.findIndex((x) => x.version === val)
|
||||
if (index > maximumIndex) {
|
||||
maximumIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
const newForge = maximumIndex < cutoffIndex;
|
||||
const newForge = maximumIndex < cutoffIndex
|
||||
|
||||
const forgeModsToml = {
|
||||
modLoader: newForge ? "lowcodefml" : "javafml",
|
||||
loaderVersion: newForge ? "[40,)" : "[25,)",
|
||||
license: project.license.id,
|
||||
showAsResourcePack: false,
|
||||
mods: [
|
||||
{
|
||||
modId: newSlug,
|
||||
version: newVersionNumber,
|
||||
displayName: project.title,
|
||||
description: project.description,
|
||||
logoFile: iconPath,
|
||||
updateJSONURL: `${config.public.apiBaseUrl.replace("/v2/", "")}/updates/${
|
||||
project.id
|
||||
}/forge_updates.json`,
|
||||
credits: "Generated by Modrinth",
|
||||
authors: members.map((x) => x.name).join(", "),
|
||||
displayURL: `${config.public.siteUrl}/${project.project_type}/${
|
||||
project.slug ?? project.id
|
||||
}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
const forgeModsToml = {
|
||||
modLoader: newForge ? 'lowcodefml' : 'javafml',
|
||||
loaderVersion: newForge ? '[40,)' : '[25,)',
|
||||
license: project.license.id,
|
||||
showAsResourcePack: false,
|
||||
mods: [
|
||||
{
|
||||
modId: newSlug,
|
||||
version: newVersionNumber,
|
||||
displayName: project.title,
|
||||
description: project.description,
|
||||
logoFile: iconPath,
|
||||
updateJSONURL: `${config.public.apiBaseUrl.replace('/v2/', '')}/updates/${
|
||||
project.id
|
||||
}/forge_updates.json`,
|
||||
credits: 'Generated by Modrinth',
|
||||
authors: members.map((x) => x.name).join(', '),
|
||||
displayURL: `${config.public.siteUrl}/${project.project_type}/${
|
||||
project.slug ?? project.id
|
||||
}`,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
if (project.source_url) {
|
||||
quiltModJson.quilt_loader.metadata.contact.sources = project.source_url;
|
||||
fabricModJson.contact.sources = project.source_url;
|
||||
}
|
||||
if (project.source_url) {
|
||||
quiltModJson.quilt_loader.metadata.contact.sources = project.source_url
|
||||
fabricModJson.contact.sources = project.source_url
|
||||
}
|
||||
|
||||
if (project.issues_url) {
|
||||
quiltModJson.quilt_loader.metadata.contact.issues = project.issues_url;
|
||||
fabricModJson.contact.issues = project.issues_url;
|
||||
forgeModsToml.issueTrackerURL = project.issues_url;
|
||||
}
|
||||
if (project.issues_url) {
|
||||
quiltModJson.quilt_loader.metadata.contact.issues = project.issues_url
|
||||
fabricModJson.contact.issues = project.issues_url
|
||||
forgeModsToml.issueTrackerURL = project.issues_url
|
||||
}
|
||||
|
||||
const neoModsToml = {
|
||||
...forgeModsToml,
|
||||
modLoader: "javafml",
|
||||
loaderVersion: "[1,)",
|
||||
mods: forgeModsToml.mods.map((mod) => ({
|
||||
...mod,
|
||||
updateJSONURL: mod.updateJSONURL + "?neoforge=only",
|
||||
})),
|
||||
};
|
||||
const neoModsToml = {
|
||||
...forgeModsToml,
|
||||
modLoader: 'javafml',
|
||||
loaderVersion: '[1,)',
|
||||
mods: forgeModsToml.mods.map((mod) => ({
|
||||
...mod,
|
||||
updateJSONURL: mod.updateJSONURL + '?neoforge=only',
|
||||
})),
|
||||
}
|
||||
|
||||
const primaryFileData = await (await fetch(primaryFile.url)).blob();
|
||||
const primaryFileData = await (await fetch(primaryFile.url)).blob()
|
||||
|
||||
const primaryZipReader = new JSZip();
|
||||
await primaryZipReader.loadAsync(primaryFileData);
|
||||
const primaryZipReader = new JSZip()
|
||||
await primaryZipReader.loadAsync(primaryFileData)
|
||||
|
||||
if (loaders.includes("fabric")) {
|
||||
primaryZipReader.file("fabric.mod.json", JSON.stringify(fabricModJson));
|
||||
}
|
||||
if (loaders.includes("quilt")) {
|
||||
primaryZipReader.file("quilt.mod.json", JSON.stringify(quiltModJson));
|
||||
}
|
||||
if (loaders.includes("forge")) {
|
||||
primaryZipReader.file("META-INF/mods.toml", TOML.stringify(forgeModsToml, { newline: "\n" })); // eslint-disable-line import/no-named-as-default-member
|
||||
}
|
||||
if (loaders.includes("neoforge")) {
|
||||
primaryZipReader.file(
|
||||
"META-INF/neoforge.mods.toml",
|
||||
TOML.stringify(neoModsToml, { newline: "\n" }), // eslint-disable-line import/no-named-as-default-member
|
||||
);
|
||||
}
|
||||
if (loaders.includes('fabric')) {
|
||||
primaryZipReader.file('fabric.mod.json', JSON.stringify(fabricModJson))
|
||||
}
|
||||
if (loaders.includes('quilt')) {
|
||||
primaryZipReader.file('quilt.mod.json', JSON.stringify(quiltModJson))
|
||||
}
|
||||
if (loaders.includes('forge')) {
|
||||
primaryZipReader.file('META-INF/mods.toml', TOML.stringify(forgeModsToml, { newline: '\n' }))
|
||||
}
|
||||
if (loaders.includes('neoforge')) {
|
||||
primaryZipReader.file(
|
||||
'META-INF/neoforge.mods.toml',
|
||||
TOML.stringify(neoModsToml, { newline: '\n' }),
|
||||
)
|
||||
}
|
||||
|
||||
if (!newForge && loaders.includes("forge")) {
|
||||
const classFile = new Uint8Array(
|
||||
await (
|
||||
await fetch("https://cdn.modrinth.com/wrapper/ModrinthWrapperRestiched.class")
|
||||
).arrayBuffer(),
|
||||
);
|
||||
if (!newForge && loaders.includes('forge')) {
|
||||
const classFile = new Uint8Array(
|
||||
await (
|
||||
await fetch('https://cdn.modrinth.com/wrapper/ModrinthWrapperRestiched.class')
|
||||
).arrayBuffer(),
|
||||
)
|
||||
|
||||
let binary = "";
|
||||
for (let i = 0; i < classFile.byteLength; i++) {
|
||||
binary += String.fromCharCode(classFile[i]);
|
||||
}
|
||||
let binary = ''
|
||||
for (let i = 0; i < classFile.byteLength; i++) {
|
||||
binary += String.fromCharCode(classFile[i])
|
||||
}
|
||||
|
||||
let sanitizedId = project.id;
|
||||
let sanitizedId = project.id
|
||||
|
||||
if (project.id.match(/^(\d+)/g)) {
|
||||
sanitizedId = "_" + sanitizedId;
|
||||
}
|
||||
if (project.id.match(/^(\d+)/g)) {
|
||||
sanitizedId = '_' + sanitizedId
|
||||
}
|
||||
|
||||
sanitizedId = sanitizedId.substring(0, 8);
|
||||
sanitizedId = sanitizedId.substring(0, 8)
|
||||
|
||||
binary = binary
|
||||
.replace(
|
||||
String.fromCharCode(32) + "needs1to1be1changed1modrinth1mod",
|
||||
String.fromCharCode(newSlug.length) + newSlug,
|
||||
)
|
||||
.replace("/wrappera/", `/${sanitizedId}/`);
|
||||
binary = binary
|
||||
.replace(
|
||||
String.fromCharCode(32) + 'needs1to1be1changed1modrinth1mod',
|
||||
String.fromCharCode(newSlug.length) + newSlug,
|
||||
)
|
||||
.replace('/wrappera/', `/${sanitizedId}/`)
|
||||
|
||||
const newArr = [];
|
||||
for (let i = 0; i < binary.length; i++) {
|
||||
newArr.push(binary.charCodeAt(i));
|
||||
}
|
||||
const newArr = []
|
||||
for (let i = 0; i < binary.length; i++) {
|
||||
newArr.push(binary.charCodeAt(i))
|
||||
}
|
||||
|
||||
primaryZipReader.file(
|
||||
`com/modrinth/${sanitizedId}/ModrinthWrapper.class`,
|
||||
new Uint8Array(newArr),
|
||||
);
|
||||
}
|
||||
primaryZipReader.file(
|
||||
`com/modrinth/${sanitizedId}/ModrinthWrapper.class`,
|
||||
new Uint8Array(newArr),
|
||||
)
|
||||
}
|
||||
|
||||
const resourcePack = version.files.find((x) => x.file_type === "required-resource-pack");
|
||||
const resourcePack = version.files.find((x) => x.file_type === 'required-resource-pack')
|
||||
|
||||
const resourcePackData = resourcePack ? await (await fetch(resourcePack.url)).blob() : null;
|
||||
const resourcePackData = resourcePack ? await (await fetch(resourcePack.url)).blob() : null
|
||||
|
||||
if (resourcePackData) {
|
||||
const resourcePackReader = new JSZip();
|
||||
await resourcePackReader.loadAsync(resourcePackData);
|
||||
if (resourcePackData) {
|
||||
const resourcePackReader = new JSZip()
|
||||
await resourcePackReader.loadAsync(resourcePackData)
|
||||
|
||||
for (const [path, file] of Object.entries(resourcePackReader.files)) {
|
||||
if (!primaryZipReader.file(path) && !path.includes(".mcassetsroot")) {
|
||||
primaryZipReader.file(path, await file.async("uint8array"));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const [path, file] of Object.entries(resourcePackReader.files)) {
|
||||
if (!primaryZipReader.file(path) && !path.includes('.mcassetsroot')) {
|
||||
primaryZipReader.file(path, await file.async('uint8array'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (primaryZipReader.file("pack.png")) {
|
||||
primaryZipReader.file(iconPath, await primaryZipReader.file("pack.png").async("uint8array"));
|
||||
}
|
||||
if (primaryZipReader.file('pack.png')) {
|
||||
primaryZipReader.file(iconPath, await primaryZipReader.file('pack.png').async('uint8array'))
|
||||
}
|
||||
|
||||
return await primaryZipReader.generateAsync({
|
||||
type: "blob",
|
||||
mimeType: "application/java-archive",
|
||||
});
|
||||
};
|
||||
return await primaryZipReader.generateAsync({
|
||||
type: 'blob',
|
||||
mimeType: 'application/java-archive',
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,179 +1,179 @@
|
||||
import { injectNotificationManager } from "@modrinth/ui";
|
||||
import type { Organization, Project, Report, User, Version } from "@modrinth/utils";
|
||||
import { injectNotificationManager } from '@modrinth/ui'
|
||||
import type { Organization, Project, Report, User, Version } from '@modrinth/utils'
|
||||
|
||||
type Thread = { id: string };
|
||||
type Thread = { id: string }
|
||||
|
||||
export type PlatformNotificationAction = {
|
||||
title: string;
|
||||
action_route: [string, string];
|
||||
};
|
||||
title: string
|
||||
action_route: [string, string]
|
||||
}
|
||||
|
||||
export type PlatformNotificationBody = {
|
||||
project_id?: string;
|
||||
version_id?: string;
|
||||
report_id?: string;
|
||||
thread_id?: string;
|
||||
invited_by?: string;
|
||||
organization_id?: string;
|
||||
};
|
||||
project_id?: string
|
||||
version_id?: string
|
||||
report_id?: string
|
||||
thread_id?: string
|
||||
invited_by?: string
|
||||
organization_id?: string
|
||||
}
|
||||
|
||||
export type PlatformNotification = {
|
||||
id: string;
|
||||
user_id: string;
|
||||
type: "project_update" | "team_invite" | "status_change" | "moderator_message";
|
||||
title: string;
|
||||
text: string;
|
||||
link: string;
|
||||
read: boolean;
|
||||
created: string;
|
||||
actions: PlatformNotificationAction[];
|
||||
body?: PlatformNotificationBody;
|
||||
extra_data?: Record<string, unknown>;
|
||||
grouped_notifs?: PlatformNotification[];
|
||||
};
|
||||
id: string
|
||||
user_id: string
|
||||
type: 'project_update' | 'team_invite' | 'status_change' | 'moderator_message'
|
||||
title: string
|
||||
text: string
|
||||
link: string
|
||||
read: boolean
|
||||
created: string
|
||||
actions: PlatformNotificationAction[]
|
||||
body?: PlatformNotificationBody
|
||||
extra_data?: Record<string, unknown>
|
||||
grouped_notifs?: PlatformNotification[]
|
||||
}
|
||||
|
||||
async function getBulk<T extends { id: string }>(
|
||||
type: string,
|
||||
ids: string[],
|
||||
apiVersion = 2,
|
||||
type: string,
|
||||
ids: string[],
|
||||
apiVersion = 2,
|
||||
): Promise<T[]> {
|
||||
if (!ids || ids.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const url = `${type}?ids=${encodeURIComponent(JSON.stringify([...new Set(ids)]))}`;
|
||||
try {
|
||||
const res = await useBaseFetch(url, { apiVersion });
|
||||
return Array.isArray(res) ? res : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
if (!ids || ids.length === 0) {
|
||||
return []
|
||||
}
|
||||
const url = `${type}?ids=${encodeURIComponent(JSON.stringify([...new Set(ids)]))}`
|
||||
try {
|
||||
const res = await useBaseFetch(url, { apiVersion })
|
||||
return Array.isArray(res) ? res : []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchExtraNotificationData(
|
||||
notifications: PlatformNotification[],
|
||||
notifications: PlatformNotification[],
|
||||
): Promise<PlatformNotification[]> {
|
||||
const bulk = {
|
||||
projects: [] as string[],
|
||||
reports: [] as string[],
|
||||
threads: [] as string[],
|
||||
users: [] as string[],
|
||||
versions: [] as string[],
|
||||
organizations: [] as string[],
|
||||
};
|
||||
const bulk = {
|
||||
projects: [] as string[],
|
||||
reports: [] as string[],
|
||||
threads: [] as string[],
|
||||
users: [] as string[],
|
||||
versions: [] as string[],
|
||||
organizations: [] as string[],
|
||||
}
|
||||
|
||||
for (const notification of notifications) {
|
||||
if (notification.body) {
|
||||
if (notification.body.project_id) bulk.projects.push(notification.body.project_id);
|
||||
if (notification.body.version_id) bulk.versions.push(notification.body.version_id);
|
||||
if (notification.body.report_id) bulk.reports.push(notification.body.report_id);
|
||||
if (notification.body.thread_id) bulk.threads.push(notification.body.thread_id);
|
||||
if (notification.body.invited_by) bulk.users.push(notification.body.invited_by);
|
||||
if (notification.body.organization_id)
|
||||
bulk.organizations.push(notification.body.organization_id);
|
||||
}
|
||||
}
|
||||
for (const notification of notifications) {
|
||||
if (notification.body) {
|
||||
if (notification.body.project_id) bulk.projects.push(notification.body.project_id)
|
||||
if (notification.body.version_id) bulk.versions.push(notification.body.version_id)
|
||||
if (notification.body.report_id) bulk.reports.push(notification.body.report_id)
|
||||
if (notification.body.thread_id) bulk.threads.push(notification.body.thread_id)
|
||||
if (notification.body.invited_by) bulk.users.push(notification.body.invited_by)
|
||||
if (notification.body.organization_id)
|
||||
bulk.organizations.push(notification.body.organization_id)
|
||||
}
|
||||
}
|
||||
|
||||
const reports = (await getBulk<Report>("reports", bulk.reports)).filter(Boolean);
|
||||
for (const r of reports) {
|
||||
if (!r?.item_type) continue;
|
||||
if (r.item_type === "project") bulk.projects.push(r.item_id);
|
||||
else if (r.item_type === "user") bulk.users.push(r.item_id);
|
||||
else if (r.item_type === "version") bulk.versions.push(r.item_id);
|
||||
}
|
||||
const reports = (await getBulk<Report>('reports', bulk.reports)).filter(Boolean)
|
||||
for (const r of reports) {
|
||||
if (!r?.item_type) continue
|
||||
if (r.item_type === 'project') bulk.projects.push(r.item_id)
|
||||
else if (r.item_type === 'user') bulk.users.push(r.item_id)
|
||||
else if (r.item_type === 'version') bulk.versions.push(r.item_id)
|
||||
}
|
||||
|
||||
const versions = (await getBulk<Version>("versions", bulk.versions)).filter(Boolean);
|
||||
for (const v of versions) bulk.projects.push(v.project_id);
|
||||
const versions = (await getBulk<Version>('versions', bulk.versions)).filter(Boolean)
|
||||
for (const v of versions) bulk.projects.push(v.project_id)
|
||||
|
||||
const [projects, threads, users, organizations] = await Promise.all([
|
||||
getBulk<Project>("projects", bulk.projects),
|
||||
getBulk<Thread>("threads", bulk.threads),
|
||||
getBulk<User>("users", bulk.users),
|
||||
getBulk<Organization>("organizations", bulk.organizations, 3),
|
||||
]);
|
||||
const [projects, threads, users, organizations] = await Promise.all([
|
||||
getBulk<Project>('projects', bulk.projects),
|
||||
getBulk<Thread>('threads', bulk.threads),
|
||||
getBulk<User>('users', bulk.users),
|
||||
getBulk<Organization>('organizations', bulk.organizations, 3),
|
||||
])
|
||||
|
||||
for (const n of notifications) {
|
||||
n.extra_data = {};
|
||||
if (n.body) {
|
||||
if (n.body.project_id)
|
||||
n.extra_data.project = projects.find((x) => x.id === n.body!.project_id);
|
||||
if (n.body.organization_id)
|
||||
n.extra_data.organization = organizations.find((x) => x.id === n.body!.organization_id);
|
||||
if (n.body.report_id) {
|
||||
n.extra_data.report = reports.find((x) => x.id === n.body!.report_id);
|
||||
const t = (n.extra_data.report as Report | undefined)?.item_type;
|
||||
if (t === "project")
|
||||
n.extra_data.project = projects.find(
|
||||
(x) => x.id === (n.extra_data?.report as Report | undefined)?.item_id,
|
||||
);
|
||||
else if (t === "user")
|
||||
n.extra_data.user = users.find(
|
||||
(x) => x.id === (n.extra_data?.report as Report | undefined)?.item_id,
|
||||
);
|
||||
else if (t === "version") {
|
||||
n.extra_data.version = versions.find(
|
||||
(x) => x.id === (n.extra_data?.report as Report | undefined)?.item_id,
|
||||
);
|
||||
n.extra_data.project = projects.find(
|
||||
(x) => x.id === (n.extra_data?.version as Version | undefined)?.project_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (n.body.thread_id) n.extra_data.thread = threads.find((x) => x.id === n.body!.thread_id);
|
||||
if (n.body.invited_by)
|
||||
n.extra_data.invited_by = users.find((x) => x.id === n.body!.invited_by);
|
||||
if (n.body.version_id)
|
||||
n.extra_data.version = versions.find((x) => x.id === n.body!.version_id);
|
||||
}
|
||||
}
|
||||
return notifications;
|
||||
for (const n of notifications) {
|
||||
n.extra_data = {}
|
||||
if (n.body) {
|
||||
if (n.body.project_id)
|
||||
n.extra_data.project = projects.find((x) => x.id === n.body!.project_id)
|
||||
if (n.body.organization_id)
|
||||
n.extra_data.organization = organizations.find((x) => x.id === n.body!.organization_id)
|
||||
if (n.body.report_id) {
|
||||
n.extra_data.report = reports.find((x) => x.id === n.body!.report_id)
|
||||
const t = (n.extra_data.report as Report | undefined)?.item_type
|
||||
if (t === 'project')
|
||||
n.extra_data.project = projects.find(
|
||||
(x) => x.id === (n.extra_data?.report as Report | undefined)?.item_id,
|
||||
)
|
||||
else if (t === 'user')
|
||||
n.extra_data.user = users.find(
|
||||
(x) => x.id === (n.extra_data?.report as Report | undefined)?.item_id,
|
||||
)
|
||||
else if (t === 'version') {
|
||||
n.extra_data.version = versions.find(
|
||||
(x) => x.id === (n.extra_data?.report as Report | undefined)?.item_id,
|
||||
)
|
||||
n.extra_data.project = projects.find(
|
||||
(x) => x.id === (n.extra_data?.version as Version | undefined)?.project_id,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (n.body.thread_id) n.extra_data.thread = threads.find((x) => x.id === n.body!.thread_id)
|
||||
if (n.body.invited_by)
|
||||
n.extra_data.invited_by = users.find((x) => x.id === n.body!.invited_by)
|
||||
if (n.body.version_id)
|
||||
n.extra_data.version = versions.find((x) => x.id === n.body!.version_id)
|
||||
}
|
||||
}
|
||||
return notifications
|
||||
}
|
||||
|
||||
export function groupNotifications(notifications: PlatformNotification[]): PlatformNotification[] {
|
||||
const grouped: PlatformNotification[] = [];
|
||||
for (let i = 0; i < notifications.length; i++) {
|
||||
const current = notifications[i];
|
||||
const next = notifications[i + 1];
|
||||
if (current.body && i < notifications.length - 1 && isSimilar(current, next)) {
|
||||
current.grouped_notifs = [next];
|
||||
let j = i + 2;
|
||||
while (j < notifications.length && isSimilar(current, notifications[j])) {
|
||||
current.grouped_notifs.push(notifications[j]);
|
||||
j++;
|
||||
}
|
||||
grouped.push(current);
|
||||
i = j - 1;
|
||||
} else {
|
||||
grouped.push(current);
|
||||
}
|
||||
}
|
||||
return grouped;
|
||||
const grouped: PlatformNotification[] = []
|
||||
for (let i = 0; i < notifications.length; i++) {
|
||||
const current = notifications[i]
|
||||
const next = notifications[i + 1]
|
||||
if (current.body && i < notifications.length - 1 && isSimilar(current, next)) {
|
||||
current.grouped_notifs = [next]
|
||||
let j = i + 2
|
||||
while (j < notifications.length && isSimilar(current, notifications[j])) {
|
||||
current.grouped_notifs.push(notifications[j])
|
||||
j++
|
||||
}
|
||||
grouped.push(current)
|
||||
i = j - 1
|
||||
} else {
|
||||
grouped.push(current)
|
||||
}
|
||||
}
|
||||
return grouped
|
||||
}
|
||||
|
||||
function isSimilar(a: PlatformNotification, b: PlatformNotification | undefined): boolean {
|
||||
return !!a?.body?.project_id && a.body!.project_id === b?.body?.project_id;
|
||||
return !!a?.body?.project_id && a.body!.project_id === b?.body?.project_id
|
||||
}
|
||||
|
||||
export async function markAsRead(
|
||||
ids: string[],
|
||||
ids: string[],
|
||||
): Promise<(notifications: PlatformNotification[]) => PlatformNotification[]> {
|
||||
try {
|
||||
await useBaseFetch(`notifications?ids=${JSON.stringify([...new Set(ids)])}`, {
|
||||
method: "PATCH",
|
||||
});
|
||||
return (notifications: PlatformNotification[]) => {
|
||||
const newNotifs = notifications ?? [];
|
||||
newNotifs.forEach((n) => {
|
||||
if (ids.includes(n.id)) n.read = true;
|
||||
});
|
||||
return newNotifs;
|
||||
};
|
||||
} catch (err: any) {
|
||||
const { addNotification } = injectNotificationManager();
|
||||
addNotification({
|
||||
title: "Error marking notification as read",
|
||||
text: err?.data?.description ?? err,
|
||||
type: "error",
|
||||
});
|
||||
return () => [];
|
||||
}
|
||||
try {
|
||||
await useBaseFetch(`notifications?ids=${JSON.stringify([...new Set(ids)])}`, {
|
||||
method: 'PATCH',
|
||||
})
|
||||
return (notifications: PlatformNotification[]) => {
|
||||
const newNotifs = notifications ?? []
|
||||
newNotifs.forEach((n) => {
|
||||
if (ids.includes(n.id)) n.read = true
|
||||
})
|
||||
return newNotifs
|
||||
}
|
||||
} catch (err: any) {
|
||||
const { addNotification } = injectNotificationManager()
|
||||
addNotification({
|
||||
title: 'Error marking notification as read',
|
||||
text: err?.data?.description ?? err,
|
||||
type: 'error',
|
||||
})
|
||||
return () => []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,257 +1,257 @@
|
||||
export const getProjectTypeForUrl = (type, categories) => {
|
||||
return getProjectTypeForUrlShorthand(type, categories);
|
||||
};
|
||||
return getProjectTypeForUrlShorthand(type, categories)
|
||||
}
|
||||
|
||||
export const getProjectTypeForUrlShorthand = (type, categories, overrideTags) => {
|
||||
const tags = overrideTags ?? useTags().value;
|
||||
const tags = overrideTags ?? useTags().value
|
||||
|
||||
if (type === "mod") {
|
||||
const isMod = categories.some((category) => {
|
||||
return tags.loaderData.modLoaders.includes(category);
|
||||
});
|
||||
if (type === 'mod') {
|
||||
const isMod = categories.some((category) => {
|
||||
return tags.loaderData.modLoaders.includes(category)
|
||||
})
|
||||
|
||||
const isPlugin = categories.some((category) => {
|
||||
return tags.loaderData.allPluginLoaders.includes(category);
|
||||
});
|
||||
const isPlugin = categories.some((category) => {
|
||||
return tags.loaderData.allPluginLoaders.includes(category)
|
||||
})
|
||||
|
||||
const isDataPack = categories.some((category) => {
|
||||
return tags.loaderData.dataPackLoaders.includes(category);
|
||||
});
|
||||
const isDataPack = categories.some((category) => {
|
||||
return tags.loaderData.dataPackLoaders.includes(category)
|
||||
})
|
||||
|
||||
if (isDataPack) {
|
||||
return "datapack";
|
||||
} else if (isPlugin) {
|
||||
return "plugin";
|
||||
} else if (isMod) {
|
||||
return "mod";
|
||||
} else {
|
||||
return "mod";
|
||||
}
|
||||
} else {
|
||||
return type;
|
||||
}
|
||||
};
|
||||
if (isDataPack) {
|
||||
return 'datapack'
|
||||
} else if (isPlugin) {
|
||||
return 'plugin'
|
||||
} else if (isMod) {
|
||||
return 'mod'
|
||||
} else {
|
||||
return 'mod'
|
||||
}
|
||||
} else {
|
||||
return type
|
||||
}
|
||||
}
|
||||
|
||||
export const getProjectLink = (project) => {
|
||||
return `/${getProjectTypeForUrl(project.project_type, project.loaders)}/${
|
||||
project.slug ? project.slug : project.id
|
||||
}`;
|
||||
};
|
||||
return `/${getProjectTypeForUrl(project.project_type, project.loaders)}/${
|
||||
project.slug ? project.slug : project.id
|
||||
}`
|
||||
}
|
||||
|
||||
export const getVersionLink = (project, version) => {
|
||||
if (version) {
|
||||
return getProjectLink(project) + "/version/" + version.id;
|
||||
} else {
|
||||
return getProjectLink(project);
|
||||
}
|
||||
};
|
||||
if (version) {
|
||||
return getProjectLink(project) + '/version/' + version.id
|
||||
} else {
|
||||
return getProjectLink(project)
|
||||
}
|
||||
}
|
||||
|
||||
export const isApproved = (project) => {
|
||||
return project && APPROVED_PROJECT_STATUSES.includes(project.status);
|
||||
};
|
||||
return project && APPROVED_PROJECT_STATUSES.includes(project.status)
|
||||
}
|
||||
|
||||
export const isListed = (project) => {
|
||||
return project && LISTED_PROJECT_STATUSES.includes(project.status);
|
||||
};
|
||||
return project && LISTED_PROJECT_STATUSES.includes(project.status)
|
||||
}
|
||||
|
||||
export const isUnlisted = (project) => {
|
||||
return project && UNLISTED_PROJECT_STATUSES.includes(project.status);
|
||||
};
|
||||
return project && UNLISTED_PROJECT_STATUSES.includes(project.status)
|
||||
}
|
||||
|
||||
export const isPrivate = (project) => {
|
||||
return project && PRIVATE_PROJECT_STATUSES.includes(project.status);
|
||||
};
|
||||
return project && PRIVATE_PROJECT_STATUSES.includes(project.status)
|
||||
}
|
||||
|
||||
export const isRejected = (project) => {
|
||||
return project && REJECTED_PROJECT_STATUSES.includes(project.status);
|
||||
};
|
||||
return project && REJECTED_PROJECT_STATUSES.includes(project.status)
|
||||
}
|
||||
|
||||
export const isUnderReview = (project) => {
|
||||
return project && UNDER_REVIEW_PROJECT_STATUSES.includes(project.status);
|
||||
};
|
||||
return project && UNDER_REVIEW_PROJECT_STATUSES.includes(project.status)
|
||||
}
|
||||
|
||||
export const isDraft = (project) => {
|
||||
return project && DRAFT_PROJECT_STATUSES.includes(project.status);
|
||||
};
|
||||
return project && DRAFT_PROJECT_STATUSES.includes(project.status)
|
||||
}
|
||||
|
||||
export const APPROVED_PROJECT_STATUSES = ["approved", "archived", "unlisted", "private"];
|
||||
export const LISTED_PROJECT_STATUSES = ["approved", "archived"];
|
||||
export const UNLISTED_PROJECT_STATUSES = ["unlisted", "withheld"];
|
||||
export const PRIVATE_PROJECT_STATUSES = ["private", "rejected", "processing"];
|
||||
export const REJECTED_PROJECT_STATUSES = ["rejected", "withheld"];
|
||||
export const UNDER_REVIEW_PROJECT_STATUSES = ["processing"];
|
||||
export const DRAFT_PROJECT_STATUSES = ["draft"];
|
||||
export const APPROVED_PROJECT_STATUSES = ['approved', 'archived', 'unlisted', 'private']
|
||||
export const LISTED_PROJECT_STATUSES = ['approved', 'archived']
|
||||
export const UNLISTED_PROJECT_STATUSES = ['unlisted', 'withheld']
|
||||
export const PRIVATE_PROJECT_STATUSES = ['private', 'rejected', 'processing']
|
||||
export const REJECTED_PROJECT_STATUSES = ['rejected', 'withheld']
|
||||
export const UNDER_REVIEW_PROJECT_STATUSES = ['processing']
|
||||
export const DRAFT_PROJECT_STATUSES = ['draft']
|
||||
|
||||
export function getVersionsToDisplay(project) {
|
||||
return formatVersionsForDisplay(project.game_versions.slice());
|
||||
return formatVersionsForDisplay(project.game_versions.slice())
|
||||
}
|
||||
|
||||
export function formatVersionsForDisplay(gameVersions, overrideTags) {
|
||||
const tags = overrideTags ?? useTags().value;
|
||||
const tags = overrideTags ?? useTags().value
|
||||
|
||||
const inputVersions = gameVersions.slice();
|
||||
const allVersions = tags.gameVersions.slice();
|
||||
const inputVersions = gameVersions.slice()
|
||||
const allVersions = tags.gameVersions.slice()
|
||||
|
||||
const allSnapshots = allVersions.filter((version) => version.version_type === "snapshot");
|
||||
const allReleases = allVersions.filter((version) => version.version_type === "release");
|
||||
const allLegacy = allVersions.filter(
|
||||
(version) => version.version_type !== "snapshot" && version.version_type !== "release",
|
||||
);
|
||||
const allSnapshots = allVersions.filter((version) => version.version_type === 'snapshot')
|
||||
const allReleases = allVersions.filter((version) => version.version_type === 'release')
|
||||
const allLegacy = allVersions.filter(
|
||||
(version) => version.version_type !== 'snapshot' && version.version_type !== 'release',
|
||||
)
|
||||
|
||||
{
|
||||
const indices = allVersions.reduce((map, gameVersion, index) => {
|
||||
map[gameVersion.version] = index;
|
||||
return map;
|
||||
}, {});
|
||||
inputVersions.sort((a, b) => indices[a] - indices[b]);
|
||||
}
|
||||
{
|
||||
const indices = allVersions.reduce((map, gameVersion, index) => {
|
||||
map[gameVersion.version] = index
|
||||
return map
|
||||
}, {})
|
||||
inputVersions.sort((a, b) => indices[a] - indices[b])
|
||||
}
|
||||
|
||||
const releaseVersions = inputVersions.filter((projVer) =>
|
||||
allReleases.some((gameVer) => gameVer.version === projVer),
|
||||
);
|
||||
const releaseVersions = inputVersions.filter((projVer) =>
|
||||
allReleases.some((gameVer) => gameVer.version === projVer),
|
||||
)
|
||||
|
||||
const latestReleaseVersionDate = Date.parse(
|
||||
allReleases.find((version) => version.version === releaseVersions[0])?.date,
|
||||
);
|
||||
const latestSnapshot = inputVersions.find((projVer) =>
|
||||
allSnapshots.some(
|
||||
(gameVer) =>
|
||||
gameVer.version === projVer &&
|
||||
(!latestReleaseVersionDate || latestReleaseVersionDate < Date.parse(gameVer.date)),
|
||||
),
|
||||
);
|
||||
const latestReleaseVersionDate = Date.parse(
|
||||
allReleases.find((version) => version.version === releaseVersions[0])?.date,
|
||||
)
|
||||
const latestSnapshot = inputVersions.find((projVer) =>
|
||||
allSnapshots.some(
|
||||
(gameVer) =>
|
||||
gameVer.version === projVer &&
|
||||
(!latestReleaseVersionDate || latestReleaseVersionDate < Date.parse(gameVer.date)),
|
||||
),
|
||||
)
|
||||
|
||||
const allReleasesGrouped = groupVersions(
|
||||
allReleases.map((release) => release.version),
|
||||
false,
|
||||
);
|
||||
const projectVersionsGrouped = groupVersions(releaseVersions, true);
|
||||
const allReleasesGrouped = groupVersions(
|
||||
allReleases.map((release) => release.version),
|
||||
false,
|
||||
)
|
||||
const projectVersionsGrouped = groupVersions(releaseVersions, true)
|
||||
|
||||
const releaseVersionsAsRanges = projectVersionsGrouped.map(({ major, minor }) => {
|
||||
if (minor.length === 1) {
|
||||
return formatVersion(major, minor[0]);
|
||||
}
|
||||
const releaseVersionsAsRanges = projectVersionsGrouped.map(({ major, minor }) => {
|
||||
if (minor.length === 1) {
|
||||
return formatVersion(major, minor[0])
|
||||
}
|
||||
|
||||
if (
|
||||
allReleasesGrouped
|
||||
.find((x) => x.major === major)
|
||||
.minor.every((value, index) => value === minor[index])
|
||||
) {
|
||||
return `${major}.x`;
|
||||
}
|
||||
if (
|
||||
allReleasesGrouped
|
||||
.find((x) => x.major === major)
|
||||
.minor.every((value, index) => value === minor[index])
|
||||
) {
|
||||
return `${major}.x`
|
||||
}
|
||||
|
||||
return `${formatVersion(major, minor[0])}–${formatVersion(major, minor[minor.length - 1])}`;
|
||||
});
|
||||
return `${formatVersion(major, minor[0])}–${formatVersion(major, minor[minor.length - 1])}`
|
||||
})
|
||||
|
||||
const legacyVersionsAsRanges = groupConsecutiveIndices(
|
||||
inputVersions.filter((projVer) => allLegacy.some((gameVer) => gameVer.version === projVer)),
|
||||
allLegacy,
|
||||
);
|
||||
const legacyVersionsAsRanges = groupConsecutiveIndices(
|
||||
inputVersions.filter((projVer) => allLegacy.some((gameVer) => gameVer.version === projVer)),
|
||||
allLegacy,
|
||||
)
|
||||
|
||||
let output = [...legacyVersionsAsRanges];
|
||||
let output = [...legacyVersionsAsRanges]
|
||||
|
||||
// show all snapshots if there's no release versions
|
||||
if (releaseVersionsAsRanges.length === 0) {
|
||||
const snapshotVersionsAsRanges = groupConsecutiveIndices(
|
||||
inputVersions.filter((projVer) =>
|
||||
allSnapshots.some((gameVer) => gameVer.version === projVer),
|
||||
),
|
||||
allSnapshots,
|
||||
);
|
||||
output = [...snapshotVersionsAsRanges, ...output];
|
||||
} else {
|
||||
output = [...releaseVersionsAsRanges, ...output];
|
||||
}
|
||||
// show all snapshots if there's no release versions
|
||||
if (releaseVersionsAsRanges.length === 0) {
|
||||
const snapshotVersionsAsRanges = groupConsecutiveIndices(
|
||||
inputVersions.filter((projVer) =>
|
||||
allSnapshots.some((gameVer) => gameVer.version === projVer),
|
||||
),
|
||||
allSnapshots,
|
||||
)
|
||||
output = [...snapshotVersionsAsRanges, ...output]
|
||||
} else {
|
||||
output = [...releaseVersionsAsRanges, ...output]
|
||||
}
|
||||
|
||||
if (latestSnapshot && !output.includes(latestSnapshot)) {
|
||||
output = [latestSnapshot, ...output];
|
||||
}
|
||||
return output;
|
||||
if (latestSnapshot && !output.includes(latestSnapshot)) {
|
||||
output = [latestSnapshot, ...output]
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
const mcVersionRegex = /^([0-9]+.[0-9]+)(.[0-9]+)?$/;
|
||||
const mcVersionRegex = /^([0-9]+.[0-9]+)(.[0-9]+)?$/
|
||||
|
||||
function groupVersions(versions, consecutive = false) {
|
||||
return versions
|
||||
.slice()
|
||||
.reverse()
|
||||
.reduce((ranges, version) => {
|
||||
const matchesVersion = version.match(mcVersionRegex);
|
||||
return versions
|
||||
.slice()
|
||||
.reverse()
|
||||
.reduce((ranges, version) => {
|
||||
const matchesVersion = version.match(mcVersionRegex)
|
||||
|
||||
if (matchesVersion) {
|
||||
const majorVersion = matchesVersion[1];
|
||||
const minorVersion = matchesVersion[2];
|
||||
const minorNumeric = minorVersion ? parseInt(minorVersion.replace(".", "")) : 0;
|
||||
if (matchesVersion) {
|
||||
const majorVersion = matchesVersion[1]
|
||||
const minorVersion = matchesVersion[2]
|
||||
const minorNumeric = minorVersion ? parseInt(minorVersion.replace('.', '')) : 0
|
||||
|
||||
let prevInRange;
|
||||
if (
|
||||
(prevInRange = ranges.find(
|
||||
(x) =>
|
||||
x.major === majorVersion && (!consecutive || x.minor.at(-1) === minorNumeric - 1),
|
||||
))
|
||||
) {
|
||||
prevInRange.minor.push(minorNumeric);
|
||||
return ranges;
|
||||
}
|
||||
let prevInRange
|
||||
if (
|
||||
(prevInRange = ranges.find(
|
||||
(x) =>
|
||||
x.major === majorVersion && (!consecutive || x.minor.at(-1) === minorNumeric - 1),
|
||||
))
|
||||
) {
|
||||
prevInRange.minor.push(minorNumeric)
|
||||
return ranges
|
||||
}
|
||||
|
||||
return [...ranges, { major: majorVersion, minor: [minorNumeric] }];
|
||||
}
|
||||
return [...ranges, { major: majorVersion, minor: [minorNumeric] }]
|
||||
}
|
||||
|
||||
return ranges;
|
||||
}, [])
|
||||
.reverse();
|
||||
return ranges
|
||||
}, [])
|
||||
.reverse()
|
||||
}
|
||||
|
||||
function groupConsecutiveIndices(versions, referenceList) {
|
||||
if (!versions || versions.length === 0) {
|
||||
return [];
|
||||
}
|
||||
if (!versions || versions.length === 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
const referenceMap = new Map();
|
||||
referenceList.forEach((item, index) => {
|
||||
referenceMap.set(item.version, index);
|
||||
});
|
||||
const referenceMap = new Map()
|
||||
referenceList.forEach((item, index) => {
|
||||
referenceMap.set(item.version, index)
|
||||
})
|
||||
|
||||
const sortedList = versions.slice().sort((a, b) => referenceMap.get(a) - referenceMap.get(b));
|
||||
const sortedList = versions.slice().sort((a, b) => referenceMap.get(a) - referenceMap.get(b))
|
||||
|
||||
const ranges = [];
|
||||
let start = sortedList[0];
|
||||
let previous = sortedList[0];
|
||||
const ranges = []
|
||||
let start = sortedList[0]
|
||||
let previous = sortedList[0]
|
||||
|
||||
for (let i = 1; i < sortedList.length; i++) {
|
||||
const current = sortedList[i];
|
||||
if (referenceMap.get(current) !== referenceMap.get(previous) + 1) {
|
||||
ranges.push(validateRange(`${previous}–${start}`));
|
||||
start = current;
|
||||
}
|
||||
previous = current;
|
||||
}
|
||||
for (let i = 1; i < sortedList.length; i++) {
|
||||
const current = sortedList[i]
|
||||
if (referenceMap.get(current) !== referenceMap.get(previous) + 1) {
|
||||
ranges.push(validateRange(`${previous}–${start}`))
|
||||
start = current
|
||||
}
|
||||
previous = current
|
||||
}
|
||||
|
||||
ranges.push(validateRange(`${previous}–${start}`));
|
||||
ranges.push(validateRange(`${previous}–${start}`))
|
||||
|
||||
return ranges;
|
||||
return ranges
|
||||
}
|
||||
|
||||
function validateRange(range) {
|
||||
switch (range) {
|
||||
case "rd-132211–b1.8.1":
|
||||
return "All legacy versions";
|
||||
case "a1.0.4–b1.8.1":
|
||||
return "All alpha and beta versions";
|
||||
case "a1.0.4–a1.2.6":
|
||||
return "All alpha versions";
|
||||
case "b1.0–b1.8.1":
|
||||
return "All beta versions";
|
||||
case "rd-132211–inf20100618":
|
||||
return "All pre-alpha versions";
|
||||
}
|
||||
const splitRange = range.split("–");
|
||||
if (splitRange && splitRange[0] === splitRange[1]) {
|
||||
return splitRange[0];
|
||||
}
|
||||
return range;
|
||||
switch (range) {
|
||||
case 'rd-132211–b1.8.1':
|
||||
return 'All legacy versions'
|
||||
case 'a1.0.4–b1.8.1':
|
||||
return 'All alpha and beta versions'
|
||||
case 'a1.0.4–a1.2.6':
|
||||
return 'All alpha versions'
|
||||
case 'b1.0–b1.8.1':
|
||||
return 'All beta versions'
|
||||
case 'rd-132211–inf20100618':
|
||||
return 'All pre-alpha versions'
|
||||
}
|
||||
const splitRange = range.split('–')
|
||||
if (splitRange && splitRange[0] === splitRange[1]) {
|
||||
return splitRange[0]
|
||||
}
|
||||
return range
|
||||
}
|
||||
|
||||
function formatVersion(major, minor) {
|
||||
return minor === 0 ? major : `${major}.${minor}`;
|
||||
return minor === 0 ? major : `${major}.${minor}`
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
export const acceptTeamInvite = async (teamId) => {
|
||||
await useBaseFetch(`team/${teamId}/join`, {
|
||||
apiVersion: 3,
|
||||
method: "POST",
|
||||
});
|
||||
};
|
||||
await useBaseFetch(`team/${teamId}/join`, {
|
||||
apiVersion: 3,
|
||||
method: 'POST',
|
||||
})
|
||||
}
|
||||
export const removeSelfFromTeam = async (teamId) => {
|
||||
const auth = await useAuth();
|
||||
await removeTeamMember(teamId, auth.value.user.id);
|
||||
};
|
||||
const auth = await useAuth()
|
||||
await removeTeamMember(teamId, auth.value.user.id)
|
||||
}
|
||||
export const removeTeamMember = async (teamId, userId) => {
|
||||
await useBaseFetch(`team/${teamId}/members/${userId}`, {
|
||||
apiVersion: 3,
|
||||
method: "DELETE",
|
||||
});
|
||||
};
|
||||
await useBaseFetch(`team/${teamId}/members/${userId}`, {
|
||||
apiVersion: 3,
|
||||
method: 'DELETE',
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
export function addReportMessage(thread, report) {
|
||||
if (!thread || !report) {
|
||||
return thread;
|
||||
}
|
||||
if (
|
||||
!thread.members.some((user) => {
|
||||
return user.id === report.reporterUser.id;
|
||||
})
|
||||
) {
|
||||
thread.members.push(report.reporterUser);
|
||||
}
|
||||
if (!thread.messages.some((message) => message.id === "original")) {
|
||||
thread.messages.push({
|
||||
id: "original",
|
||||
author_id: report.reporterUser.id,
|
||||
body: {
|
||||
type: "text",
|
||||
body: report.body,
|
||||
private: false,
|
||||
replying_to: null,
|
||||
},
|
||||
created: report.created,
|
||||
});
|
||||
}
|
||||
return thread;
|
||||
if (!thread || !report) {
|
||||
return thread
|
||||
}
|
||||
if (
|
||||
!thread.members.some((user) => {
|
||||
return user.id === report.reporterUser.id
|
||||
})
|
||||
) {
|
||||
thread.members.push(report.reporterUser)
|
||||
}
|
||||
if (!thread.messages.some((message) => message.id === 'original')) {
|
||||
thread.messages.push({
|
||||
id: 'original',
|
||||
author_id: report.reporterUser.id,
|
||||
body: {
|
||||
type: 'text',
|
||||
body: report.body,
|
||||
private: false,
|
||||
replying_to: null,
|
||||
},
|
||||
created: report.created,
|
||||
})
|
||||
}
|
||||
return thread
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export const getUserLink = (user) => {
|
||||
return `/user/${user.username}`;
|
||||
};
|
||||
return `/user/${user.username}`
|
||||
}
|
||||
|
||||
export const isStaff = (user) => {
|
||||
return user && STAFF_ROLES.includes(user.role);
|
||||
};
|
||||
return user && STAFF_ROLES.includes(user.role)
|
||||
}
|
||||
|
||||
export const STAFF_ROLES = ["moderator", "admin"];
|
||||
export const STAFF_ROLES = ['moderator', 'admin']
|
||||
|
||||
Reference in New Issue
Block a user