Example #1
0
        public async Task <IActionResult> OnPostAsync(CancellationToken cancellationToken)
        {
            var ip     = this.getIp.GetIp(this.Request);
            var ipHash = this.ipHasher.Hash(ip);

            var key = $"{nameof(this.Post)}.{nameof(this.Post.File)}";

            this.bannedImageLogger.Log(this.ModelState[key], ip, ipHash);

            var t = await this.threadService.GetThread(this.Post.ThreadId, Constants.PageSize, cancellationToken).ConfigureAwait(false);

            return(await t.Match(async thread =>
            {
                if (!this.ModelState.IsValid)
                {
                    this.IsAdmin = this.isAdmin.IsAdmin(this.HttpContext);
                    this.Thread = thread;
                    return this.Page().ToIAR();
                }
                else
                {
                    var trip = tripCodeHasher.Hash(StringFuncs.MapString(this.Post.Name, "anonymous"));
                    var options = OptionsMapper.Map(this.Post.Options);
                    var postId = Guid.NewGuid();
                    var f = uploadMapper.Map(this.Post.File, postId);
                    var result = await this.postService.Add(postId, this.Post.ThreadId, trip, this.Post.Comment, options.Sage,
                                                            ipHash, f, cancellationToken);
                    return result.Match(
                        _ =>
                    {
                        this.cookieStorage.SetNameCookie(this.Response, this.Post.Name);
                        if (options.NoNoko)
                        {
                            return this.RedirectToPage <BoardModel>(new { boardKey = thread.Board.BoardKey });
                        }
                        else
                        {
                            return this.RedirectToPage <ThreadModel>(new { boardKey = thread.Board.BoardKey, threadId = this.Post.ThreadId }).ToIAR();
                        }
                    },
                        _ => this.RedirectToPage <BannedModel>().ToIAR(),
                        _ =>
                    {
                        this.ModelState.AddModelError(string.Empty, "Image count exceeded");
                        return Page().ToIAR();
                    },
                        _ =>
                    {
                        this.ModelState.AddModelError(string.Empty, "Post count exceeded");
                        return Page().ToIAR();
                    });
                }
            }, () => this.NotFound().ToIART()));
        }
Example #2
0
        public async Task <IActionResult> OnPostAsync(string boardKey, string filter, CancellationToken cancellationToken, int pageNumber = 1)
        {
            var ip     = this.getIp.GetIp(this.Request);
            var ipHash = this.ipHasher.Hash(ip);

            this.bannedImageLogger.Log(this.ModelState[nameof(this.Thread.File)], ip, ipHash);

            var filterOption = NullableMapper.ToOption(filter);

            var t = await this.threadService.GetOrderedThreads(boardKey, filterOption, Constants.PageSize, pageNumber, cancellationToken);

            return(await t.Match(async threads =>
            {
                if (!ModelState.IsValid)
                {
                    this.Threads = threads;
                    return Page().ToIAR();
                }

                var threadId = Guid.NewGuid();
                var postId = Guid.NewGuid();
                var trip = tripCodeHasher.Hash(StringFuncs.MapString(this.Thread.Name, "anonymous"));
                var options = OptionsMapper.Map(this.Thread.Options);
                var f = uploadMapper.Map(this.Thread.File, postId);

                var result = await this.postService.AddThread(postId, threadId, this.Thread.BoardId, this.Thread.Subject ?? string.Empty, trip, this.Thread.Comment, options.Sage, ipHash, f, cancellationToken);

                return result.Match(
                    _ =>
                {
                    this.cookieStorage.SetNameCookie(this.Response, this.Thread.Name);
                    if (options.NoNoko)
                    {
                        return this.RedirectToPage <BoardModel>(new { boardKey = boardKey }).ToIAR();
                    }
                    else
                    {
                        return this.RedirectToPage <ThreadModel>(new { threadId = threadId }).ToIAR();
                    }
                },
                    _ => this.RedirectToPage <BannedModel>().ToIAR());
            }, () => this.NotFound().ToIART()));
        }