From d0ae6c45413293ead2caa7f2932ab2619709319f Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 13 Sep 2024 01:28:16 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Methode=20"Upload"=20zur=20Datei=C3=BCb?= =?UTF-8?q?ertragung=20mit=20Abfrageparametern=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Methode "Upload" für das Hochladen von Dateien hinzugefügt. - Unterstützung für Abfrageparameter wie item_id, item_location, item_name, flags und stream_identity hinzugefügt. - Methode auf MultipartFormDataContent für die Dateiverarbeitung aktualisiert. --- .../{Create => }/Response/Attribute.cs | 2 +- .../DocResponse.cs} | 4 +- .../Documents/{Create => }/Response/Error.cs | 2 +- .../{Create => }/Response/IndexingDetails.cs | 2 +- .../Documents/{Create => }/Response/Item.cs | 2 +- .../{Create => }/Response/ObjectType.cs | 2 +- .../Response/ParentWindreamObject.cs | 2 +- .../Response/TypeSpecificDetails.cs | 2 +- .../{Create => }/Response/VectorDetails.cs | 2 +- .../Routes/DocumentsRouteService.cs | 44 ++++++++++++++++--- .../WindreamHub.Legacy.Client.csproj | 19 ++++---- 11 files changed, 59 insertions(+), 24 deletions(-) rename src/WindreamHub.Legacy.Client/Models/Documents/{Create => }/Response/Attribute.cs (91%) rename src/WindreamHub.Legacy.Client/Models/Documents/{Create/Response/DocCreateResponse.cs => Response/DocResponse.cs} (73%) rename src/WindreamHub.Legacy.Client/Models/Documents/{Create => }/Response/Error.cs (75%) rename src/WindreamHub.Legacy.Client/Models/Documents/{Create => }/Response/IndexingDetails.cs (57%) rename src/WindreamHub.Legacy.Client/Models/Documents/{Create => }/Response/Item.cs (87%) rename src/WindreamHub.Legacy.Client/Models/Documents/{Create => }/Response/ObjectType.cs (62%) rename src/WindreamHub.Legacy.Client/Models/Documents/{Create => }/Response/ParentWindreamObject.cs (75%) rename src/WindreamHub.Legacy.Client/Models/Documents/{Create => }/Response/TypeSpecificDetails.cs (57%) rename src/WindreamHub.Legacy.Client/Models/Documents/{Create => }/Response/VectorDetails.cs (55%) diff --git a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/Attribute.cs b/src/WindreamHub.Legacy.Client/Models/Documents/Response/Attribute.cs similarity index 91% rename from src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/Attribute.cs rename to src/WindreamHub.Legacy.Client/Models/Documents/Response/Attribute.cs index 51bfec7..e157d2a 100644 --- a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/Attribute.cs +++ b/src/WindreamHub.Legacy.Client/Models/Documents/Response/Attribute.cs @@ -1,4 +1,4 @@ -namespace WindreamHub.Legacy.Client.Models.Documents.Create.Response +namespace WindreamHub.Legacy.Client.Models.Documents.Response { public class Attribute { diff --git a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/DocCreateResponse.cs b/src/WindreamHub.Legacy.Client/Models/Documents/Response/DocResponse.cs similarity index 73% rename from src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/DocCreateResponse.cs rename to src/WindreamHub.Legacy.Client/Models/Documents/Response/DocResponse.cs index 2b9658d..8d6f77e 100644 --- a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/DocCreateResponse.cs +++ b/src/WindreamHub.Legacy.Client/Models/Documents/Response/DocResponse.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -namespace WindreamHub.Legacy.Client.Models.Documents.Create.Response +namespace WindreamHub.Legacy.Client.Models.Documents.Response { - public class DocCreateResponse + public class DocResponse { public Item Item { get; set; } public IndexingDetails IndexingDetails { get; set; } diff --git a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/Error.cs b/src/WindreamHub.Legacy.Client/Models/Documents/Response/Error.cs similarity index 75% rename from src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/Error.cs rename to src/WindreamHub.Legacy.Client/Models/Documents/Response/Error.cs index 2b94a21..4cfa1c3 100644 --- a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/Error.cs +++ b/src/WindreamHub.Legacy.Client/Models/Documents/Response/Error.cs @@ -1,6 +1,6 @@ using WindreamHub.Legacy.Client.Models.Shared; -namespace WindreamHub.Legacy.Client.Models.Documents.Create.Response +namespace WindreamHub.Legacy.Client.Models.Documents.Response { public class Error { diff --git a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/IndexingDetails.cs b/src/WindreamHub.Legacy.Client/Models/Documents/Response/IndexingDetails.cs similarity index 57% rename from src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/IndexingDetails.cs rename to src/WindreamHub.Legacy.Client/Models/Documents/Response/IndexingDetails.cs index 326a7f2..fdcaafa 100644 --- a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/IndexingDetails.cs +++ b/src/WindreamHub.Legacy.Client/Models/Documents/Response/IndexingDetails.cs @@ -1,4 +1,4 @@ -namespace WindreamHub.Legacy.Client.Models.Documents.Create.Response +namespace WindreamHub.Legacy.Client.Models.Documents.Response { public class IndexingDetails { diff --git a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/Item.cs b/src/WindreamHub.Legacy.Client/Models/Documents/Response/Item.cs similarity index 87% rename from src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/Item.cs rename to src/WindreamHub.Legacy.Client/Models/Documents/Response/Item.cs index e52ab85..0f2b969 100644 --- a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/Item.cs +++ b/src/WindreamHub.Legacy.Client/Models/Documents/Response/Item.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace WindreamHub.Legacy.Client.Models.Documents.Create.Response +namespace WindreamHub.Legacy.Client.Models.Documents.Response { public class Item { diff --git a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/ObjectType.cs b/src/WindreamHub.Legacy.Client/Models/Documents/Response/ObjectType.cs similarity index 62% rename from src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/ObjectType.cs rename to src/WindreamHub.Legacy.Client/Models/Documents/Response/ObjectType.cs index 1069c13..6d4f649 100644 --- a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/ObjectType.cs +++ b/src/WindreamHub.Legacy.Client/Models/Documents/Response/ObjectType.cs @@ -1,4 +1,4 @@ -namespace WindreamHub.Legacy.Client.Models.Documents.Create.Response +namespace WindreamHub.Legacy.Client.Models.Documents.Response { public class ObjectType { diff --git a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/ParentWindreamObject.cs b/src/WindreamHub.Legacy.Client/Models/Documents/Response/ParentWindreamObject.cs similarity index 75% rename from src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/ParentWindreamObject.cs rename to src/WindreamHub.Legacy.Client/Models/Documents/Response/ParentWindreamObject.cs index c4c4281..847b427 100644 --- a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/ParentWindreamObject.cs +++ b/src/WindreamHub.Legacy.Client/Models/Documents/Response/ParentWindreamObject.cs @@ -1,4 +1,4 @@ -namespace WindreamHub.Legacy.Client.Models.Documents.Create.Response +namespace WindreamHub.Legacy.Client.Models.Documents.Response { public class ParentWindreamObject { diff --git a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/TypeSpecificDetails.cs b/src/WindreamHub.Legacy.Client/Models/Documents/Response/TypeSpecificDetails.cs similarity index 57% rename from src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/TypeSpecificDetails.cs rename to src/WindreamHub.Legacy.Client/Models/Documents/Response/TypeSpecificDetails.cs index 10b4c61..8edaf85 100644 --- a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/TypeSpecificDetails.cs +++ b/src/WindreamHub.Legacy.Client/Models/Documents/Response/TypeSpecificDetails.cs @@ -1,4 +1,4 @@ -namespace WindreamHub.Legacy.Client.Models.Documents.Create.Response +namespace WindreamHub.Legacy.Client.Models.Documents.Response { public class TypeSpecificDetails { diff --git a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/VectorDetails.cs b/src/WindreamHub.Legacy.Client/Models/Documents/Response/VectorDetails.cs similarity index 55% rename from src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/VectorDetails.cs rename to src/WindreamHub.Legacy.Client/Models/Documents/Response/VectorDetails.cs index df7bee1..a508d9d 100644 --- a/src/WindreamHub.Legacy.Client/Models/Documents/Create/Response/VectorDetails.cs +++ b/src/WindreamHub.Legacy.Client/Models/Documents/Response/VectorDetails.cs @@ -1,4 +1,4 @@ -namespace WindreamHub.Legacy.Client.Models.Documents.Create.Response +namespace WindreamHub.Legacy.Client.Models.Documents.Response { public class VectorDetails { diff --git a/src/WindreamHub.Legacy.Client/Routes/DocumentsRouteService.cs b/src/WindreamHub.Legacy.Client/Routes/DocumentsRouteService.cs index 4488e61..907e866 100644 --- a/src/WindreamHub.Legacy.Client/Routes/DocumentsRouteService.cs +++ b/src/WindreamHub.Legacy.Client/Routes/DocumentsRouteService.cs @@ -4,8 +4,10 @@ using System.Net.Http; using DigitalData.Core.Legacy.Client; using System.Threading.Tasks; using WindreamHub.Legacy.Client.Models; -using WindreamHub.Legacy.Client.Models.Documents.Create.Response; +using WindreamHub.Legacy.Client.Models.Documents.Response; using WindreamHub.Legacy.Client.Models.Documents.Create.Request; +using System.IO; +using System.Web; namespace WindreamHub.Legacy.Client.Routes { @@ -15,12 +17,44 @@ namespace WindreamHub.Legacy.Client.Routes { } - public async Task> Create(HttpContent docCreateBody) + public async Task> Create(HttpContent docCreateBody) => await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody) - .ThenAsync(res => res.Simplify()); + .ThenAsync(res => res.Simplify()); - public async Task> Create(DocCreateBody docCreateBody) + public async Task> Create(DocCreateBody docCreateBody) => await FetchAsync(route: "/Create", method: HttpMethod.Post, body: docCreateBody.Stringify()) - .ThenAsync(res => res.Simplify()); + .ThenAsync(res => res.Simplify()); + + public async Task> Upload(string path, long? item_id = null, string item_location = null, string item_name = null, object stream_identity = null, params int[] flags) + { + using (var fileStream = File.OpenRead(path)) + { + var fileContent = new StreamContent(fileStream); + var formData = new MultipartFormDataContent + { + { fileContent, "file", "filename.pdf" } + }; + + var query = HttpUtility.ParseQueryString(string.Empty); + + if (item_id != null) + query["parameter.item.id"] = item_id.ToString(); + + if (item_location != null) + query["parameter.item.location"] = item_location; + + if (item_name != null) + query["parameter.item.name"] = item_name; + + if (flags != null && flags.Length > 0) + query["parameter.flags"] = string.Join(",", flags); + + if (stream_identity != null) + query["parameter.stream.__identity"] = stream_identity.ToString(); + + return await FetchAsync(route: "/Upload", method: HttpMethod.Post, body: fileContent) + .ThenAsync(res => res.Simplify()); + } + } } } \ No newline at end of file diff --git a/src/WindreamHub.Legacy.Client/WindreamHub.Legacy.Client.csproj b/src/WindreamHub.Legacy.Client/WindreamHub.Legacy.Client.csproj index 5a9ea24..263970f 100644 --- a/src/WindreamHub.Legacy.Client/WindreamHub.Legacy.Client.csproj +++ b/src/WindreamHub.Legacy.Client/WindreamHub.Legacy.Client.csproj @@ -74,6 +74,7 @@ ..\..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll + @@ -84,7 +85,7 @@ - + @@ -93,14 +94,14 @@ - - - - - - - - + + + + + + + +