Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@vue-email/components": "^0.0.21",
"@vue-email/render": "^0.0.9",
"@vueuse/core": "^11.1.0",
"@zip.js/zip.js": "^2.8.34",
"ace-builds": "^1.36.2",
"ansi-to-html": "^0.7.2",
"chart.js": "^4.5.1",
Expand Down
29 changes: 28 additions & 1 deletion apps/frontend/src/helpers/infer/infer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ export interface InferredVersionInfo {
game_versions?: string[]
}

async function readMrpackManifest(rawFile: RawFile): Promise<string> {
const { BlobReader, TextWriter, ZipReader } = await import('@zip.js/zip.js')
const reader = new ZipReader(new BlobReader(rawFile))

try {
const entries = await reader.getEntries()
const manifest = entries.find(
(entry) => !entry.directory && entry.filename === 'modrinth.index.json',
)

if (!manifest || manifest.directory) {
throw new Error('Missing modrinth.index.json')
}

return await manifest.getData(new TextWriter())
} finally {
await reader.close()
}
}

/**
* Fills in missing version information from the filename if not already present.
*/
Expand Down Expand Up @@ -56,11 +76,18 @@ export const inferVersionInfo = async function (
const simplifiedGameVersions = gameVersions
.filter((it) => it.version_type === 'release')
.map((it) => it.version)
const loaderParsers = createLoaderParsers(project, gameVersions, simplifiedGameVersions)
const fileName = rawFile.name.toLowerCase()

if (fileName.endsWith('.mrpack') || fileName.endsWith('.mrpack-primary')) {
const manifest = await readMrpackManifest(rawFile)
const result = loaderParsers['modrinth.index.json'](manifest)
return fillMissingFromFilename(result, rawFile.name, project.title)
}

const zipReader = new JSZip()
const zip = await zipReader.loadAsync(rawFile)

const loaderParsers = createLoaderParsers(project, gameVersions, simplifiedGameVersions)
const packParser = createPackParser(project, gameVersions, rawFile)
const multiFileDetectors = createMultiFileDetectors(project, gameVersions, rawFile)

Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading