Skip to content

Commit 9ad8ddb

Browse files
committed
refactor: storateFileApi methods
1 parent 2d1c836 commit 9ad8ddb

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

example/next-storage/components/Account.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function Account({
4343

4444
let { error: uploadError } = await supabase.storage
4545
.from(DEFAULT_AVATARS_BUCKET)
46-
.uploadFile(filePath, file)
46+
.upload(filePath, file)
4747

4848
if (uploadError) {
4949
throw uploadError

example/next-storage/components/Avatar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function Avatar({ url, size }: { url: string | null; size: number
1111

1212
async function downloadImage(path: string) {
1313
try {
14-
const { data, error } = await supabase.storage.from(DEFAULT_AVATARS_BUCKET).downloadFile(path)
14+
const { data, error } = await supabase.storage.from(DEFAULT_AVATARS_BUCKET).download(path)
1515
if (error) {
1616
throw error
1717
}

src/lib/storage/StorageFileApi.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class StorageFileApi {
3333
* @param file The File object to be stored in the bucket.
3434
* @param fileOptions HTTP headers. For example `cacheControl`
3535
*/
36-
async uploadFile(
36+
async upload(
3737
path: string,
3838
file: File,
3939
fileOptions?: FileOptions
@@ -73,7 +73,7 @@ export class StorageFileApi {
7373
* @param file The file object to be stored in the bucket.
7474
* @param fileOptions HTTP headers. For example `cacheControl`
7575
*/
76-
async updateFile(
76+
async update(
7777
path: string,
7878
file: File,
7979
fileOptions?: FileOptions
@@ -112,7 +112,7 @@ export class StorageFileApi {
112112
* @param fromPath The original file path, including the current file name. For example `folder/image.png`.
113113
* @param toPath The new file path, including the new file name. For example `folder/image-copy.png`.
114114
*/
115-
async moveFile(
115+
async move(
116116
fromPath: string,
117117
toPath: string
118118
): Promise<{ data: { message: string } | null; error: Error | null }> {
@@ -158,7 +158,7 @@ export class StorageFileApi {
158158
*
159159
* @param path The file path to be downloaded, including the path and file name. For example `folder/image.png`.
160160
*/
161-
async downloadFile(path: string): Promise<{ data: Blob | null; error: Error | null }> {
161+
async download(path: string): Promise<{ data: Blob | null; error: Error | null }> {
162162
try {
163163
const _path = this._getFinalPath(path)
164164
const res = await get(`${this.url}/object/${_path}`, {
@@ -173,28 +173,11 @@ export class StorageFileApi {
173173
}
174174

175175
/**
176-
* Deletes a file.
177-
*
178-
* @param path The file path to be deleted, including the path and file name. For example `folder/image.png`.
179-
*/
180-
async deleteFile(
181-
path: string
182-
): Promise<{ data: { message: string } | null; error: Error | null }> {
183-
try {
184-
const _path = this._getFinalPath(path)
185-
const data = await remove(`${this.url}/object/${_path}`, {}, { headers: this.headers })
186-
return { data, error: null }
187-
} catch (error) {
188-
return { data: null, error }
189-
}
190-
}
191-
192-
/**
193-
* Deletes multiple files within the same bucket
176+
* Deletes files within the same bucket
194177
*
195178
* @param paths An array of files to be deletes, including the path and file name. For example [`folder/image.png`].
196179
*/
197-
async deleteFiles(paths: string[]): Promise<{ data: FileObject[] | null; error: Error | null }> {
180+
async remove(paths: string[]): Promise<{ data: FileObject[] | null; error: Error | null }> {
198181
try {
199182
const data = await remove(
200183
`${this.url}/object/${this.bucketId}`,
@@ -242,7 +225,7 @@ export class StorageFileApi {
242225
* @param path The folder path.
243226
* @param options Search options, including `limit`, `offset`, and `sortBy`.
244227
*/
245-
async listFiles(
228+
async list(
246229
path?: string,
247230
options?: SearchOptions
248231
): Promise<{ data: FileObject[] | null; error: Error | null }> {

0 commit comments

Comments
 (0)