79 lines
2.5 KiB
C#
79 lines
2.5 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 KART_API.Services;
|
|
using KART_API.Utils;
|
|
using KART_API.Dto;
|
|
|
|
namespace KART_API.Controllers
|
|
{
|
|
[Route("api/v2/uri")]
|
|
[ApiController]
|
|
public class UriController : 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;
|
|
}
|
|
|
|
projectCodeInfo projectCodeInfo = new projectCodeInfo(skey);
|
|
ProjectService project = new ProjectService();
|
|
DataTable proejctInfo = project.getProjectInfo(projectCodeInfo.projectCode);
|
|
|
|
if(proejctInfo.Rows.Count > 0)
|
|
{
|
|
int mode = shortURLParam.Mode == "P" ? 1 : 0;
|
|
string returnString = "https://kart.kric.com/External/" + URIService.GetURIKey(shortURLParam.RealURI, mode, skey, proejctInfo.Rows[0]["IN_TT"].ToString(), okey);
|
|
string cLogContent = "{ \"REAL_URI\": \"" + shortURLParam.RealURI + "\",\"MODE\": \"" + shortURLParam.Mode + "\", \"COPY_URI\": \"" + returnString + "\" }";
|
|
LogService.InsertSiteLog(userInfo.ID, projectCodeInfo.projectCode, "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 = URIService.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);
|
|
}
|
|
}
|
|
}
|