Simplify shell command execution

pull/3676/head
BeziCZ 2025-02-17 14:22:44 +01:00
parent 4b7de8e14b
commit c17c4de9b0
11 changed files with 17 additions and 21 deletions

View File

@ -145,7 +145,7 @@ func printSettings(ser *settings.Server, set *settings.Settings, auther auth.Aut
fmt.Fprintf(w, "Sign up:\t%t\n", set.Signup) fmt.Fprintf(w, "Sign up:\t%t\n", set.Signup)
fmt.Fprintf(w, "Create User Dir:\t%t\n", set.CreateUserDir) fmt.Fprintf(w, "Create User Dir:\t%t\n", set.CreateUserDir)
fmt.Fprintf(w, "Auth method:\t%s\n", set.AuthMethod) fmt.Fprintf(w, "Auth method:\t%s\n", set.AuthMethod)
fmt.Fprintf(w, "Shell:\t%s\t\n", strings.Join(set.Shell, " ")) fmt.Fprintf(w, "Shell:\t%s\t\n", set.Shell)
fmt.Fprintln(w, "\nBranding:") fmt.Fprintln(w, "\nBranding:")
fmt.Fprintf(w, "\tName:\t%s\n", set.Branding.Name) fmt.Fprintf(w, "\tName:\t%s\n", set.Branding.Name)
fmt.Fprintf(w, "\tFiles override:\t%s\n", set.Branding.Files) fmt.Fprintf(w, "\tFiles override:\t%s\n", set.Branding.Files)

View File

@ -32,7 +32,7 @@ override the options.`,
Key: generateKey(), Key: generateKey(),
Signup: mustGetBool(flags, "signup"), Signup: mustGetBool(flags, "signup"),
CreateUserDir: mustGetBool(flags, "create-user-dir"), CreateUserDir: mustGetBool(flags, "create-user-dir"),
Shell: convertCmdStrToCmdArray(mustGetString(flags, "shell")), Shell: mustGetString(flags, "shell"),
AuthMethod: authMethod, AuthMethod: authMethod,
Defaults: defaults, Defaults: defaults,
Branding: settings.Branding{ Branding: settings.Branding{

View File

@ -48,7 +48,7 @@ you want to change. Other options will remain unchanged.`,
case "auth.method": case "auth.method":
hasAuth = true hasAuth = true
case "shell": case "shell":
set.Shell = convertCmdStrToCmdArray(mustGetString(flags, flag.Name)) set.Shell = mustGetString(flags, flag.Name)
case "create-user-dir": case "create-user-dir":
set.CreateUserDir = mustGetBool(flags, flag.Name) set.CreateUserDir = mustGetBool(flags, flag.Name)
case "branding.name": case "branding.name":

View File

@ -344,7 +344,7 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) {
RetryCount: settings.DefaultTusRetryCount, RetryCount: settings.DefaultTusRetryCount,
}, },
Commands: nil, Commands: nil,
Shell: nil, Shell: "",
Rules: nil, Rules: nil,
} }

View File

@ -6,7 +6,7 @@ interface ISettings {
rules: any[]; rules: any[];
branding: SettingsBranding; branding: SettingsBranding;
tus: SettingsTus; tus: SettingsTus;
shell: string[]; shell: string;
commands: SettingsCommand; commands: SettingsCommand;
} }

View File

@ -296,12 +296,7 @@ const save = async () => {
if (settings.value === null) return false; if (settings.value === null) return false;
let newSettings: ISettings = { let newSettings: ISettings = {
...settings.value, ...settings.value,
shell: shell: settings.value?.shell?.trim() ?? "", // Change this to a string
settings.value?.shell
.join(" ")
.trim()
.split(" ")
.filter((s: string) => s !== "") ?? [],
commands: {}, commands: {},
}; };
@ -309,7 +304,6 @@ const save = async () => {
keyof SettingsCommand keyof SettingsCommand
>; >;
for (const key of keys) { for (const key of keys) {
// not sure if we can safely assume non-null
const newValue = commandObject.value[key]; const newValue = commandObject.value[key];
if (!newValue) continue; if (!newValue) continue;
@ -321,7 +315,9 @@ const save = async () => {
.filter((cmd: string) => cmd !== ""); .filter((cmd: string) => cmd !== "");
} }
} }
newSettings.shell = shellValue.value.split("\n");
// Update this line to assign the string directly, without splitting
newSettings.shell = shellValue.value.trim();
if (newSettings.branding.theme !== getTheme()) { if (newSettings.branding.theme !== getTheme()) {
setTheme(newSettings.branding.theme); setTheme(newSettings.branding.theme);
@ -386,7 +382,7 @@ onMounted(async () => {
originalSettings.value = original; originalSettings.value = original;
settings.value = newSettings; settings.value = newSettings;
shellValue.value = newSettings.shell.join("\n"); shellValue.value = newSettings.shell;
} catch (err) { } catch (err) {
if (err instanceof Error) { if (err instanceof Error) {
error.value = err; error.value = err;

View File

@ -16,7 +16,7 @@ type settingsData struct {
Rules []rules.Rule `json:"rules"` Rules []rules.Rule `json:"rules"`
Branding settings.Branding `json:"branding"` Branding settings.Branding `json:"branding"`
Tus settings.Tus `json:"tus"` Tus settings.Tus `json:"tus"`
Shell []string `json:"shell"` Shell string `json:"shell"`
Commands map[string][]string `json:"commands"` Commands map[string][]string `json:"commands"`
} }

View File

@ -157,7 +157,7 @@ func tusPatchHandler() handleFunc {
w.Header().Set("Upload-Offset", strconv.FormatInt(uploadOffset+bytesWritten, 10)) w.Header().Set("Upload-Offset", strconv.FormatInt(uploadOffset+bytesWritten, 10))
if bytesWritten < int64(d.Settings.Tus.ChunkSize) { if uint64(bytesWritten) < (d.Settings.Tus.ChunkSize) {
err = d.RunAfterHook("upload", r.URL.Path, "", d.user) err = d.RunAfterHook("upload", r.URL.Path, "", d.user)
if err != nil { if err != nil {
return errToStatus(err), err return errToStatus(err), err

View File

@ -12,7 +12,7 @@ import (
func ParseCommand(s *settings.Settings, raw string) ([]string, error) { func ParseCommand(s *settings.Settings, raw string) ([]string, error) {
var command []string var command []string
if len(s.Shell) == 0 || s.Shell[0] == "" { if s.Shell == "" {
cmd, args, err := SplitCommandAndArgs(raw) cmd, args, err := SplitCommandAndArgs(raw)
if err != nil { if err != nil {
return nil, err return nil, err
@ -26,7 +26,7 @@ func ParseCommand(s *settings.Settings, raw string) ([]string, error) {
command = append(command, cmd) command = append(command, cmd)
command = append(command, args...) command = append(command, args...)
} else { } else {
cmd, args, err := SplitCommandAndArgs(s.Shell[0]) cmd, args, err := SplitCommandAndArgs(s.Shell)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -25,7 +25,7 @@ type Settings struct {
Branding Branding `json:"branding"` Branding Branding `json:"branding"`
Tus Tus `json:"tus"` Tus Tus `json:"tus"`
Commands map[string][]string `json:"commands"` Commands map[string][]string `json:"commands"`
Shell []string `json:"shell"` Shell string `json:"shell"`
Rules []rules.Rule `json:"rules"` Rules []rules.Rule `json:"rules"`
} }

View File

@ -72,8 +72,8 @@ func (s *Storage) Save(set *Settings) error {
set.Rules = []rules.Rule{} set.Rules = []rules.Rule{}
} }
if set.Shell == nil { if set.Shell == "" {
set.Shell = []string{} set.Shell = ""
} }
if set.Commands == nil { if set.Commands == nil {