From c7d39144cdce5f68910d97d599093e53fa63e77d Mon Sep 17 00:00:00 2001 From: Elijah Kuntz Date: Thu, 11 Jun 2026 16:24:34 -0700 Subject: [PATCH] Revert last 4 commits --- backend/handlers/onlyoffice.go | 14 +--- backend/main.go | 16 +--- frontend/src/components/OfficeHome.tsx | 2 - frontend/src/components/OnlyOfficeEditor.tsx | 78 ++------------------ frontend/src/components/ThumbnailImage.tsx | 4 +- 5 files changed, 14 insertions(+), 100 deletions(-) diff --git a/backend/handlers/onlyoffice.go b/backend/handlers/onlyoffice.go index 5eeab38..87357e5 100644 --- a/backend/handlers/onlyoffice.go +++ b/backend/handlers/onlyoffice.go @@ -335,20 +335,16 @@ func (h *OnlyOfficeHandler) ListOfficeFiles(c *fiber.Ctx) error { var results []OfficeFile checksums := make(map[string]string) - dbPaths := []string{} - rows, err := h.DB.Query("SELECT path, checksum FROM files WHERE checksum IS NOT NULL AND checksum != ''") + rows, err := h.DB.Query("SELECT path, checksum FROM files WHERE checksum != '' AND is_trashed = 0") if err == nil { defer rows.Close() for rows.Next() { var p, c string if rows.Scan(&p, &c) == nil { checksums[p] = c - dbPaths = append(dbPaths, p) } } } - - walkPaths := []string{} filepath.Walk(h.Config.StorageDir, func(path string, info os.FileInfo, err error) error { if err != nil { @@ -366,16 +362,12 @@ func (h *OnlyOfficeHandler) ListOfficeFiles(c *fiber.Ctx) error { if strings.HasSuffix(strings.ToLower(info.Name()), ext) { relPath, _ := filepath.Rel(h.Config.StorageDir, path) relPathSlash := filepath.ToSlash(relPath) - - chk := checksums[relPathSlash] - walkPaths = append(walkPaths, relPathSlash) - results = append(results, OfficeFile{ Name: info.Name(), Path: relPathSlash, Size: info.Size(), ModTime: info.ModTime().UTC().Format("2006-01-02T15:04:05Z"), - Checksum: chk, + Checksum: checksums[relPathSlash], }) } return nil @@ -388,8 +380,6 @@ func (h *OnlyOfficeHandler) ListOfficeFiles(c *fiber.Ctx) error { return c.JSON(fiber.Map{ "files": results, "count": len(results), - "debug_db": dbPaths, - "debug_walk": walkPaths, }) } diff --git a/backend/main.go b/backend/main.go index 2e21b4b..0df2814 100644 --- a/backend/main.go +++ b/backend/main.go @@ -103,21 +103,9 @@ func main() { c.Set("Cache-Control", "no-store, no-cache, must-revalidate") return c.Next() }) - app.Use(helmet.New(helmet.Config{ - // Relax cross-origin policies to allow OnlyOffice Document Server - // iframe embedding from a different origin (e.g. office.elijahkuntz.com) - CrossOriginEmbedderPolicy: "unsafe-none", - CrossOriginResourcePolicy: "cross-origin", - })) - - // Build CSP with dynamic frame-src for the OnlyOffice Document Server - onlyOfficeFrameSrc := "https://" + cfg.OnlyOfficeHost - cspHeader := fmt.Sprintf( - "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' wss: https: http:; frame-src 'self' %s;", - onlyOfficeFrameSrc, - ) + app.Use(helmet.New()) app.Use(func(c *fiber.Ctx) error { - c.Set("Content-Security-Policy", cspHeader) + c.Set("Content-Security-Policy", "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' wss: https: http:;") return c.Next() }) allowedOrigins := os.Getenv("ALLOWED_ORIGINS") diff --git a/frontend/src/components/OfficeHome.tsx b/frontend/src/components/OfficeHome.tsx index 9f583ef..e100293 100644 --- a/frontend/src/components/OfficeHome.tsx +++ b/frontend/src/components/OfficeHome.tsx @@ -92,8 +92,6 @@ export default function OfficeHome({ type, onFileSelect, onCreateBlank, onPinCha // Fetch ALL office files recursively api.listOfficeFiles(fileTypeParam) .then(data => { - console.log("ListOfficeFiles Debug DB:", data.debug_db); - console.log("ListOfficeFiles Debug Walk:", data.debug_walk); const files = (data.files || []).map((f: any) => ({ ...f, is_dir: false, diff --git a/frontend/src/components/OnlyOfficeEditor.tsx b/frontend/src/components/OnlyOfficeEditor.tsx index 7d3335b..6300cbc 100644 --- a/frontend/src/components/OnlyOfficeEditor.tsx +++ b/frontend/src/components/OnlyOfficeEditor.tsx @@ -1,6 +1,6 @@ -import React, { useEffect, useState, useRef, useCallback } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { DocumentEditor } from '@onlyoffice/document-editor-react'; -import { Sun, Moon, Loader2, ArrowLeft, RefreshCw, Download, ShieldAlert, X } from 'lucide-react'; +import { Sun, Moon, Loader2, ArrowLeft, RefreshCw, Download } from 'lucide-react'; import api from '@/lib/api'; import { FileItem } from '@/types/files'; @@ -18,10 +18,6 @@ export default function OnlyOfficeEditor({ file, type, onClose, onRename, theme, const [loadError, setLoadError] = useState(null); const [config, setConfig] = useState(null); const [isRenaming, setIsRenaming] = useState(false); - const [adblockWarning, setAdblockWarning] = useState(false); - const [documentReady, setDocumentReady] = useState(false); - const documentReadyRef = useRef(false); - const loadTimeoutRef = useRef(null); const extMatch = file.name.match(/\.[^.]+$/); const ext = extMatch ? extMatch[0] : ''; @@ -134,39 +130,9 @@ export default function OnlyOfficeEditor({ file, type, onClose, onRename, theme, const docServerUrl = process.env.NEXT_PUBLIC_ONLYOFFICE_URL || 'https://office.elijahkuntz.com/'; - // Proactively detect if an adblocker is blocking OnlyOffice resources - useEffect(() => { - if (!config) return; - - // Test fetch for a resource commonly blocked by adblockers (Brave Shields, uBlock, etc.) - const testUrl = `${docServerUrl}web-apps/apps/common/Analytics.js`; - fetch(testUrl, { method: 'HEAD', mode: 'no-cors' }) - .then(() => { - // mode: 'no-cors' always resolves — check with a timeout fallback instead - }) - .catch(() => { - setAdblockWarning(true); - }); - - // Fallback: if onDocumentReady hasn't fired in 8s, show the warning - loadTimeoutRef.current = setTimeout(() => { - if (!documentReadyRef.current) { - setAdblockWarning(true); - } - }, 8000); - - return () => { - if (loadTimeoutRef.current) clearTimeout(loadTimeoutRef.current); - }; - }, [config, docServerUrl]); - - const onDocumentReady = useCallback(function (event: any) { + const onDocumentReady = function (event: any) { console.log("Document is loaded"); - documentReadyRef.current = true; - setDocumentReady(true); - setAdblockWarning(false); - if (loadTimeoutRef.current) clearTimeout(loadTimeoutRef.current); - }, []); + }; const onLoadComponentError = function (errorCode: number, errorDescription: string) { setLoadError(`${errorCode}: ${errorDescription}`); @@ -226,44 +192,16 @@ export default function OnlyOfficeEditor({ file, type, onClose, onRename, theme,
{loadError ? ( -
+
-

Failed to load OnlyOffice Editor

-

{loadError}

-

Check if your OnlyOffice server is running and accessible at the configured URL.

+

Failed to load OnlyOffice Editor

+

{loadError}

+

Check if your OnlyOffice server is running and accessible at the configured URL.

) : (
- {/* Adblocker / Brave Shields warning banner */} - {adblockWarning && !documentReady && ( -
- -
-

Ad Blocker Detected

-

- Your ad blocker or browser shield is blocking resources required by the document editor. - The editor may not load or function correctly. -

-
-

To fix this:

-
    -
  • Brave: Click the Shields icon (lion) in the address bar → set Shields to Down for this site
  • -
  • uBlock / AdBlock: Click the extension icon → disable for this site
  • -
-

Then refresh the page.

-
-
- -
- )} 0 ? `&t=${key}` : ''}` : ''} alt="" - className={`object-contain ${docType ? 'w-full h-full mix-blend-multiply' : 'w-full h-full'}`} + className={`object-contain ${docType ? 'w-full h-full object-cover mix-blend-multiply' : 'w-full h-full'}`} style={{ display: showFallback ? 'none' : 'block' }} onError={(e) => { if (errorCount < 20) {