You've already forked AstralRinth
forked from didirus/AstralRinth
Envs v3 frontend (#4267)
* New envs frontend * lint fix * Add blog post, user-facing changes, dashboard warning, project page member warning, and migration reviewing. maybe some other misc stuff * lint * lint * ignore .data in .prettierignore * i18n as fuck * fix proj page * Improve news markdown rendering * improve phrasing of initial paragraph * Fix environments not reloading after save * index.ts instead of underscored name * shrink-0 back on these icons
This commit is contained in:
41
packages/utils/api/default_impl.ts
Normal file
41
packages/utils/api/default_impl.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { Project, ProjectV3Partial } from '../types'
|
||||
import type { ModrinthApi } from './index'
|
||||
import type { ModrinthApiProjects, ProjectEditBody, ProjectV3EditBodyPartial } from './projects'
|
||||
|
||||
export class RestModrinthApi implements ModrinthApi {
|
||||
projects: ModrinthApiProjects
|
||||
|
||||
constructor(requestApi: (url: string, options?: object) => Promise<Response>) {
|
||||
this.projects = new RestModrinthApiProjects(requestApi)
|
||||
}
|
||||
}
|
||||
|
||||
class RestModrinthApiProjects implements ModrinthApiProjects {
|
||||
constructor(private request: (url: string, options?: object) => Promise<Response>) {}
|
||||
|
||||
async get(id: string): Promise<Project> {
|
||||
const res = await this.request(`/v2/project/${id}`)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
async getV3(id: string): Promise<ProjectV3Partial> {
|
||||
const res = await this.request(`/v3/project/${id}`)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
async edit(id: string, data: ProjectEditBody): Promise<void> {
|
||||
await this.request(`/v2/project/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
|
||||
async editV3(id: string, data: ProjectV3EditBodyPartial): Promise<void> {
|
||||
await this.request(`/v3/project/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
}
|
||||
}
|
||||
7
packages/utils/api/index.ts
Normal file
7
packages/utils/api/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { ModrinthApiProjects } from './projects'
|
||||
|
||||
export interface ModrinthApi {
|
||||
projects: ModrinthApiProjects
|
||||
}
|
||||
|
||||
export { RestModrinthApi } from './default_impl'
|
||||
41
packages/utils/api/projects.ts
Normal file
41
packages/utils/api/projects.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type {
|
||||
DonationLink,
|
||||
DonationPlatform,
|
||||
Environment,
|
||||
EnvironmentMigrationReviewStatus,
|
||||
EnvironmentV3,
|
||||
Project,
|
||||
ProjectStatus,
|
||||
ProjectV3Partial,
|
||||
RequestableStatus,
|
||||
} from '../types'
|
||||
|
||||
export type ProjectEditBody = {
|
||||
slug?: string
|
||||
title?: string
|
||||
description?: string
|
||||
categories?: string[]
|
||||
client_side?: Environment
|
||||
server_side?: Environment
|
||||
status?: ProjectStatus
|
||||
requested_status?: RequestableStatus
|
||||
additional_categories?: string[]
|
||||
issues_url?: string
|
||||
source_url?: string
|
||||
wiki_url?: string
|
||||
discord_url?: string
|
||||
donation_urls?: DonationLink<DonationPlatform>[]
|
||||
license_id?: string
|
||||
license_url?: string
|
||||
}
|
||||
export type ProjectV3EditBodyPartial = {
|
||||
environment?: EnvironmentV3
|
||||
side_types_migration_review_status: EnvironmentMigrationReviewStatus
|
||||
}
|
||||
|
||||
export interface ModrinthApiProjects {
|
||||
get(id: string): Promise<Project>
|
||||
getV3(id: string): Promise<ProjectV3Partial>
|
||||
edit(id: string, data: ProjectEditBody): Promise<void>
|
||||
editV3(id: string, data: ProjectV3EditBodyPartial): Promise<void>
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './api'
|
||||
export * from './billing'
|
||||
export * from './changelog'
|
||||
export * from './highlight'
|
||||
|
||||
@@ -112,13 +112,11 @@ export interface ProjectV3 {
|
||||
color?: number
|
||||
thread_id: ModrinthId
|
||||
monetization_status: MonetizationStatus
|
||||
side_types_migration_review_status: 'reviewed' | 'pending'
|
||||
side_types_migration_review_status: EnvironmentMigrationReviewStatus
|
||||
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
export type SideTypesMigrationReviewStatus = 'reviewed' | 'pending'
|
||||
|
||||
export interface Project {
|
||||
id: ModrinthId
|
||||
project_type: ProjectType
|
||||
@@ -172,6 +170,26 @@ export interface Project {
|
||||
}
|
||||
}
|
||||
|
||||
export type EnvironmentMigrationReviewStatus = 'reviewed' | 'pending'
|
||||
export type EnvironmentV3 =
|
||||
| 'client_and_server'
|
||||
| 'client_only'
|
||||
| 'client_only_server_optional'
|
||||
| 'singleplayer_only'
|
||||
| 'server_only'
|
||||
| 'server_only_client_optional'
|
||||
| 'dedicated_server_only'
|
||||
| 'client_or_server'
|
||||
| 'client_or_server_prefers_both'
|
||||
| 'unknown'
|
||||
|
||||
// This is only the fields we care about from v3, since we use v2 for the vast majority of project metadata.
|
||||
export interface ProjectV3Partial {
|
||||
side_types_migration_review_status: EnvironmentMigrationReviewStatus
|
||||
environment: EnvironmentV3[]
|
||||
project_types: ProjectType[]
|
||||
}
|
||||
|
||||
export interface SearchResult {
|
||||
id: ModrinthId
|
||||
project_type: ProjectType
|
||||
|
||||
Reference in New Issue
Block a user