feat: add support for memory storage driver

zio/stable
Daniel Roe 2023-01-16 21:52:50 +00:00
parent 80da856402
commit 2587225b95
1 changed files with 6 additions and 0 deletions

View File

@ -2,6 +2,8 @@
import _fs from 'unstorage/drivers/fs' import _fs from 'unstorage/drivers/fs'
// @ts-expect-error unstorage needs to provide backwards-compatible subpath types // @ts-expect-error unstorage needs to provide backwards-compatible subpath types
import _kv from 'unstorage/drivers/cloudflare-kv-http' import _kv from 'unstorage/drivers/cloudflare-kv-http'
// @ts-expect-error unstorage needs to provide backwards-compatible subpath types
import _memory from 'unstorage/drivers/memory'
import { stringifyQuery } from 'ufo' import { stringifyQuery } from 'ufo'
@ -17,6 +19,7 @@ const config = useRuntimeConfig()
const fs = _fs as typeof import('unstorage/dist/drivers/fs')['default'] const fs = _fs as typeof import('unstorage/dist/drivers/fs')['default']
const kv = _kv as typeof import('unstorage/dist/drivers/cloudflare-kv-http')['default'] const kv = _kv as typeof import('unstorage/dist/drivers/cloudflare-kv-http')['default']
const memory = _memory as typeof import('unstorage/dist/drivers/memory')['default']
const storage = useStorage() as Storage const storage = useStorage() as Storage
@ -30,6 +33,9 @@ else if (config.storage.driver === 'cloudflare') {
apiToken: config.cloudflare.apiToken, apiToken: config.cloudflare.apiToken,
}))) })))
} }
else if (config.storage.driver === 'memory') {
storage.mount('servers', memory())
}
export function getRedirectURI(origin: string, server: string) { export function getRedirectURI(origin: string, server: string) {
return `${origin}/api/${server}/oauth?${stringifyQuery({ origin })}` return `${origin}/api/${server}/oauth?${stringifyQuery({ origin })}`