public async Task <IActionResult> OnPostAsync(Guid id, CancellationToken cancellationToken) { EnsureArg.IsNotEmpty(id, nameof(id)); var f = await this.fileService.GetPostFile(id, cancellationToken); return(await f.Match(async some => { var hash = ImageHasher.Hash(some.Data); await fileService.BanImage(hash, Reason, cancellationToken); return this.RedirectToPage <IndexModel>().ToIAR(); }, () => this.NotFound().ToIART())); }
/// <summary> /// CONSTRUCTOR /// </summary> /// <param name="PathToOriginal"></param> public ReportImage(string PathToOriginal, ReportImageStateEnum reportsSupported) { this.PathToOriginal = PathToOriginal; this.ImageReportState = reportsSupported; if (filePaths.ContainsKey(PathToOriginal)) { OriginalHash = filePaths[PathToOriginal]; } else { byte[] bytes = File.ReadAllBytes(PathToOriginal); OriginalHash = ImageHasher.Hash(bytes); filePaths.Add(PathToOriginal, OriginalHash); } }
Task <ResType> IValidateImage.ValidateAsync(Option <byte[]> data) { return(data.Match(async some => { if (some.Length > ImageMaxSize) { return (ResType) new SizeExceeded(ImageMaxSize); } var hash = ImageHasher.Hash(some); if (await this.bannedImages.IsBanned(hash, CancellationToken.None)) { return new BannedImage(); } return new Pass(); }, () => Task.FromResult <ResType>(new Pass()))); }