mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: use consistent relative paths for resources (#2683)
- always store resources with a relative path with forward slashes, which will be transformed as needed when the file is accessed - fix an issue with thumbnail generation on Windows - add several validations for local storage setting - improve front-end error feedback when changing local storage - add migrations to make existing resource paths relative (not needed, but improves database consistency)
This commit is contained in:
@ -3,6 +3,7 @@ package v1
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
@ -242,6 +243,24 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
|
||||
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
|
||||
return errors.Errorf(systemSettingUnmarshalError, settingName)
|
||||
}
|
||||
|
||||
trimmedValue := strings.TrimSpace(value)
|
||||
switch {
|
||||
case trimmedValue != value:
|
||||
return errors.New("local storage path must not contain leading or trailing whitespace")
|
||||
case trimmedValue == "":
|
||||
return errors.New("local storage path can't be empty")
|
||||
case strings.Contains(trimmedValue, "\\"):
|
||||
return errors.New("local storage path must use forward slashes `/`")
|
||||
case strings.Contains(trimmedValue, "../"):
|
||||
return errors.New("local storage path is not allowed to contain `../`")
|
||||
case strings.HasPrefix(trimmedValue, "./"):
|
||||
return errors.New("local storage path is not allowed to start with `./`")
|
||||
case filepath.IsAbs(trimmedValue) || trimmedValue[0] == '/':
|
||||
return errors.New("local storage path must be a relative path")
|
||||
case !strings.Contains(trimmedValue, "{filename}"):
|
||||
return errors.New("local storage path must contain `{filename}`")
|
||||
}
|
||||
case SystemSettingTelegramBotTokenName:
|
||||
if upsert.Value == "" {
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user