mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
27 lines
821 B
TypeScript
27 lines
821 B
TypeScript
import { getDevClientOptions } from './options'
|
|
|
|
const options = getDevClientOptions()
|
|
|
|
export const urlConverter = {
|
|
toDevUrl: (originalUrl: string) => {
|
|
if (!originalUrl) {
|
|
return null
|
|
}
|
|
const devUrlMatch = originalUrl.match(
|
|
new RegExp(`localhost:${options.port}\\/registry\\/components\\/(.+)$`),
|
|
)
|
|
if (devUrlMatch) {
|
|
return originalUrl
|
|
}
|
|
const localhostMatch = originalUrl.match(/localhost:(\d+?)\/components\/(.+)$/)
|
|
if (localhostMatch) {
|
|
return `http://localhost:${options.port}/registry/dist/components/${localhostMatch[2]}`
|
|
}
|
|
const onlineMatch = originalUrl.match(/\/registry\/dist\/components\/(.+)$/)
|
|
if (onlineMatch) {
|
|
return `http://localhost:${options.port}/registry/dist/components/${onlineMatch[1]}`
|
|
}
|
|
return null
|
|
},
|
|
}
|