From e4a09c407c6e2099462c0388e1441781829ad4b8 Mon Sep 17 00:00:00 2001 From: andrigamerita <37557992+andrigamerita@users.noreply.github.com> Date: Sun, 9 Jun 2024 13:22:13 +0200 Subject: [PATCH] feat: write memo visibility in file names when exporting (#3538) When using the dedicated feature in Memos' user settings to export all memos to Markdown files inside a ZIP folder, the output doesn't feature any kind of distinction for memos by their set visibility. While this is not a big issue for personal backups, it can reveal itself problematic if exporting the data to share it with other people, or maybe deploy to a static site generator, because there is nothing in the files that distinguishes public memos from private or workspace-restricted ones. This pull request simply modifies the ExportMemos server function, to add the Visibility status to the end of every exported file name inside the ZIP, right after the date (which is left intact). For example, the file for a public memo would now be called: `YYYY-MM-DDThh:mm:ss+hh:mm-PUBLIC.md`. An alternative solution would have been to write this information in a YAML header at the beginning of every Markdown file, but, since those are not used anywhere else in the software, I decided to stick with what is already used for export metadata, the filename. --- server/router/api/v1/memo_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/router/api/v1/memo_service.go b/server/router/api/v1/memo_service.go index 48451dd7..5794a8dc 100644 --- a/server/router/api/v1/memo_service.go +++ b/server/router/api/v1/memo_service.go @@ -568,7 +568,7 @@ func (s *APIV1Service) ExportMemos(ctx context.Context, request *v1pb.ExportMemo if err != nil { return nil, errors.Wrap(err, "failed to convert memo") } - file, err := writer.Create(time.Unix(memo.CreatedTs, 0).Format(time.RFC3339) + ".md") + file, err := writer.Create(time.Unix(memo.CreatedTs, 0).Format(time.RFC3339) + "-" + string(memo.Visibility) + ".md") if err != nil { return nil, status.Errorf(codes.Internal, "Failed to create memo file") }