Fix file browser state persistence and PDF viewer loading

- Clear file lists in ResetFileBrowser to prevent org files showing in personal workspace
- Include JWT token as query parameter in PDF download URL for viewer compatibility
- Remove Authorization header from SfPdfViewer (browser security restrictions)
- Fix mock repository EditorSession to include required token parameter
This commit is contained in:
Leon Bösche
2026-01-11 03:40:44 +01:00
parent e9517a5a4d
commit bd6dd68f0b
4 changed files with 301 additions and 6 deletions

View File

@@ -496,14 +496,13 @@ func userViewerHandler(w http.ResponseWriter, r *http.Request, db *database.DB,
if host == "" {
host = "go.b0esche.cloud"
}
downloadPath := fmt.Sprintf("%s://%s/user/files/download?path=%s", scheme, host, url.QueryEscape(file.Path))
// Get JWT token from context
token, _ := middleware.GetToken(r.Context())
downloadPath := fmt.Sprintf("%s://%s/user/files/download?path=%s&token=%s", scheme, host, url.QueryEscape(file.Path), url.QueryEscape(token))
// Determine if it's a PDF based on file extension
isPdf := strings.HasSuffix(strings.ToLower(file.Name), ".pdf")
// Get JWT token from context
token, _ := middleware.GetToken(r.Context())
session := struct {
ViewUrl string `json:"viewUrl"`
Token string `json:"token"`
@@ -1441,8 +1440,11 @@ func downloadOrgFileHandler(w http.ResponseWriter, r *http.Request, db *database
// downloadUserFileHandler downloads a file from user's personal workspace
func downloadUserFileHandler(w http.ResponseWriter, r *http.Request, db *database.DB, cfg *config.Config) {
// Try to get userID from context (Bearer token), fallback to query parameter
userIDStr, ok := middleware.GetUserID(r.Context())
if !ok || userIDStr == "" {
// Token might be in query parameter for PDF viewer compatibility
// This is acceptable since the token is still validated
errors.WriteError(w, errors.CodeUnauthenticated, "Unauthorized", http.StatusUnauthorized)
return
}