Ejemplo n.º 1
0
        [ProducesResponseType(404)]         // not found
        public IActionResult DownloadSidecar(string f)
        {
            if (!ExtensionRolesHelper.IsExtensionSidecar(f))
            {
                return(NotFound("FileName is not a sidecar"));
            }

            if (!_iStorage.ExistFile(f))
            {
                return(NotFound($"source image missing {f}"));
            }

            var fs = _iStorage.ReadStream(f);

            return(File(fs, MimeHelper.GetMimeTypeByFileName(f)));
        }
Ejemplo n.º 2
0
        [ProducesResponseType(206)]         // "Not Ready"
        public ActionResult Status(string f, bool json = false)
        {
            var(status, sourceFullPath) = _export.StatusIsReady(f);
            switch (status)
            {
            case null:
                return(NotFound("Path is not found"));

            case false:
                Response.StatusCode = 206;
                return(Json("Not Ready"));
            }

            if (json)
            {
                return(Json("OK"));
            }

            var fs = _hostFileSystemStorage.ReadStream(sourceFullPath);

            // Return the right mime type
            return(File(fs, MimeHelper.GetMimeTypeByFileName(sourceFullPath)));
        }
Ejemplo n.º 3
0
 public void GetMimeTypeByFileNameTest()
 {
     Assert.AreEqual("unknown/unknown", MimeHelper.GetMimeTypeByFileName("test.unknown"));
     Assert.AreEqual("image/jpeg", MimeHelper.GetMimeTypeByFileName("test.jpg"));
 }
Ejemplo n.º 4
0
        [ProducesResponseType(500)] // "Thumbnail generation failed"
        public async Task <IActionResult> DownloadPhoto(string f, bool isThumbnail = true, bool cache = true)
        {
            // f = subpath/filepath
            if (f.Contains("?isthumbnail"))
            {
                return(NotFound("please use &isthumbnail = " +
                                "instead of ?isthumbnail= "));
            }

            var fileIndexItem = await _query.GetObjectByFilePathAsync(f);

            if (fileIndexItem == null)
            {
                return(NotFound("not in index " + f));
            }

            if (!_iStorage.ExistFile(fileIndexItem.FilePath))
            {
                return(NotFound($"source image missing {fileIndexItem.FilePath}"));
            }

            // Return full image
            if (!isThumbnail)
            {
                if (cache)
                {
                    CacheControlOverwrite.SetExpiresResponseHeaders(Request);
                }
                var fileStream = _iStorage.ReadStream(fileIndexItem.FilePath);
                // Return the right mime type (enableRangeProcessing = needed for safari and mp4)
                return(File(fileStream, MimeHelper.GetMimeTypeByFileName(fileIndexItem.FilePath), true));
            }

            if (!_thumbnailStorage.ExistFolder("/"))
            {
                return(NotFound("ThumbnailTempFolder not found"));
            }

            var data = new ThumbnailSizesExistStatusModel {
                Small = _thumbnailStorage.ExistFile(
                    ThumbnailNameHelper.Combine(fileIndexItem.FileHash, ThumbnailSize.Small)),
                Large = _thumbnailStorage.ExistFile(
                    ThumbnailNameHelper.Combine(fileIndexItem.FileHash, ThumbnailSize.Large)),
                ExtraLarge = _thumbnailStorage.ExistFile(
                    ThumbnailNameHelper.Combine(fileIndexItem.FileHash, ThumbnailSize.ExtraLarge))
            };

            if (!data.Small || !data.Large || !data.ExtraLarge)
            {
                await new Thumbnail(_iStorage,
                                    _thumbnailStorage, _logger).CreateThumb(fileIndexItem.FilePath,
                                                                            fileIndexItem.FileHash);

                if (!_thumbnailStorage.ExistFile(
                        ThumbnailNameHelper.Combine(fileIndexItem.FileHash,
                                                    ThumbnailSize.Large)))
                {
                    Response.StatusCode = 500;
                    return(Json("Thumbnail generation failed"));
                }
            }

            var thumbnailFs = _thumbnailStorage.ReadStream(
                ThumbnailNameHelper.Combine(fileIndexItem.FileHash, ThumbnailSize.Large));

            return(File(thumbnailFs, "image/jpeg"));
        }