Ejemplo n.º 1
0
        public ActionResult Index()
        {
            Image img = wallpaperCache;

            if (img == null)
            {
                UpdateWallpaperCache();
            }
            img = wallpaperCache;
            if (img == null)
            {
                return(StatusCode("404 Not Found"));
            }
            else if (!string.IsNullOrWhiteSpace(img.hsh) && Context.httpProcessor.GetHeaderValue("If-None-Match") == img.hsh)
            {
                return(StatusCode("304 Not Modified"));
            }
            else
            {
                ActionResult result = new JpegImageResult(img.ext_ImageData);

                if (!string.IsNullOrWhiteSpace(img.hsh))
                {
                    result.AddOrUpdateHeader("ETag", img.hsh);
                }

                result.AddOrUpdateHeader("Copyright", img.copyright);
                result.AddOrUpdateHeader("Link", img.copyrightlink);
                result.AddOrUpdateHeader("Title", img.title);

                return(result);
            }
        }
Ejemplo n.º 2
0
        public ActionResult Index(params string[] args)
        {
            if (args.Length == 0)
            {
                return(Error("Bad Request", "400 Bad Request"));
            }

            CameraSpec cs = TimelapseWrapper.cfg.GetCameraSpec(args[0]);

            if (cs == null || !cs.enabled)
            {
                return(Error("Camera Not Found", "404 Not Found"));
            }

            if (!IpWhitelist.IsWhitelisted(Context.httpProcessor.RemoteIPAddressStr, cs.ipWhitelist))
            {
                return(Error("Forbidden", "403 Forbidden"));
            }

            string latestImagePathPart;

            try
            {
                latestImagePathPart = Navigation.GetLatestImagePath(cs, out string latestImgTime, out DateTime dateTime);
            }
            catch (NavigationException)
            {
                return(Error("Service Unavailable", "503 Service Unavailable"));
            }

            string path = cs.id + "/" + latestImagePathPart;

            if (path == Context.httpProcessor.GetHeaderValue("if-none-match"))
            {
                return new StatusCodeResult("304 Not Modified")
                       {
                           ContentType = "image/jpeg"
                       }
            }
            ;
            byte[]          data   = WebServerUtil.GetImageData(path);
            JpegImageResult result = new JpegImageResult(data);

            List <KeyValuePair <string, string> > headers = WebServerUtil.GetCacheEtagHeaders(TimeSpan.Zero, path);
            FileInfo imgFile = new FileInfo(TimelapseGlobals.ImageArchiveDirectoryBase + path);

            headers.Add(new KeyValuePair <string, string>("Content-Disposition", "inline; filename=\"" + cs.name + " " + imgFile.Name.Substring(0, imgFile.Name.Length - imgFile.Extension.Length) + ".jpg\""));
            headers.ForEach(h => result.AddOrUpdateHeader(h.Key, h.Value));

            return(result);
        }