Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
feat: introduce publicid to filename template (#1713)
Athurg Gooth616b8b0ee60c
diff --git a/server/resource.go b/server/resource.goindex 8bf5c800f..c506d7f57 100644--- a/server/resource.go+++ b/server/resource.go@@ -142,19 +142,20 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {if err != nil && common.ErrorCode(err) != common.NotFound {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find local storage path setting").SetInternal(err)}- localStoragePath := "assets/{timestamp}_{filename}"- if systemSettingLocalStoragePath != nil {+ localStoragePath := "assets/{publicid}"+ if systemSettingLocalStoragePath != nil && systemSettingLocalStoragePath.Value != "" {err = json.Unmarshal([]byte(systemSettingLocalStoragePath.Value), &localStoragePath)if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal local storage path setting").SetInternal(err)}}filePath := filepath.FromSlash(localStoragePath)- if !strings.Contains(filePath, "{filename}") {- filePath = filepath.Join(filePath, "{filename}")+ if !strings.Contains(filePath, "{publicid}") {+ filePath = filepath.Join(filePath, "{publicid}")}- filePath = filepath.Join(s.Profile.Data, replacePathTemplate(filePath, file.Filename))- dir, filename := filepath.Split(filePath)+ filePath = filepath.Join(s.Profile.Data, replacePathTemplate(filePath, file.Filename, publicID+filepath.Ext(file.Filename)))++ dir := filepath.Dir(filePath)if err = os.MkdirAll(dir, os.ModePerm); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create directory").SetInternal(err)}@@ -170,7 +171,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {resourceCreate = &api.ResourceCreate{CreatorID: userID,- Filename: filename,+ Filename: file.Filename,Type: filetype,Size: size,InternalPath: filePath,@@ -197,10 +198,10 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {}filePath := s3Config.Path- if !strings.Contains(filePath, "{filename}") {- filePath = path.Join(filePath, "{filename}")+ if !strings.Contains(filePath, "{publicid}") {+ filePath = path.Join(filePath, "{publicid}")}- filePath = replacePathTemplate(filePath, file.Filename)+ filePath = replacePathTemplate(filePath, file.Filename, publicID+filepath.Ext(file.Filename))_, filename := filepath.Split(filePath)link, err := s3Client.UploadFile(ctx, filePath, filetype, sourceFile)if err != nil {@@ -476,10 +477,12 @@ func (s *Server) createResourceCreateActivity(c echo.Context, resource *api.Resoreturn err}-func replacePathTemplate(path string, filename string) string {+func replacePathTemplate(path, filename, publicID string) string {t := time.Now()path = fileKeyPattern.ReplaceAllStringFunc(path, func(s string) string {switch s {+ case "{publicid}":+ return publicIDcase "{filename}":return filenamecase "{timestamp}":diff --git a/web/src/components/UpdateLocalStorageDialog.tsx b/web/src/components/UpdateLocalStorageDialog.tsxindex 4e7aa6ae8..acb2d5317 100644--- a/web/src/components/UpdateLocalStorageDialog.tsx+++ b/web/src/components/UpdateLocalStorageDialog.tsx@@ -52,7 +52,7 @@ const UpdateLocalStorageDialog: React.FC<Props> = (props: Props) => {<p className="text-sm break-words mb-1">{t("setting.storage-section.update-local-path-description")}</p><div className="flex flex-row"><p className="text-sm text-gray-400 mb-2 break-all">- {t("common.e.g")} {"assets/{timestamp}_{filename}"}+ {t("common.e.g")} {"assets/{publicid}"}</p><HelpButton hint={t("common.learn-more")} url="https://usememos.com/docs/local-storage" /></div>