From ddf3ec744cb54c7a0978ce9cd4969af381aa7463 Mon Sep 17 00:00:00 2001 From: Kien Nguyen Date: Sun, 4 Feb 2024 00:56:24 -0800 Subject: [PATCH] Allow to set prefix for saved blob --- csclip/Program.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/csclip/Program.cs b/csclip/Program.cs index d4c6a44..6b97c18 100755 --- a/csclip/Program.cs +++ b/csclip/Program.cs @@ -228,7 +228,8 @@ async Task GetDataAsync(string format) public struct SaveDataToFileOptions { public string cf; - public string store_path; + public string path; + public string prefix; } async Task GetDataToFileAsync(SaveDataToFileOptions options) @@ -242,7 +243,7 @@ async Task GetDataToFileAsync(SaveDataToFileOptions options) if (data.Contains(stdFormat)) { - if (options.store_path == null) + if (options.path == null) { return (string)await data.GetDataAsync(stdFormat); ; } @@ -253,7 +254,7 @@ async Task GetDataToFileAsync(SaveDataToFileOptions options) { var sblob = await (blob as RandomAccessStreamReference).OpenReadAsync(); var ext = MimeTypes.MimeTypeMap.GetExtension(sblob.ContentType); - var fileName = $"{Guid.NewGuid().ToString()}{ext}"; + var fileName = $"{options.prefix}{Guid.NewGuid()}{ext}"; _ = Task.Run(async () => { try @@ -263,7 +264,8 @@ async Task GetDataToFileAsync(SaveDataToFileOptions options) await RandomAccessStream.CopyAndCloseAsync(sblob, sout); }, null); - var path = Path.GetFullPath($"{options.store_path}/"); + var path = Path.GetFullPath($"{options.path}/"); + // Ensure the directory exists (new FileInfo(path)).Directory.Create(); var folder = await StorageFolder.GetFolderFromPathAsync(path); await tempFile.CopyAsync(folder, fileName, NameCollisionOption.ReplaceExisting); @@ -341,7 +343,7 @@ public Responser(int id, Program prog) // Received: // - :copy: [{cf:, data:}+] -> nil // - :get: -> - // - :get-to-file: {cf:, store_path:} -> + // - :get-to-file: {cf:, path:} -> [JsonRpcMethod("copy")] public async Task HandleCopyDataAsync(IList data) {