Exemplo n.º 1
0
        public async Task <WebResult> Post([FromBody] BaseDanmuDataIn data)
        {
            if (string.IsNullOrWhiteSpace(data.Id) || string.IsNullOrWhiteSpace(data.Text))
            {
                return(new WebResult(1));
            }
            data.Ip = IPAddress.TryParse(Request.Headers["X-Real-IP"], out var ip)
                    ? ip
                    : Request.HttpContext.Connection.RemoteIpAddress;
            data.Referer ??= Request.Headers["Referer"].FirstOrDefault();
            var video = await VideoDao.InsertAsync(data.Id, new Uri(data.Referer));

            var danmu = new DanmuTable
            {
                Vid   = data.Id,
                Data  = data,
                Ip    = data.Ip,
                Video = video
            };
            var result = await DanmuDao.InsertDanmuAsync(danmu);

            return(new WebResult(result ? 0 : 1));
        }