-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storage): add
createSignedURLs
method (#273)
* feat: add createSignedURLs method * Add storage example and storage test
- Loading branch information
Showing
23 changed files
with
543 additions
and
102 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
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,87 @@ | ||
// | ||
// BucketDetailView.swift | ||
// Examples | ||
// | ||
// Created by Guilherme Souza on 21/03/24. | ||
// | ||
|
||
import Supabase | ||
import SwiftUI | ||
|
||
struct BucketDetailView: View { | ||
let bucket: Bucket | ||
|
||
@State private var fileObjects = ActionState<[FileObject], Error>.idle | ||
@State private var presentBucketDetails = false | ||
|
||
var body: some View { | ||
Group { | ||
switch fileObjects { | ||
case .idle: | ||
Color.clear | ||
case .inFlight: | ||
ProgressView() | ||
case let .result(.success(files)): | ||
List { | ||
ForEach(files) { file in | ||
NavigationLink(file.name, value: file) | ||
} | ||
} | ||
case let .result(.failure(error)): | ||
VStack { | ||
ErrorText(error) | ||
Button("Retry") { | ||
Task { await load() } | ||
} | ||
} | ||
} | ||
} | ||
.task { await load() } | ||
.navigationTitle("Objects") | ||
.toolbar { | ||
ToolbarItem(placement: .primaryAction) { | ||
Button { | ||
presentBucketDetails = true | ||
} label: { | ||
Label("Detail", systemImage: "info.circle") | ||
} | ||
} | ||
} | ||
.popover(isPresented: $presentBucketDetails) { | ||
ScrollView { | ||
Text(stringfy(bucket)) | ||
.monospaced() | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.padding() | ||
} | ||
} | ||
.navigationDestination(for: FileObject.self) { | ||
FileObjectDetailView(api: supabase.storage.from(bucket.id), fileObject: $0) | ||
} | ||
} | ||
|
||
@MainActor | ||
private func load() async { | ||
fileObjects = .inFlight | ||
fileObjects = await .result( | ||
Result { | ||
try await supabase.storage.from(bucket.id).list() | ||
} | ||
) | ||
} | ||
} | ||
|
||
#Preview { | ||
BucketDetailView( | ||
bucket: Bucket( | ||
id: UUID().uuidString, | ||
name: "name", | ||
owner: "owner", | ||
isPublic: false, | ||
createdAt: Date(), | ||
updatedAt: Date(), | ||
allowedMimeTypes: nil, | ||
fileSizeLimit: nil | ||
) | ||
) | ||
} |
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,75 @@ | ||
// | ||
// BucketList.swift | ||
// Examples | ||
// | ||
// Created by Guilherme Souza on 21/03/24. | ||
// | ||
|
||
import Supabase | ||
import SwiftUI | ||
|
||
struct BucketList: View { | ||
@State var buckets = ActionState<[Bucket], Error>.idle | ||
|
||
var body: some View { | ||
Group { | ||
switch buckets { | ||
case .idle: | ||
Color.clear | ||
case .inFlight: | ||
ProgressView() | ||
case let .result(.success(buckets)): | ||
List { | ||
ForEach(buckets, id: \.self) { bucket in | ||
NavigationLink(bucket.name, value: bucket) | ||
} | ||
} | ||
.overlay { | ||
if buckets.isEmpty { | ||
Text("No buckets found.") | ||
} | ||
} | ||
case let .result(.failure(error)): | ||
VStack { | ||
ErrorText(error) | ||
Button("Retry") { | ||
Task { | ||
await load() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
.task { | ||
await load() | ||
} | ||
.navigationTitle("Bucket list") | ||
.toolbar { | ||
ToolbarItem(placement: .primaryAction) { | ||
Button("Add") { | ||
Task { | ||
do { | ||
try await supabase.storage.createBucket("bucket-\(UUID().uuidString)") | ||
await load() | ||
} catch {} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@MainActor | ||
private func load() async { | ||
do { | ||
self.buckets = .inFlight | ||
let buckets = try await supabase.storage.listBuckets() | ||
self.buckets = .result(.success(buckets)) | ||
} catch { | ||
buckets = .result(.failure(error)) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
BucketList() | ||
} |
Oops, something went wrong.