public async Task <IActionResult> Resolve([FromQuery] string uri) { if (string.IsNullOrEmpty(uri)) { return(this.ErrorResponse(4001)); } var result = await ImgAzyobuziNetService.Resolve(this.HttpContext.RequestServices, uri).ConfigureAwait(false); if (result == null) { return(this.ErrorResponse(4002)); } if (result.Exception != null) { return(this.HandleException(result.PatternProvider.ServiceId, result.Exception)); } return(JilJsonResult.Create(new { service_id = result.PatternProvider.ServiceId, service_name = result.PatternProvider.ServiceName, images = result.Images.ConvertAll(x => new { full = x.Full, large = x.Large, thumb = x.Thumb, video_full = x.VideoFull, video_large = x.VideoLarge, video_mobile = x.VideoMobile }) })); }
public async Task AllSizes() { var uri = this.Request.Query["uri"].FirstOrDefault(); if (string.IsNullOrEmpty(uri)) { this.ErrorResponse(4001); return; } var result = await ImgAzyobuziNetService.Resolve(this.HttpContext.RequestServices, uri).ConfigureAwait(false); if (result == null) { this.ErrorResponse(4002); return; } if (result.Exception != null) { this.HandleException(result.Exception); return; } if (result.Images.Count == 0) { this.ErrorResponse(4043); return; } var img = result.Images[0]; this.Json(new { service = result.PatternProvider.ServiceName, full = img.Full, full_https = img.Full, large = img.Large, large_https = img.Large, thumb = img.Thumb, thumb_https = img.Thumb, video = img.VideoFull, video_https = img.VideoFull }); }
public async Task Redirect() { var uri = this.Request.Query["uri"].FirstOrDefault(); if (string.IsNullOrEmpty(uri)) { this.ErrorResponse(4001); return; } var size = this.Request.Query["size"].FirstOrDefault(); switch (size) { case "full": case "large": case "thumb": case "video": break; case "": case null: size = "full"; break; default: this.ErrorResponse(4003); return; } var result = await ImgAzyobuziNetService.Resolve(this.HttpContext.RequestServices, uri).ConfigureAwait(false); if (result == null) { this.ErrorResponse(4002); return; } if (result.Exception != null) { this.HandleException(result.Exception); return; } if (result.Images.Count == 0) { this.ErrorResponse(4043); return; } var img = result.Images[0]; string location; switch (size) { case "full": location = img.Full; break; case "large": location = img.Large; break; case "thumb": location = img.Thumb; break; case "video": location = img.VideoFull; if (string.IsNullOrEmpty(location)) { this.ErrorResponse(4045); return; } goto RETURN; default: throw new Exception("unreachable"); } if (string.IsNullOrEmpty(location)) { this.ErrorResponse(4044); return; } RETURN: this.Response.StatusCode = 302; this.Response.GetTypedHeaders().Location = new Uri(location); }
public async Task <IActionResult> Redirect([FromQuery] string uri, [FromQuery] string size = "full") { if (string.IsNullOrEmpty(uri)) { return(this.ErrorResponse(4001)); } bool isVideo; switch (size) { case "full": case "large": case "thumb": isVideo = false; break; case "video_full": case "video_large": case "video_mobile": isVideo = true; break; case "": case null: size = "full"; isVideo = false; break; default: return(this.ErrorResponse(4003)); } var result = await ImgAzyobuziNetService.Resolve(this.HttpContext.RequestServices, uri).ConfigureAwait(false); if (result == null) { return(this.ErrorResponse(4002)); } if (result.Exception != null) { return(this.HandleException(result.PatternProvider.ServiceId, result.Exception)); } if (result.Images.Count == 0) { return(this.ErrorResponse(4043, result.PatternProvider.ServiceId)); } var img = result.Images[0]; string location; switch (size) { case "full": location = img.Full; break; case "large": location = img.Large; break; case "thumb": location = img.Thumb; break; case "video_full": location = img.VideoFull; break; case "video_large": location = img.VideoLarge; break; case "video_mobile": location = img.VideoMobile; break; default: throw new Exception("unreachable"); } if (string.IsNullOrEmpty(location)) { return(this.ErrorResponse(isVideo ? 4045 : 4044, result.PatternProvider.ServiceId)); } return(base.Redirect(location)); }