78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Data;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Web;
|
|
using REPORT_API_ver6.Services;
|
|
using REPORT_API_ver6.Models;
|
|
|
|
namespace REPORT_API_ver6.Controllers
|
|
{
|
|
[Route("api/v1/uri")]
|
|
[ApiController]
|
|
public class UriAPI : ControllerBase
|
|
{
|
|
|
|
[Route("short")]
|
|
[HttpPost]
|
|
public IActionResult ShortURL([FromHeader] string token, [FromBody] ShortURLParam shortURLParam, [FromHeader] string skey)
|
|
{
|
|
HttpContextAccessor hcAccessor = new HttpContextAccessor();
|
|
hcAccessor.HttpContext.Response.ContentType = "text/plain";
|
|
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null)
|
|
{
|
|
string okey = "REPORT";
|
|
if(userInfo.ID == "KON" || userInfo.ID == "KIWI" || userInfo.ID == "NEWSSAK")
|
|
{
|
|
okey = userInfo.ID;
|
|
}
|
|
|
|
PkeyInfo pkeyInfo = new PkeyInfo(skey);
|
|
Project project = new Project();
|
|
DataTable proejctInfo = project.getProjectInfo(pkeyInfo.Pkey, pkeyInfo.isKiwi);
|
|
|
|
if(proejctInfo.Rows.Count > 0)
|
|
{
|
|
int mode = shortURLParam.Mode == "P" ? 1 : 0;
|
|
string returnString = "https://kart.kric.com/External/" + URI.GetURIKey(shortURLParam.RealURI, mode, skey, proejctInfo.Rows[0]["title"].ToString(), okey);
|
|
string cLogContent = "{ \"REAL_URI\": \"" + shortURLParam.RealURI + "\",\"MODE\": \"" + shortURLParam.Mode + "\", \"COPY_URI\": \"" + returnString + "\" }";
|
|
Log.InsertSiteLog(userInfo.ID, pkeyInfo.Pkey, "URL Copy", cLogContent);
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return Content(returnString);
|
|
}
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
|
|
[Route("short/{urikey}")]
|
|
[HttpGet]
|
|
public IActionResult ShortURL([FromHeader] string token, string urikey)
|
|
{
|
|
HttpContextAccessor hcAccessor = new HttpContextAccessor();
|
|
hcAccessor.HttpContext.Response.ContentType = "application/json";
|
|
|
|
UserInfo userInfo = Security.ValidateToken(token);
|
|
if (userInfo != null)
|
|
{
|
|
DataTable realUritable = URI.GetRealURL(urikey, true);
|
|
if (realUritable.Rows.Count > 0)
|
|
{
|
|
Response.StatusCode = (int)HttpStatusCode.OK;
|
|
return Content(Common.GetJsonFromObject(realUritable));
|
|
}
|
|
}
|
|
|
|
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
|
return Content(null);
|
|
}
|
|
}
|
|
}
|