summaryrefslogtreecommitdiff
path: root/src/commandline.cpp
diff options
context:
space:
mode:
authorEddoursul <89222451+eddoursul@users.noreply.github.com>2023-09-18 19:48:13 +0200
committerGitHub <noreply@github.com>2023-09-18 19:48:13 +0200
commit59b5b1cfca1614df681055d98d602692f482f0e2 (patch)
tree3f7a5c5b83acb5e7139283502344328825f4fcb6 /src/commandline.cpp
parenta6879e2c63755c3f2254101cc48566e1e4611332 (diff)
Download files from direct URLs via a command line parameter (#1873)
* Download files via a command line parameter * Use a GET parameter to predetermine Content-Disposition header in S3-compatible temporary URLs
Diffstat (limited to 'src/commandline.cpp')
-rw-r--r--src/commandline.cpp50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/commandline.cpp b/src/commandline.cpp
index 9082d710..1d44e043 100644
--- a/src/commandline.cpp
+++ b/src/commandline.cpp
@@ -2,6 +2,7 @@
#include "env.h"
#include "instancemanager.h"
#include "loglist.h"
+#include "messagedialog.h"
#include "multiprocess.h"
#include "organizercore.h"
#include "shared/appconfig.h"
@@ -49,8 +50,8 @@ CommandLine::CommandLine() : m_command(nullptr)
{
createOptions();
- add<RunCommand, ReloadPluginCommand, RefreshCommand, CrashDumpCommand,
- LaunchCommand>();
+ add<RunCommand, ReloadPluginCommand, DownloadFileCommand, RefreshCommand,
+ CrashDumpCommand, LaunchCommand>();
}
std::optional<int> CommandLine::process(const std::wstring& line)
@@ -833,6 +834,51 @@ std::optional<int> ReloadPluginCommand::runPostOrganizer(OrganizerCore& core)
return {};
}
+Command::Meta DownloadFileCommand::meta() const
+{
+ return {"download", "downloads a file", "URL", ""};
+}
+
+po::options_description DownloadFileCommand::getInternalOptions() const
+{
+ po::options_description d;
+
+ d.add_options()("URL", po::value<std::string>()->required(), "file URL");
+
+ return d;
+}
+
+po::positional_options_description DownloadFileCommand::getPositional() const
+{
+ po::positional_options_description d;
+
+ d.add("URL", 1);
+
+ return d;
+}
+
+bool DownloadFileCommand::canForwardToPrimary() const
+{
+ return true;
+}
+
+std::optional<int> DownloadFileCommand::runPostOrganizer(OrganizerCore& core)
+{
+ const QString url = QString::fromStdString(vm()["URL"].as<std::string>());
+
+ if (!url.startsWith("https://")) {
+ reportError(QObject::tr("Download URL must start with https://"));
+ return 1;
+ }
+
+ log::debug("starting direct download from command line: {}", url.toStdString());
+ MessageDialog::showMessage(QObject::tr("Download started"), qApp->activeWindow(),
+ false);
+ core.downloadManager()->startDownloadURLs(QStringList() << url);
+
+ return {};
+}
+
Command::Meta RefreshCommand::meta() const
{
return {"refresh", "refreshes MO (same as F5)", "", ""};