* Migrate to Nuxt 3 * Update vercel config * remove tsconfig comment * Changelog experiment + working proj pages * Fix package json * Prevent vercel complaining * fix deploy (hopefully) * Tag generator * Switch to yarn * Vercel pls 🙏 * Fix tag generation bug * Make (most) non-logged in pages work * fix base build * Linting + state * Eradicate axios, make most user pages work * Fix checkbox state being set incorrectly * Make most things work * Final stretch * Finish (most) things * Move to update model value * Fix modal text getting blurred from transforms (#964) * Adjust nav-link border radius when focused (#961) * Transition between animation states on TextLogo (#955) * Transition between animation states on TextLogo * Remove unused refs * Fixes from review * Disable tabbing to pagination arrows when disabled (#972) * Make position of the "no results" text on grid/gallery views consistent (fixes #963) (#965) * Fix position of the "no results" text on grid view * fix padding * Remove extra margin on main page, fixes #957 (#959) * Fix layout shift and placeholder line height (#973) * Fix a lot of issues * Fix more nuxt 3 issues * fix not all versions showing up (temp) * inline inter css file * More nuxt 3 fixes * [skip ci] broken- backup changes * Change modpack warnings to blue instead of red (#991) * Fix some hydration issues * Update nuxt * Fix some images not showing * Add pagination to versions page + fix lag * Make changelog page consistent with versions page * sync before merge * Delete old file * Fix actions failing * update branch * Fixes navbar transition animation. (#1012) * Fixes navbar transition animation. * Fixes Y-axis animation. Fixes mobile menu. Removes highlightjs prop. * Changes xss call to renderString. * Fixes renderString call. * Removes unnecessary styling. * Reverts mobile nav change. * Nuxt 3 Lazy Loading Search (#1022) * Uses lazyFetch for results. onSearchChange refreshes. Adds loading circle. * Removes console.log * Preserves old page when paging. * Diagnosing filtering bugs. * Fix single facet filtering * Implements useAuth in settings/account. * tiny ssr fix * Updating nuxt.config checklist. * Implements useAuth in revenue, moneitzation, and dashboard index pages. * Fixes setups. * Eliminates results when path changes. Adds animated logo. * Ensures loading animation renders on search page. --------- Co-authored-by: Jai A <jaiagr+gpg@pm.me> * Fix navigation issues * Square button fix (#1023) * Removes checklist from nuxt.config. * Modifies Nuxt CI to build after linting. * Fixes prettierignore file. * bug fixes * Update whitelist domains * Page improvements, fix CLS * Fix a lot of things * Fix project type redirect * Fix 404 errors * Fix user settings + hydration error * Final fixes * fix(creator-section): border radius on icons not aligning with bg (#1027) Co-authored-by: MagnusHJensen <magnus.holm.jensen@lego.dk> * Improvements to the mobile navbar (#984) * Transition between animation states on TextLogo * Remove unused refs * Fixes from review * Improvements to the mobile nav menu * fix avatar alt text * Nevermind, got confused for a moment * Tab bar, menu layout improvements * Highlight search icon when menu is open * Update layouts/default.vue Co-authored-by: Magnus Jensen <magnushjensen.mail@gmail.com> * Fix some issues * Use caret instead * Run prettier * Add create a project --------- Co-authored-by: Magnus Jensen <magnushjensen.mail@gmail.com> Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com> Co-authored-by: Jai A <jaiagr+gpg@pm.me> * Fix mobile menu issues * More issues * Fix lint --------- Co-authored-by: Kaeden Murphy <kmurphy@kaedenmurphy.dev> Co-authored-by: triphora <emmaffle@modrinth.com> Co-authored-by: Zach Baird <30800863+ZachBaird@users.noreply.github.com> Co-authored-by: stairman06 <36215135+stairman06@users.noreply.github.com> Co-authored-by: Zachary Baird <zdb1994@yahoo.com> Co-authored-by: Magnus Jensen <magnushjensen.mail@gmail.com> Co-authored-by: MagnusHJensen <magnus.holm.jensen@lego.dk>
199 lines
5.6 KiB
JavaScript
199 lines
5.6 KiB
JavaScript
import JSZip from 'jszip'
|
|
import TOML from 'toml'
|
|
|
|
export const createDataPackVersion = async function (
|
|
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}`
|
|
|
|
const targetStartingDigitsRegex = /^(\d+)(\D+)$/g
|
|
const newSlug = `${project.slug
|
|
.replace('-', '_')
|
|
.replace(/\W/g, '')
|
|
.replace(targetStartingDigitsRegex, '$2')
|
|
.replace(/^(\d+)$/g, project.id.replace(targetStartingDigitsRegex, '$2'))
|
|
.substring(0, 63)}_mr`
|
|
|
|
const iconPath = `${project.slug}_pack.png`
|
|
|
|
const fabricModJson = {
|
|
schemaVersion: 1,
|
|
id: newSlug,
|
|
version: newVersionNumber,
|
|
name: project.title,
|
|
description: project.description,
|
|
authors: members.map((x) => x.name),
|
|
contact: {
|
|
homepage: `${process.env.domain}/${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: `${process.env.domain}/${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')
|
|
|
|
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 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: `${getAuthUrl().replace('/v2/', '')}/updates/${
|
|
project.id
|
|
}/forge_updates.json`,
|
|
credits: 'Generated by Modrinth',
|
|
authors: members.map((x) => x.name).join(', '),
|
|
displayURL: `${process.env.domain}/${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.issues_url) {
|
|
quiltModJson.quilt_loader.metadata.contact.issues = project.issues_url
|
|
fabricModJson.contact.issues = project.issues_url
|
|
forgeModsToml.issueTrackerURL = project.issues_url
|
|
}
|
|
|
|
const primaryFileData = await (await fetch(primaryFile.url)).blob()
|
|
|
|
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))
|
|
}
|
|
|
|
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 sanitizedId = project.id
|
|
|
|
if (project.id.match(/^(\d+)/g)) {
|
|
sanitizedId = '_' + sanitizedId
|
|
}
|
|
|
|
sanitizedId = sanitizedId.substring(0, 8)
|
|
|
|
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))
|
|
}
|
|
|
|
primaryZipReader.file(
|
|
`com/modrinth/${sanitizedId}/ModrinthWrapper.class`,
|
|
new Uint8Array(newArr)
|
|
)
|
|
}
|
|
|
|
const resourcePack = version.files.find((x) => x.file_type === 'required-resource-pack')
|
|
|
|
const resourcePackData = resourcePack ? await (await fetch(resourcePack.url)).blob() : null
|
|
|
|
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'))
|
|
}
|
|
}
|
|
}
|
|
|
|
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',
|
|
})
|
|
}
|