|
| 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 | + |
| 26 | + private static uint ResolveFileType(string fileName) |
| 27 | + { |
| 28 | + return Path.GetExtension(fileName).ToLowerInvariant() switch |
| 29 | + { |
| 30 | + ".mp3" or ".wav" or ".aac" or ".flac" => 1, |
| 31 | + ".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, |
| 32 | + ".doc" or ".docx" => 3, |
| 33 | + ".zip" or ".rar" or ".tar" or ".gz" => 4, |
| 34 | + ".apk" => 5, |
| 35 | + ".xls" or ".xlsx" => 6, |
| 36 | + ".ppt" or ".pptx" => 7, |
| 37 | + ".html" or ".htm" => 8, |
| 38 | + ".pdf" => 9, |
| 39 | + ".txt" => 10, |
| 40 | + ".psd" => 12, |
| 41 | + ".pt" or ".pth" or ".onnx" or ".model" or ".mlmodel" => 15, |
| 42 | + ".ttf" or ".otf" => 16, |
| 43 | + ".ipa" => 17, |
| 44 | + ".key" => 18, |
| 45 | + ".note" => 19, |
| 46 | + ".numbers" => 20, |
| 47 | + ".pages" => 21, |
| 48 | + ".sketch" => 22, |
| 49 | + ".dmg" => 23, |
| 50 | + ".pkg" => 24, |
| 51 | + ".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, |
| 52 | + _ => DefaultFileType |
| 53 | + }; |
| 54 | + } |
| 55 | + |
| 56 | + private static FlashTransferFileCategory ResolveCategory(uint fileType) |
| 57 | + { |
| 58 | + return fileType switch |
| 59 | + { |
| 60 | + 3 or 6 or 7 or 9 or 10 or 13 or 18 or 19 or 20 or 21 => FlashTransferFileCategory.Document, |
| 61 | + 26 => FlashTransferFileCategory.Image, |
| 62 | + 2 => FlashTransferFileCategory.Video, |
| 63 | + 4 => FlashTransferFileCategory.Archive, |
| 64 | + 25 => FlashTransferFileCategory.Folder, |
| 65 | + _ => FlashTransferFileCategory.Other |
| 66 | + }; |
| 67 | + } |
| 68 | + |
| 69 | + private static string ResolveCategoryName(FlashTransferFileCategory category) |
| 70 | + { |
| 71 | + return category switch |
| 72 | + { |
| 73 | + FlashTransferFileCategory.Document => "文档", |
| 74 | + FlashTransferFileCategory.Image => "图片", |
| 75 | + FlashTransferFileCategory.Video => "视频", |
| 76 | + FlashTransferFileCategory.Archive => "压缩包", |
| 77 | + FlashTransferFileCategory.Folder => "文件夹", |
| 78 | + _ => "其他" |
| 79 | + }; |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +internal enum FlashTransferFileCategory : uint |
| 84 | +{ |
| 85 | + Document = 1, |
| 86 | + Image = 2, |
| 87 | + Video = 3, |
| 88 | + Archive = 4, |
| 89 | + Folder = 5, |
| 90 | + Other = 6 |
| 91 | +} |
| 92 | + |
| 93 | + |
| 94 | +internal class FlashTransferCreateFileSetEventReq(string title, string asciiTitle, List<FlashTransferFile> files) : ProtocolEvent |
| 95 | +{ |
| 96 | + public string Title { get; } = title; |
| 97 | + |
| 98 | + public string AsciiTitle { get; } = asciiTitle; |
| 99 | + |
| 100 | + public List<FlashTransferFile> Files { get; } = files; |
| 101 | + |
| 102 | +} |
| 103 | + |
| 104 | +internal class FlashTransferCreateFileSetEventResp(string fileSetId, string shareLink) : ProtocolEvent |
| 105 | +{ |
| 106 | + public string FileSetId { get; } = fileSetId; |
| 107 | + |
| 108 | + public string ShareLink { get; } = shareLink; |
| 109 | +} |
| 110 | + |
| 111 | +internal class FlashTransferRegisterFilesEventReq(string fileSetId, List<FlashTransferFile> files) : ProtocolEvent |
| 112 | +{ |
| 113 | + public string FileSetId { get; } = fileSetId; |
| 114 | + |
| 115 | + public List<FlashTransferFile> Files { get; } = files; |
| 116 | +} |
| 117 | + |
| 118 | +internal class FlashTransferRegisterFilesEventResp : ProtocolEvent; |
| 119 | + |
| 120 | +internal class FlashTransferQueryFileSetStatusEventReq(string fileSetId) : ProtocolEvent |
| 121 | +{ |
| 122 | + public string FileSetId { get; } = fileSetId; |
| 123 | +} |
| 124 | + |
| 125 | +internal class FlashTransferQueryFileSetStatusEventResp : ProtocolEvent; |
| 126 | + |
| 127 | +internal class FlashTransferUploadAuthorizeEventReq(string fileSetId, FlashTransferFile file, uint scene) : ProtocolEvent |
| 128 | +{ |
| 129 | + public string FileSetId { get; } = fileSetId; |
| 130 | + |
| 131 | + public FlashTransferFile File { get; } = file; |
| 132 | + |
| 133 | + public uint Scene { get; } = scene; |
| 134 | +} |
| 135 | + |
| 136 | +internal class FlashTransferUploadAuthorizeEventResp(string uploadToken, string resourceKey, uint appId, string uploadHost, uint chunkSize, uint bindingStage, uint bindingField5, uint bindingField6) : ProtocolEvent |
| 137 | +{ |
| 138 | + public string UploadToken { get; } = uploadToken; |
| 139 | + |
| 140 | + public string ResourceKey { get; } = resourceKey; |
| 141 | + |
| 142 | + public uint AppId { get; } = appId; |
| 143 | + |
| 144 | + public string UploadHost { get; } = uploadHost; |
| 145 | + |
| 146 | + public uint ChunkSize { get; } = chunkSize; |
| 147 | + |
| 148 | + public uint BindingStage { get; } = bindingStage; |
| 149 | + |
| 150 | + public uint BindingField5 { get; } = bindingField5; |
| 151 | + |
| 152 | + public uint BindingField6 { get; } = bindingField6; |
| 153 | +} |
| 154 | + |
| 155 | +internal class FlashTransferUploadCompleteEventReq(string fileSetId, FlashTransferFile file, string resourceKey, uint scene, uint bindingStage, uint bindingField5, uint bindingField6) : ProtocolEvent |
| 156 | +{ |
| 157 | + public string FileSetId { get; } = fileSetId; |
| 158 | + |
| 159 | + public FlashTransferFile File { get; } = file; |
| 160 | + |
| 161 | + public string ResourceKey { get; } = resourceKey; |
| 162 | + |
| 163 | + public uint Scene { get; } = scene; |
| 164 | + |
| 165 | + public uint BindingStage { get; } = bindingStage; |
| 166 | + |
| 167 | + public uint BindingField5 { get; } = bindingField5; |
| 168 | + |
| 169 | + public uint BindingField6 { get; } = bindingField6; |
| 170 | +} |
| 171 | + |
| 172 | +internal class FlashTransferUploadCompleteEventResp : ProtocolEvent; |
| 173 | + |
| 174 | +internal class FlashTransferUpdateFileSetStatusEventReq(string fileSetId, uint status) : ProtocolEvent |
| 175 | +{ |
| 176 | + public string FileSetId { get; } = fileSetId; |
| 177 | + |
| 178 | + public uint Status { get; } = status; |
| 179 | +} |
| 180 | + |
| 181 | +internal class FlashTransferUpdateFileSetStatusEventResp : ProtocolEvent; |
0 commit comments