From cb01aac5e4c451a8e7b0798c5c8775ffc689fe59 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Mon, 18 Mar 2024 15:59:54 -0400 Subject: [PATCH 1/2] bump version, update naming so naming is more consistent for all async methods --- GoFileSharp/GoFileSharp/GoFileSharp.csproj | 6 ++-- .../Model/GoFileData/Wrappers/GoFileFile.cs | 20 ++++++------- .../Model/GoFileData/Wrappers/GoFileFolder.cs | 30 +++++++++---------- GoFileSharp/Tests/GoFileTests.cs | 20 ++++++------- README.md | 20 ++++++------- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/GoFileSharp/GoFileSharp/GoFileSharp.csproj b/GoFileSharp/GoFileSharp/GoFileSharp.csproj index f8c2d27..1ecea5f 100644 --- a/GoFileSharp/GoFileSharp/GoFileSharp.csproj +++ b/GoFileSharp/GoFileSharp/GoFileSharp.csproj @@ -10,9 +10,9 @@ https://github.com/waffle-lord/GoFileSharp git gofilesharp gofile - 1.0.3 - 1.0.3 - 1.0.3 + 1.0.4 + 1.0.4 + 1.0.4 README.md gofilesharp_icon.png GPL-3.0-only diff --git a/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs b/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs index b009f52..35f6d1e 100644 --- a/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs +++ b/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs @@ -114,7 +114,7 @@ public async Task> DeleteAsync() /// /// The new name of the file /// Returns true if the name was updated, otherwise false - public async Task SetName(string newName) => + public async Task SetNameAsync(string newName) => await SetOptionAndRefresh(FileContentOption.Name(newName)); /// @@ -122,10 +122,10 @@ public async Task SetName(string newName) => /// /// The options builder to use for link options /// A or null if the link fails to be added - public async Task AddDirectLink(DirectLinkOptionsBuilder? optionsBuilder = null) - => await AddDirectLink(optionsBuilder?.Build()); + public async Task AddDirectLinkAsync(DirectLinkOptionsBuilder? optionsBuilder = null) + => await AddDirectLinkAsync(optionsBuilder?.Build()); - private async Task AddDirectLink(DirectLinkOptions? options = null) + private async Task AddDirectLinkAsync(DirectLinkOptions? options = null) { var response = await _api.AddDirectLink(_options.ApiToken, Id, options); @@ -141,10 +141,10 @@ public async Task SetName(string newName) => /// The direct link to update /// The options builder to use to update the link /// A or null if the link fails to be updated - public async Task UpdateDirectLink(DirectLink directLink, DirectLinkOptionsBuilder optionsBuilder) - => await UpdateDirectLink(directLink.Id, optionsBuilder.Build()); + public async Task UpdateDirectLinkAsync(DirectLink directLink, DirectLinkOptionsBuilder optionsBuilder) + => await UpdateDirectLinkAsync(directLink.Id, optionsBuilder.Build()); - private async Task UpdateDirectLink(string directLinkId, DirectLinkOptions options) + private async Task UpdateDirectLinkAsync(string directLinkId, DirectLinkOptions options) { var response = await _api.UpdateDirectLink(_options.ApiToken, Id, directLinkId, options); @@ -159,10 +159,10 @@ public async Task SetName(string newName) => /// /// The direct link to remove /// Returns true if the link was removed, otherwise false - public async Task RemoveDirectLink(DirectLink directLink) - => await RemoveDirectLink(directLink.Id); + public async Task RemoveDirectLinkAsync(DirectLink directLink) + => await RemoveDirectLinkAsync(directLink.Id); - private async Task RemoveDirectLink(string directLinkId) + private async Task RemoveDirectLinkAsync(string directLinkId) { var response = await _api.RemoveDirectLink(_options.ApiToken, Id, directLinkId); diff --git a/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFolder.cs b/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFolder.cs index 41ab1d5..4f902e3 100644 --- a/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFolder.cs +++ b/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFolder.cs @@ -168,7 +168,7 @@ public async Task CopyIntoAsync(IContent[] content) /// /// the tags to set on this folder /// Returns true is the option was set, otherwise false - public async Task SetTags(List tags) + public async Task SetTagsAsync(List tags) => await SetOptionAndRefresh(FolderContentOption.Tags(tags)); /// @@ -176,7 +176,7 @@ public async Task SetTags(List tags) /// /// /// Returns true is the option was set, otherwise false - public async Task SetPassword(string password) + public async Task SetPasswordAsync(string password) => await SetOptionAndRefresh(FolderContentOption.Password(password)); /// @@ -184,7 +184,7 @@ public async Task SetPassword(string password) /// /// /// Returns true is the option was set, otherwise false - public async Task SetExpire(DateTimeOffset date) + public async Task SetExpireAsync(DateTimeOffset date) => await SetOptionAndRefresh(FolderContentOption.Expire(date)); /// @@ -192,7 +192,7 @@ public async Task SetExpire(DateTimeOffset date) /// /// /// Returns true is the option was set, otherwise false - public async Task SetPublic(bool value) + public async Task SetPublicAsync(bool value) => await SetOptionAndRefresh(FolderContentOption.Public(value)); /// @@ -200,7 +200,7 @@ public async Task SetPublic(bool value) /// /// /// Returns true is the option was set, otherwise false - public async Task SetDescription(string description) + public async Task SetDescriptionAsync(string description) => await SetOptionAndRefresh(FolderContentOption.Description(description)); /// @@ -208,7 +208,7 @@ public async Task SetDescription(string description) /// /// The new name of the folder /// Returns true if the name was updated, otherwise false - public async Task SetName(string newName) + public async Task SetNameAsync(string newName) => await SetOptionAndRefresh(FolderContentOption.Name(newName)); /// @@ -216,10 +216,10 @@ public async Task SetName(string newName) /// /// The options builder to use for link options /// A or null if the link fails to be added - public async Task AddDirectLink(DirectLinkOptionsBuilder? optionsBuilder = null) - => await AddDirectLink(optionsBuilder?.Build()); + public async Task AddDirectLinkAsync(DirectLinkOptionsBuilder? optionsBuilder = null) + => await AddDirectLinkAsync(optionsBuilder?.Build()); - private async Task AddDirectLink(DirectLinkOptions? options = null) + private async Task AddDirectLinkAsync(DirectLinkOptions? options = null) { var response = await _api.AddDirectLink(_options.ApiToken, Id, options); @@ -235,10 +235,10 @@ public async Task SetName(string newName) /// The direct link to update /// The options builder to use to update the link /// A or null if the link fails to be updated - public async Task UpdateDirectLink(DirectLink directLink, DirectLinkOptionsBuilder optionsBuilder) - => await UpdateDirectLink(directLink.Id, optionsBuilder.Build()); + public async Task UpdateDirectLinkAsync(DirectLink directLink, DirectLinkOptionsBuilder optionsBuilder) + => await UpdateDirectLinkAsync(directLink.Id, optionsBuilder.Build()); - private async Task UpdateDirectLink(string directLinkId, DirectLinkOptions options) + private async Task UpdateDirectLinkAsync(string directLinkId, DirectLinkOptions options) { var response = await _api.UpdateDirectLink(_options.ApiToken, Id, directLinkId, options); @@ -253,10 +253,10 @@ public async Task SetName(string newName) /// /// The direct link to remove /// Returns true if the link was removed, otherwise false - public async Task RemoveDirectLink(DirectLink directLink) - => await RemoveDirectLink(directLink.Id); + public async Task RemoveDirectLinkAsync(DirectLink directLink) + => await RemoveDirectLinkAsync(directLink.Id); - private async Task RemoveDirectLink(string directLinkId) + private async Task RemoveDirectLinkAsync(string directLinkId) { var response = await _api.RemoveDirectLink(_options.ApiToken, Id, directLinkId); diff --git a/GoFileSharp/Tests/GoFileTests.cs b/GoFileSharp/Tests/GoFileTests.cs index 31c5022..e9b6b3a 100644 --- a/GoFileSharp/Tests/GoFileTests.cs +++ b/GoFileSharp/Tests/GoFileTests.cs @@ -363,9 +363,9 @@ public async Task SetFileOptions() var fileOptionsFolder = await testFolder.CreateFolderAsync("fileOptions"); var testFile = await fileOptionsFolder.UploadIntoAsync(_testFile); - var link = await testFile.AddDirectLink(); + var link = await testFile.AddDirectLinkAsync(); - Assert.IsTrue(await testFile.SetName(newName)); + Assert.IsTrue(await testFile.SetNameAsync(newName)); Assert.IsTrue(testFile.Name == newName); @@ -389,14 +389,14 @@ public async Task SetFolderOptions() var testFolder = await _goFile.GetFolderAsync(_testFolderId); var folderOptionsFolder = await testFolder.CreateFolderAsync("folderOptions"); - var link = await folderOptionsFolder.AddDirectLink(); + var link = await folderOptionsFolder.AddDirectLinkAsync(); - Assert.IsTrue(await folderOptionsFolder.SetName(newName)); - Assert.IsTrue(await folderOptionsFolder.SetDescription(desc)); - Assert.IsTrue(await folderOptionsFolder.SetTags(tags)); - Assert.IsTrue(await folderOptionsFolder.SetPublic(true)); - Assert.IsTrue(await folderOptionsFolder.SetExpire(expiry)); - Assert.IsTrue(await folderOptionsFolder.SetPassword(pass)); + Assert.IsTrue(await folderOptionsFolder.SetNameAsync(newName)); + Assert.IsTrue(await folderOptionsFolder.SetDescriptionAsync(desc)); + Assert.IsTrue(await folderOptionsFolder.SetTagsAsync(tags)); + Assert.IsTrue(await folderOptionsFolder.SetPublicAsync(true)); + Assert.IsTrue(await folderOptionsFolder.SetExpireAsync(expiry)); + Assert.IsTrue(await folderOptionsFolder.SetPasswordAsync(pass)); Assert.IsTrue(folderOptionsFolder.Name == newName); Assert.IsNotNull(folderOptionsFolder.Description); @@ -476,7 +476,7 @@ public async Task DirectLinkOptions() .AddAllowedSourceIp(IPAddress.Parse("192.168.1.2")); - var link = await linkOptionsFile.AddDirectLink(optionsBuilder); + var link = await linkOptionsFile.AddDirectLinkAsync(optionsBuilder); Assert.IsNotNull(link); Assert.IsTrue(link.ExpireTime == expireTime.ToUnixTimeSeconds()); diff --git a/README.md b/README.md index 92a189a..3e4fd66 100644 --- a/README.md +++ b/README.md @@ -71,30 +71,30 @@ var optionsBuuilder = new DirectLinkOptionsBuilder() .AddAuth("user", "password"); // you can also add the options when creating the initial link here -var directLink = await uploadedFile.AddDirectLink(); +var directLink = await uploadedFile.AddDirectLinkAsync(); -var updatedLink = await uploadedFile.UpdateDirectLink(directLink, optionsBuuilder); +var updatedLink = await uploadedFile.UpdateDirectLinkAsync(directLink, optionsBuuilder); ``` ### Removing a direct link ```cs // returns true if the link was removed, otherwise false -var removed = await uploadedFile.RemoveDirectLink(updatedLink); +var removed = await uploadedFile.RemoveDirectLinkAsync(updatedLink); ``` ### Setting file/folder options Setting an option will always return a bool value. True is success, otherwise false ```cs // files can only have their name updated -var ok = await uploadedFile.SetName("my new name.txt"); +var ok = await uploadedFile.SetNameAsync("my new name.txt"); // folders have quite a few more options -ok = await newFolder.SetName("some name here"); -ok = await newFolder.SetDescription("my cool folder description"); -ok = await newFolder.SetExpire(DateTime.Now.AddDays(5)); -ok = await newFolder.SetPublic(true); -ok = await newFolder.SetPassword("password"); -ok = await newFolder.SetTags(new[] {"tag1", "tag2", "tag3"}.ToList()); +ok = await newFolder.SetNameAsync("some name here"); +ok = await newFolder.SetDescriptionAsync("my cool folder description"); +ok = await newFolder.SetExpireAsync(DateTime.Now.AddDays(5)); +ok = await newFolder.SetPublicAsync(true); +ok = await newFolder.SetPasswordAsync("password"); +ok = await newFolder.SetTagsAsync(new[] {"tag1", "tag2", "tag3"}.ToList()); ``` ### Downloading a file From 3e20a372ae49256031122db1525ddc8cc3103204 Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Mon, 18 Mar 2024 16:19:47 -0400 Subject: [PATCH 2/2] add passwordhash param, update some method info --- GoFileSharp/GoFileSharp/GoFile.cs | 17 +++++++++++------ .../Model/GoFileData/Wrappers/GoFileFile.cs | 6 ++++-- .../Model/GoFileData/Wrappers/GoFileFolder.cs | 6 ++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/GoFileSharp/GoFileSharp/GoFile.cs b/GoFileSharp/GoFileSharp/GoFile.cs index 99495cc..cb7db52 100644 --- a/GoFileSharp/GoFileSharp/GoFile.cs +++ b/GoFileSharp/GoFileSharp/GoFile.cs @@ -30,11 +30,13 @@ public GoFile(GoFileOptions? options = null) /// /// Get from an ID /// - /// + /// The content ID to try and get + /// Wheather or not to use GoFile cache with this request + /// The SHA256 hash of the password to use for password protected content /// Returns content of the id - private async Task GetContentAsync(string contentId, bool noCache = false) + private async Task GetContentAsync(string contentId, bool noCache = false, string? passwordHash = null) { - var response = await _api.GetContentAsync(contentId, _options.ApiToken, noCache); + var response = await _api.GetContentAsync(contentId, _options.ApiToken, noCache, passwordHash); if(response is { IsOK: true, Data: { } data }) { @@ -51,10 +53,12 @@ public GoFile(GoFileOptions? options = null) /// Get a folder object from an ID /// /// + /// Wheather or not to use GoFile cache with this request + /// The SHA256 hash of the password to use for password protected content /// - public async Task GetFolderAsync(string contentId, bool noCache = false) + public async Task GetFolderAsync(string contentId, bool noCache = false, string? passwordHash = null) { - var folder = await GetContentAsync(contentId, noCache); + var folder = await GetContentAsync(contentId, noCache, passwordHash); if(folder is GoFileFolder gofileFolder) { @@ -85,7 +89,8 @@ public GoFile(GoFileOptions? options = null) /// Upload a file to Gofile /// /// The file to upload - /// + /// The progress object to use with the upload for progress updates + /// The id of the folder to upload the file into /// Returns the uploaded file /// If the preferred zone option was set, the upload will use a server in that zone public async Task UploadFileAsync(FileInfo file, IProgress progress = null, string folderId = null) diff --git a/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs b/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs index 35f6d1e..caee858 100644 --- a/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs +++ b/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs @@ -36,10 +36,12 @@ private async Task SetOptionAndRefresh(IContentOption option) /// /// Refresh this files information /// + /// The SHA256 hash of the parent folder's password to use when refreshing this file /// - public async Task RefreshAsync() + /// Automatic refreshes, like when using a Set method (SetNameAsync for example) will not refresh if a password is set. You will need to call this manually with the password hash + public async Task RefreshAsync(string? parentFolderPasswordHash = null) { - var parent = await _api.GetContentAsync(ParentFolderId, _options.ApiToken, true); + var parent = await _api.GetContentAsync(ParentFolderId, _options.ApiToken, true, parentFolderPasswordHash); if (!parent.IsOK || parent.Data == null) return false; diff --git a/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFolder.cs b/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFolder.cs index 4f902e3..bff66ad 100644 --- a/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFolder.cs +++ b/GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFolder.cs @@ -36,10 +36,12 @@ private async Task SetOptionAndRefresh(IContentOption option) /// /// Refresh this folders information /// + /// The SHA256 hash of the password set on this folder /// - public async Task RefreshAsync() + /// Automatic refreshes, like when using a Set method (SetNameAsync for example) will not refresh if a password is set. You will need to call this manually with the password hash + public async Task RefreshAsync(string? passwordHash = null) { - var thisFolder = await _api.GetContentAsync(Id, _options.ApiToken, true); + var thisFolder = await _api.GetContentAsync(Id, _options.ApiToken, true, passwordHash); if(!thisFolder.IsOK || thisFolder.Data == null) return false;