public async Task <ActionResult <int> > Decode(string id) { return(await Task.Run(() => { using UrlShorten _urlShorten = new UrlShorten(); return _urlShorten.Decode(id); })); }
public UrlShorten GenerateUrlShortenObject(string url, string token) { var newObject = new UrlShorten() { LongUrl = url, Token = token, ShortenedUrl = BASE_URL + token }; return(newObject); }
public async Task <ActionResult <string> > Shorten([FromBody] dynamic kurl) { //_logger.LogInformation("Url shortened from original " + url); return(await Task.Run(() => { try { var options = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true }; //use non-standard port for debugging var debugPort = _config["debugport:port"]; //Rick Grimes says- kurl! gimme that knife! we're still hurr..thAts whut matters //create a URL knife object var knife = JsonSerializer.Deserialize <UrlKnife>(kurl.ToString(), options); if (!Uri.TryCreate(knife.normalizedUrl, UriKind.Absolute, out Uri uri) || null == uri) { return "invalid url (e.g. http://mydomain.com/index.html)"; } var url = (uri.Host + uri.PathAndQuery + uri.Fragment).TrimEnd('/'); using UrlShorten _urlShorten = new UrlShorten(url); var urlBase = !String.IsNullOrEmpty(debugPort) ? "https://localhost:" + debugPort + "/" : "https://localhost/"; return urlBase + _urlShorten.ShortenedUrl; } catch (Exception ex) { return "error processing url please try again."; } })); }
public bool CreateUrlShorten(UrlShorten objectToBeCreated) { _urlContext.Add(objectToBeCreated); return(Save()); }