mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: opt-in testURL encoding
This commit is contained in:
parent
69cd8d71a7
commit
562749d442
1 changed files with 5 additions and 5 deletions
|
|
@ -1,11 +1,11 @@
|
|||
// string template function, take input URL string and add a search param
|
||||
// example: url`http://g.com` => `http://g.com?k1=v1`
|
||||
// example: url`http://g.com` => `http://g.com?k1="json-value"`
|
||||
export function testURL(strings: TemplateStringsArray, ...values: unknown[]) {
|
||||
const raw = strings.reduce((acc, str, i) => acc + str + (values[i] ?? ''), '')
|
||||
const GITAKO_ACCESS_TOKEN = process.env.GITAKO_ACCESS_TOKEN
|
||||
if (!GITAKO_ACCESS_TOKEN) return raw
|
||||
|
||||
const url = new URL(raw, 'http://localhost')
|
||||
url.searchParams.append(
|
||||
'gitako-config-accessToken',
|
||||
JSON.stringify(process.env.GITAKO_ACCESS_TOKEN ?? 'fallback_token'),
|
||||
)
|
||||
url.searchParams.set('gitako-config-accessToken', JSON.stringify(GITAKO_ACCESS_TOKEN))
|
||||
return url.href
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue