예제 #1
0
        /// <summary>
        /// When the file is not supported or does not exist return status
        /// </summary>
        /// <param name="subPath">relative path</param>
        /// <returns>item with status</returns>
        private FileIndexItem CheckForStatusNotOk(string subPath)
        {
            var statusItem = new FileIndexItem(subPath)
            {
                Status = FileIndexItem.ExifStatus.Ok
            };

            // File extension is not supported
            if (!ExtensionRolesHelper.IsExtensionSyncSupported(subPath))
            {
                statusItem.Status = FileIndexItem.ExifStatus.OperationNotSupported;
                return(statusItem);
            }

            // File check if jpg #not corrupt
            var imageFormat = ExtensionRolesHelper.GetImageFormat(_subPathStorage.ReadStream(subPath, 160));

            if (imageFormat == ExtensionRolesHelper.ImageFormat.notfound)
            {
                statusItem.Status = FileIndexItem.ExifStatus.NotFoundSourceMissing;
                return(statusItem);
            }

            // ReSharper disable once InvertIf
            if (!ExtensionRolesHelper.ExtensionSyncSupportedList.Contains(imageFormat.ToString()))
            {
                statusItem.Status = FileIndexItem.ExifStatus.OperationNotSupported;
                return(statusItem);
            }
            return(statusItem);
        }
예제 #2
0
        public void GetImageFormat_QuickTimeMp4_Test()
        {
            var newImage = CreateAnQuickTimeMp4.Bytes.Take(15).ToArray();
            var result   = ExtensionRolesHelper.GetImageFormat(newImage);

            Assert.AreEqual(ExtensionRolesHelper.ImageFormat.mp4, result);
        }
예제 #3
0
        public void Files_GetImageFormat_gif_Test()
        {
            byte[] bmBytes  = Encoding.ASCII.GetBytes("GIF");
            var    fileType = ExtensionRolesHelper.GetImageFormat(bmBytes);

            Assert.AreEqual(fileType, ExtensionRolesHelper.ImageFormat.gif);
        }
예제 #4
0
        // used by the html generator
        public List <FileIndexItem> ReadExifAndXmpFromFileAddFilePathHash(List <string> subPathList, List <string> fileHashes = null)
        {
            var fileIndexList = new List <FileIndexItem>();

            for (int i = 0; i < subPathList.Count; i++)
            {
                var subPath = subPathList[i];

                var returnItem  = ReadExifAndXmpFromFile(subPath);
                var imageFormat = ExtensionRolesHelper.GetImageFormat(_iStorage.ReadStream(subPath, 50));

                returnItem.ImageFormat     = imageFormat;
                returnItem.FileName        = Path.GetFileName(subPath);
                returnItem.IsDirectory     = false;
                returnItem.Status          = FileIndexItem.ExifStatus.Ok;
                returnItem.ParentDirectory = FilenamesHelper.GetParentPath(subPath);

                if (fileHashes == null || fileHashes.Count <= i)
                {
                    returnItem.FileHash = new FileHash(_iStorage).GetHashCode(subPath).Key;
                }
                else
                {
                    returnItem.FileHash = fileHashes[i];
                }

                fileIndexList.Add(returnItem);
            }
            return(fileIndexList);
        }
예제 #5
0
        public void Files_GetImageFormat_xmp_Test()
        {
            byte[] bmBytes  = Encoding.ASCII.GetBytes("<x:xmpmeta");
            var    fileType = ExtensionRolesHelper.GetImageFormat(bmBytes);

            Assert.AreEqual(fileType, ExtensionRolesHelper.ImageFormat.xmp);
        }
예제 #6
0
        public void GetImageFormat_Jpeg_Test()
        {
            var newImage = CreateAnImage.Bytes.Take(15).ToArray();
            var result   = ExtensionRolesHelper.GetImageFormat(newImage);

            Assert.AreEqual(ExtensionRolesHelper.ImageFormat.jpg, result);
        }
예제 #7
0
        private IActionResult ReturnThumbnailResult(string f, bool json, ThumbnailSize size)
        {
            Response.Headers.Add("x-image-size", new StringValues(size.ToString()));
            var stream      = _thumbnailStorage.ReadStream(ThumbnailNameHelper.Combine(f, size), 50);
            var imageFormat = ExtensionRolesHelper.GetImageFormat(stream);

            if (imageFormat == ExtensionRolesHelper.ImageFormat.unknown)
            {
                SetExpiresResponseHeadersToZero();
                return(NoContent());                // 204
            }

            // When using the api to check using javascript
            // use the cached version of imageFormat, otherwise you have to check if it deleted
            if (json)
            {
                return(Json("OK"));
            }

            stream = _thumbnailStorage.ReadStream(
                ThumbnailNameHelper.Combine(f, size));

            // thumbs are always in jpeg
            Response.Headers.Add("x-filename", new StringValues(FilenamesHelper.GetFileName(f + ".jpg")));
            return(File(stream, "image/jpeg"));
        }
예제 #8
0
        public void Gpx_WithXmlNoPrefix()
        {
            var gpxExample = Encoding.ASCII.GetBytes("<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:gpxx=\"h");

            var result = ExtensionRolesHelper.GetImageFormat(gpxExample);

            Assert.AreEqual(ExtensionRolesHelper.ImageFormat.gpx, result);
        }
예제 #9
0
        public void Gpx_Stream_WithXmlPrefix()
        {
            var gpxExample = Encoding.ASCII.GetBytes(
                "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><gpx version=\"1.1\" creator=\"Trails 4.06 - https://www.trails.io\"");
            var ms     = new MemoryStream(gpxExample);
            var result = ExtensionRolesHelper.GetImageFormat(ms);

            Assert.AreEqual(ExtensionRolesHelper.ImageFormat.gpx, result);
        }
예제 #10
0
        public Task <List <ImportIndexItem> > Preflight(List <string> inputFileFullPaths, ImportSettingsModel importSettings)
        {
            var results = new List <ImportIndexItem>();

            foreach (var inputFileFullPath in inputFileFullPaths)
            {
                // if the item fails
                var importIndexFileError = new ImportIndexItem {
                    FilePath           = "/" + FilenamesHelper.GetFileName(inputFileFullPath),
                    SourceFullFilePath = "~/temp/test",
                    FileHash           = "FAKE",
                    MakeModel          = "added if the item fails",
                    Status             = ImportStatus.FileError
                };

                // Check if extension is correct
                if (!ExtensionRolesHelper.IsExtensionSyncSupported(inputFileFullPath))
                {
                    results.Add(importIndexFileError);
                }

                // Check if the file is correct
                var imageFormat = ExtensionRolesHelper.GetImageFormat(
                    _selectorStorage.Get(SelectorStorage.StorageServices.HostFilesystem)
                    .ReadStream(inputFileFullPath, 160));

                if (!ExtensionRolesHelper.ExtensionSyncSupportedList.Contains($"{imageFormat}"))
                {
                    results.Add(importIndexFileError);
                }

                results.Add(new ImportIndexItem
                {
                    Id = 4,
                    SourceFullFilePath = inputFileFullPath,
                    FilePath           = inputFileFullPath,
                    Status             = ImportStatus.Ok,
                    FileHash           = "FAKE",
                    MakeModel          = "added okay",
                    FileIndexItem      = new FileIndexItem()
                    {
                        FileHash = "FAKE_OK", FilePath = inputFileFullPath
                    }
                });
            }
            PreflightList.AddRange(results);
            return(Task.FromResult(results));
        }
예제 #11
0
파일: Thumbnail.cs 프로젝트: qdraw/starsky
        /// <summary>
        /// Check if the image has the right first bytes, if not remove
        /// </summary>
        /// <param name="fileHash">the fileHash file</param>
        /// <param name="thumbnailToSourceSize">size of output thumbnail Large/ExtraLarge</param>
        internal bool RemoveCorruptImage(string fileHash,
                                         ThumbnailSize thumbnailToSourceSize)
        {
            if (!_thumbnailStorage.ExistFile(ThumbnailNameHelper.Combine(fileHash, thumbnailToSourceSize)))
            {
                return(false);
            }
            var imageFormat = ExtensionRolesHelper.GetImageFormat(_thumbnailStorage.ReadStream(
                                                                      ThumbnailNameHelper.Combine(fileHash, thumbnailToSourceSize), 160));

            if (imageFormat != ExtensionRolesHelper.ImageFormat.unknown)
            {
                return(false);
            }
            _thumbnailStorage.FileDelete(ThumbnailNameHelper.Combine(fileHash, thumbnailToSourceSize));
            return(true);
        }
예제 #12
0
파일: NewItem.cs 프로젝트: qdraw/starsky
        /// <summary>
        /// Prepare an new item (no update in db)
        /// </summary>
        /// <param name="filePath">path of file</param>
        /// <param name="fileHash">optional could be null</param>
        /// <param name="parentDirectory">parent directory name</param>
        /// <param name="fileName">name without path</param>
        /// <returns></returns>
        public async Task <FileIndexItem> NewFileItem(string filePath, string fileHash, string parentDirectory, string fileName)
        {
            var updatedDatabaseItem = _readMeta.ReadExifAndXmpFromFile(filePath);

            updatedDatabaseItem.ImageFormat = ExtensionRolesHelper
                                              .GetImageFormat(_subPathStorage.ReadStream(filePath, 50));

            // future: read json sidecar
            await SetFileHashStatus(filePath, fileHash, updatedDatabaseItem);

            updatedDatabaseItem.SetAddToDatabase();
            updatedDatabaseItem.SetLastEdited();
            updatedDatabaseItem.IsDirectory     = false;
            updatedDatabaseItem.Size            = _subPathStorage.Info(filePath).Size;
            updatedDatabaseItem.ParentDirectory = parentDirectory;
            updatedDatabaseItem.FileName        = fileName;
            return(updatedDatabaseItem);
        }
예제 #13
0
        /// <summary>
        /// Resize image with overlay
        /// </summary>
        /// <param name="outputPath">absolute path of output on host disk</param>
        /// <param name="profile">size of output, overlay size, must contain metaData </param>
        /// <param name="item">database item with filePath</param>
        /// <returns>true when success</returns>
        /// <exception cref="DecodingException">when output is not valid</exception>
        private async Task <bool> Resizer(string outputPath, AppSettingsPublishProfiles profile,
                                          FileIndexItem item)
        {
            // for less than 1000px
            if (profile.SourceMaxWidth <= 1000 && _thumbnailStorage.ExistFile(ThumbnailNameHelper.
                                                                              Combine(item.FileHash, ThumbnailSize.Large)))
            {
                await _overlayImage.ResizeOverlayImageThumbnails(item.FileHash, outputPath, profile);
            }
            else if (profile.SourceMaxWidth <= 2000 && _thumbnailStorage.ExistFile(ThumbnailNameHelper.
                                                                                   Combine(item.FileHash, ThumbnailSize.ExtraLarge)))
            {
                await _overlayImage.ResizeOverlayImageThumbnails(
                    ThumbnailNameHelper.Combine(item.FileHash, ThumbnailSize.ExtraLarge), outputPath, profile);
            }
            else if (_subPathStorage.ExistFile(item.FilePath))
            {
                // Thumbs are 2000 px (and larger)
                await _overlayImage.ResizeOverlayImageLarge(item.FilePath, outputPath, profile);
            }

            if (profile.MetaData)
            {
                await MetaData(item, outputPath);
            }

            var imageFormat = ExtensionRolesHelper.GetImageFormat(_hostFileSystemStorage.ReadStream(outputPath, 160));

            if (imageFormat == ExtensionRolesHelper.ImageFormat.jpg)
            {
                return(true);
            }

            _hostFileSystemStorage.FileDelete(outputPath);

            throw new DecodingException("[WebHtmlPublishService] image output is not valid");
        }
예제 #14
0
        public void Files_GetImageFormat_png_Test()
        {
            var fileType = ExtensionRolesHelper.GetImageFormat(new byte[] { 137, 80, 78, 71 });

            Assert.AreEqual(fileType, ExtensionRolesHelper.ImageFormat.png);
        }
예제 #15
0
        public void Files_GetImageFormat_h264_Test()
        {
            var fileType = ExtensionRolesHelper.GetImageFormat(new byte[] { 00, 00, 00, 20, 102, 116, 121, 112 });

            Assert.AreEqual(ExtensionRolesHelper.ImageFormat.mp4, fileType);
        }
예제 #16
0
        public void Gpx_CreateAnGpx()
        {
            var result = ExtensionRolesHelper.GetImageFormat(CreateAnGpx.Bytes);

            Assert.AreEqual(ExtensionRolesHelper.ImageFormat.gpx, result);
        }
예제 #17
0
 public void GetImageFormat_NotFound()
 {
     Assert.AreEqual(ExtensionRolesHelper.ImageFormat.notfound,
                     ExtensionRolesHelper.GetImageFormat(Stream.Null));
 }
예제 #18
0
        public void Files_GetImageFormat_corrupt_Test()
        {
            var fileType = ExtensionRolesHelper.GetImageFormat(new CreateAnImageCorrupt().Bytes);

            Assert.AreEqual(fileType, ExtensionRolesHelper.ImageFormat.unknown);
        }
예제 #19
0
        public void Files_GetImageFormat_tiff2_Test()
        {
            var fileType = ExtensionRolesHelper.GetImageFormat(new byte[] { 77, 77, 42 });

            Assert.AreEqual(fileType, ExtensionRolesHelper.ImageFormat.tiff);
        }
예제 #20
0
파일: Import.cs 프로젝트: qdraw/starsky
        internal async Task <ImportIndexItem> PreflightPerFile(KeyValuePair <string, bool> inputFileFullPath,
                                                               ImportSettingsModel importSettings)
        {
            if (_appSettings.ImportIgnore.Any(p => inputFileFullPath.Key.Contains(p)))
            {
                if (_appSettings.IsVerbose())
                {
                    _console.WriteLine($"❌ skip due rules: {inputFileFullPath.Key} ");
                }
                return(new ImportIndexItem {
                    Status = ImportStatus.Ignore,
                    FilePath = inputFileFullPath.Key,
                    SourceFullFilePath = inputFileFullPath.Key,
                    AddToDatabase = DateTime.UtcNow
                });
            }

            if (!inputFileFullPath.Value || !_filesystemStorage.ExistFile(inputFileFullPath.Key))
            {
                if (_appSettings.IsVerbose())
                {
                    _console.WriteLine($"❌ not found: {inputFileFullPath.Key}");
                }
                return(new ImportIndexItem {
                    Status = ImportStatus.NotFound,
                    FilePath = inputFileFullPath.Key,
                    SourceFullFilePath = inputFileFullPath.Key,
                    AddToDatabase = DateTime.UtcNow
                });
            }

            var imageFormat = ExtensionRolesHelper.GetImageFormat(
                _filesystemStorage.ReadStream(inputFileFullPath.Key,
                                              160));

            // Check if extension is correct && Check if the file is correct
            if (!ExtensionRolesHelper.IsExtensionSyncSupported(inputFileFullPath.Key) ||
                !ExtensionRolesHelper.IsExtensionSyncSupported($".{imageFormat}"))
            {
                if (_appSettings.IsVerbose())
                {
                    _console.WriteLine($"❌ extension not supported: {inputFileFullPath.Key}");
                }
                return(new ImportIndexItem {
                    Status = ImportStatus.FileError, FilePath = inputFileFullPath.Key, SourceFullFilePath = inputFileFullPath.Key
                });
            }

            var hashList = await
                           new FileHash(_filesystemStorage).GetHashCodeAsync(inputFileFullPath.Key);

            if (!hashList.Value)
            {
                if (_appSettings.IsVerbose())
                {
                    _console.WriteLine($"❌ FileHash error {inputFileFullPath.Key}");
                }
                return(new ImportIndexItem {
                    Status = ImportStatus.FileError, FilePath = inputFileFullPath.Key, SourceFullFilePath = inputFileFullPath.Key
                });
            }

            if (importSettings.IndexMode && await _importQuery !.IsHashInImportDbAsync(hashList.Key))
            {
                if (_appSettings.IsVerbose())
                {
                    _console.WriteLine($"🤷 Ignored, exist already {inputFileFullPath.Key}");
                }
                return(new ImportIndexItem
                {
                    Status = ImportStatus.IgnoredAlreadyImported,
                    FilePath = inputFileFullPath.Key,
                    FileHash = hashList.Key,
                    AddToDatabase = DateTime.UtcNow,
                    SourceFullFilePath = inputFileFullPath.Key
                });
            }

            // Only accept files with correct meta data
            // Check if there is a xmp file that contains data
            var fileIndexItem = _readMetaHost.ReadExifAndXmpFromFile(inputFileFullPath.Key);

            // Parse the filename and create a new importIndexItem object
            var importIndexItem = ObjectCreateIndexItem(inputFileFullPath.Key, imageFormat,
                                                        hashList.Key, fileIndexItem, importSettings.ColorClass,
                                                        _filesystemStorage.Info(inputFileFullPath.Key).Size);

            // Update the parent and filenames
            importIndexItem = ApplyStructure(importIndexItem, importSettings.Structure);

            return(importIndexItem);
        }
예제 #21
0
        public void Files_GetImageFormat_jpeg2_Test()
        {
            var fileType = ExtensionRolesHelper.GetImageFormat(new byte[] { 255, 216, 255, 225 });

            Assert.AreEqual(fileType, ExtensionRolesHelper.ImageFormat.jpg);
        }