Re-add `?key=` support, fixes #222

This commit is contained in:
Niek van der Maas 2023-07-10 14:42:57 +02:00
parent e892e1a297
commit 0ce386a209
1 changed files with 8 additions and 1 deletions

View File

@ -1,5 +1,5 @@
<script lang="ts">
import Router, { location, replace } from 'svelte-spa-router'
import Router, { location, replace, querystring } from 'svelte-spa-router'
import { wrap } from 'svelte-spa-router/wrap'
import Navbar from './lib/Navbar.svelte'
@ -11,6 +11,13 @@
import { Modals, closeModal } from 'svelte-modals'
import { dispatchModalEsc, checkModalEsc } from './lib/Util.svelte'
// Check if the API key is passed in as a "key" query parameter - if so, save it
// Example: https://niek.github.io/chatgpt-web/#/?key=sk-...
const urlParams: URLSearchParams = new URLSearchParams($querystring)
if (urlParams.has('key')) {
apiKeyStorage.set(urlParams.get('key') as string)
}
// The definition of the routes with some conditions
const routes = {
'/': Home,