Пример #1
0
        public async Task <bool> ValidateSendFile(Send send)
        {
            var fileData = JsonSerializer.Deserialize <SendFileData>(send.Data);

            var(valid, realSize) = await _sendFileStorageService.ValidateFileAsync(send, fileData.Id, fileData.Size, _fileSizeLeeway);

            if (!valid || realSize > MAX_FILE_SIZE)
            {
                // File reported differs in size from that promised. Must be a rogue client. Delete Send
                await DeleteSendAsync(send);

                return(false);
            }

            // Update Send data if necessary
            if (realSize != fileData.Size)
            {
                fileData.Size = realSize.Value;
            }
            fileData.Validated = true;
            send.Data          = JsonSerializer.Serialize(fileData,
                                                          JsonHelpers.IgnoreWritingNull);
            await SaveSendAsync(send);

            return(valid);
        }
Пример #2
0
        public async Task <bool> ValidateSendFile(Send send)
        {
            var fileData = JsonConvert.DeserializeObject <SendFileData>(send.Data);

            var(valid, realSize) = await _sendFileStorageService.ValidateFileAsync(send, fileData.Id, fileData.Size, _fileSizeLeeway);

            if (!valid)
            {
                // File reported differs in size from that promised. Must be a rogue client. Delete Send
                await DeleteSendAsync(send);
            }

            // Update Send data if necessary
            if (realSize != fileData.Size)
            {
                fileData.Size = realSize.Value;
            }
            fileData.Validated = true;
            send.Data          = JsonConvert.SerializeObject(fileData,
                                                             new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });
            await SaveSendAsync(send);

            return(valid);
        }