refactor: less code

This commit is contained in:
Robert Schäfer 2025-05-31 00:53:26 +08:00
parent 9dc5d5068f
commit 602e8a0ffe
2 changed files with 7 additions and 10 deletions

View File

@ -1,4 +1,5 @@
import crypto from 'node:crypto'
import { join as joinPath } from 'node:path/posix'
import type { Context } from '@src/server'
@ -27,16 +28,12 @@ const changeDomain: (opts: { transformations: UrlResolver[] }) => UrlResolver =
return url
}
const transformedUrl = new URL(
chain(...transformations)({ url: originalUrl.href }, _args, context),
)
const publicUrl = new URL(S3_PUBLIC_GATEWAY)
publicUrl.pathname = originalUrl.pathname
let newUrl = publicUrl.href
newUrl = chain(...transformations)({ url: newUrl }, _args, context)
const result = new URL(newUrl)
if (new URL(S3_PUBLIC_GATEWAY).pathname === '/') {
return result.href
}
result.pathname = new URL(S3_PUBLIC_GATEWAY).pathname + result.pathname
return result.href
publicUrl.pathname = joinPath(publicUrl.pathname, transformedUrl.pathname)
return publicUrl.href
}
const sign: UrlResolver = ({ url }, _args, { config: { IMAGOR_SECRET } }) => {

View File

@ -23,7 +23,7 @@ beforeAll(async () => {
await cleanDatabase()
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
const contextUser = async (_req) => authenticatedUser
const contextUser = (_req) => authenticatedUser
const context = getContext({ user: contextUser, database, config: TEST_CONFIG })
const { server } = createServer({ context })
query = createTestClient(server).query