Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.4 #14

Merged
merged 2 commits into from
Mar 18, 2024
Merged
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
17 changes: 11 additions & 6 deletions GoFileSharp/GoFileSharp/GoFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
/// <summary>
/// Get <see cref="IContent"/> from an ID
/// </summary>
/// <param name="contentId"></param>
/// <param name="contentId">The content ID to try and get</param>
/// <param name="noCache">Wheather or not to use GoFile cache with this request</param>
/// <param name="passwordHash">The SHA256 hash of the password to use for password protected content</param>
/// <returns>Returns content of the id</returns>
private async Task<IContent?> GetContentAsync(string contentId, bool noCache = false)
private async Task<IContent?> 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 })
{
Expand All @@ -51,10 +53,12 @@
/// Get a folder object from an ID
/// </summary>
/// <param name="contentId"></param>
/// <param name="noCache">Wheather or not to use GoFile cache with this request</param>
/// <param name="passwordHash">The SHA256 hash of the password to use for password protected content</param>
/// <returns></returns>
public async Task<GoFileFolder?> GetFolderAsync(string contentId, bool noCache = false)
public async Task<GoFileFolder?> 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)
{
Expand Down Expand Up @@ -85,10 +89,11 @@
/// Upload a file to Gofile
/// </summary>
/// <param name="file">The file to upload</param>
/// <param name="progress"></param>
/// <param name="progress">The progress object to use with the upload for progress updates</param>
/// <param name="folderId">The id of the folder to upload the file into</param>
/// <returns>Returns the uploaded file</returns>
/// <remarks>If the preferred zone option was set, the upload will use a server in that zone</remarks>
public async Task<GoFileFile?> UploadFileAsync(FileInfo file, IProgress<double> progress = null, string folderId = null)

Check warning on line 96 in GoFileSharp/GoFileSharp/GoFile.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 96 in GoFileSharp/GoFileSharp/GoFile.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
var uploadResponse = await _api.UploadFileAsync(file, _options.PreferredZone, _options.ApiToken, progress, folderId);

Expand Down
6 changes: 3 additions & 3 deletions GoFileSharp/GoFileSharp/GoFileSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<RepositoryUrl>https://github.com/waffle-lord/GoFileSharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>gofilesharp gofile</PackageTags>
<AssemblyVersion>1.0.3</AssemblyVersion>
<FileVersion>1.0.3</FileVersion>
<Version>1.0.3</Version>
<AssemblyVersion>1.0.4</AssemblyVersion>
<FileVersion>1.0.4</FileVersion>
<Version>1.0.4</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>gofilesharp_icon.png</PackageIcon>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
Expand Down
26 changes: 14 additions & 12 deletions GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
/// <summary>
/// Refresh this files information
/// </summary>
/// <param name="parentFolderPasswordHash">The SHA256 hash of the parent folder's password to use when refreshing this file</param>
/// <returns></returns>
public async Task<bool> RefreshAsync()
/// <remarks>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</remarks>
public async Task<bool> 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;
Expand Down Expand Up @@ -67,7 +69,7 @@
/// <param name="overwrite">Whether or not to overwrite the destination file if it exists</param>
/// <param name="progress">Pregress to track the download with</param>
/// <returns>Returns true if the file was downloaded, otherwise false</returns>
public async Task<bool> DownloadAsync(FileInfo destinationFile, DirectLink directLink, bool overwrite = false, IProgress<double> progress = null)

Check warning on line 72 in GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
var result = await _api.DownloadFileAsync(directLink.Link, destinationFile, overwrite, progress);

Expand All @@ -81,7 +83,7 @@
/// <param name="overwrite">Whether or not to overwrite the destination file if it exists</param>
/// <param name="progress">Progress to track the download with</param>
/// <returns>Returns true if the file was downloaded, otherwise false</returns>
public async Task<bool> DownloadAsync(FileInfo destinationFile, bool overwrite = false, IProgress<double> progress = null)

Check warning on line 86 in GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFile.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
var result = await _api.DownloadFileAsync(DirectLinks.First().Link, destinationFile, overwrite, progress);

Expand Down Expand Up @@ -114,18 +116,18 @@
/// </summary>
/// <param name="newName">The new name of the file</param>
/// <returns>Returns true if the name was updated, otherwise false</returns>
public async Task<bool> SetName(string newName) =>
public async Task<bool> SetNameAsync(string newName) =>
await SetOptionAndRefresh(FileContentOption.Name(newName));

/// <summary>
/// Add a direct link to this file
/// </summary>
/// <param name="optionsBuilder">The options builder to use for link options</param>
/// <returns>A <see cref="DirectLink"/> or null if the link fails to be added</returns>
public async Task<DirectLink?> AddDirectLink(DirectLinkOptionsBuilder? optionsBuilder = null)
=> await AddDirectLink(optionsBuilder?.Build());
public async Task<DirectLink?> AddDirectLinkAsync(DirectLinkOptionsBuilder? optionsBuilder = null)
=> await AddDirectLinkAsync(optionsBuilder?.Build());

private async Task<DirectLink?> AddDirectLink(DirectLinkOptions? options = null)
private async Task<DirectLink?> AddDirectLinkAsync(DirectLinkOptions? options = null)
{
var response = await _api.AddDirectLink(_options.ApiToken, Id, options);

Expand All @@ -141,10 +143,10 @@
/// <param name="directLink">The direct link to update</param>
/// <param name="optionsBuilder">The options builder to use to update the link</param>
/// <returns>A <see cref="DirectLink"/> or null if the link fails to be updated</returns>
public async Task<DirectLink?> UpdateDirectLink(DirectLink directLink, DirectLinkOptionsBuilder optionsBuilder)
=> await UpdateDirectLink(directLink.Id, optionsBuilder.Build());
public async Task<DirectLink?> UpdateDirectLinkAsync(DirectLink directLink, DirectLinkOptionsBuilder optionsBuilder)
=> await UpdateDirectLinkAsync(directLink.Id, optionsBuilder.Build());

private async Task<DirectLink?> UpdateDirectLink(string directLinkId, DirectLinkOptions options)
private async Task<DirectLink?> UpdateDirectLinkAsync(string directLinkId, DirectLinkOptions options)
{
var response = await _api.UpdateDirectLink(_options.ApiToken, Id, directLinkId, options);

Expand All @@ -159,10 +161,10 @@
/// </summary>
/// <param name="directLink">The direct link to remove</param>
/// <returns>Returns true if the link was removed, otherwise false</returns>
public async Task<bool> RemoveDirectLink(DirectLink directLink)
=> await RemoveDirectLink(directLink.Id);
public async Task<bool> RemoveDirectLinkAsync(DirectLink directLink)
=> await RemoveDirectLinkAsync(directLink.Id);

private async Task<bool> RemoveDirectLink(string directLinkId)
private async Task<bool> RemoveDirectLinkAsync(string directLinkId)
{
var response = await _api.RemoveDirectLink(_options.ApiToken, Id, directLinkId);

Expand Down
36 changes: 19 additions & 17 deletions GoFileSharp/GoFileSharp/Model/GoFileData/Wrappers/GoFileFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ private async Task<bool> SetOptionAndRefresh(IContentOption option)
/// <summary>
/// Refresh this folders information
/// </summary>
/// <param name="passwordHash">The SHA256 hash of the password set on this folder</param>
/// <returns></returns>
public async Task<bool> RefreshAsync()
/// <remarks>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</remarks>
public async Task<bool> 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;
Expand Down Expand Up @@ -168,58 +170,58 @@ public async Task<bool> CopyIntoAsync(IContent[] content)
/// </summary>
/// <param name="tags">the tags to set on this folder</param>
/// <returns>Returns true is the option was set, otherwise false</returns>
public async Task<bool> SetTags(List<string> tags)
public async Task<bool> SetTagsAsync(List<string> tags)
=> await SetOptionAndRefresh(FolderContentOption.Tags(tags));

/// <summary>
/// Set the password for this folder
/// </summary>
/// <param name="password"></param>
/// <returns>Returns true is the option was set, otherwise false</returns>
public async Task<bool> SetPassword(string password)
public async Task<bool> SetPasswordAsync(string password)
=> await SetOptionAndRefresh(FolderContentOption.Password(password));

/// <summary>
/// Set the expiration date of the folder
/// </summary>
/// <param name="date"></param>
/// <returns>Returns true is the option was set, otherwise false</returns>
public async Task<bool> SetExpire(DateTimeOffset date)
public async Task<bool> SetExpireAsync(DateTimeOffset date)
=> await SetOptionAndRefresh(FolderContentOption.Expire(date));

/// <summary>
/// Set the public flag of this folder
/// </summary>
/// <param name="value"></param>
/// <returns>Returns true is the option was set, otherwise false</returns>
public async Task<bool> SetPublic(bool value)
public async Task<bool> SetPublicAsync(bool value)
=> await SetOptionAndRefresh(FolderContentOption.Public(value));

/// <summary>
/// Set the description of this folder
/// </summary>
/// <param name="description"></param>
/// <returns>Returns true is the option was set, otherwise false</returns>
public async Task<bool> SetDescription(string description)
public async Task<bool> SetDescriptionAsync(string description)
=> await SetOptionAndRefresh(FolderContentOption.Description(description));

/// <summary>
/// Update the name of this folder
/// </summary>
/// <param name="newName">The new name of the folder</param>
/// <returns>Returns true if the name was updated, otherwise false</returns>
public async Task<bool> SetName(string newName)
public async Task<bool> SetNameAsync(string newName)
=> await SetOptionAndRefresh(FolderContentOption.Name(newName));

/// <summary>
/// Add a direct link to this folder
/// </summary>
/// <param name="optionsBuilder">The options builder to use for link options</param>
/// <returns>A <see cref="DirectLink"/> or null if the link fails to be added</returns>
public async Task<DirectLink?> AddDirectLink(DirectLinkOptionsBuilder? optionsBuilder = null)
=> await AddDirectLink(optionsBuilder?.Build());
public async Task<DirectLink?> AddDirectLinkAsync(DirectLinkOptionsBuilder? optionsBuilder = null)
=> await AddDirectLinkAsync(optionsBuilder?.Build());

private async Task<DirectLink?> AddDirectLink(DirectLinkOptions? options = null)
private async Task<DirectLink?> AddDirectLinkAsync(DirectLinkOptions? options = null)
{
var response = await _api.AddDirectLink(_options.ApiToken, Id, options);

Expand All @@ -235,10 +237,10 @@ public async Task<bool> SetName(string newName)
/// <param name="directLink">The direct link to update</param>
/// <param name="optionsBuilder">The options builder to use to update the link</param>
/// <returns>A <see cref="DirectLink"/> or null if the link fails to be updated</returns>
public async Task<DirectLink?> UpdateDirectLink(DirectLink directLink, DirectLinkOptionsBuilder optionsBuilder)
=> await UpdateDirectLink(directLink.Id, optionsBuilder.Build());
public async Task<DirectLink?> UpdateDirectLinkAsync(DirectLink directLink, DirectLinkOptionsBuilder optionsBuilder)
=> await UpdateDirectLinkAsync(directLink.Id, optionsBuilder.Build());

private async Task<DirectLink?> UpdateDirectLink(string directLinkId, DirectLinkOptions options)
private async Task<DirectLink?> UpdateDirectLinkAsync(string directLinkId, DirectLinkOptions options)
{
var response = await _api.UpdateDirectLink(_options.ApiToken, Id, directLinkId, options);

Expand All @@ -253,10 +255,10 @@ public async Task<bool> SetName(string newName)
/// </summary>
/// <param name="directLink">The direct link to remove</param>
/// <returns>Returns true if the link was removed, otherwise false</returns>
public async Task<bool> RemoveDirectLink(DirectLink directLink)
=> await RemoveDirectLink(directLink.Id);
public async Task<bool> RemoveDirectLinkAsync(DirectLink directLink)
=> await RemoveDirectLinkAsync(directLink.Id);

private async Task<bool> RemoveDirectLink(string directLinkId)
private async Task<bool> RemoveDirectLinkAsync(string directLinkId)
{
var response = await _api.RemoveDirectLink(_options.ApiToken, Id, directLinkId);

Expand Down
20 changes: 10 additions & 10 deletions GoFileSharp/Tests/GoFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading