Skip to content

内容源参考:provider ​

你在 api.register(provider) 里传的对象。只实现 capabilities 声明为 true 的方法。

ts
api.register({
	search, browse, detail, versions, resolveDownload, checkUpdate,
	filters, resolveModpack,
})
方法需要声明说明
searchcapabilities.search搜索
browsecapabilities.browse浏览
detailcapabilities.detail详情页
versionscapabilities.versions版本列表
resolveDownloadcapabilities.resolve_download下载地址
checkUpdatecapabilities.update_check更新检查
filters无需声明侧边栏筛选
resolveModpack无需声明整合包

所有方法都可以是 async。

search(request) ​

ts
search?(request: ContentQuery): Promise<ContentPage>
参数类型
requestContentQuery

返回 ContentPage:{ items: ContentCard[], total: number }。

browse(request) ​

ts
browse?(request: ContentQuery): Promise<ContentPage>

签名同 search,区别是 request.query 为空。

detail(id, contentType) ​

ts
detail?(id: string, contentType: ContentType): Promise<ContentProject>
参数类型说明
idstring你给的项目 id
contentTypeContentType用户从哪个标签页点进来的

返回 ContentProject(ContentCard + body / gallery / license / links / versions)。

versions(id, request) ​

ts
versions?(id: string, request: ContentQuery): Promise<ContentVersion[]>

返回版本数组。

resolveDownload(id, versionId?, fileId?) ​

ts
resolveDownload?(
	id: string,
	versionId?: string,
	fileId?: string,
): Promise<DownloadDescriptor>
参数说明
id项目 id
versionId用户选的版本(没选则 undefined)
fileId用户在 versions() 的 files 里挑的文件 id

返回 DownloadDescriptor:{ url, headers?, fileName?, hash? }。

checkUpdate(items) ​

ts
checkUpdate?(items: UpdateQueryItem[]): Promise<UpdateResult[]>

传入要检查的条目数组,返回结果数组(没更新的条目也要返回 { id })。

filters(contentType) ​

ts
filters?(contentType: ContentType): Promise<SourceFilterGroup[]>

返回侧边栏筛选组。不需要在 capabilities 里声明。

resolveModpack(manifestJson) ​

ts
resolveModpack?(manifestJson: string): Promise<ContentModpackPlan>

启动器下载整合包 zip、解压出 manifest.json 后,把原文交给你,你返回安装计划。不需要在 capabilities 里声明(content_types 里有 modpack 时才会被调用)。

数据结构 ​

ContentQuery ​

字段类型说明
querystring | undefined搜索词,browse 时为空
contentTypeContentType当前标签页
gameVersionstring | undefined用户选的游戏版本
loaderstring | undefined用户选的加载器
sortContentSortrelevance / downloads / follows / newest / updated
pagenumber从 1 开始
limitnumber每页条数
categorystring | undefined源自己的分类 id
filtersRecord<string, unknown> | undefined组 id → 勾选的选项 id 数组

ContentCard ​

字段类型必填
sourceIdstring✅ 填 api.source.id
idstring✅ 你的项目 id
contentTypeContentType✅
namestring✅
summarystring
iconUrlstring
authorstring
downloadsnumber原始值,启动器会乘倍率
followsnumber
publishedAtstringISO 8601
updatedAtstringISO 8601
gameVersionsstring[]
loadersstring[]
tagsstring[]

ContentProject ​

ContentCard 加上:

字段类型
bodystring —— 按 detail_format 渲染
gallery{ url: string; title?: string }[]
licensestring
links{ label: string; url: string }[]
versionsContentVersion[]

ContentVersion ​

字段类型说明
idstring✅ 会传回 resolveDownload
namestring
versionNumberstring表格「版本」列显示的就是它
gameVersionsstring[]
loadersstring[]用启动器的拼写
publishedAtstringISO 8601
downloadsnumber
channelstringrelease / beta / alpha
bodystring更新日志
urlstring该版本在你站点的页面
filesContentFile[]多文件时列出

ContentFile ​

字段类型说明
idstring✅ 会作为 fileId 传回
namestring
sizenumber字节

DownloadDescriptor ​

字段类型必填
urlstring✅ 文件直链
headersRecord<string, string>
fileNamestring不填用 URL 最后一段
hash{ algorithm: 'sha1' | 'sha512'; value: string }

SourceFilterGroup / SourceFilterOption ​

ts
SourceFilterGroup {
	id: string
	header: string // 'categories' / 'features' / 'performance impact' 时合并
	options: SourceFilterOption[]
}

SourceFilterOption {
	id: string // 稳定,会回传
	label?: string // 可翻译
}

ContentModpackPlan / ContentModpackFile ​

ts
ContentModpackPlan {
	gameVersion: string
	loader: 'vanilla' | 'forge' | 'neoforge' | 'fabric' | 'quilt'
	loaderVersion?: string
	files: ContentModpackFile[]
}

ContentModpackFile {
	url: string
	fileName: string
	hashSha1?: string
	folder?: string // 默认 'mods'
}

UpdateQueryItem / UpdateResult ​

ts
UpdateQueryItem {
	id: string
	contentType: ContentType
	currentVersionId?: string
	gameVersion?: string
	loader?: string
	installRule?: Record<string, unknown>
}

UpdateResult {
	id: string
	latestVersionId?: string
	latestVersionName?: string
}

下一篇:manifest 全字段。

Celestial Launcher 基于 Modrinth App 构建,遵循其开源许可。