mirror of
https://github.com/modrinth/code.git
synced 2026-07-31 21:26:40 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b13f1ad0a |
@@ -1,7 +1,6 @@
|
||||
import { AbstractFeature, type FeatureConfig } from '../core/abstract-feature'
|
||||
import { ModrinthApiError } from '../core/errors'
|
||||
import type { RequestContext } from '../types/request'
|
||||
import { getNodeBaseUrl } from '../utils/node-url'
|
||||
|
||||
/**
|
||||
* Node authentication credentials
|
||||
@@ -108,7 +107,7 @@ export class NodeAuthFeature extends AbstractFeature {
|
||||
}
|
||||
|
||||
private applyAuth(context: RequestContext, auth: NodeAuth): void {
|
||||
const baseUrl = getNodeBaseUrl(auth.url)
|
||||
const baseUrl = `https://${auth.url.replace(/\/modrinth\/v\d+\/fs\/?$/, '')}`
|
||||
context.url = this.buildUrl(context.path, baseUrl, context.options.version)
|
||||
|
||||
context.options.headers = {
|
||||
|
||||
@@ -50,5 +50,4 @@ export {
|
||||
parseSyncEventData,
|
||||
SseParser,
|
||||
} from './utils/sse'
|
||||
export { getNodeWebSocketUrl } from './utils/node-url'
|
||||
export type { Override, RawDecimal } from './utils/types'
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { AbstractModule } from '../../../core/abstract-module'
|
||||
import type { UploadHandle, UploadProgress } from '../../../types/upload'
|
||||
import { getNodeBaseUrl } from '../../../utils/node-url'
|
||||
import type { Archon } from '../../archon/types'
|
||||
import type { Kyros } from '../types'
|
||||
|
||||
@@ -12,7 +11,7 @@ export class KyrosFilesV0Module extends AbstractModule {
|
||||
}
|
||||
|
||||
private getNodeBaseUrl(auth: NodeFsAuth): string {
|
||||
return getNodeBaseUrl(auth.url)
|
||||
return `https://${auth.url.replace(/\/modrinth\/v\d+\/fs\/?$/, '')}`
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,6 @@ import mitt from 'mitt'
|
||||
|
||||
import { AbstractWebSocketClient, type WebSocketConnection } from '../core/abstract-websocket'
|
||||
import type { Archon } from '../modules/archon/types'
|
||||
import { getNodeWebSocketUrl } from '../utils/node-url'
|
||||
|
||||
type WSEventMap = {
|
||||
[K in Archon.Websocket.v0.WSEvent as `${string}:${K['event']}`]: K
|
||||
@@ -20,7 +19,7 @@ export class GenericWebSocketClient extends AbstractWebSocketClient {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
const ws = new WebSocket(getNodeWebSocketUrl(auth.url))
|
||||
const ws = new WebSocket(`wss://${auth.url}`)
|
||||
|
||||
const connection: WebSocketConnection = {
|
||||
serverId,
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
const NODE_FS_PATH_REGEX = /\/modrinth\/v\d+\/fs\/?$/
|
||||
const HTTP_SCHEME_REGEX = /^https?:\/\//i
|
||||
const WS_SCHEME_REGEX = /^wss?:\/\//i
|
||||
const HTTP_SECURE_SCHEME_REGEX = /^https:\/\//i
|
||||
const HTTP_INSECURE_SCHEME_REGEX = /^http:\/\//i
|
||||
|
||||
export function getNodeBaseUrl(url: string): string {
|
||||
const baseUrl = url.replace(NODE_FS_PATH_REGEX, '')
|
||||
return HTTP_SCHEME_REGEX.test(baseUrl) ? baseUrl : `https://${baseUrl}`
|
||||
}
|
||||
|
||||
export function getNodeWebSocketUrl(url: string): string {
|
||||
if (WS_SCHEME_REGEX.test(url)) return url
|
||||
if (HTTP_SECURE_SCHEME_REGEX.test(url)) return url.replace(HTTP_SECURE_SCHEME_REGEX, 'wss://')
|
||||
if (HTTP_INSECURE_SCHEME_REGEX.test(url)) return url.replace(HTTP_INSECURE_SCHEME_REGEX, 'ws://')
|
||||
|
||||
return `wss://${url}`
|
||||
}
|
||||
@@ -344,7 +344,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { Archon, Labrinth } from '@modrinth/api-client'
|
||||
import { getNodeWebSocketUrl, ModrinthApiError } from '@modrinth/api-client'
|
||||
import { ModrinthApiError } from '@modrinth/api-client'
|
||||
import {
|
||||
BoxesIcon,
|
||||
CheckIcon,
|
||||
@@ -1299,7 +1299,7 @@ async function testNodeReachability(): Promise<boolean> {
|
||||
const nodeInstance = serverData.value?.node?.instance
|
||||
if (!nodeInstance) return false
|
||||
|
||||
const wsUrl = getNodeWebSocketUrl(`${nodeInstance}/pingtest`)
|
||||
const wsUrl = `wss://${nodeInstance}/pingtest`
|
||||
|
||||
try {
|
||||
return await new Promise((resolve) => {
|
||||
|
||||
@@ -484,7 +484,7 @@ export function useSearch(
|
||||
}
|
||||
orGroups[field].push(val)
|
||||
} else {
|
||||
parts.push(`${field} = ${enquoteNonBools(val)}`)
|
||||
parts.push(`${field} = ${formatSearchFilterValue(val)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -492,15 +492,15 @@ export function useSearch(
|
||||
for (const [field, values] of Object.entries(orGroups)) {
|
||||
if (values.length === 1) {
|
||||
const val = values[0]
|
||||
parts.push(`${field} = ${enquoteNonBools(val)}`)
|
||||
parts.push(`${field} = ${formatSearchFilterValue(val)}`)
|
||||
} else {
|
||||
const quoted = values.map(enquoteNonBools).join(', ')
|
||||
const quoted = values.map(formatSearchFilterValue).join(', ')
|
||||
parts.push(`${field} IN [${quoted}]`)
|
||||
}
|
||||
}
|
||||
|
||||
for (const [field, values] of Object.entries(negativeByType)) {
|
||||
const quoted = values.map(enquoteNonBools).join(', ')
|
||||
const quoted = values.map(formatSearchFilterValue).join(', ')
|
||||
parts.push(`${field} NOT IN [${quoted}]`)
|
||||
}
|
||||
|
||||
@@ -514,11 +514,11 @@ export function useSearch(
|
||||
for (const envGroup of getEnvironmentFilterGroups(client, server)) {
|
||||
if (envGroup.length === 1) {
|
||||
const [field, val] = envGroup[0].split(':')
|
||||
parts.push(`${field} = ${enquoteNonBools(val)}`)
|
||||
parts.push(`${field} = ${formatSearchFilterValue(val)}`)
|
||||
} else if (envGroup.length > 1) {
|
||||
const conditions = envGroup.map((f) => {
|
||||
const [field, val] = f.split(':')
|
||||
return `${field} = ${enquoteNonBools(val)}`
|
||||
return `${field} = ${formatSearchFilterValue(val)}`
|
||||
})
|
||||
parts.push(`(${conditions.join(' OR ')})`)
|
||||
}
|
||||
@@ -527,9 +527,9 @@ export function useSearch(
|
||||
// Project types
|
||||
const mappedProjectTypes = projectTypes.value.map(mapProjectTypeToSearch)
|
||||
if (mappedProjectTypes.length === 1) {
|
||||
parts.push(`project_types = ${enquoteNonBools(mappedProjectTypes[0])}`)
|
||||
parts.push(`project_types = ${formatSearchFilterValue(mappedProjectTypes[0])}`)
|
||||
} else if (mappedProjectTypes.length > 1) {
|
||||
const quoted = mappedProjectTypes.map(enquoteNonBools).join(', ')
|
||||
const quoted = mappedProjectTypes.map(formatSearchFilterValue).join(', ')
|
||||
parts.push(`project_types IN [${quoted}]`)
|
||||
}
|
||||
|
||||
@@ -792,11 +792,11 @@ function getEnvironmentFilterGroups(client: boolean, server: boolean): string[][
|
||||
return groups
|
||||
}
|
||||
|
||||
function enquoteNonBools(value: string): string {
|
||||
export function formatSearchFilterValue(value: string): string {
|
||||
if (value === 'true' || value === 'false') {
|
||||
return value
|
||||
}
|
||||
return `"${value}"`
|
||||
return `\`${value}\``
|
||||
}
|
||||
|
||||
function getOptionValue(option: FilterOption, negative?: boolean): string {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useRoute } from 'vue-router'
|
||||
|
||||
import { defineMessage, LOCALES, useVIntl } from '../composables/i18n'
|
||||
import type { FilterType, FilterValue, SortType, Tags } from './search'
|
||||
import { formatSearchFilterValue } from './search'
|
||||
import { formatCategory, formatCategoryHeader } from './tag-messages'
|
||||
|
||||
export const SERVER_REGIONS = {
|
||||
@@ -363,11 +364,11 @@ export function useServerSearch(opts: {
|
||||
const included = matched.filter((f) => !f.negative)
|
||||
const excluded = matched.filter((f) => f.negative)
|
||||
if (included.length > 0) {
|
||||
const values = included.map((f) => `"${f.option}"`).join(', ')
|
||||
const values = included.map((f) => formatSearchFilterValue(f.option)).join(', ')
|
||||
parts.push(`${field} IN [${values}]`)
|
||||
}
|
||||
if (excluded.length > 0) {
|
||||
const values = excluded.map((f) => `"${f.option}"`).join(', ')
|
||||
const values = excluded.map((f) => formatSearchFilterValue(f.option)).join(', ')
|
||||
parts.push(`${field} NOT IN [${values}]`)
|
||||
}
|
||||
}
|
||||
@@ -389,11 +390,11 @@ export function useServerSearch(opts: {
|
||||
.map((filter) => filter.projectId)
|
||||
|
||||
if (includedProjectIds.length > 0) {
|
||||
const values = includedProjectIds.map((projectId) => `"${projectId}"`).join(', ')
|
||||
const values = includedProjectIds.map(formatSearchFilterValue).join(', ')
|
||||
parts.push(`project_id IN [${values}]`)
|
||||
}
|
||||
if (excludedProjectIds.length > 0) {
|
||||
const values = excludedProjectIds.map((projectId) => `"${projectId}"`).join(', ')
|
||||
const values = excludedProjectIds.map(formatSearchFilterValue).join(', ')
|
||||
parts.push(`project_id NOT IN [${values}]`)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user