public async Task LoadBuffer(IChannel channel, UploadPartCommand command) { if (!_uploadPool.ContainsKey(channel)) { throw new InvalidOperationException("尚未准备完毕"); } if (string.IsNullOrEmpty(command.Base64Buffer)) { throw new InvalidOperationException("数据为空"); } byte[] buffy = Convert.FromBase64String(command.Base64Buffer); IFileModel uploadVideoModel = _uploadPool[channel]; if (uploadVideoModel == null) { throw new InvalidOperationException("不存在该文件"); } uploadVideoModel.LoadBuffer(buffy, command.Index); if (uploadVideoModel.CanComplete) { (string _, string path, long _) = await new UploadAccessory().SaveAccessoryAsync(uploadVideoModel.FileContent, $"{AppDomain.CurrentDomain.BaseDirectory}//Backup", uploadVideoModel.FileName, false); await UpdateWebFileAsync(path, channel); new HttpHandler().ClearCache(); var @event = new UploadEndEvent(); await channel.SendJsonEventAsync(@event); _uploadPool.Remove(channel); } else { var @event = new UploadReadyEvent(); await channel.SendJsonEventAsync(@event); } }
public async Task NewUpload(IChannel channel, UploadStartCommand command) { int uploadingFileCount = _uploadPool.Count(m => m.Value.FileAbstract.Equals(command.Abstract)); if (uploadingFileCount > 0) { throw new InvalidOperationException("该文件正在上传"); } string fileName = Path.Combine(workingDirectory, command.Name); if (File.Exists(fileName)) { File.Delete(fileName); } IFileModel fileModel = new MemoryFileModel { FileAbstract = command.Abstract, FileName = command.Name, Size = command.Size }; _uploadPool.Add(channel, fileModel); var @event = new UploadReadyEvent(); await channel.SendJsonEventAsync(@event); }