From cb15adc9a6c878c9ab6a231c0a4fa1da66c2eef8 Mon Sep 17 00:00:00 2001 From: Zetaphor Date: Sat, 25 Jan 2025 23:54:03 -0600 Subject: [PATCH] Add a basic UI --- README.md | 20 ++++++++- app/main.py | 38 ++++++++++++++++- app/static/css/main.css | 34 +++++++++++++++ app/templates/base.html | 64 ++++++++++++++++++++++++++++ app/templates/bookmarks.html | 32 ++++++++++++++ app/templates/index.html | 29 +++++++++++++ app/templates/search.html | 82 ++++++++++++++++++++++++++++++++++++ config/reader_config.yaml | 1 + requirements.txt | 8 ++++ 9 files changed, 306 insertions(+), 2 deletions(-) create mode 100644 app/static/css/main.css create mode 100644 app/templates/base.html create mode 100644 app/templates/bookmarks.html create mode 100644 app/templates/index.html create mode 100644 app/templates/search.html diff --git a/README.md b/README.md index da2826d..4b7a32e 100644 --- a/README.md +++ b/README.md @@ -86,12 +86,30 @@ python main.py - Send content to the backend server - Update history and bookmarks -3. Access the API endpoints: +3. Access the web interface: + - Home page: `http://localhost:8523/` + - Search interface: `http://localhost:8523/search` + - Bookmarks page: `http://localhost:8523/bookmarks` + +4. Access the API endpoints: - Search history: `GET /history/search` - Search bookmarks: `GET /bookmarks/search` - Advanced search: `GET /history/search/advanced` - Manage ignored domains: `GET/POST/DELETE /config/ignored-domains` +## Web Interface + +Browser Recall includes a basic web interface for viewing and searching your browsing history and bookmarks: + +- **Home Page**: Displays recent browsing history +- **Search Page**: Provides a form interface for searching history with filters +- **Bookmarks Page**: Shows your browser bookmarks + +The interface is built with: +- Tailwind CSS for styling +- Responsive design for mobile and desktop +- Dark mode for comfortable viewing + ## API Documentation The API documentation is available through FastAPI's interactive interface at `http://localhost:8523/docs`. This provides a complete API reference with: diff --git a/app/main.py b/app/main.py index 21af921..eac0600 100644 --- a/app/main.py +++ b/app/main.py @@ -12,6 +12,9 @@ from bs4 import BeautifulSoup from sqlalchemy import text from sqlalchemy.sql import text from .logging_config import setup_logger +from fastapi.templating import Jinja2Templates +from fastapi.staticfiles import StaticFiles +from fastapi import Request from .database import get_db, HistoryEntry, Bookmark from .scheduler import HistoryScheduler @@ -34,6 +37,9 @@ app.add_middleware( allow_headers=["*"], ) +templates = Jinja2Templates(directory="app/templates") +app.mount("/static", StaticFiles(directory="app/static"), name="static") + @app.on_event("startup") async def startup_event(): logger.info("Starting application") @@ -342,4 +348,34 @@ async def add_ignored_domain(pattern: str): async def remove_ignored_domain(pattern: str): """Remove a domain pattern from ignored list""" config.remove_ignored_domain(pattern) - return {"status": "success", "message": f"Removed pattern: {pattern}"} \ No newline at end of file + return {"status": "success", "message": f"Removed pattern: {pattern}"} + +@app.get("/") +async def home(request: Request, db: Session = Depends(get_db)): + # Get recent history entries + entries = db.query(HistoryEntry)\ + .order_by(HistoryEntry.visit_time.desc())\ + .limit(50)\ + .all() + return templates.TemplateResponse( + "index.html", + {"request": request, "entries": entries} + ) + +@app.get("/search") +async def search_page(request: Request): + return templates.TemplateResponse( + "search.html", + {"request": request} + ) + +@app.get("/bookmarks") +async def bookmarks_page(request: Request, db: Session = Depends(get_db)): + bookmarks = db.query(Bookmark)\ + .order_by(Bookmark.added_time.desc())\ + .limit(50)\ + .all() + return templates.TemplateResponse( + "bookmarks.html", + {"request": request, "bookmarks": bookmarks} + ) \ No newline at end of file diff --git a/app/static/css/main.css b/app/static/css/main.css new file mode 100644 index 0000000..1f82bbc --- /dev/null +++ b/app/static/css/main.css @@ -0,0 +1,34 @@ +/* Custom styles can be added here */ +.active-nav-link { + border-color: #60a5fa; + color: #60a5fa; +} + +/* Add smooth transitions for hover effects */ +.hover\:border-primary { + transition: border-color 0.2s ease-in-out; +} + +/* Custom scrollbar styles */ +::-webkit-scrollbar { + width: 8px; +} + +::-webkit-scrollbar-track { + background: #1f2937; +} + +::-webkit-scrollbar-thumb { + background: #60a5fa; + border-radius: 4px; +} + +::-webkit-scrollbar-thumb:hover { + background: #3b82f6; +} + +/* Dark mode input styles */ +input[type="date"]::-webkit-calendar-picker-indicator { + filter: invert(1); + opacity: 0.5; +} \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html new file mode 100644 index 0000000..a7ee4d2 --- /dev/null +++ b/app/templates/base.html @@ -0,0 +1,64 @@ + + + + + + + {% block title %}Browser History{% endblock %} + + + + + + + + +
+ {% block content %}{% endblock %} +
+ + + \ No newline at end of file diff --git a/app/templates/bookmarks.html b/app/templates/bookmarks.html new file mode 100644 index 0000000..f33f989 --- /dev/null +++ b/app/templates/bookmarks.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} + +{% block title %}Browser History - Bookmarks{% endblock %} + +{% block content %} +
+
+

Bookmarks

+
+
+
    + {% for bookmark in bookmarks %} +
  • +
    +
    +

    + {{ bookmark.title }} +

    +

    + {{ bookmark.domain }} • {{ bookmark.added_time }} + {% if bookmark.folder %} + {{ bookmark.folder }} + {% endif %} +

    +
    +
    +
  • + {% endfor %} +
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..b0f5e9a --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} + +{% block title %}Browser History - Home{% endblock %} + +{% block content %} +
+
+

Recent History

+
+
+
    + {% for entry in entries %} +
  • +
    +
    +

    + {{ entry.title }} +

    +

    + {{ entry.domain }} • {{ entry.visit_time }} +

    +
    +
    +
  • + {% endfor %} +
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/search.html b/app/templates/search.html new file mode 100644 index 0000000..1af9046 --- /dev/null +++ b/app/templates/search.html @@ -0,0 +1,82 @@ +{% extends "base.html" %} + +{% block title %}Browser History - Search{% endblock %} + +{% block content %} +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+
+ +
+
+
    + +
+
+
+
+ + +{% endblock %} \ No newline at end of file diff --git a/config/reader_config.yaml b/config/reader_config.yaml index f764257..4a27bfd 100644 --- a/config/reader_config.yaml +++ b/config/reader_config.yaml @@ -8,6 +8,7 @@ excluded_domains: - 192.168.*.* - 10.*.*.* - 172.16.*.* + - "0.0.0.*" # Example wildcard patterns # - *.local diff --git a/requirements.txt b/requirements.txt index 58ed474..54bb7dc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,14 @@ fastapi uvicorn sqlalchemy +jinja2 +python-multipart +aiofiles +websockets +beautifulsoup4 +markdown +python-iso8601 +pytz browser-history beautifulsoup4>=4.9.3 markdownify