瀏覽代碼

qdr-temporary-shared-storage: CLI FileUploadService.UploadFileAsync returns FileId and ResultCode

Dalibor Votruba 1 年之前
父節點
當前提交
7491245791

+ 7 - 4
qdr-temporary-shared-storage/@client/qdr.app.tss.client/qdr.app.tss.client/Services/FileUploadService.cs

@@ -48,7 +48,7 @@ namespace Quadarax.Application.TemporarySharedStorage.Client.Services
         /// Progress is reported to the console in real-time showing percentage completion.
         /// All errors are caught and displayed in a user-friendly format.
         /// </remarks>
-        public async Task UploadFileAsync(UploadFileRequest request)
+        public async Task<Tuple<string, TssResultEnum>> UploadFileAsync(UploadFileRequest request)
         {
             try
             {
@@ -59,7 +59,7 @@ namespace Quadarax.Application.TemporarySharedStorage.Client.Services
                 if (!fileInfo.Exists)
                 {
                     Log(LogSeverityEnum.Error, $"File '{request.FilePath}' not found");
-                    return;
+                    return new Tuple<string, TssResultEnum>(string.Empty, TssResultEnum.FileNotFound);
                 }
                 
                 Log(LogSeverityEnum.Info, $"File: {fileInfo.Name}, Size: {FormatFileSize(fileInfo.Length)}");
@@ -75,7 +75,7 @@ namespace Quadarax.Application.TemporarySharedStorage.Client.Services
                 if (initResponse == null || string.IsNullOrEmpty(initResponse.UploadId))
                 {
                     Log(LogSeverityEnum.Error, "Failed to initialize upload");
-                    return;
+                    return new Tuple<string, TssResultEnum>(string.Empty, TssResultEnum.InitUploadFailed);
                 }
                 
                 Log(LogSeverityEnum.Debug, $"Upload initialized with ID: {initResponse.UploadId}");
@@ -93,7 +93,7 @@ namespace Quadarax.Application.TemporarySharedStorage.Client.Services
                 if (!uploadSuccess)
                 {
                     Log(LogSeverityEnum.Error, "Failed to upload chunks");
-                    return;
+                    return new Tuple<string, TssResultEnum>(string.Empty, TssResultEnum.UploadChunkFailed);
                 }
                 
                  Log(LogSeverityEnum.Info, "All chunks uploaded successfully");
@@ -124,15 +124,18 @@ namespace Quadarax.Application.TemporarySharedStorage.Client.Services
                     Log(LogSeverityEnum.Info, $"File ID: {finalizeResponse.FileId}");
                     Log(LogSeverityEnum.Info, $"Permalink: {finalizeResponse.Permalink}");
                     Log(LogSeverityEnum.Debug, $"Shortcode: {finalizeResponse.Shortcode}");
+                    return new Tuple<string, TssResultEnum>(finalizeResponse.FileId, TssResultEnum.Success);
                 }
                 else
                 {
                     Log(LogSeverityEnum.Error,"Failed to finalize upload");
+                    return new Tuple<string, TssResultEnum>(string.Empty, TssResultEnum.UploadFinalizeFailed);
                 }
             }
             catch (Exception ex)
             {
                 Log(LogSeverityEnum.Error,"Internal error. See exception:", ex);
+                return new Tuple<string, TssResultEnum>(string.Empty, TssResultEnum.GeneralFailure);
             }
         }
         

+ 38 - 0
qdr-temporary-shared-storage/@client/qdr.app.tss.client/qdr.app.tss.client/Services/TssResultEnum.cs

@@ -0,0 +1,38 @@
+namespace Quadarax.Application.TemporarySharedStorage.Client.Services
+{
+    /// <summary>
+    /// Represents the possible outcomes of a TSS (Trusted Storage System) operation.
+    /// </summary>
+    /// <remarks>This enumeration is used to indicate the result of operations performed within the TSS
+    /// system.  Each value corresponds to a specific outcome, allowing callers to handle success or failure scenarios
+    /// appropriately.</remarks>
+    public enum TssResultEnum
+    {
+        /// <summary>
+        /// Operation succeeded without errors.
+        /// </summary>
+        Success = 0,
+        /// <summary>
+        /// Indicates that the specified file could not be found.
+        /// </summary>
+        FileNotFound = 1,
+        /// <summary>
+        /// Represents a failure that occurred during the initialization of an upload process (cannot resolve chunk token).
+        /// </summary>
+        InitUploadFailed = 2,
+
+        /// <summary>
+        /// Represents a failure that occurred during the upload of a file chunk. 
+        /// </summary>
+        UploadChunkFailed = 3,
+        /// <summary>
+        /// Represents a failure that occurred during the finalization of an upload process (cannot resolve upload token).
+        /// </summary>
+        UploadFinalizeFailed = 4,
+
+        /// <summary>
+        /// General failure that does not fit into other categories.
+        /// </summary>
+        GeneralFailure = 100,
+    }
+}