File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { AbstractFeature , type FeatureConfig } from '../core/abstract-feature'
22import { ModrinthApiError } from '../core/errors'
33import type { RequestContext } from '../types/request'
4+ import { getNodeBaseUrl } from '../utils/node-url'
45
56/**
67 * Node authentication credentials
@@ -107,7 +108,7 @@ export class NodeAuthFeature extends AbstractFeature {
107108 }
108109
109110 private applyAuth ( context : RequestContext , auth : NodeAuth ) : void {
110- const baseUrl = `https:// ${ auth . url . replace ( / \/ m o d r i n t h \/ v \d + \/ f s \/ ? $ / , '' ) } `
111+ const baseUrl = getNodeBaseUrl ( auth . url )
111112 context . url = this . buildUrl ( context . path , baseUrl , context . options . version )
112113
113114 context . options . headers = {
Original file line number Diff line number Diff line change 11import { AbstractModule } from '../../../core/abstract-module'
22import type { UploadHandle , UploadProgress } from '../../../types/upload'
3+ import { getNodeBaseUrl } from '../../../utils/node-url'
34import type { Archon } from '../../archon/types'
45import type { Kyros } from '../types'
56
@@ -11,7 +12,7 @@ export class KyrosFilesV0Module extends AbstractModule {
1112 }
1213
1314 private getNodeBaseUrl ( auth : NodeFsAuth ) : string {
14- return `https:// ${ auth . url . replace ( / \/ m o d r i n t h \/ v \d + \/ f s \/ ? $ / , '' ) } `
15+ return getNodeBaseUrl ( auth . url )
1516 }
1617
1718 /**
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import mitt from 'mitt'
22
33import { AbstractWebSocketClient , type WebSocketConnection } from '../core/abstract-websocket'
44import type { Archon } from '../modules/archon/types'
5+ import { getNodeWebSocketUrl } from '../utils/node-url'
56
67type WSEventMap = {
78 [ K in Archon . Websocket . v0 . WSEvent as `${string } :${K [ 'event' ] } `] : K
@@ -19,7 +20,7 @@ export class GenericWebSocketClient extends AbstractWebSocketClient {
1920
2021 return new Promise ( ( resolve , reject ) => {
2122 try {
22- const ws = new WebSocket ( `wss:// ${ auth . url } ` )
23+ const ws = new WebSocket ( getNodeWebSocketUrl ( auth . url ) )
2324
2425 const connection : WebSocketConnection = {
2526 serverId,
Original file line number Diff line number Diff line change 1+ const NODE_FS_PATH_REGEX = / \/ m o d r i n t h \/ v \d + \/ f s \/ ? $ /
2+ const HTTP_SCHEME_REGEX = / ^ h t t p s ? : \/ \/ / i
3+ const WS_SCHEME_REGEX = / ^ w s s ? : \/ \/ / i
4+
5+ export function getNodeBaseUrl ( url : string ) : string {
6+ const baseUrl = url . replace ( NODE_FS_PATH_REGEX , '' )
7+ return HTTP_SCHEME_REGEX . test ( baseUrl ) ? baseUrl : `https://${ baseUrl } `
8+ }
9+
10+ export function getNodeWebSocketUrl ( url : string ) : string {
11+ return WS_SCHEME_REGEX . test ( url ) ? url : `wss://${ url } `
12+ }
You can’t perform that action at this time.
0 commit comments