|
| 1 | +import type { ChecksumOptions, DirectoryListing, FileContents, MimeTypeOptions, PublicUrlOptions, StatEntry, TemporaryUrlOptions } from '@flystorage/file-storage' |
| 2 | +import type { StorageDriver } from '@stacksjs/types' |
1 | 3 | import { S3Client } from '@aws-sdk/client-s3'
|
2 | 4 | import { AwsS3StorageAdapter } from '@flystorage/aws-s3'
|
3 | 5 | import { FileStorage } from '@flystorage/file-storage'
|
4 | 6 |
|
5 | 7 | const client = new S3Client()
|
6 | 8 | const adapter = new AwsS3StorageAdapter(client, {
|
7 |
| - bucket: '{your-bucket-name}', |
8 |
| - prefix: '{optional-path-prefix}', |
| 9 | + bucket: 'stacks', |
| 10 | + prefix: 'stx', |
9 | 11 | })
|
10 | 12 |
|
11 | 13 | export const awsStorage: FileStorage = new FileStorage(adapter)
|
| 14 | + |
| 15 | +export const local: StorageDriver = { |
| 16 | + async write(path: string, contents: FileContents): Promise<void> { |
| 17 | + await localStorage.write(path, contents) |
| 18 | + }, |
| 19 | + |
| 20 | + async deleteFile(path: string): Promise<void> { |
| 21 | + await localStorage.deleteFile(path) |
| 22 | + }, |
| 23 | + |
| 24 | + async createDirectory(path: string): Promise<void> { |
| 25 | + await localStorage.createDirectory(path) |
| 26 | + }, |
| 27 | + |
| 28 | + async moveFile(from: string, to: string): Promise<void> { |
| 29 | + await localStorage.moveFile(from, to) |
| 30 | + }, |
| 31 | + |
| 32 | + async copyFile(from: string, to: string): Promise<void> { |
| 33 | + await localStorage.copyFile(from, to) |
| 34 | + }, |
| 35 | + |
| 36 | + async stat(path: string): Promise<StatEntry> { |
| 37 | + return await localStorage.stat(path) |
| 38 | + }, |
| 39 | + |
| 40 | + list(path: string, options: { deep: boolean }): DirectoryListing { |
| 41 | + return localStorage.list(path, options) |
| 42 | + }, |
| 43 | + |
| 44 | + async changeVisibility(path: string, visibility: string): Promise<void> { |
| 45 | + await localStorage.changeVisibility(path, visibility) |
| 46 | + }, |
| 47 | + |
| 48 | + async visibility(path: string): Promise<string> { |
| 49 | + return await localStorage.visibility(path) |
| 50 | + }, |
| 51 | + |
| 52 | + async fileExists(path: string): Promise<boolean> { |
| 53 | + return await localStorage.fileExists(path) |
| 54 | + }, |
| 55 | + |
| 56 | + async directoryExists(path: string): Promise<boolean> { |
| 57 | + return await localStorage.directoryExists(path) |
| 58 | + }, |
| 59 | + |
| 60 | + async publicUrl(path: string, options: PublicUrlOptions): Promise<string> { |
| 61 | + return await localStorage.publicUrl(path, options) |
| 62 | + }, |
| 63 | + |
| 64 | + async temporaryUrl(path: string, options: TemporaryUrlOptions): Promise<string> { |
| 65 | + return await localStorage.temporaryUrl(path, options) |
| 66 | + }, |
| 67 | + |
| 68 | + async checksum(path: string, options: ChecksumOptions): Promise<string> { |
| 69 | + return await localStorage.checksum(path, options) |
| 70 | + }, |
| 71 | + |
| 72 | + async mimeType(path: string, options: MimeTypeOptions): Promise<string> { |
| 73 | + return await localStorage.mimeType(path, options) |
| 74 | + }, |
| 75 | + |
| 76 | + async lastModified(path: string): Promise<number> { |
| 77 | + return await localStorage.lastModified(path) |
| 78 | + }, |
| 79 | + |
| 80 | + async fileSize(path: string): Promise<number> { |
| 81 | + return await localStorage.fileSize(path) |
| 82 | + }, |
| 83 | + |
| 84 | + async read(path: string): Promise<FileContents> { |
| 85 | + const contents = await localStorage.read(path) |
| 86 | + |
| 87 | + return contents |
| 88 | + }, |
| 89 | +} |
0 commit comments