-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(katzencore): Checking out Storage Methods
- Loading branch information
maxlkatze
committed
Jul 22, 2024
1 parent
4753880
commit e2eeadf
Showing
6 changed files
with
69 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createStorage, type Storage, type Driver } from 'unstorage' | ||
import type { RuntimeConfig } from 'nuxt/schema' | ||
|
||
interface StorageManagmentDriver extends Storage { | ||
publishContent: (content: string) => Promise<void> | ||
} | ||
|
||
export const useContentStorage = async (runtimeConfig: RuntimeConfig): Promise<StorageManagmentDriver> => { | ||
let driver: Driver | ||
try { | ||
driver = (await import(`unstorage/drivers/${runtimeConfig.storage.type}`))(runtimeConfig.storage.options) | ||
} | ||
catch (e) { | ||
try { | ||
driver = (await import(`unstorage/drivers/${runtimeConfig.storage.type}`)).default(JSON.parse(JSON.stringify(runtimeConfig.storage.options))) | ||
} | ||
catch (e) { | ||
throw new Error(`Driver ${runtimeConfig.storage.type} not found`) | ||
} | ||
} | ||
|
||
const storage = createStorage<object>({ | ||
driver, | ||
}) as StorageManagmentDriver | ||
// Add custom method to publish content | ||
storage.publishContent = async (content) => { | ||
// TODO | ||
console.log('Publishing content', content) | ||
} | ||
return storage | ||
} |