Files
modrinth/packages/ui/src/utils/auto-icons.ts
T
e7926083fb feat: new modpack permissions system (#6005)
* Begin external projects moderator database frontend

* add copy link button

* begin project page permissions settings

* MEL database backend routes

* include filename in external files

* wip: when uploading a version file, fetch its overrides as a list

* wip: override license checks

* improve FileHost ref counting

* file host read capability

* scan files when inserting version file

* add dependency sha1 field

* clean up version files

* wip: attributions

* update s3 file host

* attribution scanning basic works

* works

* insert attribution info after resolving

* add routes

* remove dep sha1 stuff

* prepr

* wip: override file sources

* add files_missing_attributions to versions

* return extended version info + attributed at/by

* hook up frontend to backend (mostly)

* expose version date published

* withholding version visibility

* frontend work

* prepr

* use api-client for img upload

* moar frontend

* prepr

* Add schema to attribution resolution and Flame project results

* sqlx prepare

* changes

* remove feature flag, fix optional proof images

* fix schema

* fmt

* fix deletion and file fetch

* prepare

* fix admonition

* update frontend stuff to new schema

* prepr

* attribution on dependencies

* fixes

* sqlx prepare

* fixes

* routes

* fix routes

* Version grandfathering

* prepare

* wip: bulk routes

* pushing what i've got rn

* include link in NoPermission

* change hash insert to bulk route

* query flame even if entry in MEL

* delete file with weird name

* Prioritise putting override files in existing groups even with ExternalLicense

* fix how hex bytes are handled in route

* feat: coolbot moderation changes (#6215)

* Update moderator checklist

* move permissions stage order

* Updated nagContext.versions to v3, added nag for permissions

* Update permissions.vue default messages

* prepr

---------

Co-authored-by: coolbot100s <76798835+coolbot100s@users.noreply.github.com>

* QA

* prepr

* should group by project

* return attribution resolution correctly

* updated by moderator info

* Track what moderator reviewed an attribution moderation status

* default deser FMA field

* new version page

* clean up fetching + add a couple missing features

* qa items

* prepr

* provide moderation package stuff with DI

* format?

* don't redact moderated_at

* move supplementary resources

* Reorganize moderation messages.

* Quick replies for external content permissions.

* prepare

* QA

* allow exempting projects

* Ignore Flame projects which 404

* fix ci

* fix cross project attribution stuff

* Fix permission error

* change what files get cscanned

* add more logging

* QA Jun 22

* fix

* idempotency

* Expose route for rescanning

* update blog link

---------

Co-authored-by: aecsocket <aecsocket@tutanota.com>
Co-authored-by: coolbot100s <76798835+coolbot100s@users.noreply.github.com>
Co-authored-by: aecsocket <43144841+aecsocket@users.noreply.github.com>
2026-06-23 21:27:51 +02:00

178 lines
4.5 KiB
TypeScript

import {
ArchiveIcon,
BoxIcon,
BracesIcon,
CalendarIcon,
CardIcon,
CheckCircleIcon,
CircleAlertIcon,
CurrencyIcon,
DiscordIcon,
FileArchiveIcon,
FileCodeIcon,
FileIcon,
FileImageIcon,
FileTextIcon,
FolderOpenIcon,
GithubIcon,
GlassesIcon,
GlobeIcon,
InfoIcon,
IssuesIcon,
LinkIcon,
LockIcon,
PackageOpenIcon,
PaintbrushIcon,
PayPalIcon,
PlugIcon,
PolygonIcon,
ScaleIcon,
ServerIcon,
UnknownIcon,
UpdatedIcon,
USDCColorIcon,
XCircleIcon,
XIcon,
} from '@modrinth/assets'
import type { ProjectStatus, ProjectType } from '@modrinth/utils'
import type { Component } from 'vue'
import {
FILE_ARCHIVE_EXTENSIONS,
FILE_CODE_EXTENSIONS,
FILE_IMAGE_EXTENSIONS,
FILE_TEXT_EXTENSIONS,
} from './file-extensions'
export const PROJECT_TYPE_ICONS: Record<ProjectType, Component> = {
mod: BoxIcon,
modpack: PackageOpenIcon,
resourcepack: PaintbrushIcon,
shader: GlassesIcon,
plugin: PlugIcon,
datapack: BracesIcon,
project: BoxIcon,
minecraft_java_server: ServerIcon,
}
export const PAYMENT_METHOD_ICONS: Record<string, Component> = {
card: CardIcon,
cashapp: CurrencyIcon,
paypal: PayPalIcon,
}
export const SOCIAL_PLATFORM_ICONS: Record<string, Component> = {
discord: DiscordIcon,
github: GithubIcon,
}
export const SEVERITY_ICONS: Record<string, Component> = {
info: InfoIcon,
warning: IssuesIcon,
error: XCircleIcon,
critical: XCircleIcon,
success: CheckCircleIcon,
moderation: ScaleIcon,
'circle-warning': CircleAlertIcon,
}
export const PROJECT_STATUS_ICONS: Record<ProjectStatus, Component> = {
approved: GlobeIcon,
unlisted: LinkIcon,
withheld: LinkIcon,
private: LockIcon,
scheduled: CalendarIcon,
draft: FileTextIcon,
archived: ArchiveIcon,
rejected: XIcon,
processing: UpdatedIcon,
unknown: UnknownIcon,
}
export const DIRECTORY_ICONS: Record<string, Component> = {
config: FolderOpenIcon,
world: FolderOpenIcon,
resourcepacks: PaintbrushIcon,
_default: FolderOpenIcon,
}
const CURRENCY_CONFIG: Record<string, { icon: Component; color: string }> = {
usdc: { icon: USDCColorIcon, color: 'text-blue' },
}
const BLOCKCHAIN_CONFIG: Record<string, { icon: Component; color: string }> = {
polygon: { icon: PolygonIcon, color: 'text-purple' },
}
export function getProjectTypeIcon(projectType: ProjectType): Component {
return PROJECT_TYPE_ICONS[projectType] ?? BoxIcon
}
export function getPaymentMethodIcon(method: string): Component {
return PAYMENT_METHOD_ICONS[method] ?? UnknownIcon
}
export function getSocialPlatformIcon(platform: string): Component {
return SOCIAL_PLATFORM_ICONS[platform.toLowerCase()] ?? UnknownIcon
}
export function getSeverityIcon(severity: string): Component {
return SEVERITY_ICONS[severity] ?? InfoIcon
}
export function getProjectStatusIcon(status: ProjectStatus): Component {
return PROJECT_STATUS_ICONS[status] ?? UnknownIcon
}
export function getDirectoryIcon(name: string): Component {
return DIRECTORY_ICONS[name.toLowerCase()] ?? DIRECTORY_ICONS._default
}
export function getFileExtensionIcon(extension: string): Component {
const ext: string = extension.toLowerCase()
if ((FILE_CODE_EXTENSIONS as readonly string[]).includes(ext)) {
return FileCodeIcon
}
if ((FILE_TEXT_EXTENSIONS as readonly string[]).includes(ext)) {
return FileTextIcon
}
if ((FILE_IMAGE_EXTENSIONS as readonly string[]).includes(ext)) {
return FileImageIcon
}
if ((FILE_ARCHIVE_EXTENSIONS as readonly string[]).includes(ext)) {
return FileArchiveIcon
}
return FileIcon
}
export function getFileIcon(fileName: string): Component {
const extension = fileName.split('.').pop()?.toLowerCase() || ''
return getFileExtensionIcon(extension)
}
export function getCurrencyIcon(currency: string): Component | null {
const lower = currency.toLowerCase()
const key = Object.keys(CURRENCY_CONFIG).find((k) => lower.includes(k))
return key ? CURRENCY_CONFIG[key].icon : null
}
export function getCurrencyColor(currency: string): string {
const lower = currency.toLowerCase()
const key = Object.keys(CURRENCY_CONFIG).find((k) => lower.includes(k))
return key ? CURRENCY_CONFIG[key].color : 'text-contrast'
}
export function getBlockchainIcon(blockchain: string): Component | null {
const lower = blockchain.toLowerCase()
const key = Object.keys(BLOCKCHAIN_CONFIG).find((k) => lower.includes(k))
return key ? BLOCKCHAIN_CONFIG[key].icon : null
}
export function getBlockchainColor(blockchain: string): string {
const lower = blockchain.toLowerCase()
const key = Object.keys(BLOCKCHAIN_CONFIG).find((k) => lower.includes(k))
return key ? BLOCKCHAIN_CONFIG[key].color : 'text-contrast'
}