|
| 1 | +using Lagrange.Core.Utility.Extension; |
| 2 | + |
| 3 | +namespace Lagrange.Core.Internal.Events.System; |
| 4 | + |
| 5 | +internal class FlashTransferFile(string fileId, uint index, string fileName, Stream stream) |
| 6 | +{ |
| 7 | + public const uint DefaultFileType = 11; |
| 8 | + |
| 9 | + public string FileId { get; } = fileId; |
| 10 | + |
| 11 | + public uint Index { get; } = index; |
| 12 | + |
| 13 | + public string FileName { get; } = fileName; |
| 14 | + |
| 15 | + public uint FileType { get; } = ResolveFileType(fileName); |
| 16 | + |
| 17 | + public FlashTransferFileCategory Category => ResolveCategory(FileType); |
| 18 | + |
| 19 | + public Stream Stream { get; } = stream; |
| 20 | + |
| 21 | + public byte[] FileSha1 { get; } = stream.Sha1(); |
| 22 | + |
| 23 | + public byte[] FileMd5 { get; } = stream.Md5(); |
| 24 | + |
| 25 | + public static List<FlashTransferFileCategoryStatistic> CreateCategoryStatistics(IReadOnlyList<FlashTransferFile> files) |
| 26 | + { |
| 27 | + return files |
| 28 | + .GroupBy(file => file.Category) |
| 29 | + .OrderBy(group => group.Key) |
| 30 | + .Select(group => new FlashTransferFileCategoryStatistic(group.Key, group.Count(), $"{ResolveCategoryName(group.Key)}({group.Count()})")) |
| 31 | + .ToList(); |
| 32 | + } |
| 33 | + |
| 34 | + private static uint ResolveFileType(string fileName) |
| 35 | + { |
| 36 | + return Path.GetExtension(fileName).ToLowerInvariant() switch |
| 37 | + { |
| 38 | + ".mp3" or ".wav" or ".aac" or ".flac" => 1, |
| 39 | + ".mp4" or ".avi" or ".mkv" or ".mov" or ".3gp" or ".mpeg" or ".rmvb" or ".rm" or ".wmv" or ".flv" or ".asf" or ".webm" or ".mpg" or ".vob" or ".m4v" or ".f4v" => 2, |
| 40 | + ".doc" or ".docx" => 3, |
| 41 | + ".zip" or ".rar" or ".tar" or ".gz" => 4, |
| 42 | + ".apk" => 5, |
| 43 | + ".xls" or ".xlsx" => 6, |
| 44 | + ".ppt" or ".pptx" => 7, |
| 45 | + ".html" or ".htm" => 8, |
| 46 | + ".pdf" => 9, |
| 47 | + ".txt" => 10, |
| 48 | + ".psd" => 12, |
| 49 | + ".pt" or ".pth" or ".onnx" or ".model" or ".mlmodel" => 15, |
| 50 | + ".ttf" or ".otf" => 16, |
| 51 | + ".ipa" => 17, |
| 52 | + ".key" => 18, |
| 53 | + ".note" => 19, |
| 54 | + ".numbers" => 20, |
| 55 | + ".pages" => 21, |
| 56 | + ".sketch" => 22, |
| 57 | + ".dmg" => 23, |
| 58 | + ".pkg" => 24, |
| 59 | + ".jpg" or ".jpeg" or ".png" or ".gif" or ".bmp" or ".webp" or ".heic" or ".heif" or ".dib" or ".ico" or ".avif" or ".tif" or ".tiff" => 26, |
| 60 | + _ => DefaultFileType |
| 61 | + }; |
| 62 | + } |
| 63 | + |
| 64 | + private static FlashTransferFileCategory ResolveCategory(uint fileType) |
| 65 | + { |
| 66 | + return fileType switch |
| 67 | + { |
| 68 | + 3 or 6 or 7 or 9 or 10 or 13 or 18 or 19 or 20 or 21 => FlashTransferFileCategory.Document, |
| 69 | + 26 => FlashTransferFileCategory.Image, |
| 70 | + 2 => FlashTransferFileCategory.Video, |
| 71 | + 4 => FlashTransferFileCategory.Archive, |
| 72 | + 25 => FlashTransferFileCategory.Folder, |
| 73 | + _ => FlashTransferFileCategory.Other |
| 74 | + }; |
| 75 | + } |
| 76 | + |
| 77 | + private static string ResolveCategoryName(FlashTransferFileCategory category) |
| 78 | + { |
| 79 | + return category switch |
| 80 | + { |
| 81 | + FlashTransferFileCategory.Document => "文档", |
| 82 | + FlashTransferFileCategory.Image => "图片", |
| 83 | + FlashTransferFileCategory.Video => "视频", |
| 84 | + FlashTransferFileCategory.Archive => "压缩包", |
| 85 | + FlashTransferFileCategory.Folder => "文件夹", |
| 86 | + _ => "其他" |
| 87 | + }; |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +internal enum FlashTransferFileCategory : uint |
| 92 | +{ |
| 93 | + Document = 1, |
| 94 | + Image = 2, |
| 95 | + Video = 3, |
| 96 | + Archive = 4, |
| 97 | + Folder = 5, |
| 98 | + Other = 6 |
| 99 | +} |
| 100 | + |
| 101 | +internal readonly record struct FlashTransferFileCategoryStatistic(FlashTransferFileCategory Category, int Count, string DisplayName); |
| 102 | + |
| 103 | +internal class FlashTransferCreateFileSetEventReq(string title, string asciiTitle, List<FlashTransferFile> files) : ProtocolEvent |
| 104 | +{ |
| 105 | + public string Title { get; } = title; |
| 106 | + |
| 107 | + public string AsciiTitle { get; } = asciiTitle; |
| 108 | + |
| 109 | + public List<FlashTransferFile> Files { get; } = files; |
| 110 | + |
| 111 | + public List<FlashTransferFileCategoryStatistic> CategoryStatistics { get; } = FlashTransferFile.CreateCategoryStatistics(files); |
| 112 | +} |
| 113 | + |
| 114 | +internal class FlashTransferCreateFileSetEventResp(string fileSetId, string shareLink) : ProtocolEvent |
| 115 | +{ |
| 116 | + public string FileSetId { get; } = fileSetId; |
| 117 | + |
| 118 | + public string ShareLink { get; } = shareLink; |
| 119 | +} |
| 120 | + |
| 121 | +internal class FlashTransferRegisterFilesEventReq(string fileSetId, List<FlashTransferFile> files) : ProtocolEvent |
| 122 | +{ |
| 123 | + public string FileSetId { get; } = fileSetId; |
| 124 | + |
| 125 | + public List<FlashTransferFile> Files { get; } = files; |
| 126 | +} |
| 127 | + |
| 128 | +internal class FlashTransferRegisterFilesEventResp : ProtocolEvent; |
| 129 | + |
| 130 | +internal class FlashTransferQueryFileSetStatusEventReq(string fileSetId) : ProtocolEvent |
| 131 | +{ |
| 132 | + public string FileSetId { get; } = fileSetId; |
| 133 | +} |
| 134 | + |
| 135 | +internal class FlashTransferQueryFileSetStatusEventResp : ProtocolEvent; |
| 136 | + |
| 137 | +internal class FlashTransferUploadAuthorizeEventReq(string fileSetId, FlashTransferFile file, uint scene) : ProtocolEvent |
| 138 | +{ |
| 139 | + public string FileSetId { get; } = fileSetId; |
| 140 | + |
| 141 | + public FlashTransferFile File { get; } = file; |
| 142 | + |
| 143 | + public uint Scene { get; } = scene; |
| 144 | +} |
| 145 | + |
| 146 | +internal class FlashTransferUploadAuthorizeEventResp(string uploadToken, string resourceKey, uint appId, string uploadHost, uint chunkSize, uint bindingStage, uint bindingField5, uint bindingField6) : ProtocolEvent |
| 147 | +{ |
| 148 | + public string UploadToken { get; } = uploadToken; |
| 149 | + |
| 150 | + public string ResourceKey { get; } = resourceKey; |
| 151 | + |
| 152 | + public uint AppId { get; } = appId; |
| 153 | + |
| 154 | + public string UploadHost { get; } = uploadHost; |
| 155 | + |
| 156 | + public uint ChunkSize { get; } = chunkSize; |
| 157 | + |
| 158 | + public uint BindingStage { get; } = bindingStage; |
| 159 | + |
| 160 | + public uint BindingField5 { get; } = bindingField5; |
| 161 | + |
| 162 | + public uint BindingField6 { get; } = bindingField6; |
| 163 | +} |
| 164 | + |
| 165 | +internal class FlashTransferUploadCompleteEventReq(string fileSetId, FlashTransferFile file, string resourceKey, uint scene, uint bindingStage, uint bindingField5, uint bindingField6) : ProtocolEvent |
| 166 | +{ |
| 167 | + public string FileSetId { get; } = fileSetId; |
| 168 | + |
| 169 | + public FlashTransferFile File { get; } = file; |
| 170 | + |
| 171 | + public string ResourceKey { get; } = resourceKey; |
| 172 | + |
| 173 | + public uint Scene { get; } = scene; |
| 174 | + |
| 175 | + public uint BindingStage { get; } = bindingStage; |
| 176 | + |
| 177 | + public uint BindingField5 { get; } = bindingField5; |
| 178 | + |
| 179 | + public uint BindingField6 { get; } = bindingField6; |
| 180 | +} |
| 181 | + |
| 182 | +internal class FlashTransferUploadCompleteEventResp : ProtocolEvent; |
| 183 | + |
| 184 | +internal class FlashTransferUpdateFileSetStatusEventReq(string fileSetId, uint status) : ProtocolEvent |
| 185 | +{ |
| 186 | + public string FileSetId { get; } = fileSetId; |
| 187 | + |
| 188 | + public uint Status { get; } = status; |
| 189 | +} |
| 190 | + |
| 191 | +internal class FlashTransferUpdateFileSetStatusEventResp : ProtocolEvent; |
0 commit comments