Esempio n. 1
0
        public static async Task <string> GetRealPath(
            IPhotoDatabase pdb,
            ulong userId,
            string encodedPath)
        {
            var path       = Base64Decode(encodedPath);
            var sourceName = path.Substring(1).Split("/").FirstOrDefault();

            if (string.IsNullOrEmpty(sourceName))
            {
                return(null);
            }

            var imageSourcesForUser = await pdb.GetImageSourcesForUser(userId);

            var source = imageSourcesForUser?.FirstOrDefault(x => x.SourceName == sourceName);

            if (source == null)
            {
                return(null);
            }

            var absoluteVirtualPath = Path.GetFullPath(Path.DirectorySeparatorChar + path);

            if (!absoluteVirtualPath.StartsWith(source.SourceNameAbsolute))
            {
                return(null);
            }

            var realPath = $"/{source.Path}/" + absoluteVirtualPath.Substring(source.SourceName.Length + 2);

            realPath = Path.GetFullPath(realPath);
            return(realPath);
        }
Esempio n. 2
0
        public static async Task <Tuple <FileStream, string> > GetFileStreamAndContentType(
            IPhotoDatabase pdb,
            ulong userId,
            string encodedPath)
        {
            var path = await GetRealPath(pdb, userId, encodedPath);

            if (path == null)
            {
                return(null);
            }

            if (!System.IO.File.Exists(path))
            {
                return(null);
            }

            var mimeDetector = new FileExtensionContentTypeProvider();

            var successfulMimeDetection = mimeDetector.TryGetContentType(path, out var contentType);

            return(successfulMimeDetection
                ? new Tuple <FileStream, string>(System.IO.File.OpenRead(path), contentType)
                : null);
        }
 public ImageSourceController(IPhotoDatabase pdb)
 {
     this._pdb = pdb;
 }
 public HandleQueuedImagesService(IPhotoDatabase pdb, IImageHelper imageHelper)
 {
     _pdb         = pdb;
     _imageHelper = imageHelper;
 }
Esempio n. 5
0
 public SpaConfigController(IPhotoDatabase pdb)
 {
     this._pdb = pdb;
 }
Esempio n. 6
0
        public static async Task <List <string> > GetDirectoryContent(
            IPhotoDatabase pdb,
            ulong userId,
            string encodedPath)
        {
            var path = await GetRealPath(pdb, userId, encodedPath);

            if (path == null)
            {
                return(null);
            }

            if (!Directory.Exists(path))
            {
                return(null);
            }

            var dirs = new List <string>();

            var mimeDetector = new FileExtensionContentTypeProvider();

            foreach (var fsEntry in Directory.EnumerateFileSystemEntries(path))
            {
                if (Path.GetFileName(fsEntry).StartsWith("."))
                {
                    continue;
                }

                if (System.IO.File.Exists(fsEntry))
                {
                    var successfulMimeDetection = mimeDetector.TryGetContentType(fsEntry, out var contentType);
                    if (!successfulMimeDetection)
                    {
                        continue;
                    }
                    if (ContentTypeIsImage(contentType))
                    {
                        dirs.Add(Path.GetFileName(fsEntry));
                    }
                    else if (ContentTypeIsVideo(contentType))
                    {
                        // TODO: Implement this
                    }
                }
                else if (System.IO.Directory.Exists(fsEntry))
                {
                    dirs.Add(Path.GetFileName(fsEntry) + Path.DirectorySeparatorChar);
                }
            }

            dirs.Sort((a, b) =>
            {
                var aIsDir = a.EndsWith(Path.DirectorySeparatorChar) ? 1 : 0;
                var bIsDir = b.EndsWith(Path.DirectorySeparatorChar) ? 1 : 0;
                return(aIsDir != bIsDir
                    ? bIsDir.CompareTo(aIsDir)
                    : (string.Compare(a, b, StringComparison.CurrentCulture)));
            });

            return(dirs);
        }
Esempio n. 7
0
 public ImageController(IPhotoDatabase pdb, IImageHelper imageHelper)
 {
     _pdb         = pdb;
     _imageHelper = imageHelper;
 }
Esempio n. 8
0
 public AlbumController(IPhotoDatabase pdb)
 {
     this._pdb = pdb;
 }