From bf784318c2f75bca7f4a7eec03e729ea15571f0d Mon Sep 17 00:00:00 2001 From: cadri20 Date: Fri, 25 Oct 2024 14:17:58 -0500 Subject: [PATCH 1/3] Dependencies versions updated --- Samples/SeafConsole/SeafConsole.csproj | 9 ++++++++- SeafClient.Tests/SeafClient.Tests.csproj | 4 ++-- SeafClient/SeafClient.csproj | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Samples/SeafConsole/SeafConsole.csproj b/Samples/SeafConsole/SeafConsole.csproj index 2f3ecab..fe57277 100644 --- a/Samples/SeafConsole/SeafConsole.csproj +++ b/Samples/SeafConsole/SeafConsole.csproj @@ -9,7 +9,7 @@ Properties SeafConsole SeafConsole - v4.5.2 + v4.8 512 true @@ -33,6 +33,12 @@ 4 + + ..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\..\packages\Newtonsoft.Json.Bson.1.0.2\lib\net45\Newtonsoft.Json.Bson.dll + @@ -50,6 +56,7 @@ + diff --git a/SeafClient.Tests/SeafClient.Tests.csproj b/SeafClient.Tests/SeafClient.Tests.csproj index 7c02a98..bc2eb07 100644 --- a/SeafClient.Tests/SeafClient.Tests.csproj +++ b/SeafClient.Tests/SeafClient.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + net8.0 false @@ -12,7 +12,7 @@ - + diff --git a/SeafClient/SeafClient.csproj b/SeafClient/SeafClient.csproj index f2b6450..c367aac 100644 --- a/SeafClient/SeafClient.csproj +++ b/SeafClient/SeafClient.csproj @@ -12,7 +12,7 @@ - + From 5b694faa9d1514d1dba19a6abdeee016cbecec4a Mon Sep 17 00:00:00 2001 From: cadri20 Date: Fri, 25 Oct 2024 14:19:52 -0500 Subject: [PATCH 2/3] Replace parameter added --- SeafClient/Requests/Files/UploadFilesRequest.cs | 16 +++++++++++++--- SeafClient/SeafSession.cs | 12 +++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/SeafClient/Requests/Files/UploadFilesRequest.cs b/SeafClient/Requests/Files/UploadFilesRequest.cs index 58eb61c..30eb27f 100644 --- a/SeafClient/Requests/Files/UploadFilesRequest.cs +++ b/SeafClient/Requests/Files/UploadFilesRequest.cs @@ -24,6 +24,8 @@ public class UploadFilesRequest : SessionRequest public string TargetDirectory { get; set; } List files = new List(); + + public bool Replace { get; set; } public List Files { @@ -51,8 +53,8 @@ public override HttpAccessMethod HttpAccessMethod /// /// /// - public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, string filename, Stream fileContent, Action progressCallback) - : this(authToken, uploadUri, targetDirectory, progressCallback, new UploadFileInfo(filename, fileContent)) + public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, string filename, Stream fileContent, Action progressCallback, bool replace) + : this(authToken, uploadUri, targetDirectory, replace, progressCallback, new UploadFileInfo(filename, fileContent)) { // -- } @@ -65,12 +67,13 @@ public UploadFilesRequest(string authToken, string uploadUri, string targetDirec /// /// /// - public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, Action progressCallback, params UploadFileInfo[] uploadFiles) + public UploadFilesRequest(string authToken, string uploadUri, string targetDirectory, bool replace, Action progressCallback, params UploadFileInfo[] uploadFiles) : base(authToken) { UploadUri = uploadUri; UploadProgress = progressCallback; TargetDirectory = targetDirectory; + Replace = replace; files.AddRange(uploadFiles); } @@ -117,6 +120,12 @@ public override HttpRequestMessage GetCustomizedRequest(Uri serverUri) dirContent.Headers.TryAddWithoutValidation("Content-Disposition", @"form-data; name=""parent_dir"""); content.Add(dirContent); + var replaceContent = new StringContent(Replace ? "1" : "0"); + replaceContent.Headers.ContentType = null; + replaceContent.Headers.TryAddWithoutValidation("Content-Disposition", @"form-data; name=""replace"""); + content.Add(replaceContent); + + // transmit the content length long conLen; if (!content.ComputeLength(out conLen)) @@ -139,6 +148,7 @@ public override HttpRequestMessage GetCustomizedRequest(Uri serverUri) return request; } + } /// diff --git a/SeafClient/SeafSession.cs b/SeafClient/SeafSession.cs index 0932ac7..6d3aed2 100644 --- a/SeafClient/SeafSession.cs +++ b/SeafClient/SeafSession.cs @@ -877,13 +877,14 @@ public string GetThumbnailUrl(string libraryId, string path, int size) /// The library the file should be uploaded to /// The directory the file should be uploaded to /// The name of the file + /// If true, the files will be replaced if it already exists /// The new content of the file /// Optional progress callback (will report percentage of upload) - public async Task UploadSingle(SeafLibrary library, string targetDirectory, string targetFilename, Stream fileContent, Action progressCallback = null) + public async Task UploadSingle(SeafLibrary library, string targetDirectory, string targetFilename, bool replace, Stream fileContent, Action progressCallback = null) { library.ThrowOnNull(nameof(library)); - return await UploadSingle(library.Id, targetDirectory, targetFilename, fileContent, progressCallback); + return await UploadSingle(library.Id, targetDirectory, targetFilename, replace, fileContent, progressCallback); } /// @@ -895,15 +896,16 @@ public async Task UploadSingle(SeafLibrary library, string targetDirectory /// The id of the library the file should be uploaded to /// The directory the file should be uploaded to /// The name of the file + /// If true, the files will be replaced if it already exists /// The new content of the file /// Optional progress callback (will report percentage of upload) - public async Task UploadSingle(string libraryId, string targetDirectory, string targetFilename, Stream fileContent, Action progressCallback = null) + public async Task UploadSingle(string libraryId, string targetDirectory, string targetFilename, bool replace, Stream fileContent, Action progressCallback = null) { // to upload files we need to get an upload link first var req = new GetUploadLinkRequest(AuthToken, libraryId); var uploadLink = await _webConnection.SendRequestAsync(ServerUri, req); - - var uploadRequest = new UploadFilesRequest(AuthToken, uploadLink, targetDirectory, targetFilename, fileContent, progressCallback); + + var uploadRequest = new UploadFilesRequest(AuthToken, uploadLink, targetDirectory, targetFilename, fileContent, progressCallback, replace); return await _webConnection.SendRequestAsync(ServerUri, uploadRequest); } From f294139cacb341a769c1948007af3d81911e25dd Mon Sep 17 00:00:00 2001 From: cadri20 Date: Fri, 25 Oct 2024 17:30:13 -0500 Subject: [PATCH 3/3] Relative path added --- SeafClient/Requests/Files/UploadFilesRequest.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/SeafClient/Requests/Files/UploadFilesRequest.cs b/SeafClient/Requests/Files/UploadFilesRequest.cs index 30eb27f..ba742f7 100644 --- a/SeafClient/Requests/Files/UploadFilesRequest.cs +++ b/SeafClient/Requests/Files/UploadFilesRequest.cs @@ -109,17 +109,21 @@ public override HttpRequestMessage GetCustomizedRequest(Uri serverUri) content.Add(fileContent); } - - // the parent dir to upload the file to + string tDir = TargetDirectory; - if (!tDir.StartsWith("/")) - tDir = "/" + tDir; + if (tDir.StartsWith("/")) + tDir = tDir.Substring(1); - var dirContent = new StringContent(tDir, Encoding.UTF8); + var dirContent = new StringContent("/", Encoding.UTF8); dirContent.Headers.ContentType = null; dirContent.Headers.TryAddWithoutValidation("Content-Disposition", @"form-data; name=""parent_dir"""); content.Add(dirContent); + var relativePathContent = new StringContent(tDir); + relativePathContent.Headers.ContentType = null; + relativePathContent.Headers.TryAddWithoutValidation("Content-Disposition", @"form-data; name=""relative_path"""); + content.Add(relativePathContent); + var replaceContent = new StringContent(Replace ? "1" : "0"); replaceContent.Headers.ContentType = null; replaceContent.Headers.TryAddWithoutValidation("Content-Disposition", @"form-data; name=""replace""");