| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using molilian.core;
- using dodohold.core;
- using Microsoft.AspNetCore.Mvc;
- using System.Text.Json;
- using TencentCloud.Ecm.V20190719.Models;
- using YunhuiKit;
- namespace molilian.api.Controllers
- {
- [ApiController]
- [Route("[controller]/[action]")]
- public class TracksController : ControllerBase
- {
- protected IHttpContextAccessor _accessor;
- public TracksController(IHttpContextAccessor accessor)
- {
- _accessor = accessor;
- }
- [HttpGet]
- public ActionResult Track([FromQuery] string eventType, [FromQuery] string platform, [FromQuery] string scene, [FromQuery] string uniqueId = "")
- {
- if (string.IsNullOrEmpty(platform) || string.IsNullOrEmpty(scene) || string.IsNullOrEmpty(eventType))
- {
- return new APIResult(new { success = false, message = "miss" });
- }
- _ = TracksCore.CreateLinkAsync(eventType, platform, scene, uniqueId);
- _ = TracksCore.TrackAsync(eventType, platform, scene, uniqueId);
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpPost]
- public async Task<ActionResult> Create([FromQuery] string eventType, [FromQuery] string platform, [FromQuery] string scene, [FromQuery] string uniqueId = "")
- {
- var link = await TracksCore.CreateLinkAsync(eventType, platform, scene, uniqueId);
- if (link == null)
- {
- return new APIResult(new { success = false, message = "invalid params or eventType" });
- }
- //var request = _accessor.HttpContext!.Request;
- //string url = $"{request.Scheme}://{request.Host}{link.path}";
- return new APIResult(new { success = true, message = "ok", url = link.path });
- }
- [HttpGet]
- public async Task<ActionResult> Daily([FromQuery] int daysAgo = 1, [FromQuery] string reportDate = "")
- {
- DateTime date;
- if (!string.IsNullOrWhiteSpace(reportDate) && DateTime.TryParse(reportDate, out var parsed))
- {
- date = parsed.Date;
- }
- else
- {
- if (daysAgo <= 0) daysAgo = 1;
- date = DateTime.Now.AddDays(-daysAgo).Date;
- }
- int rows = await TracksCore.FlushDailyAsync(date);
- return new APIResult(new { success = true, message = "ok", rows });
- }
- }
- }
|