@@ -8,28 +8,21 @@ import Foundation
8
8
public class StorageBucketApi : StorageApi , @unchecked Sendable {
9
9
/// Retrieves the details of all Storage buckets within an existing project.
10
10
public func listBuckets( ) async throws -> [ Bucket ] {
11
- let data = try await execute (
12
- HTTPRequest (
13
- url: configuration. url. appendingPathComponent ( " bucket " ) ,
14
- method: . get
15
- )
16
- )
17
-
18
- return try configuration. decoder. decode ( [ Bucket ] . self, from: data)
11
+ try await execute (
12
+ configuration. url. appendingPathComponent ( " bucket " ) ,
13
+ method: . get
14
+ ) . serializingDecodable ( [ Bucket ] . self, decoder: configuration. decoder) . value
19
15
}
20
16
21
17
/// Retrieves the details of an existing Storage bucket.
22
18
/// - Parameters:
23
19
/// - id: The unique identifier of the bucket you would like to retrieve.
24
20
public func getBucket( _ id: String ) async throws -> Bucket {
25
- let data = try await execute (
26
- HTTPRequest (
27
- url: configuration. url. appendingPathComponent ( " bucket/ \( id) " ) ,
28
- method: . get
29
- )
30
- )
31
-
32
- return try configuration. decoder. decode ( Bucket . self, from: data)
21
+ try await execute (
22
+ configuration. url. appendingPathComponent ( " bucket/ \( id) " ) ,
23
+ method: . get
24
+ ) . serializingDecodable ( Bucket . self, decoder: configuration. decoder) . value
25
+
33
26
}
34
27
35
28
struct BucketParameters : Encodable {
@@ -45,67 +38,55 @@ public class StorageBucketApi: StorageApi, @unchecked Sendable {
45
38
/// - id: A unique identifier for the bucket you are creating.
46
39
/// - options: Options for creating the bucket.
47
40
public func createBucket( _ id: String , options: BucketOptions = . init( ) ) async throws {
48
- try await execute (
49
- HTTPRequest (
50
- url: configuration. url. appendingPathComponent ( " bucket " ) ,
51
- method: . post,
52
- body: configuration. encoder. encode (
53
- BucketParameters (
54
- id: id,
55
- name: id,
56
- public: options. public,
57
- fileSizeLimit: options. fileSizeLimit,
58
- allowedMimeTypes: options. allowedMimeTypes
59
- )
60
- )
41
+ _ = try await execute (
42
+ configuration. url. appendingPathComponent ( " bucket " ) ,
43
+ method: . post,
44
+ body: BucketParameters (
45
+ id: id,
46
+ name: id,
47
+ public: options. public,
48
+ fileSizeLimit: options. fileSizeLimit,
49
+ allowedMimeTypes: options. allowedMimeTypes
61
50
)
62
- )
51
+ ) . serializingData ( ) . value
63
52
}
64
53
65
54
/// Updates a Storage bucket.
66
55
/// - Parameters:
67
56
/// - id: A unique identifier for the bucket you are updating.
68
57
/// - options: Options for updating the bucket.
69
58
public func updateBucket( _ id: String , options: BucketOptions ) async throws {
70
- try await execute (
71
- HTTPRequest (
72
- url: configuration. url. appendingPathComponent ( " bucket/ \( id) " ) ,
73
- method: . put,
74
- body: configuration. encoder. encode (
75
- BucketParameters (
76
- id: id,
77
- name: id,
78
- public: options. public,
79
- fileSizeLimit: options. fileSizeLimit,
80
- allowedMimeTypes: options. allowedMimeTypes
81
- )
82
- )
59
+ _ = try await execute (
60
+ configuration. url. appendingPathComponent ( " bucket/ \( id) " ) ,
61
+ method: . put,
62
+ body: BucketParameters (
63
+ id: id,
64
+ name: id,
65
+ public: options. public,
66
+ fileSizeLimit: options. fileSizeLimit,
67
+ allowedMimeTypes: options. allowedMimeTypes
83
68
)
84
- )
69
+ ) . serializingData ( ) . value
85
70
}
86
71
87
72
/// Removes all objects inside a single bucket.
88
73
/// - Parameters:
89
74
/// - id: The unique identifier of the bucket you would like to empty.
90
75
public func emptyBucket( _ id: String ) async throws {
91
- try await execute (
92
- HTTPRequest (
93
- url: configuration. url. appendingPathComponent ( " bucket/ \( id) /empty " ) ,
94
- method: . post
95
- )
96
- )
76
+ _ = try await execute (
77
+ configuration. url. appendingPathComponent ( " bucket/ \( id) /empty " ) ,
78
+ method: . post
79
+ ) . serializingData ( ) . value
97
80
}
98
81
99
82
/// Deletes an existing bucket. A bucket can't be deleted with existing objects inside it.
100
83
/// You must first `empty()` the bucket.
101
84
/// - Parameters:
102
85
/// - id: The unique identifier of the bucket you would like to delete.
103
86
public func deleteBucket( _ id: String ) async throws {
104
- try await execute (
105
- HTTPRequest (
106
- url: configuration. url. appendingPathComponent ( " bucket/ \( id) " ) ,
107
- method: . delete
108
- )
109
- )
87
+ _ = try await execute (
88
+ configuration. url. appendingPathComponent ( " bucket/ \( id) " ) ,
89
+ method: . delete
90
+ ) . serializingData ( ) . value
110
91
}
111
92
}
0 commit comments