private InfoResult FinishResolve(InfoResult r, int?userId, bool?autowatch)
 {
     if (r.File == null)
     {
         r.Status            = HttpStatusCode.NotFound;
         r.StatusDescription = "Video Not Found";
         return(r);
     }
     if (userId.HasValue && autowatch.HasValue && userId.Value != 0)
     {
         r.User = RepoFactory.JMMUser.GetByID(userId.Value);
         if (r.User == null)
         {
             r.Status            = HttpStatusCode.NotFound;
             r.StatusDescription = "User Not Found";
             return(r);
         }
     }
     r.Mime = r.File.ContentType;
     if (string.IsNullOrEmpty(r.Mime) || r.Mime.Equals("application/octet-stream",
                                                       StringComparison.InvariantCultureIgnoreCase))
     {
         r.Mime = Mime.GetMimeMapping(r.File.FullName);
     }
     r.Status = HttpStatusCode.OK;
     return(r);
 }
Example #2
0
        public ActionResult GetImage(string source, string type, string value)
        {
            ImageEntityType sourceType;

            try
            {
                sourceType = Image.GetImageTypeFromSourceAndType(source, type);
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }

            if (sourceType == ImageEntityType.Static)
            {
                return(GetStaticImage(value));
            }

            if (!int.TryParse(value, out int id))
            {
                return(BadRequest("The 'value' must be an integer ID for all types except 'Static'"));
            }

            string path = Image.GetImagePath(sourceType, id);

            if (string.IsNullOrEmpty(path))
            {
                return(NotFound("The image was not found"));
            }
            return(File(System.IO.File.OpenRead(path), Mime.GetMimeMapping(path)));
        }
Example #3
0
        public ActionResult GetImage([FromRoute] Image.ImageSource source, [FromRoute] Image.ImageType type, [FromRoute] string value)
        {
            var sourceType = Image.GetImageTypeFromSourceAndType(source, type) ?? ImageEntityType.None;

            if (sourceType == ImageEntityType.None)
            {
                return(NotFound("The requested resource does not exist."));
            }

            if (sourceType == ImageEntityType.Static)
            {
                return(GetStaticImage(value));
            }

            if (!int.TryParse(value, out int id))
            {
                return(NotFound("The requested resource does not exist."));
            }

            string path = Image.GetImagePath(sourceType, id);

            if (string.IsNullOrEmpty(path))
            {
                return(NotFound("The requested resource does not exist."));
            }
            return(File(System.IO.File.OpenRead(path), Mime.GetMimeMapping(path)));
        }
Example #4
0
        public FileResult GetThumb(int type, int id, string ratio = "0")
        {
            string contentType;

            ratio = ratio.Replace(',', '.');
            if (!float.TryParse(ratio, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-EN"), out float newratio))
            {
                newratio = 0.6667f;
            }

            string path = GetImagePath(type, id, false);

            if (string.IsNullOrEmpty(path))
            {
                Response.StatusCode = 404;
                return(File(MissingImage(), "image/png"));
            }
            else
            {
                FileStream fs = System.IO.File.OpenRead(path);
                contentType = Mime.GetMimeMapping(path);
                System.Drawing.Image im = System.Drawing.Image.FromStream(fs);
                return(File(ResizeImageToRatio(im, newratio), contentType));
            }
        }
Example #5
0
        public object GetImageUsingPath(string serverImagePath)
        {
            if (!System.IO.File.Exists(serverImagePath))
            {
                logger.Trace("Could not find AniDB_Cover image: {0}", serverImagePath);
                return(NotFound());
            }

            Response.ContentType = Mime.GetMimeMapping(serverImagePath);
            return(System.IO.File.OpenRead(serverImagePath));
        }
Example #6
0
        public FileResult GetImage(int type, int id)
        {
            string path = GetImagePath(type, id);

            if (string.IsNullOrEmpty(path))
            {
                Response.StatusCode = 404;
                return(File(MissingImage(), "image/png"));
            }

            return(File(System.IO.File.OpenRead(path), Mime.GetMimeMapping(path)));
        }
Example #7
0
        public object GetImage(int imageid, int imageType, bool?thumnbnailOnly = false)
        {
            string path = GetImagePath(imageid, imageType, thumnbnailOnly);

            if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path))
            {
                return(NotFound());
            }
            string mime = Mime.GetMimeMapping(path);

            Response.ContentType = mime;
            return(System.IO.File.OpenRead(path));
        }
        public Stream GetImage(int imageid, int imageType, bool?thumnbnailOnly = false)
        {
            string path = GetImagePath(imageid, imageType, thumnbnailOnly);

            if (string.IsNullOrEmpty(path) || !System.IO.File.Exists(path))
            {
                return(new StreamWithResponse(HttpStatusCode.NotFound));
            }
            string mime = Mime.GetMimeMapping(path);

            Response.ContentType = mime;
            return(new StreamWithResponse(System.IO.File.OpenRead(path), mime));
        }
Example #9
0
        public ActionResult GetStaticImage(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(NotFound("The requested resource does not exist."));
            }

            var fileName = Path.GetFileNameWithoutExtension(filePath);
            var buffer   = (byte[])Resources.ResourceManager.GetObject(fileName);

            if ((buffer == null) || (buffer.Length == 0))
            {
                return(NotFound("The requested resource does not exist."));
            }

            return(File(buffer, Mime.GetMimeMapping(fileName) ?? "image/png"));
        }
Example #10
0
 private InfoResult FinishResolve(InfoResult r, int?userId, bool?autowatch)
 {
     if (r.File == null)
     {
         r.Status            = HttpStatusCode.NotFound;
         r.StatusDescription = "Video Not Found";
         return(r);
     }
     if (userId.HasValue && autowatch.HasValue && userId.Value != 0)
     {
         r.User = RepoFactory.JMMUser.GetByID(userId.Value);
         if (r.User == null)
         {
             r.Status            = HttpStatusCode.NotFound;
             r.StatusDescription = "User Not Found";
             return(r);
         }
     }
     r.Mime   = Mime.GetMimeMapping(r.File.FullName);
     r.Status = HttpStatusCode.OK;
     return(r);
 }
 public Stream GetImageUsingPath(string serverImagePath)
 {
     if (System.IO.File.Exists(serverImagePath))
     {
         return(new StreamWithResponse(System.IO.File.OpenRead(serverImagePath), Mime.GetMimeMapping(serverImagePath)));
     }
     logger.Trace("Could not find AniDB_Cover image: {0}", serverImagePath);
     return(new StreamWithResponse(HttpStatusCode.NotFound));
 }