/// <summary> /// Command line importer to Database and update disk /// </summary> /// <param name="args">arguments provided by command line app</param> /// <returns>Void Task</returns> public async Task Importer(string[] args) { Console.WriteLine("run importer"); _appSettings.Verbose = ArgsHelper.NeedVerbose(args); await _exifToolDownload.DownloadExifTool(_appSettings.IsWindows); _appSettings.ApplicationType = AppSettings.StarskyAppType.Importer; if (new ArgsHelper().NeedHelp(args) || new ArgsHelper(_appSettings) .GetPathFormArgs(args, false).Length <= 1) { new ArgsHelper(_appSettings, _console).NeedHelpShowDialog(); return; } var inputPathListFormArgs = new ArgsHelper(_appSettings).GetPathListFormArgs(args); if (_appSettings.IsVerbose()) { foreach (var inputPath in inputPathListFormArgs) { _console.WriteLine($">> import: {inputPath}"); } } var importSettings = new ImportSettingsModel { DeleteAfter = ArgsHelper.GetMove(args), RecursiveDirectory = ArgsHelper.NeedRecursive(args), IndexMode = new ArgsHelper().GetIndexMode(args), ColorClass = ArgsHelper.GetColorClass(args), ConsoleOutputMode = ArgsHelper.GetConsoleOutputMode(args) }; if (_appSettings.IsVerbose()) { _console.WriteLine($"Options: DeleteAfter: {importSettings.DeleteAfter}, " + $"RecursiveDirectory {importSettings.RecursiveDirectory}, " + $"ColorClass (overwrite) {importSettings.ColorClass}, " + $"Structure {_appSettings.Structure}, " + $"IndexMode {importSettings.IndexMode}"); } var stopWatch = Stopwatch.StartNew(); var result = await _importService.Importer(inputPathListFormArgs, importSettings); WriteOutputStatus(importSettings, result, stopWatch); Console.WriteLine("done import"); }
public async Task <IActionResult> FromUrl(string fileUrl, string filename, string structure) { if (filename == null) { filename = Base32.Encode(FileHash.GenerateRandomBytes(8)) + ".unknown"; } // I/O function calls should not be vulnerable to path injection attacks if (!Regex.IsMatch(filename, "^[a-zA-Z0-9_\\s\\.]+$") || !FilenamesHelper.IsValidFileName(filename)) { return(BadRequest()); } var tempImportFullPath = Path.Combine(_appSettings.TempFolder, filename); var importSettings = new ImportSettingsModel(Request) { Structure = structure }; var isDownloaded = await _httpClientHelper.Download(fileUrl, tempImportFullPath); if (!isDownloaded) { return(NotFound("'file url' not found or domain not allowed " + fileUrl)); } var importedFiles = await _import.Importer(new List <string> { tempImportFullPath }, importSettings); RemoveTempAndParentStreamFolder(tempImportFullPath); if (importedFiles.Count == 0) { Response.StatusCode = 206; } return(Json(importedFiles)); }