From 28b3c3d255f11db1e0a63701b8fb6cb5a377f4af Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Sat, 13 Mar 2021 13:22:26 +0100 Subject: [PATCH] Fix missing repeated words bug and incorrect gate --- src/excmds.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/excmds.ts b/src/excmds.ts index 7d28dfce..3b7d81b5 100644 --- a/src/excmds.ts +++ b/src/excmds.ts @@ -904,25 +904,31 @@ export async function restart() { export async function saveas(...args: string[]) { let overwrite = false let cleanup = false - const uniqueArgs = new Set(args) - if (uniqueArgs.has("--overwrite")) { - overwrite = true - uniqueArgs.delete("--overwrite") - } - if (uniqueArgs.has("--cleanup")) { - cleanup = true - uniqueArgs.delete("--cleanup") + const argParse = (args: string[]): string[] => { + if (args[0] === "--overwrite") { + overwrite = true + args.shift() + argParse(args) + } + if (args[0] === "--cleanup") { + cleanup = true + args.shift() + argParse(args) + } + return args } - const requiredNativeMessengerVersion = "0.3.0" - if ((overwrite || cleanup) && (await Native.nativegate(requiredNativeMessengerVersion, false))) { + const file = argParse(args).join(" ") || undefined + + const requiredNativeMessengerVersion = "0.3.2" + if ((overwrite || cleanup) && !(await Native.nativegate(requiredNativeMessengerVersion, false))) { throw new Error(`":saveas --{overwrite, cleanup}" requires native ${requiredNativeMessengerVersion} or later`) } if (args.length > 0) { - const filename = await Messaging.message("download_background", "downloadUrlAs", window.location.href, [...uniqueArgs].join(" "), overwrite, cleanup) - return fillcmdline_tmp(10000, `Download completed: ${filename} stored in ${Array.from(uniqueArgs).join(" ")}`) + const filename = await Messaging.message("download_background", "downloadUrlAs", window.location.href, file, overwrite, cleanup) + return fillcmdline_tmp(10000, `Download completed: ${filename} stored in ${file}`) } else { return Messaging.message("download_background", "downloadUrl", window.location.href, true) }