Skip to content

Commit 2cb30c6

Browse files
committed
try: ip fix for cludflare
- Introduced AI File Sorting functionality to automatically organize documents into a smart folder hierarchy based on source, date, and topic. - Updated README.md to include the new feature. - Enhanced homepage components with new illustrations and descriptions for AI File Sorting. - Refactored rate limiting logic to extract real client IPs more accurately.
1 parent 99995c6 commit 2cb30c6

6 files changed

Lines changed: 143 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ NotebookLM is one of the best and most useful AI platforms out there, but once y
4141
- **No Vendor Lock-in** - Configure any LLM, image, TTS, and STT models to use.
4242
- **25+ External Data Sources** - Add your sources from Google Drive, OneDrive, Dropbox, Notion, and many other external services.
4343
- **Real-Time Multiplayer Support** - Work easily with your team members in a shared notebook.
44+
- **AI File Sorting** - Automatically organize your documents into a smart folder hierarchy using AI-powered categorization by source, date, and topic.
4445
- **Desktop App** - Get AI assistance in any application with Quick Assist, General Assist, Extreme Assist, and local folder sync.
4546

4647
...and more to come.
@@ -199,6 +200,7 @@ All features operate against your chosen search space, so your answers are alway
199200
| **Video Generation** | Cinematic Video Overviews via Veo 3 (Ultra only) | Available (NotebookLM is better here, actively improving) |
200201
| **Presentation Generation** | Better looking slides but not editable | Create editable, slide-based presentations |
201202
| **Podcast Generation** | Audio Overviews with customizable hosts and languages | Available with multiple TTS providers (NotebookLM is better here, actively improving) |
203+
| **AI File Sorting** | No | LLM-powered auto-categorization into source, date, category, and subcategory folders |
202204
| **Desktop App** | No | Native app with General Assist, Quick Assist, Extreme Assist, and local folder sync |
203205
| **Browser Extension** | No | Cross-browser extension to save any webpage, including auth-protected pages |
204206

surfsense_backend/app/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from fastapi.responses import JSONResponse
1616
from slowapi.errors import RateLimitExceeded
1717
from slowapi.middleware import SlowAPIMiddleware
18-
from slowapi.util import get_remote_address
18+
from slowapi.util import get_remote_address # noqa: F401 — kept for reference
1919
from sqlalchemy.ext.asyncio import AsyncSession
2020
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
2121
from starlette.requests import Request as StarletteRequest
@@ -35,7 +35,7 @@
3535
)
3636
from app.db import User, create_db_and_tables, get_async_session
3737
from app.exceptions import GENERIC_5XX_MESSAGE, ISSUES_URL, SurfSenseError
38-
from app.rate_limiter import limiter
38+
from app.rate_limiter import get_real_client_ip, limiter
3939
from app.routes import router as crud_router
4040
from app.routes.auth_routes import router as auth_router
4141
from app.schemas import UserCreate, UserRead, UserUpdate
@@ -290,7 +290,7 @@ def _check_rate_limit(
290290
Uses atomic INCR + EXPIRE to avoid race conditions.
291291
Falls back to in-memory sliding window if Redis is unavailable.
292292
"""
293-
client_ip = get_remote_address(request)
293+
client_ip = get_real_client_ip(request)
294294
key = f"surfsense:auth_rate_limit:{scope}:{client_ip}"
295295

296296
try:

surfsense_backend/app/rate_limiter.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
"""Shared SlowAPI limiter instance used by app.py and route modules."""
22

3+
from __future__ import annotations
4+
35
from limits.storage import MemoryStorage
46
from slowapi import Limiter
5-
from slowapi.util import get_remote_address
7+
from starlette.requests import Request
68

79
from app.config import config
810

11+
12+
def get_real_client_ip(request: Request) -> str:
13+
"""Extract the real client IP behind Cloudflare / reverse proxies.
14+
15+
Priority: CF-Connecting-IP > X-Real-IP > X-Forwarded-For (first entry) > socket peer.
16+
"""
17+
cf_ip = request.headers.get("cf-connecting-ip")
18+
if cf_ip:
19+
return cf_ip.strip()
20+
real_ip = request.headers.get("x-real-ip")
21+
if real_ip:
22+
return real_ip.strip()
23+
forwarded = request.headers.get("x-forwarded-for")
24+
if forwarded:
25+
return forwarded.split(",")[0].strip()
26+
return request.client.host if request.client else "127.0.0.1"
27+
28+
929
limiter = Limiter(
10-
key_func=get_remote_address,
30+
key_func=get_real_client_ip,
1131
storage_uri=config.REDIS_APP_URL,
1232
default_limits=["1024/minute"],
1333
in_memory_fallback_enabled=True,

surfsense_backend/app/routes/anonymous_chat_routes.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,17 @@ def _get_or_create_session_id(request: Request, response: Response) -> str:
5151

5252

5353
def _get_client_ip(request: Request) -> str:
54+
"""Extract the real client IP, preferring Cloudflare's header."""
55+
cf_ip = request.headers.get("cf-connecting-ip")
56+
if cf_ip:
57+
return cf_ip.strip()
58+
real_ip = request.headers.get("x-real-ip")
59+
if real_ip:
60+
return real_ip.strip()
5461
forwarded = request.headers.get("x-forwarded-for")
55-
return (
56-
forwarded.split(",")[0].strip()
57-
if forwarded
58-
else (request.client.host if request.client else "unknown")
59-
)
62+
if forwarded:
63+
return forwarded.split(",")[0].strip()
64+
return request.client.host if request.client else "unknown"
6065

6166

6267
# ---------------------------------------------------------------------------

surfsense_web/components/homepage/features-bento-grid.tsx

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { IconMessage, IconMicrophone, IconSearch, IconUsers } from "@tabler/icons-react";
1+
import {
2+
IconBinaryTree,
3+
IconMessage,
4+
IconMicrophone,
5+
IconSearch,
6+
IconUsers,
7+
} from "@tabler/icons-react";
28
import Image from "next/image";
39
import React from "react";
410
import { BentoGrid, BentoGridItem } from "@/components/ui/bento-grid";
@@ -414,6 +420,91 @@ const AudioCommentIllustration = () => (
414420
</div>
415421
);
416422

423+
const AiSortIllustration = () => (
424+
<div className="relative flex w-full h-full min-h-[6rem] items-center justify-center overflow-hidden rounded-xl bg-gradient-to-br from-emerald-50 via-teal-50 to-cyan-50 dark:from-emerald-950/20 dark:via-teal-950/20 dark:to-cyan-950/20 p-4">
425+
<svg viewBox="0 0 400 200" className="w-full h-full" xmlns="http://www.w3.org/2000/svg">
426+
<title>AI File Sorting illustration showing automatic folder organization</title>
427+
{/* Scattered documents on the left */}
428+
<g opacity="0.5">
429+
<rect x="20" y="40" width="35" height="45" rx="4" className="fill-neutral-200 dark:fill-neutral-700" transform="rotate(-8 37 62)" />
430+
<rect x="50" y="80" width="35" height="45" rx="4" className="fill-neutral-200 dark:fill-neutral-700" transform="rotate(5 67 102)" />
431+
<rect x="15" y="110" width="35" height="45" rx="4" className="fill-neutral-200 dark:fill-neutral-700" transform="rotate(-3 32 132)" />
432+
</g>
433+
434+
{/* AI sparkle / magic in the center */}
435+
<g transform="translate(140, 90)">
436+
<path d="M 0,-18 L 4,-6 L 16,-4 L 6,4 L 8,16 L 0,10 L -8,16 L -6,4 L -16,-4 L -4,-6 Z" className="fill-emerald-500 dark:fill-emerald-400" opacity="0.85">
437+
<animateTransform attributeName="transform" type="rotate" from="0" to="360" dur="10s" repeatCount="indefinite" />
438+
</path>
439+
<circle cx="0" cy="0" r="3" className="fill-white dark:fill-emerald-200">
440+
<animate attributeName="opacity" values="0.5;1;0.5" dur="2s" repeatCount="indefinite" />
441+
</circle>
442+
</g>
443+
444+
{/* Animated sorting arrows */}
445+
<g className="stroke-emerald-500 dark:stroke-emerald-400" strokeWidth="2" fill="none" opacity="0.6">
446+
<path d="M 100 70 Q 140 60, 180 50" strokeDasharray="4,4">
447+
<animate attributeName="stroke-dashoffset" from="8" to="0" dur="1s" repeatCount="indefinite" />
448+
</path>
449+
<path d="M 100 100 Q 140 100, 180 100" strokeDasharray="4,4">
450+
<animate attributeName="stroke-dashoffset" from="8" to="0" dur="1s" repeatCount="indefinite" />
451+
</path>
452+
<path d="M 100 130 Q 140 140, 180 150" strokeDasharray="4,4">
453+
<animate attributeName="stroke-dashoffset" from="8" to="0" dur="1s" repeatCount="indefinite" />
454+
</path>
455+
</g>
456+
457+
{/* Organized folder tree on the right */}
458+
{/* Root folder */}
459+
<g>
460+
<rect x="220" y="30" width="160" height="28" rx="6" className="fill-white dark:fill-neutral-800" opacity="0.9" />
461+
<rect x="228" y="36" width="16" height="14" rx="3" className="fill-emerald-500 dark:fill-emerald-400" />
462+
<line x1="252" y1="43" x2="330" y2="43" className="stroke-neutral-400 dark:stroke-neutral-500" strokeWidth="2.5" strokeLinecap="round" />
463+
</g>
464+
465+
{/* Subfolder 1 */}
466+
<g>
467+
<line x1="240" y1="58" x2="240" y2="76" className="stroke-neutral-300 dark:stroke-neutral-600" strokeWidth="1.5" />
468+
<line x1="240" y1="76" x2="250" y2="76" className="stroke-neutral-300 dark:stroke-neutral-600" strokeWidth="1.5" />
469+
<rect x="250" y="64" width="130" height="24" rx="5" className="fill-white dark:fill-neutral-800" opacity="0.85" />
470+
<rect x="257" y="70" width="12" height="11" rx="2" className="fill-teal-400 dark:fill-teal-500" />
471+
<line x1="276" y1="76" x2="340" y2="76" className="stroke-neutral-400 dark:stroke-neutral-500" strokeWidth="2" strokeLinecap="round" />
472+
</g>
473+
474+
{/* Subfolder 2 */}
475+
<g>
476+
<line x1="240" y1="76" x2="240" y2="108" className="stroke-neutral-300 dark:stroke-neutral-600" strokeWidth="1.5" />
477+
<line x1="240" y1="108" x2="250" y2="108" className="stroke-neutral-300 dark:stroke-neutral-600" strokeWidth="1.5" />
478+
<rect x="250" y="96" width="130" height="24" rx="5" className="fill-white dark:fill-neutral-800" opacity="0.85" />
479+
<rect x="257" y="102" width="12" height="11" rx="2" className="fill-cyan-400 dark:fill-cyan-500" />
480+
<line x1="276" y1="108" x2="350" y2="108" className="stroke-neutral-400 dark:stroke-neutral-500" strokeWidth="2" strokeLinecap="round" />
481+
</g>
482+
483+
{/* Subfolder 3 */}
484+
<g>
485+
<line x1="240" y1="108" x2="240" y2="140" className="stroke-neutral-300 dark:stroke-neutral-600" strokeWidth="1.5" />
486+
<line x1="240" y1="140" x2="250" y2="140" className="stroke-neutral-300 dark:stroke-neutral-600" strokeWidth="1.5" />
487+
<rect x="250" y="128" width="130" height="24" rx="5" className="fill-white dark:fill-neutral-800" opacity="0.85" />
488+
<rect x="257" y="134" width="12" height="11" rx="2" className="fill-emerald-400 dark:fill-emerald-500" />
489+
<line x1="276" y1="140" x2="325" y2="140" className="stroke-neutral-400 dark:stroke-neutral-500" strokeWidth="2" strokeLinecap="round" />
490+
</g>
491+
492+
{/* Sparkle accents */}
493+
<g className="opacity-60">
494+
<circle cx="170" cy="45" r="2" className="fill-emerald-400">
495+
<animate attributeName="opacity" values="0;1;0" dur="2s" repeatCount="indefinite" />
496+
</circle>
497+
<circle cx="190" cy="155" r="1.5" className="fill-teal-400">
498+
<animate attributeName="opacity" values="0;1;0" dur="2.5s" begin="0.8s" repeatCount="indefinite" />
499+
</circle>
500+
<circle cx="155" cy="120" r="1.5" className="fill-cyan-400">
501+
<animate attributeName="opacity" values="0;1;0" dur="3s" begin="0.4s" repeatCount="indefinite" />
502+
</circle>
503+
</g>
504+
</svg>
505+
</div>
506+
);
507+
417508
const items = [
418509
{
419510
title: "Find, Ask, Act",
@@ -431,6 +522,14 @@ const items = [
431522
className: "md:col-span-1",
432523
icon: <IconUsers className="h-4 w-4 text-neutral-500" />,
433524
},
525+
{
526+
title: "AI File Sorting",
527+
description:
528+
"Automatically organize documents into a smart folder hierarchy using AI-powered categorization by source, date, and topic.",
529+
header: <AiSortIllustration />,
530+
className: "md:col-span-1",
531+
icon: <IconBinaryTree className="h-4 w-4 text-neutral-500" />,
532+
},
434533
{
435534
title: "Collaborate Beyond Text",
436535
description:
@@ -443,7 +542,7 @@ const items = [
443542
title: "Context Where It Counts",
444543
description: "Add comments directly to your chats and docs for clear, in-the-moment feedback.",
445544
header: <AnnotationIllustration />,
446-
className: "md:col-span-2",
545+
className: "md:col-span-1",
447546
icon: <IconMessage className="h-4 w-4 text-neutral-500" />,
448547
},
449548
];

surfsense_web/components/homepage/why-surfsense.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ const comparisonRows: {
348348
notebookLm: false,
349349
surfSense: true,
350350
},
351+
{
352+
feature: "AI File Sorting",
353+
notebookLm: false,
354+
surfSense: true,
355+
},
351356
];
352357

353358
function ComparisonStrip() {

0 commit comments

Comments
 (0)