perf!: allow tree-shaking unstorage drivers (#1516)
* perf: allow tree-shaking unstorage drivers * fix: allow overriding fsBase at runtime * fix: remove `fsBase` export
This commit is contained in:
parent
415d36ce32
commit
fa44fae991
4 changed files with 24 additions and 8 deletions
|
@ -14,29 +14,31 @@ import cached from './cache-driver'
|
|||
|
||||
// @ts-expect-error virtual import
|
||||
import { env } from '#build-info'
|
||||
// @ts-expect-error virtual import
|
||||
import { driver } from '#storage-config'
|
||||
|
||||
import type { AppInfo } from '~/types'
|
||||
import { APP_NAME } from '~/constants'
|
||||
|
||||
const config = useRuntimeConfig()
|
||||
|
||||
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 memory = _memory as typeof import('unstorage/dist/drivers/memory')['default']
|
||||
|
||||
const storage = useStorage() as Storage
|
||||
|
||||
if (config.storage.driver === 'fs') {
|
||||
if (driver === 'fs') {
|
||||
const config = useRuntimeConfig()
|
||||
storage.mount('servers', fs({ base: config.storage.fsBase }))
|
||||
}
|
||||
else if (config.storage.driver === 'cloudflare') {
|
||||
else if (driver === 'cloudflare') {
|
||||
const config = useRuntimeConfig()
|
||||
storage.mount('servers', cached(kv({
|
||||
accountId: config.cloudflare.accountId,
|
||||
namespaceId: config.cloudflare.namespaceId,
|
||||
apiToken: config.cloudflare.apiToken,
|
||||
})))
|
||||
}
|
||||
else if (config.storage.driver === 'memory') {
|
||||
else if (driver === 'memory') {
|
||||
storage.mount('servers', memory())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue