diff --git a/middleware/share_preview.go b/middleware/share_preview.go index 1537dfff..4f312357 100644 --- a/middleware/share_preview.go +++ b/middleware/share_preview.go @@ -216,7 +216,14 @@ func loadShareForOG(c *gin.Context, shareID int, password string) (*explorer.Sha func renderOGHTML(data *ogData) string { var buf bytes.Buffer - if err := ogTemplate.Execute(&buf, data); err != nil { + if err := ogTemplate.Execute(&buf, map[string]string{ + "SiteName": data.SiteName, + "Title": data.Title, + "Description": data.Description, + "ImageURL": data.ImageURL, + "ShareURL": data.ShareURL, + "RedirectURL": data.RedirectURL, + }); err != nil { return "" } return buf.String() diff --git a/pkg/email/template.go b/pkg/email/template.go index 213c092c..5813e891 100644 --- a/pkg/email/template.go +++ b/pkg/email/template.go @@ -44,7 +44,7 @@ func NewResetEmail(ctx context.Context, settings setting.Provider, user *ent.Use } var resTitle strings.Builder - err = tmplTitle.Execute(&resTitle, resetCtx) + err = tmplTitle.Execute(&resTitle, resetCtx.templateData()) if err != nil { return "", "", fmt.Errorf("failed to execute email title: %w", err) } @@ -55,7 +55,7 @@ func NewResetEmail(ctx context.Context, settings setting.Provider, user *ent.Use } var resBody strings.Builder - err = tmplBody.Execute(&resBody, resetCtx) + err = tmplBody.Execute(&resBody, resetCtx.templateData()) if err != nil { return "", "", fmt.Errorf("failed to execute email template: %w", err) } @@ -90,7 +90,7 @@ func NewActivationEmail(ctx context.Context, settings setting.Provider, user *en } var resTitle strings.Builder - err = tmplTitle.Execute(&resTitle, activationCtx) + err = tmplTitle.Execute(&resTitle, activationCtx.templateData()) if err != nil { return "", "", fmt.Errorf("failed to execute email title: %w", err) } @@ -101,7 +101,7 @@ func NewActivationEmail(ctx context.Context, settings setting.Provider, user *en } var resBody strings.Builder - err = tmplBody.Execute(&resBody, activationCtx) + err = tmplBody.Execute(&resBody, activationCtx.templateData()) if err != nil { return "", "", fmt.Errorf("failed to execute email template: %w", err) } @@ -112,24 +112,57 @@ func NewActivationEmail(ctx context.Context, settings setting.Provider, user *en func commonContext(ctx context.Context, settings setting.Provider) *CommonContext { logo := settings.Logo(ctx) siteUrl := settings.SiteURL(ctx) - res := &CommonContext{ - SiteBasic: settings.SiteBasic(ctx), - Logo: settings.Logo(ctx), - SiteUrl: siteUrl.String(), - } + resolvedLogo := *logo // Add site url if logo is not an url if !strings.HasPrefix(logo.Light, "http") { logoPath, _ := url.Parse(logo.Light) - res.Logo.Light = siteUrl.ResolveReference(logoPath).String() + resolvedLogo.Light = siteUrl.ResolveReference(logoPath).String() } if !strings.HasPrefix(logo.Normal, "http") { logoPath, _ := url.Parse(logo.Normal) - res.Logo.Normal = siteUrl.ResolveReference(logoPath).String() + resolvedLogo.Normal = siteUrl.ResolveReference(logoPath).String() + } + + return &CommonContext{ + SiteBasic: settings.SiteBasic(ctx), + Logo: &resolvedLogo, + SiteUrl: siteUrl.String(), + } +} + +func (c *CommonContext) templateData() map[string]any { + return map[string]any{ + "SiteBasic": map[string]string{ + "Name": c.SiteBasic.Name, + "Title": c.SiteBasic.Title, + "ID": c.SiteBasic.ID, + "Description": c.SiteBasic.Description, + "Script": c.SiteBasic.Script, + }, + "Logo": map[string]string{ + "Normal": c.Logo.Normal, + "Light": c.Logo.Light, + }, + "SiteUrl": c.SiteUrl, + } +} + +func (c ResetContext) templateData() map[string]any { + return map[string]any{ + "CommonContext": c.CommonContext.templateData(), + "User": c.User, + "Url": c.Url, } +} - return res +func (c ActivationContext) templateData() map[string]any { + return map[string]any{ + "CommonContext": c.CommonContext.templateData(), + "User": c.User, + "Url": c.Url, + } } func selectTemplate(templates []setting.EmailTemplate, u *ent.User) setting.EmailTemplate { @@ -144,4 +177,4 @@ func selectTemplate(templates []setting.EmailTemplate, u *ent.User) setting.Emai } return selected -} \ No newline at end of file +} diff --git a/service/explorer/entity.go b/service/explorer/entity.go index d182a26f..2b0a2c6c 100644 --- a/service/explorer/entity.go +++ b/service/explorer/entity.go @@ -56,8 +56,8 @@ func (s *EntityDownloadService) Serve(c *gin.Context) error { type ( SetCurrentVersionParamCtx struct{} SetCurrentVersionService struct { - Uri string `uri:"uri" binding:"required"` - Version string `uri:"version" binding:"required"` + Uri string `json:"uri" uri:"uri" binding:"required"` + Version string `json:"version" uri:"version" binding:"required"` } ) @@ -88,8 +88,8 @@ func (s *SetCurrentVersionService) Set(c *gin.Context) error { type ( DeleteVersionParamCtx struct{} DeleteVersionService struct { - Uri string `uri:"uri" binding:"required"` - Version string `uri:"version" binding:"required"` + Uri string `json:"uri" uri:"uri" binding:"required"` + Version string `json:"version" uri:"version" binding:"required"` } ) diff --git a/service/explorer/response.go b/service/explorer/response.go index f4084f54..92de9bb5 100644 --- a/service/explorer/response.go +++ b/service/explorer/response.go @@ -59,8 +59,8 @@ func BuildArchiveListFilesResponse(files []manager.ArchivedFile) *ArchiveListFil } type PutRelativeResponse struct { - Name string - Url string + Name string `json:"Name"` + Url string `json:"Url"` } type DirectLinkResponse struct { @@ -196,45 +196,45 @@ func BuildUploadSessionResponse(session *fs.UploadCredential, hasher hashid.Enco // WopiFileInfo Response for `CheckFileInfo` type WopiFileInfo struct { // Required - BaseFileName string - Version string - Size int64 + BaseFileName string `json:"BaseFileName"` + Version string `json:"Version"` + Size int64 `json:"Size"` // Breadcrumb - BreadcrumbBrandName string - BreadcrumbBrandUrl string - BreadcrumbFolderName string - BreadcrumbFolderUrl string + BreadcrumbBrandName string `json:"BreadcrumbBrandName"` + BreadcrumbBrandUrl string `json:"BreadcrumbBrandUrl"` + BreadcrumbFolderName string `json:"BreadcrumbFolderName"` + BreadcrumbFolderUrl string `json:"BreadcrumbFolderUrl"` // Post Message - FileSharingPostMessage bool - FileVersionPostMessage bool - ClosePostMessage bool - PostMessageOrigin string + FileSharingPostMessage bool `json:"FileSharingPostMessage"` + FileVersionPostMessage bool `json:"FileVersionPostMessage"` + ClosePostMessage bool `json:"ClosePostMessage"` + PostMessageOrigin string `json:"PostMessageOrigin"` // Other miscellaneous properties - FileNameMaxLength int - LastModifiedTime string + FileNameMaxLength int `json:"FileNameMaxLength"` + LastModifiedTime string `json:"LastModifiedTime"` // User metadata - IsAnonymousUser bool - UserFriendlyName string - UserId string - OwnerId string + IsAnonymousUser bool `json:"IsAnonymousUser"` + UserFriendlyName string `json:"UserFriendlyName"` + UserId string `json:"UserId"` + OwnerId string `json:"OwnerId"` // Permission - ReadOnly bool - UserCanRename bool - UserCanReview bool - UserCanWrite bool - UserCanNotWriteRelative bool - - SupportsRename bool - SupportsReviewing bool - SupportsUpdate bool - SupportsLocks bool - - EnableShare bool + ReadOnly bool `json:"ReadOnly"` + UserCanRename bool `json:"UserCanRename"` + UserCanReview bool `json:"UserCanReview"` + UserCanWrite bool `json:"UserCanWrite"` + UserCanNotWriteRelative bool `json:"UserCanNotWriteRelative"` + + SupportsRename bool `json:"SupportsRename"` + SupportsReviewing bool `json:"SupportsReviewing"` + SupportsUpdate bool `json:"SupportsUpdate"` + SupportsLocks bool `json:"SupportsLocks"` + + EnableShare bool `json:"EnableShare"` } type ViewerSessionResponse struct { diff --git a/service/explorer/upload.go b/service/explorer/upload.go index cc12c377..4332a110 100644 --- a/service/explorer/upload.go +++ b/service/explorer/upload.go @@ -30,7 +30,7 @@ type ( Metadata map[string]string `json:"metadata" binding:"max=256"` EntityType string `json:"entity_type" binding:"eq=|eq=live_photo|eq=version"` EncryptionSupported []types.Cipher `json:"encryption_supported"` - Previous string `form:"previous"` + Previous string `json:"previous" form:"previous"` } )