mirror of
https://github.com/maker-community/ElectronBot.DotNet.git
synced 2026-10-20 23:58:11 +08:00
调整表情上传逻辑
This commit is contained in:
+1
-1
@@ -15,5 +15,5 @@ public interface IEmojisFileService
|
||||
/// </summary>
|
||||
/// <param name="emoticonAction">表情对象</param>
|
||||
/// <returns>临时目录路径</returns>
|
||||
Task<string> ExportEmojisFileToTempAsync(EmoticonAction emoticonAction);
|
||||
Task<(string path, string name)> ExportEmojisFileToTempAsync(EmoticonAction emoticonAction);
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ public interface IEmojiseShopService
|
||||
|
||||
Task<EmoticonAction> DownloadEmojisAsync(string id);
|
||||
|
||||
Task<bool> UploadEmojisAsync(EmoticonAction emoticon);
|
||||
Task<string> UploadEmojisAsync(EmoticonAction emoticon);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class EmojisFileService : IEmojisFileService
|
||||
ToastHelper.SendToast($"{text}-{destinationFile.Path}", TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
public async Task<string> ExportEmojisFileToTempAsync(EmoticonAction emoticonAction)
|
||||
public async Task<(string path, string name)> ExportEmojisFileToTempAsync(EmoticonAction emoticonAction)
|
||||
{
|
||||
StorageFolder? destinationFolder;
|
||||
|
||||
@@ -154,11 +154,11 @@ public class EmojisFileService : IEmojisFileService
|
||||
|
||||
ZipFileCreatorHelper.CreateZipFile(filePaths, destinationFile.Path);
|
||||
|
||||
return destinationFile.Path;
|
||||
return (destinationFile.Path, destinationFile.Name);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return string.Empty;
|
||||
return (string.Empty, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,26 +19,32 @@ public class EmojiseShopService : IEmojiseShopService
|
||||
public Task<EmoticonAction> DownloadEmojisAsync(string id) => throw new NotImplementedException();
|
||||
public Task<EmojisItemDto> GetEmojisItemAsync(string id) => throw new NotImplementedException();
|
||||
public Task<List<EmojisItemDto>> GetEmojisListAsync(EmojisItemQuery itemQuery) => throw new NotImplementedException();
|
||||
public async Task<bool> UploadEmojisAsync(EmoticonAction emoticon)
|
||||
public async Task<string> UploadEmojisAsync(EmoticonAction emoticon)
|
||||
{
|
||||
var path = await _emojisFileService.ExportEmojisFileToTempAsync(emoticon);
|
||||
var pathName = await _emojisFileService.ExportEmojisFileToTempAsync(emoticon);
|
||||
|
||||
if (path == null)
|
||||
if (pathName.path == null)
|
||||
{
|
||||
return false;
|
||||
return string.Empty;
|
||||
}
|
||||
var httpClient = _httpClientFactory.CreateClient();
|
||||
|
||||
var resultData = string.Empty;
|
||||
|
||||
using var content = new MultipartFormDataContent();
|
||||
//replace with your own file path
|
||||
var filePath = Path.GetFullPath(path);
|
||||
var filePath = Path.GetFullPath(pathName.path);
|
||||
|
||||
var file = System.IO.File.ReadAllBytes(filePath);
|
||||
var byteArrayContent = new ByteArrayContent(file);
|
||||
content.Add(byteArrayContent, "fs","a.zip");
|
||||
content.Add(byteArrayContent, "fs",pathName.name);
|
||||
var result = await httpClient.PostAsync(ProfileImageUploadUri, content);
|
||||
|
||||
var resultContent = await result.Content.ReadAsStringAsync();
|
||||
if (result.IsSuccessStatusCode)
|
||||
{
|
||||
resultData = await result.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
return true;
|
||||
return resultData;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user