mirror of
https://github.com/modrinth/code.git
synced 2026-08-31 12:05:53 +00:00
Merge branch 'main' into boris/dev-1205-trace-rules
This commit is contained in:
@@ -32,6 +32,7 @@ import { LabrinthCollectionsModule } from './labrinth/collections'
|
||||
import { LabrinthContentV3Module } from './labrinth/content/v3'
|
||||
import { LabrinthExternalProjectsInternalModule } from './labrinth/external-projects/internal'
|
||||
import { LabrinthFriendsV3Module } from './labrinth/friends/v3'
|
||||
import { LabrinthGeoIpModule } from './labrinth/geoip'
|
||||
import { LabrinthGlobalsInternalModule } from './labrinth/globals/internal'
|
||||
import { LabrinthImagesV3Module } from './labrinth/images/v3'
|
||||
import { LabrinthLimitsV3Module } from './labrinth/limits/v3'
|
||||
@@ -111,6 +112,7 @@ export const MODULE_REGISTRY = {
|
||||
labrinth_content_v3: LabrinthContentV3Module,
|
||||
labrinth_external_projects_internal: LabrinthExternalProjectsInternalModule,
|
||||
labrinth_friends_v3: LabrinthFriendsV3Module,
|
||||
labrinth_geoip: LabrinthGeoIpModule,
|
||||
labrinth_globals_internal: LabrinthGlobalsInternalModule,
|
||||
labrinth_images_v3: LabrinthImagesV3Module,
|
||||
labrinth_moderation_internal: LabrinthModerationInternalModule,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { AbstractModule } from '../../core/abstract-module'
|
||||
|
||||
export class LabrinthGeoIpModule extends AbstractModule {
|
||||
public getModuleID(): string {
|
||||
return 'labrinth_geoip'
|
||||
}
|
||||
|
||||
public async getCountry(): Promise<string | undefined> {
|
||||
const trace = await this.client.request<string>('/trace', {
|
||||
api: 'https://api.modrinth.com',
|
||||
version: 'cdn-cgi',
|
||||
method: 'GET',
|
||||
skipAuth: true,
|
||||
})
|
||||
const country = trace
|
||||
.split('\n')
|
||||
.find((line) => line.startsWith('loc='))
|
||||
?.slice(4)
|
||||
.toUpperCase()
|
||||
|
||||
return country?.match(/^[A-Z]{2}$/) ? country : undefined
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ export * from './collections'
|
||||
export * from './content/v3'
|
||||
export * from './external-projects/internal'
|
||||
export * from './friends/v3'
|
||||
export * from './geoip'
|
||||
export * from './globals/internal'
|
||||
export * from './images/v3'
|
||||
export * from './limits/v3'
|
||||
|
||||
@@ -222,4 +222,116 @@ export class LabrinthProjectsV3Module extends AbstractModule {
|
||||
method: 'DELETE',
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a gallery image for a project
|
||||
*
|
||||
* @param id - Project ID or slug
|
||||
* @param file - Image file to upload
|
||||
* @param options - Gallery image options
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* await client.labrinth.projects_v3.createGalleryImage('sodium', imageFile, {
|
||||
* featured: true,
|
||||
* name: 'Screenshot 1',
|
||||
* description: 'Main menu with Sodium enabled'
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
public async createGalleryImage(
|
||||
id: string,
|
||||
file: Blob,
|
||||
options: {
|
||||
ext: string
|
||||
featured: boolean
|
||||
name?: string
|
||||
description?: string
|
||||
ordering?: number
|
||||
},
|
||||
): Promise<void> {
|
||||
const params: Record<string, string> = {
|
||||
ext: options.ext,
|
||||
featured: String(options.featured),
|
||||
}
|
||||
if (options.name) params.name = options.name
|
||||
if (options.description) params.description = options.description
|
||||
if (options.ordering !== undefined) params.ordering = String(options.ordering)
|
||||
|
||||
return this.client.request(`/project/${id}/gallery`, {
|
||||
api: 'labrinth',
|
||||
version: 3,
|
||||
method: 'POST',
|
||||
params,
|
||||
body: file,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a gallery image from a project
|
||||
*
|
||||
* @param id - Project ID or slug
|
||||
* @param url - URL of the gallery image to delete
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* await client.labrinth.projects_v3.deleteGalleryImage('sodium', 'https://cdn.modrinth.com/...')
|
||||
* ```
|
||||
*/
|
||||
public async deleteGalleryImage(id: string, url: string): Promise<void> {
|
||||
return this.client.request(`/project/${id}/gallery`, {
|
||||
api: 'labrinth',
|
||||
version: 3,
|
||||
method: 'DELETE',
|
||||
params: { url },
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content disclosures for a project
|
||||
*
|
||||
* @param id - Project ID or slug
|
||||
* @returns Promise resolving to the project's disclosures
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* const { disclosures } = await client.labrinth.projects_v3.getDisclosures('sodium')
|
||||
* ```
|
||||
*/
|
||||
public async getDisclosures(id: string): Promise<Labrinth.Projects.v3.GetProjectDisclosures> {
|
||||
return this.client.request<Labrinth.Projects.v3.GetProjectDisclosures>(
|
||||
`/project/${id}/disclosures`,
|
||||
{
|
||||
api: 'labrinth',
|
||||
version: 3,
|
||||
method: 'GET',
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify content disclosures for a project
|
||||
*
|
||||
* @param id - Project ID or slug
|
||||
* @param data - Disclosures to set and types to remove
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* await client.labrinth.projects_v3.modifyDisclosures('sodium', {
|
||||
* set: [{ type: 'ai_content', uses: ['text'], note: 'Translations are AI-generated.' }],
|
||||
* remove: ['advertisements'],
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
public async modifyDisclosures(
|
||||
id: string,
|
||||
data: Labrinth.Projects.v3.ModifyProjectDisclosures,
|
||||
): Promise<void> {
|
||||
return this.client.request(`/project/${id}/disclosures`, {
|
||||
api: 'labrinth',
|
||||
version: 3,
|
||||
method: 'PATCH',
|
||||
body: data,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1301,6 +1301,80 @@ export namespace Labrinth {
|
||||
projects: Project[]
|
||||
versions: Labrinth.Versions.v3.Version[]
|
||||
}
|
||||
|
||||
export type TelemetryConsent = 'opt_in' | 'opt_out' | 'always_active'
|
||||
|
||||
export type AiUsage = 'code' | 'assets' | 'text' | 'functionality'
|
||||
|
||||
export type DisclosureLockStatus = 'unlocked' | 'cannot_disable' | 'fully_locked'
|
||||
|
||||
export type DerivativeSource = {
|
||||
label: string
|
||||
link?: string | null
|
||||
note?: string | null
|
||||
}
|
||||
|
||||
export type ProjectDisclosure =
|
||||
| {
|
||||
type: 'ai_content'
|
||||
uses: AiUsage[]
|
||||
note?: string | null
|
||||
}
|
||||
| {
|
||||
type: 'advertisements'
|
||||
note?: string | null
|
||||
}
|
||||
| {
|
||||
type: 'epilepsy_triggers'
|
||||
note?: string | null
|
||||
}
|
||||
| {
|
||||
type: 'system_interactions'
|
||||
interactions: string[]
|
||||
note?: string | null
|
||||
}
|
||||
| {
|
||||
type: 'telemetry'
|
||||
consent: TelemetryConsent
|
||||
data_collected: string[]
|
||||
}
|
||||
| {
|
||||
type: 'derivative_work'
|
||||
sources: DerivativeSource[]
|
||||
}
|
||||
| {
|
||||
type: 'paid_features'
|
||||
features: string[]
|
||||
}
|
||||
| {
|
||||
type: 'archived'
|
||||
note?: string | null
|
||||
}
|
||||
|
||||
export type ProjectDisclosureData = ProjectDisclosure & {
|
||||
set_by_moderator: boolean
|
||||
lock_status: DisclosureLockStatus
|
||||
updated_at: string
|
||||
updated_by?: string | null
|
||||
deleted_at?: string | null
|
||||
}
|
||||
|
||||
export type ProjectDisclosureType = ProjectDisclosure['type']
|
||||
|
||||
export type ProjectDisclosureOf<T extends ProjectDisclosureType> = Extract<
|
||||
ProjectDisclosureData,
|
||||
{ type: T }
|
||||
>
|
||||
|
||||
export type GetProjectDisclosures = {
|
||||
disclosures: ProjectDisclosureData[]
|
||||
}
|
||||
|
||||
export type ModifyProjectDisclosures = {
|
||||
set: ProjectDisclosure[]
|
||||
remove: ProjectDisclosureType[]
|
||||
lock_status?: DisclosureLockStatus | null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user