Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Storage/Bucket.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Supabase.Storage
{
public class Bucket

Check warning on line 7 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket'

Check warning on line 7 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket'
{
[JsonProperty("id")]
[JsonPropertyName("id")]
public string? Id { get; set; }

Check warning on line 10 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.Id'

Check warning on line 10 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.Id'

[JsonProperty("name")]
[JsonPropertyName("name")]
public string? Name { get; set; }

Check warning on line 13 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.Name'

Check warning on line 13 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.Name'

[JsonProperty("owner")]
[JsonPropertyName("owner")]
public string? Owner { get; set; }

Check warning on line 16 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.Owner'

Check warning on line 16 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.Owner'

[JsonProperty("created_at")]
[JsonPropertyName("created_at")]
public DateTime? CreatedAt { get; set; }

Check warning on line 19 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.CreatedAt'

Check warning on line 19 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.CreatedAt'

[JsonProperty("updated_at")]
[JsonPropertyName("updated_at")]
public DateTime? UpdatedAt { get; set; }

Check warning on line 22 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.UpdatedAt'

Check warning on line 22 in Storage/Bucket.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'Bucket.UpdatedAt'

/// <summary>
/// The visibility of the bucket. Public buckets don't require an authorization token to download objects,
/// but still require a valid token for all other operations. By default, buckets are private.
/// </summary>
[JsonProperty("public")]
[JsonPropertyName("public")]
public bool Public { get; set; }

/// <summary>
/// Specifies the file size limit that this bucket can accept during upload.
///
/// Expects a string value following a format like: '1kb', '50mb', '150kb', etc.
/// </summary>
[JsonProperty("file_size_limit", NullValueHandling = NullValueHandling.Include)]
[JsonPropertyName("file_size_limit")]
public string? FileSizeLimit { get; set; }

/// <summary>
/// Specifies the allowed mime types that this bucket can accept during upload.
///
/// Expects a List of values such as: ['image/jpeg', 'image/png', etc]
/// </summary>
[JsonProperty("allowed_mime_types", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("allowed_mime_types")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string>? AllowedMimes { get; set; }
}
}
9 changes: 5 additions & 4 deletions Storage/BucketUpsertOptions.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Supabase.Storage
{
public class BucketUpsertOptions

Check warning on line 6 in Storage/BucketUpsertOptions.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'BucketUpsertOptions'

Check warning on line 6 in Storage/BucketUpsertOptions.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'BucketUpsertOptions'
{
/// <summary>
/// The visibility of the bucket. Public buckets don't require an authorization token to download objects,
/// but still require a valid token for all other operations. By default, buckets are private.
/// </summary>
[JsonProperty("public")]
[JsonPropertyName("public")]
public bool Public { get; set; } = false;

/// <summary>
/// Specifies the file size limit that this bucket can accept during upload.
///
/// Expects a string value following a format like: '1kb', '50mb', '150kb', etc.
/// </summary>
[JsonProperty("file_size_limit", NullValueHandling = NullValueHandling.Include)]
[JsonPropertyName("file_size_limit")]
public string? FileSizeLimit { get; set; }

/// <summary>
/// Specifies the allowed mime types that this bucket can accept during upload.
///
/// Expects a List of values such as: ['image/jpeg', 'image/png', etc]
/// </summary>
[JsonProperty("allowed_mime_types", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("allowed_mime_types")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<string>? AllowedMimes { get; set; }
}
}
24 changes: 21 additions & 3 deletions Storage/CreateSignedUrlResponse.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Supabase.Storage
{
/// <summary>
/// Represents the response received when creating a signed URL for file access through Supabase Storage.
/// </summary>
public class CreateSignedUrlResponse
{
[JsonProperty("signedURL")]
/// <summary>
/// Represents the signed URL returned as part of a response when requesting access to a file
/// stored in Supabase Storage. This URL can be used to access the file directly with
/// the defined expiration and optional transformations or download options applied.
/// </summary>
[JsonPropertyName("signedURL")]
public string? SignedUrl { get; set; }
}

/// <summary>
/// Represents the extended response received when creating multiple signed URLs
/// for file access through Supabase Storage. In addition to the signed URL, it includes
/// the associated file path.
/// </summary>
public class CreateSignedUrlsResponse: CreateSignedUrlResponse
{
[JsonProperty("path")]
/// <summary>
/// Represents the file path associated with a signed URL in the response.
/// This property indicates the specific file path for which the signed URL
/// was generated, allowing identification of the file within the storage bucket.
/// </summary>
[JsonPropertyName("path")]
public string? Path { get; set; }
}
}
5 changes: 3 additions & 2 deletions Storage/DownloadOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Newtonsoft.Json;

namespace Supabase.Storage
{
/// <summary>
/// Represents options used when downloading files from storage.
/// </summary>
public class DownloadOptions
{
/// <summary>
Expand Down
17 changes: 13 additions & 4 deletions Storage/Extensions/HttpClientProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using BirdMessenger;
using BirdMessenger.Collections;
using BirdMessenger.Delegates;
using BirdMessenger.Infrastructure;
using Newtonsoft.Json;
using Supabase.Storage.Exceptions;

namespace Supabase.Storage.Extensions
Expand Down Expand Up @@ -47,7 +47,10 @@ public static async Task<MemoryStream> DownloadDataAsync(
if (!response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(content);
var errorResponse = JsonSerializer.Deserialize<ErrorResponse>(
content,
Helpers.JsonOptions
);
var e = new SupabaseStorageException(errorResponse?.Message ?? content)
{
Content = content,
Expand Down Expand Up @@ -182,7 +185,10 @@ public static async Task<HttpResponseMessage> UploadAsync(
if (!response.IsSuccessStatusCode)
{
var httpContent = await response.Content.ReadAsStringAsync();
var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(httpContent);
var errorResponse = JsonSerializer.Deserialize<ErrorResponse>(
httpContent,
Helpers.JsonOptions
);
var e = new SupabaseStorageException(errorResponse?.Message ?? httpContent)
{
Content = httpContent,
Expand Down Expand Up @@ -343,7 +349,10 @@ HttpResponseMessage response
)
{
var httpContent = await response.Content.ReadAsStringAsync();
var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(httpContent);
var errorResponse = JsonSerializer.Deserialize<ErrorResponse>(
httpContent,
Helpers.JsonOptions
);
var error = new SupabaseStorageException(errorResponse?.Message ?? httpContent)
{
Content = httpContent,
Expand Down
33 changes: 12 additions & 21 deletions Storage/FileObject.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Supabase.Storage
{
Expand All @@ -10,32 +10,23 @@ public class FileObject
/// Flag representing if this object is a folder, all properties will be null but the name
/// </summary>
public bool IsFolder => !string.IsNullOrEmpty(Name) && Id == null && CreatedAt == null && UpdatedAt == null;

[JsonProperty("name")]
public string? Name { get; set; }

[JsonProperty("bucket_id")]
public string? BucketId { get; set; }
[JsonPropertyName("name")] public string? Name { get; set; }

[JsonProperty("owner")]
public string? Owner { get; set; }
[JsonPropertyName("bucket_id")] public string? BucketId { get; set; }

[JsonProperty("id")]
public string? Id { get; set; }
[JsonPropertyName("owner")] public string? Owner { get; set; }

[JsonProperty("updated_at")]
public DateTime? UpdatedAt { get; set; }
[JsonPropertyName("id")] public string? Id { get; set; }

[JsonProperty("created_at")]
public DateTime? CreatedAt { get; set; }
[JsonPropertyName("updated_at")] public DateTime? UpdatedAt { get; set; }

[JsonProperty("last_accessed_at")]
public DateTime? LastAccessedAt { get; set; }
[JsonPropertyName("created_at")] public DateTime? CreatedAt { get; set; }

[JsonProperty("metadata")]
public Dictionary<string, object> MetaData = new Dictionary<string, object>();
[JsonPropertyName("last_accessed_at")] public DateTime? LastAccessedAt { get; set; }

[JsonProperty("buckets")]
public Bucket? Buckets { get; set; }
[JsonPropertyName("metadata")] public Dictionary<string, object> MetaData = new Dictionary<string, object>();

[JsonPropertyName("buckets")] public Bucket? Buckets { get; set; }
}
}
}
87 changes: 65 additions & 22 deletions Storage/FileObjectV2.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,92 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace Supabase.Storage
{
/// <summary>
/// Represents a file object in Supabase Storage with its associated metadata and properties.
/// This class is used for version 2 of the Storage API.
/// </summary>
public class FileObjectV2
{

[JsonProperty("id")]
/// <summary>
/// The unique identifier of the file.
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }

Check warning on line 18 in Storage/FileObjectV2.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 18 in Storage/FileObjectV2.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'Id' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("version")]

/// <summary>
/// The version of the file.
/// </summary>
[JsonPropertyName("version")]
public string Version { get; set; }

Check warning on line 24 in Storage/FileObjectV2.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'Version' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 24 in Storage/FileObjectV2.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Non-nullable property 'Version' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

[JsonProperty("name")]

/// <summary>
/// The name of the file.
/// </summary>
[JsonPropertyName("name")]
public string? Name { get; set; }

[JsonProperty("bucket_id")]
/// <summary>
/// The identifier of the bucket containing the file.
/// </summary>
[JsonPropertyName("bucket_id")]
public string? BucketId { get; set; }

[JsonProperty("updated_at")]
/// <summary>
/// The timestamp when the file was last updated.
/// </summary>
[JsonPropertyName("updated_at")]
public DateTime? UpdatedAt { get; set; }

[JsonProperty("created_at")]
/// <summary>
/// The timestamp when the file was created.
/// </summary>
[JsonPropertyName("created_at")]
public DateTime? CreatedAt { get; set; }

[JsonProperty("last_accessed_at")]
/// <summary>
/// The timestamp when the file was last accessed.
/// </summary>
[JsonPropertyName("last_accessed_at")]
public DateTime? LastAccessedAt { get; set; }

[JsonProperty("size")]

/// <summary>
/// The size of the file in bytes.
/// </summary>
[JsonPropertyName("size")]
public int? Size { get; set; }

[JsonProperty("cache_control")]

/// <summary>
/// The cache control directives for the file.
/// </summary>
[JsonPropertyName("cache_control")]
public string? CacheControl { get; set; }

[JsonProperty("content_type")]

/// <summary>
/// The MIME type of the file.
/// </summary>
[JsonPropertyName("content_type")]
public string? ContentType { get; set; }

[JsonProperty("etag")]

/// <summary>
/// The ETag of the file for caching purposes.
/// </summary>
[JsonPropertyName("etag")]
public string? Etag { get; set; }

[JsonProperty("last_modified")]

/// <summary>
/// The timestamp when the file was last modified.
/// </summary>
[JsonPropertyName("last_modified")]
public DateTime? LastModified { get; set; }

[JsonProperty("metadata")]

/// <summary>
/// The custom metadata associated with the file.
/// </summary>
[JsonPropertyName("metadata")]
public Dictionary<string, string>? Metadata { get; set; }
}
}
Loading
Loading