From 42ee3057bf9672d2abbc8cb21ab8c58b59ebe7bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Mon, 12 Jan 2026 16:10:04 +0100 Subject: [PATCH] Fix: Collabora proxy handler - create WOPI session inline instead of calling non-existent function --- go_cloud/internal/http/wopi_handlers.go | 39 +++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/go_cloud/internal/http/wopi_handlers.go b/go_cloud/internal/http/wopi_handlers.go index 26a1894..c7ada1d 100644 --- a/go_cloud/internal/http/wopi_handlers.go +++ b/go_cloud/internal/http/wopi_handlers.go @@ -625,14 +625,43 @@ func collaboraProxyHandler(w http.ResponseWriter, r *http.Request, db *database. return } - // Create WOPI session - wopiSrc, accessToken, err := createWOPISession(r.Context(), db, jwtManager, userID, fileID) + // Get file info + fileUUID, err := uuid.Parse(fileID) if err != nil { - fmt.Printf("[WOPI-ERROR] Failed to create session: %v\n", err) - errors.WriteError(w, errors.CodeInternal, "Failed to create WOPI session", http.StatusInternalServerError) + errors.WriteError(w, errors.CodeInvalidArgument, "Invalid fileId format", http.StatusBadRequest) return } + file, err := db.GetFileByID(r.Context(), fileUUID) + if err != nil { + errors.WriteError(w, errors.CodeNotFound, "File not found", http.StatusNotFound) + return + } + + // Verify access + canAccess := false + if file.UserID != nil && *file.UserID == userID { + canAccess = true + } else if file.OrgID != nil { + member, err := db.GetOrgMember(r.Context(), *file.OrgID, userID) + canAccess = (err == nil && member != nil) + } + + if !canAccess { + errors.WriteError(w, errors.CodePermissionDenied, "Access denied", http.StatusForbidden) + return + } + + // Generate WOPI access token (1 hour duration) + accessToken, err := jwtManager.GenerateWithDuration(userID.String(), nil, "", 1*time.Hour) + if err != nil { + errors.WriteError(w, errors.CodeInternal, "Failed to generate token", http.StatusInternalServerError) + return + } + + // Build WOPISrc URL + wopiSrc := fmt.Sprintf("https://go.b0esche.cloud/wopi/files/%s?access_token=%s", fileID, accessToken) + // Return HTML page with auto-submitting form htmlContent := fmt.Sprintf(` @@ -663,5 +692,5 @@ func collaboraProxyHandler(w http.ResponseWriter, r *http.Request, db *database. w.WriteHeader(http.StatusOK) w.Write([]byte(htmlContent)) - fmt.Printf("[COLLABORA-PROXY] Served HTML form: file=%s user=%s\n", fileID, userID.String()) + fmt.Printf("[COLLABORA-PROXY] Served HTML form: file=%s user=%s wopi_src=%s\n", fileID, userID.String(), wopiSrc) } \ No newline at end of file