Example #1
0
        public async Task CommandLineAsync(string[] args)
        {
            _appSettings.Verbose         = ArgsHelper.NeedVerbose(args);
            _appSettings.ApplicationType = AppSettings.StarskyAppType.MetaThumbnail;

            if (new ArgsHelper().NeedHelp(args))
            {
                new ArgsHelper(_appSettings, _console).NeedHelpShowDialog();
                return;
            }

            new ArgsHelper().SetEnvironmentByArgs(args);

            var subPath            = new ArgsHelper(_appSettings).SubPathOrPathValue(args);
            var getSubPathRelative = new ArgsHelper(_appSettings).GetRelativeValue(args);

            if (getSubPathRelative != null)
            {
                subPath = new StructureService(_selectorStorage.Get(SelectorStorage.StorageServices.SubPath), _appSettings.Structure)
                          .ParseSubfolders(getSubPathRelative);
            }

            await _metaExifThumbnailService.AddMetaThumbnail(subPath);

            _console.WriteLine("Done!");
        }
Example #2
0
        internal async Task <bool> CreateMataThumbnail(IEnumerable <ImportIndexItem>
                                                       importIndexItemsList, ImportSettingsModel importSettings)
        {
            if (_appSettings.MetaThumbnailOnImport == false || !importSettings.IndexMode)
            {
                return(false);
            }
            var items = importIndexItemsList
                        .Where(p => p.Status == ImportStatus.Ok)
                        .Select(p => (p.FilePath, p.FileIndexItem.FileHash)).ToList();

            if (!items.Any())
            {
                return(false);
            }
            return(await _metaExifThumbnailService.AddMetaThumbnail(items));
        }
Example #3
0
        public async Task <IActionResult> UploadToFolder()
        {
            var to = Request.Headers["to"].ToString();

            if (string.IsNullOrWhiteSpace(to))
            {
                return(BadRequest("missing 'to' header"));
            }

            var parentDirectory = GetParentDirectoryFromRequestHeader();

            if (parentDirectory == null)
            {
                return(NotFound(new ImportIndexItem {
                    Status = ImportStatus.ParentDirectoryNotFound
                }));
            }

            var tempImportPaths = await Request.StreamFile(_appSettings, _selectorStorage);

            var fileIndexResultsList = await _import.Preflight(tempImportPaths,
                                                               new ImportSettingsModel { IndexMode = false });

            for (var i = 0; i < fileIndexResultsList.Count; i++)
            {
                if (fileIndexResultsList[i].Status != ImportStatus.Ok)
                {
                    continue;
                }

                var tempFileStream = _iHostStorage.ReadStream(tempImportPaths[i]);
                var fileName       = Path.GetFileName(tempImportPaths[i]);

                // subPath is always unix style
                var subPath = PathHelper.AddSlash(parentDirectory) + fileName;
                if (parentDirectory == "/")
                {
                    subPath = parentDirectory + fileName;
                }

                // to get the output in the result right
                fileIndexResultsList[i].FileIndexItem.FileName        = fileName;
                fileIndexResultsList[i].FileIndexItem.ParentDirectory = parentDirectory;
                fileIndexResultsList[i].FilePath = subPath;
                // Do sync action before writing it down
                fileIndexResultsList[i].FileIndexItem = await SyncItem(fileIndexResultsList[i].FileIndexItem);

                var writeStatus =
                    await _iStorage.WriteStreamAsync(tempFileStream, subPath + ".tmp");

                await tempFileStream.DisposeAsync();

                // to avoid partly written stream to be read by an other application
                _iStorage.FileDelete(subPath);
                _iStorage.FileMove(subPath + ".tmp", subPath);
                _logger.LogInformation($"write {subPath} is {writeStatus}");

                // clear directory cache
                _query.RemoveCacheParentItem(subPath);

                var deleteStatus = _iHostStorage.FileDelete(tempImportPaths[i]);
                _logger.LogInformation($"[UploadController] delete {tempImportPaths[i]} is {deleteStatus}");

                var parentPath = Directory.GetParent(tempImportPaths[i])?.FullName;
                if (!string.IsNullOrEmpty(parentPath) && parentPath != _appSettings.TempFolder)
                {
                    _iHostStorage.FolderDelete(parentPath);
                }

                await _metaExifThumbnailService.AddMetaThumbnail(subPath,
                                                                 fileIndexResultsList[i].FileIndexItem.FileHash);
            }

            // send all uploads as list
            var socketResult = fileIndexResultsList
                               .Where(p => p.Status == ImportStatus.Ok)
                               .Select(item => item.FileIndexItem).ToList();

            var webSocketResponse = new ApiNotificationResponseModel <List <FileIndexItem> >(
                socketResult, ApiNotificationType.UploadFile);
            await _connectionsService.NotificationToAllAsync(webSocketResponse, CancellationToken.None);

            // Wrong input (extension is not allowed)
            if (fileIndexResultsList.All(p => p.Status == ImportStatus.FileError))
            {
                _logger.LogInformation($"Wrong input extension is not allowed" +
                                       $" {string.Join(",",fileIndexResultsList.Select(p => p.FilePath))}");
                Response.StatusCode = 415;
            }

            return(Json(fileIndexResultsList));
        }