Skip to content

Commit 4760efe

Browse files
chore: wip
1 parent 07ed2b6 commit 4760efe

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed
Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,89 @@
1+
import type { ChecksumOptions, DirectoryListing, FileContents, MimeTypeOptions, PublicUrlOptions, StatEntry, TemporaryUrlOptions } from '@flystorage/file-storage'
2+
import type { StorageDriver } from '@stacksjs/types'
13
import { S3Client } from '@aws-sdk/client-s3'
24
import { AwsS3StorageAdapter } from '@flystorage/aws-s3'
35
import { FileStorage } from '@flystorage/file-storage'
46

57
const client = new S3Client()
68
const adapter = new AwsS3StorageAdapter(client, {
7-
bucket: '{your-bucket-name}',
8-
prefix: '{optional-path-prefix}',
9+
bucket: 'stacks',
10+
prefix: 'stx',
911
})
1012

1113
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+
}

storage/framework/core/types/src/storage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface StorageOptions {
1515
export type StorageConfig = Partial<StorageOptions>
1616

1717
export interface StorageDriver {
18-
list: (path: string, options?: any) => Promise<any>
18+
list: (path: string, options?: any) => DirectoryListing
1919
changeVisibility: (path: string, visibility: string) => Promise<void>
2020
visibility: (path: string) => Promise<string>
2121
fileExists: (path: string) => Promise<boolean>
@@ -27,4 +27,10 @@ export interface StorageDriver {
2727
lastModified: (path: string) => Promise<number>
2828
fileSize: (path: string) => Promise<number>
2929
read: (path: string) => Promise<FileContents>
30+
deleteFile: (path: string) => Promise<void>
31+
copyFile: (from: string, to: string) => Promise<void>
32+
moveFile: (from: string, to: string) => Promise<void>
33+
stat: (path: string) => Promise<StatEntry>
34+
createDirectory: (path: string) => Promise<void>
35+
write: (path: string, contents: FileContents) => Promise<void>
3036
}

0 commit comments

Comments
 (0)