import type { Labrinth } from '@modrinth/api-client' import { invoke } from '@tauri-apps/api/core' // Converts user profile links from rendered Markdown/any dynamic content into app routes. export function parse_modrinth_user_link(href: string): string | null { try { const url = new URL(href) if (url.hostname !== 'modrinth.com' && url.hostname !== 'www.modrinth.com') return null const segments = url.pathname.split('/').filter(Boolean) if (segments[0]?.toLowerCase() !== 'user' || !segments[1] || segments.length > 3) return null const path = `/user/${encodeURIComponent(decodeURIComponent(segments[1]))}` return segments[2] ? `${path}/${encodeURIComponent(decodeURIComponent(segments[2]))}` : path } catch { return null } } export async function search_user(query: string): Promise { return await invoke('plugin:users|search_user', { query }) } export async function get_user_profile(userId: string): Promise { return await invoke('plugin:users|get_user_profile', { userId }) } export async function get_user_projects(userId: string): Promise { return await invoke('plugin:users|get_user_projects', { userId, }) } export async function get_user_organizations( userId: string, ): Promise { return await invoke( 'plugin:users|get_user_organizations', { userId }, ) } export async function get_user_collections( userId: string, ): Promise { return await invoke('plugin:users|get_user_collections', { userId, }) } export async function patch_user( userId: string, patch: Partial>, ): Promise { await invoke('plugin:users|patch_user', { userId, patch }) }