Fix avatar URL to full URL and increase WebDAV timeout to 60s with ensureParent enabled

This commit is contained in:
Leon Bösche
2026-01-29 21:04:13 +01:00
parent 38c4d071c9
commit def7626b37
2 changed files with 6 additions and 8 deletions

View File

@@ -3848,7 +3848,7 @@ func getUserProfileHandler(w http.ResponseWriter, r *http.Request, db *database.
// If avatar exists, return the backend URL instead of the internal WebDAV URL
if user.AvatarURL != nil && *user.AvatarURL != "" {
user.AvatarURL = &[]string{fmt.Sprintf("/user/avatar?v=%d", time.Now().Unix())}[0]
user.AvatarURL = &[]string{fmt.Sprintf("https://go.b0esche.cloud/user/avatar?v=%d", time.Now().Unix())}[0]
}
w.Header().Set("Content-Type", "application/json")
@@ -4048,7 +4048,7 @@ func uploadUserAvatarHandler(w http.ResponseWriter, r *http.Request, db *databas
// Get public URL - for now, construct it manually since Nextcloud doesn't provide direct public URLs
// In a real setup, you'd configure Nextcloud to serve public URLs or use a CDN
publicURL := fmt.Sprintf("/user/avatar?v=%d", time.Now().Unix())
publicURL := fmt.Sprintf("https://go.b0esche.cloud/user/avatar?v=%d", time.Now().Unix())
webdavURL := fmt.Sprintf("%s/%s", client.BaseURL, avatarPath)
// Update user profile with avatar URL

View File

@@ -42,7 +42,7 @@ func NewWebDAVClient(cfg *config.Config) *WebDAVClient {
user: cfg.NextcloudUser,
pass: cfg.NextcloudPass,
basePrefix: strings.TrimRight(base, "/"),
httpClient: &http.Client{Timeout: 30 * time.Second},
httpClient: &http.Client{Timeout: 60 * time.Second},
}
}
@@ -91,12 +91,10 @@ func (c *WebDAVClient) Upload(ctx context.Context, remotePath string, r io.Reade
if c == nil {
return fmt.Errorf("no webdav client configured")
}
// Ensure parent collections (skip for hidden avatar folders to avoid MKCOL timeouts)
if !strings.HasPrefix(remotePath, ".avatars") {
// Ensure parent collections
if err := c.ensureParent(ctx, remotePath); err != nil {
return err
}
}
// Construct URL
// remotePath might be like /orgs/<id>/file.txt; ensure it joins to basePrefix
rel := strings.TrimLeft(remotePath, "/")