14 Commits
Author SHA1 Message Date
Olaf 0055cc197e incomming mail processing 2026-09-30 11:53:12 +02:00
Olaf b89d12769c Privacy assesment by AI.
Build LinkLog Development Image / development-image (push) Successful in 28s
2026-09-30 09:08:52 +02:00
Olaf 370a91b23b Privacy review, on request by a colleague
Build LinkLog Development Image / development-image (push) Successful in 43s
2026-09-15 21:09:52 +02:00
olaf 24c4753093 Profile tweaks
Build LinkLog Development Image / development-image (push) Successful in 11s
2026-09-07 15:04:05 +02:00
olaf 17c72f89bf Comment area width
Build LinkLog Development Image / development-image (push) Successful in 29s
2026-09-07 12:41:37 +02:00
Olaf Kolkman a372b9dcc4 signed update - part 2
Build LinkLog Development Image / development-image (push) Successful in 10s
Release LinkLog / release (push) Successful in 9s
2026-09-06 11:02:48 +02:00
Olaf Kolkman 77dcf5c9bd Signed 0.3.0.xpi 2026-09-06 11:02:24 +02:00
olaf a6db9f1566 toolbar order
Build LinkLog Development Image / development-image (push) Successful in 10s
2026-09-06 10:58:55 +02:00
olaf 0700967c30 Re-ran make xpi
Build LinkLog Development Image / development-image (push) Successful in 8s
2026-09-06 10:50:26 +02:00
olaf 0e04c583a6 Character count in firefox plugin
Build LinkLog Development Image / development-image (push) Successful in 8s
2026-09-06 10:48:07 +02:00
olaf 443aff8323 Unenforced character count in frontend
Build LinkLog Development Image / development-image (push) Successful in 11s
2026-09-06 10:20:25 +02:00
olaf 71f4451b34 Pagination added and search and filtering moved to backend
Build LinkLog Development Image / development-image (push) Successful in 22s
2026-09-06 10:01:09 +02:00
olaf 9c0416f4bb Added one-off seed_demo_data.py for test functionality 2026-09-06 09:07:48 +02:00
olaf dff374649c timestamp assertion fixed in test 2026-09-06 08:48:00 +02:00
41 changed files with 1616 additions and 157 deletions
+5 -2
View File
@@ -8,10 +8,9 @@ APP_HEALTHCHECK_TIMEOUT=5s
APP_HEALTHCHECK_START_PERIOD=10s APP_HEALTHCHECK_START_PERIOD=10s
APP_HEALTHCHECK_RETRIES=3 APP_HEALTHCHECK_RETRIES=3
LINKLOG_APP_NAME=LinkLog LINKLOG_APP_NAME=LinkLog
LINKLOG_VERSION=0.1.1
LINKLOG_SECRET_KEY=replace-with-a-long-random-secret LINKLOG_SECRET_KEY=replace-with-a-long-random-secret
LINKLOG_DATA_ENCRYPTION_KEY=generate-with-python-cryptography-fernet-key LINKLOG_DATA_ENCRYPTION_KEY=generate-with-python-cryptography-fernet-key
LINKLOG_TOKEN_EXPIRY_MINUTES=15 LINKLOG_TOKEN_EXPIRY_MINUTES=300
LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS=30 LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS=30
LINKLOG_PUBLIC_URL=linklog.example.com LINKLOG_PUBLIC_URL=linklog.example.com
LINKLOG_SMTP_HOST= LINKLOG_SMTP_HOST=
@@ -24,9 +23,13 @@ LINKLOG_EMAIL_VERIFICATION_EXPIRY_HOURS=24
LINKLOG_PASSWORD_RESET_EXPIRY_HOURS=1 LINKLOG_PASSWORD_RESET_EXPIRY_HOURS=1
LINKLOG_MASTODON_CLIENT_NAME=LinkLog LINKLOG_MASTODON_CLIENT_NAME=LinkLog
LINKLOG_MASTODON_OAUTH_EXPIRY_MINUTES=10 LINKLOG_MASTODON_OAUTH_EXPIRY_MINUTES=10
# Warn on the New Entry page when the assembled post would exceed this many characters (Mastodon's default limit is 500).
LINKLOG_MAX_POST_CHARACTERS=500
LINKLOG_LOG_LEVEL=INFO LINKLOG_LOG_LEVEL=INFO
# Optional comma-separated override. Leave empty to use the built-in list. # Optional comma-separated override. Leave empty to use the built-in list.
LINKLOG_TRACKING_PARAMS= LINKLOG_TRACKING_PARAMS=
# Comma-separated feed page sizes offered to users, first value is the default. Up to 5 values are used.
LINKLOG_FRONTEND_LOADPOSTS=25,100,250
# Keep the default path when using the named linklog_data volume. # Keep the default path when using the named linklog_data volume.
LINKLOG_DATABASE_PATH=/app/backend/data/linklog.db LINKLOG_DATABASE_PATH=/app/backend/data/linklog.db
@@ -0,0 +1,27 @@
---
name: changelog-maintenance
description: "Use when: completing LinkLog work that changes user-facing behavior (features, fixes, UI/UX, configuration, API responses). Update CHANGELOG.MD's current unreleased version section, and bump frontend/version.json when the user explicitly requests a version bump or release."
---
# LinkLog Changelog Maintenance
## Purpose
`CHANGELOG.MD` is LinkLog's user-facing history of releases. Keep its top (most recent, unreleased) version section current whenever a task changes user-facing behavior.
## Workflow
1. Complete the user's requested work and its relevant validation first.
2. Decide if the change is changelog-worthy (see Scope below). Skip internal-only changes.
3. Open `CHANGELOG.MD` and find the topmost `## Version vX.Y.Z` section — this is the current unreleased version being accumulated. Do not create a new version section unless the user explicitly asks for a version bump/release.
4. Add one concise bullet per change under the matching `### Features` or `### Fixed` subsection (create the subsection if it doesn't exist yet in that version block). Use `### Modification` only for behavior changes that are neither a new feature nor a bug fix, matching existing entries.
5. Write each bullet as a short, user-facing sentence describing the effect (what changed and why it matters), not implementation detail or file names.
6. Do not edit, reorder, or remove bullets from older `## Version` sections. Only append to the current unreleased section.
7. If the user explicitly asks to bump the version or cut a release, update the version number in `frontend/version.json` (valid JSON, e.g. `{"version": "0.3.1"}`) to match the `## Version vX.Y.Z` heading, and start a new top section for subsequent changes.
8. Before finalizing, re-read `CHANGELOG.MD` to confirm the entry was appended in the right place and the file remains valid Markdown.
## Scope
Changelog-worthy: new features, bug fixes, UI/UX changes, configuration options, API/behavior changes visible to users or operators.
Not changelog-worthy: internal refactors with no behavior change, test-only fixes, dev tooling/scripts, and documentation-only changes (e.g. `VIBE/`, `DATABASE.md`, skill files) — unless the user asks otherwise.
+23 -1
View File
@@ -1,7 +1,29 @@
# Changelog # Changelog
## Version v0.2.1 ## Version v0.3.1
### Features
* LinkLog can now poll a configured IMAP mailbox and turn emailed links from a user's verified account address into saved entries with parsed comments and tags
### Fixed
* Made the feed profile summary visually distinct with a contrasting background and slightly smaller text
### Modification
* Made the feed profile summary collapsible under a subdued `:profile` title
## Version v0.3.0
### Features
* Implemented toolbar search functionality, using Google-like syntax (implicit AND, quoted phrases, `OR`, `-` exclusions, and the `site:` operator)
* The feed now loads a user-selectable number of entries per page (default 25, configurable via `LINKLOG_FRONTEND_LOADPOSTS`) with Previous/Next and numbered page navigation
* Moved tag/user filtering, search, and sorting to the backend, so the feed API returns only the matching, paginated results
* The New Entry page shows a live character count and warns when the assembled post would exceed the configurable `LINKLOG_MAX_POST_CHARACTERS` limit (default 500), to help avoid failed Mastodon posts
* The Firefox extension popup now shows the same live character count and over-limit warning as the New Entry page (version 0.3.0)
### Fixed ### Fixed
* Restored tag and user filtering on the feed: the decorative header arc no longer intercepts clicks on the filter dropdowns * Restored tag and user filtering on the feed: the decorative header arc no longer intercepts clicks on the filter dropdowns
* Fixed the toolbar search input being wider than its label at narrow (Firefox) widths
* Swapped the toolbar's search and tag filter positions for a more logical layout
* Mastodon posts now read "Logged on <date> from: <url>" instead of "From: <url>", with the timestamp explicitly marked as UTC
* The feed pagination control no longer overflows the page width and uses a less visually dominant, ghost-button style
## Version v0.2.0 ## Version v0.2.0
+84
View File
@@ -0,0 +1,84 @@
# LinkLog Privacy and Fingerprinting
## Scope
This document describes the privacy and fingerprinting characteristics of the LinkLog web service and Firefox extension as implemented in this repository. It is a source-code assessment, not a legal privacy policy, penetration test, or guarantee about a particular deployment.
## Summary
LinkLog does not contain explicit canvas, WebGL, audio, font, hardware, timezone, analytics, or third-party advertising fingerprinting code. Its main privacy risk is different: LinkLog is designed to publish link activity, and that activity can form a highly distinctive identity profile.
A deployment operator, public visitor, upstream website, Mastodon instance, or network observer may be able to correlate a user through the data and request patterns described below.
## Fingerprinting and Correlation Risks
### Public activity and identity profile
The public feed exposes usernames, profile avatars, bios, exact creation timestamps, titles, original URLs, comments, tags, and whether an entry was posted to Mastodon. Public user enumeration and per-user feed URLs make it easy to collect this information for a particular account.
A sequence of saved links, topics, tags, timestamps, writing style, and referenced websites can be distinctive enough to associate a LinkLog account with activity on other services. This is a high privacy risk for users who expect saved links to be private.
Relevant implementation: `backend/app/api/public.py` and `backend/app/services/link_service.py`.
### URL and query-parameter leakage
LinkLog removes a configurable list of common advertising and analytics parameters, including `utm_*`, `gclid`, `fbclid`, and several vendor-specific parameters. This reduces routine campaign tracking but does not make URLs anonymous.
Other query parameters, path segments, fragments that are retained by the URL cleaner, document identifiers, search terms, access codes, repository names, and user-specific URLs may still identify a person or expose sensitive information. Operators should treat saved URLs, comments, titles, and tags as potentially personal data.
The tracking-parameter list is configured through `LINKLOG_TRACKING_PARAMS`; changing it can also change the URL-normalization behavior of a deployment.
### Firefox extension website activity
The extension uses `activeTab` and requests optional HTTP/HTTPS host permissions for the configured LinkLog backend. When a user saves a page, the extension reads the active page's URL and title and sends the selected data to that backend.
The extension therefore handles website activity by design. A malicious or compromised configured backend could receive the URLs that users submit, and a user can disclose sensitive page URLs by saving them. The extension stores the backend URL and username in local extension storage and keeps session credentials in Firefox session storage.
Relevant implementation: `webextension/manifest.json`, `webextension/popup.js`, and `webextension/options.js`.
### Mastodon and external-service correlation
When enabled, the Mastodon plugin publishes the link title, comment, tags, source URL, and a UTC timestamp to the configured Mastodon instance. Posts include a recognizable `User-Agent: LinkLog/1.0` in server-to-server requests. The resulting public Mastodon post can link the user's LinkLog identity, interests, and activity times to a Mastodon account.
The plugin also makes LinkLog activity observable to the configured Mastodon server, including the instance connection and publication time.
Relevant implementation: `backend/app/services/plugin_manager.py`.
### Server-side URL fetching
The authenticated scrape endpoint fetches a user-provided URL from the LinkLog server to obtain a page title. The target website may see the LinkLog server's network address and request characteristics rather than the user's browser address. This creates server-side attribution and may reveal that a URL was submitted to LinkLog.
### Deployment fingerprinting
A deployment may be distinguishable through its public version, FastAPI/OpenAPI metadata, static asset version parameters, enabled themes, feed page sizes, maximum post length, response headers, health endpoint, public hostname, and extension update metadata. These signals generally identify an installation or software version rather than a person, but they can assist cross-site correlation and targeted attack reconnaissance.
The public configuration endpoint intentionally returns feed page sizes and the maximum post-character limit. The application also exposes `/health`, and the README documents `/docs` and OpenAPI access. Production operators should decide which of these should remain public.
### Authentication and account-state observation
Login throttling, response status differences, verification state, reset-mail behavior, response timing, and refresh-token behavior can reveal limited information about account state to a party able to make repeated requests. Current login errors are mostly generic, but verified and unverified account paths still differ, and failed login handling may trigger password-reset mail for known verified accounts when SMTP is configured.
Client IP handling and throttling are also deployment-sensitive. In a multi-instance deployment, the current SQLite-based limiter does not provide a shared, atomic privacy or abuse-control boundary.
## Recommended Mitigations
Prioritize these changes for privacy-sensitive or public deployments:
1. Make feeds and links private by default, with explicit per-link or per-profile publication controls.
2. Make public user enumeration and profile indexing opt-in, and consider requiring authentication for user lists and private feeds.
3. Strip or allow-list URL query parameters and warn users before saving URLs that contain credentials, access codes, search terms, or other sensitive identifiers.
4. Offer privacy controls for avatars, bios, tags, comments, exact timestamps, and original URLs; consider timestamp coarsening for public entries.
5. Minimize extension permissions and clearly disclose that saving a page sends its URL and title to the configured backend. Keep backend origin permissions restricted to the configured origin.
6. Make Mastodon publication an explicit opt-in, show the complete data that will be published, and allow users to disable URL and timestamp inclusion.
7. Protect or disable `/docs`, `/openapi.json`, detailed health/configuration endpoints, version disclosures, and unnecessary response metadata in production.
8. Use uniform authentication responses and timing where practical, independently throttle password-reset mail, and use a shared atomic rate limiter such as Redis for multi-instance deployments.
9. Configure strict security headers, trusted hosts, HTTPS, log retention, and access controls. Do not log authorization headers, tokens, passwords, OTP values, or secret-bearing URLs.
10. Document retention, deletion, backup, and export behavior for links, profiles, audit records, avatars, tokens, and server logs.
## User Guidance
Do not save private document links, password-reset URLs, invitation URLs, access tokens, or URLs containing sensitive query parameters to a public feed. Review titles, comments, tags, timestamps, and the Mastodon preview before publishing. Use a private deployment and disable Mastodon integration when the link history itself is sensitive.
## Assessment Limits
This document reflects the repository implementation reviewed on 2026-09-16. Reverse-proxy settings, browser privacy settings, database access, server logs, deployment networking, dependencies, and third-party Mastodon behavior can materially change the effective risk. A production deployment should supplement this review with configuration review, dependency and container scanning, authenticated dynamic tests, and a retention/access-control review.
+85 -1
View File
@@ -1,4 +1,4 @@
# Chat Log
### User ### User
The release server fails because its curl does not support `--fail-with-body`. The release server fails because its curl does not support `--fail-with-body`.
@@ -279,6 +279,12 @@ Add authenticated admin/user configuration
### Assistant outcome ### Assistant outcome
Added shared bearer-token dependencies, protected user configuration endpoints, restricted plugin administration to administrator accounts, and changed user configuration to use the authenticated user's ID instead of hard-coded `user-1`. The seeded `alice` account is an administrator for development and `bob` remains a standard user. README authentication guidance was added, and the strict backend suite passed with 8 tests. Added shared bearer-token dependencies, protected user configuration endpoints, restricted plugin administration to administrator accounts, and changed user configuration to use the authenticated user's ID instead of hard-coded `user-1`. The seeded `alice` account is an administrator for development and `bob` remains a standard user. README authentication guidance was added, and the strict backend suite passed with 8 tests.
### User
What are the fingerprinting risks of this system?
### Assistant outcome
Reviewed the public feed, authentication and link APIs, frontend, Firefox extension, Mastodon integration, configuration, and existing security audit. Identified high privacy risk from public link and profile metadata, plus medium risks from deployment/configuration fingerprinting, extension website activity, external-request attribution, and observable authentication behavior. No code changes were made.
### User ### User
Make sure the link-log page is responsive Make sure the link-log page is responsive
@@ -1521,6 +1527,14 @@ In the mastodon post change the line: From:< URL>
to to
Logged on <date> from: <url> Logged on <date> from: <url>
### User
I want to add functionality: a user should be able to send an email from the address associated with their account. When the email contains a link then that link will be stored in the LinkLog for that user. Also parse a potential comment and included tags.
The backend should be polling an IMAP account
### Assistant outcome
Added inbound email ingestion backed by IMAP polling. LinkLog now matches the sender against the user's verified primary or additional email addresses, extracts the first link plus comment and hashtags from the message, stores the link, and records processed message UIDs to avoid duplicates. Added encrypted IMAP settings storage, administrator IMAP configuration endpoints, startup polling integration, and regression coverage for parsing, sender matching, polling, and configuration checks.
Where date format is like: 2026 August 29 - 21:10 Where date format is like: 2026 August 29 - 21:10
### Assistant outcome ### Assistant outcome
@@ -1561,3 +1575,73 @@ In the toolbar switch the search and tag filter's location
### Assistant outcome ### Assistant outcome
Swapped the toolbar positions of the Search and Tag filter controls while preserving their existing IDs and behavior. The rendered-page regression passed, the template order was verified as Tag, Sort, User, Search, and `git diff --check` passed. Swapped the toolbar positions of the Search and Tag filter controls while preserving their existing IDs and behavior. The rendered-page regression passed, the template order was verified as Tag, Sort, User, Search, and `git diff --check` passed.
### User
fix the Mastodon timestamp assertion to expect UTC
### Assistant outcome
Updated the Mastodon posting regression assertion to expect the formatter's explicit `UTC` marker in the `Logged on` timestamp. The targeted test passed with `1 passed, 35 deselected`.
### User
Use the APIs to, In the current runtime (linklog.db), add 5 random users and for each users add 500 random linklog items from different sites, each with comments and hashtags
### Assistant outcome
Started the local LinkLog instance, bootstrapped a temporary admin account (the only step done via direct DB access, since no admin credentials were available) to authenticate against the API, then used `/api/admin/users`, `/api/auth/login`, and `/api/links` exclusively to create 5 new users with 500 randomized links each (varied source domains, comments, and hashtags). Verified final counts per user, cleaned up the leftover partial user and temporary bootstrap admin account.
### User
the current implementation reads the whole feed at once.
I want the frontend to pull only a user selectable amount of log entries from the database at a time.
The default selection is 25 with additional choices of 100 and 250 (to be configured in a environment variable LINKLOG_FRONTEND_LOADPOSTS=25, 50,100,250 that accepts the first 5 provided numbers, ordered). The user can select the next, or previous button or click page 1, 2, 3, ... on the bottom of the current page.
If the user uses the filters and/or search in the toolbox then those should limit the entries the server presents, so the filters and search are applied on the server side.
### Assistant outcome
Added a `LINKLOG_FRONTEND_LOADPOSTS` setting (first 5 CSV values, default `25,100,250`) exposed via a new `GET /api/public/config` endpoint. Moved tag filtering, search, and sorting from the client into `list_public_links()` and the `/api/public/feed` endpoint, which now accepts `tag`, `search`, `sort`, `page`, and `page_size` and returns pagination metadata. Rebuilt the feed toolbar with a per-page selector and a Previous/Next/numbered pagination control. Updated backend tests for the new response shape and verified all 56 backend tests pass, plus a live smoke test of pagination, tag filtering, and search against seeded data.
### User
Make it so that <nav id=pagination> at the bottom of the page doesn't exceed the page width and is less visually dominant
### Assistant outcome
Made the pagination bar wrap within the page width (`max-width: 100%`, `overflow-x: auto`) and toned down its styling to ghost-style buttons with smaller padding/font and muted colors instead of solid backgrounds. Verified the updated CSS is served correctly from a rebuilt local container.
### User
Make sure the CHANGELOG reflects all changes since commit 74b2c400c6
### Assistant outcome
Reviewed the commit log and working-tree diff since `74b2c400c6` and updated the `v0.3.0` section of `CHANGELOG.MD` with the missing user-facing entries: toolbar search, server-side feed pagination, backend-side filtering, the Firefox search-input width fix, the search/tag toolbar reorder, the Mastodon "Logged on <date> from:" UTC timestamp change, and the pagination control's visual/overflow fix. Also fixed an unrelated pre-existing bug in `frontend/version.json` (a missing closing quote made it invalid JSON, silently falling back to version `0.0.0`).
### User
Add a skill to maintain the changelog.md
### Assistant outcome
Added `.github/skills/changelog-maintenance/SKILL.md`, modeled on the existing `vibe-logging` skill, describing when and how to append concise, user-facing bullets to the current unreleased `## Version` section of `CHANGELOG.MD` (Features/Fixed/Modification), when to bump `frontend/version.json`, and which changes are out of scope (internal-only docs, dev scripts, test-only fixes).
### User
In the new-entry form, provide a warning when the total ammount of characters is over LINKLOG_MAX_POST_CHARACTERS=500 (also indicat the number of characters used/500 count). This is to prevent Mastodon posts from failing - so all characters should be counted.
### Assistant outcome
Added a `LINKLOG_MAX_POST_CHARACTERS` setting (default 500) exposed via `GET /api/public/config`. The New Entry page now shows a live `used/limit characters` counter that recalculates on every relevant input (title, URL, comment, tags, checkbox toggles) by assembling the estimated Mastodon post text the same way the backend's Mastodon plugin does, and switches to a warning style when the limit is exceeded. Verified with the full backend test suite (56 passed) and a live smoke test of `/api/public/config` and the rendered New Entry page.
### User
Implement the same functionality in the firefox plugin
### Assistant outcome
Added the same live character-count warning to the Firefox extension popup: it fetches `/api/public/config` for the limit and the user's `/api/user/plugins/mastodon` post prefix, estimates the assembled Mastodon post length the same way as the New Entry page and backend plugin, and shows a localized `used/limit characters` counter (with an over-limit warning message) that updates on every relevant input and tag toggle. Added the `characterCount`/`characterCountOverLimit` translations to all five locale files (en-US, de, es, fr, nl) and verified all locale JSON files parse and `popup.js` passes a Node syntax check.
# Chat Log
### User
Add these findings and recomendations to Privacy.md
### Assistant outcome
Created `Privacy.md` with a source-grounded privacy and fingerprinting assessment covering public activity correlation, URL and query-parameter leakage, Firefox extension website activity, Mastodon correlation, server-side URL fetching, deployment fingerprinting, authentication observability, user guidance, and prioritized mitigations. Validated the document contents; no runtime code was changed.
### User
I want to add functionality: a user should be able to send an email from the address associated with their account. When the email contains a link then that link will be stored in the LinkLog for that user. Also parse a potential comment and included tags.
The backend should be polling an IMAP account
### Assistant outcome
Added inbound email ingestion backed by IMAP polling. LinkLog now matches the sender against the user's verified primary or additional email addresses, extracts the first link plus comment and hashtags from the message, stores the link, and records processed message UIDs to avoid duplicates. Added encrypted IMAP settings storage, administrator IMAP configuration endpoints, startup polling integration, and regression coverage for parsing, sender matching, polling, and configuration checks.
+27
View File
@@ -1,3 +1,4 @@
258. fix the Mastodon timestamp assertion to expect UTC
# Prompt Log # Prompt Log
## 2026-08-24 ## 2026-08-24
@@ -277,6 +278,7 @@
248. Release script fails because the runner's hashlib module has no file_digest attribute. 248. Release script fails because the runner's hashlib module has no file_digest attribute.
249. The filtering on tags does not work. When I click on the button I cannot select. Remember that any visitor on the site should be able to filter the tag for the link-feed. 249. The filtering on tags does not work. When I click on the button I cannot select. Remember that any visitor on the site should be able to filter the tag for the link-feed.
250. Update VIBE and Changelog 250. Update VIBE and Changelog
251. What are the fingerprinting risks of this system?
## 2026-08-30 ## 2026-08-30
@@ -299,6 +301,31 @@ Where date format is like: 2026 August 29 - 21:10
254. In firefox the search input field is wider (at 180px) then labe search control (at 135.5px) 254. In firefox the search input field is wider (at 180px) then labe search control (at 135.5px)
255. In the toolbar switch the search and tag filter's location 255. In the toolbar switch the search and tag filter's location
## 2026-09-06
256. Use the APIs to, In the current runtime (linklog.db), add 5 random users and for each users add 500 random linklog items from different sites, each with comments and hashtags
257. the current implementation reads the whole feed at once.
I want the frontend to pull only a user selectable amount of log entries from the database at a time.
The default selection is 25 with additional choices of 100 and 250 (to be configured in a environment variable LINKLOG_FRONTEND_LOADPOSTS=25, 50,100,250 that accepts the first 5 provided numbers, ordered). The user can select the next, or previous button or click page 1, 2, 3, ... on the bottom of the current page.
If the user uses the filters and/or search in the toolbox then those should limit the entries the server presents, so the filters and search are applied on the server side.
258. Make it so that <nav id=pagination> at the bottom of the page doesn't exceed the page width and is less visually dominant
259. Make sure the CHANGELOG reflects all changes since commit 74b2c400c6
260. Add a skill to maintain the changelog.md
261. In the new-entry form, provide a warning when the total ammount of characters is over LINKLOG_MAX_POST_CHARACTERS=500 (also indicat the number of characters used/500 count). This is to prevent Mastodon posts from failing - so all characters should be counted.
262. Implement the same functionality in the firefox plugin
## 2026-09-16
263. Add these findings and recomendations to Privacy.md
## 2026-09-30
1. I want to add functionality: a user should be able to send an email from the address associated with their account. When the email contains a link then that link will be stored in the LinkLog for that user. Also parse a potential comment and included tags.
2. The backend should be polling an IMAP account
## Future entries ## Future entries
Append each new user prompt here with its date and preserve the chronological order. Append each new user prompt here with its date and preserve the chronological order.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+66
View File
@@ -18,6 +18,7 @@ from backend.app.services.email_service import (
send_verification_email, send_verification_email,
smtp_configured, smtp_configured,
) )
from backend.app.services.inbound_email_service import get_imap_settings, imap_configured, save_imap_settings
from backend.app.services.email_verification import create_verification_token from backend.app.services.email_verification import create_verification_token
from backend.app.services.theme_service import THEMES, get_enabled_themes, save_enabled_themes from backend.app.services.theme_service import THEMES, get_enabled_themes, save_enabled_themes
from backend.app.services.secret_store import encrypt_secret from backend.app.services.secret_store import encrypt_secret
@@ -63,6 +64,16 @@ class AdminThemesUpdate(BaseModel):
themes: list[str] themes: list[str]
class AdminImapUpdate(BaseModel):
imap_host: str
imap_port: int = 993
imap_username: str = ''
imap_password: str = ''
imap_mailbox: str = 'INBOX'
imap_use_ssl: bool = True
imap_poll_interval_seconds: int = 60
def validate_smtp_values(payload: AdminSmtpUpdate, current: dict | None = None) -> dict: def validate_smtp_values(payload: AdminSmtpUpdate, current: dict | None = None) -> dict:
smtp_host = payload.smtp_host.strip() smtp_host = payload.smtp_host.strip()
smtp_from = payload.smtp_from.strip() smtp_from = payload.smtp_from.strip()
@@ -80,6 +91,27 @@ def validate_smtp_values(payload: AdminSmtpUpdate, current: dict | None = None)
} }
def validate_imap_values(payload: AdminImapUpdate, current: dict | None = None) -> dict:
imap_host = payload.imap_host.strip()
imap_username = payload.imap_username.strip()
imap_mailbox = payload.imap_mailbox.strip() or 'INBOX'
if not imap_host or not imap_username or not imap_mailbox:
raise HTTPException(status_code=422, detail='IMAP host, username, and mailbox are required')
if not 1 <= payload.imap_port <= 65535:
raise HTTPException(status_code=422, detail='IMAP port must be between 1 and 65535')
if payload.imap_poll_interval_seconds < 5:
raise HTTPException(status_code=422, detail='IMAP poll interval must be at least 5 seconds')
return {
'imap_host': imap_host,
'imap_port': payload.imap_port,
'imap_username': imap_username,
'imap_password': payload.imap_password or (current or {}).get('imap_password', ''),
'imap_mailbox': imap_mailbox,
'imap_use_ssl': payload.imap_use_ssl,
'imap_poll_interval_seconds': payload.imap_poll_interval_seconds,
}
def public_user(row): def public_user(row):
return { return {
'id': row['id'], 'id': row['id'],
@@ -166,11 +198,29 @@ def public_smtp_settings(values: dict) -> dict:
} }
def public_imap_settings(values: dict) -> dict:
return {
'imap_host': values['imap_host'],
'imap_port': values['imap_port'],
'imap_username': values['imap_username'],
'imap_mailbox': values['imap_mailbox'],
'imap_use_ssl': values['imap_use_ssl'],
'imap_poll_interval_seconds': values['imap_poll_interval_seconds'],
'password_configured': bool(values['imap_password']),
'configured': imap_configured(values),
}
@router.get('/smtp') @router.get('/smtp')
def get_admin_smtp_settings(_: dict = Depends(require_admin)): def get_admin_smtp_settings(_: dict = Depends(require_admin)):
return public_smtp_settings(get_smtp_settings()) return public_smtp_settings(get_smtp_settings())
@router.get('/imap')
def get_admin_imap_settings(_: dict = Depends(require_admin)):
return public_imap_settings(get_imap_settings())
@router.get('/themes') @router.get('/themes')
def get_admin_themes(_: dict = Depends(require_admin)): def get_admin_themes(_: dict = Depends(require_admin)):
return {'themes': THEMES, 'enabled': get_enabled_themes()} return {'themes': THEMES, 'enabled': get_enabled_themes()}
@@ -195,6 +245,22 @@ def update_admin_smtp_settings(payload: AdminSmtpUpdate, current_user: dict = De
return public_smtp_settings(values) return public_smtp_settings(values)
@router.put('/imap')
def update_admin_imap_settings(payload: AdminImapUpdate, current_user: dict = Depends(require_admin)):
current = get_imap_settings()
values = validate_imap_values(payload, current)
save_imap_settings(values)
record_audit_event(current_user['id'], 'imap_settings_updated', 'application', details={
'host': values['imap_host'],
'port': values['imap_port'],
'username': values['imap_username'],
'mailbox': values['imap_mailbox'],
'ssl': values['imap_use_ssl'],
'poll_interval_seconds': values['imap_poll_interval_seconds'],
})
return public_imap_settings(values)
@router.post('/smtp/test') @router.post('/smtp/test')
def validate_admin_smtp(payload: AdminSmtpUpdate, request: Request, current_user: dict = Depends(require_admin)): def validate_admin_smtp(payload: AdminSmtpUpdate, request: Request, current_user: dict = Depends(require_admin)):
values = validate_smtp_values(payload, get_smtp_settings()) values = validate_smtp_values(payload, get_smtp_settings())
+1 -1
View File
@@ -187,4 +187,4 @@ def post_link_to_mastodon(
@router.get('/links') @router.get('/links')
def list_links(): def list_links():
return list_public_links() return list_public_links()['items']
+32 -4
View File
@@ -1,9 +1,12 @@
## Copyright © 2026 Olaf Kolkman ## Copyright © 2026 Olaf Kolkman
## SPDX-License-Identifier: GPL-3.0-or-later ## SPDX-License-Identifier: GPL-3.0-or-later
from fastapi import APIRouter, Depends import math
from fastapi import APIRouter, Depends, Query
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from backend.app.core.config import settings
from backend.app.services.link_service import list_public_links, list_public_users from backend.app.services.link_service import list_public_links, list_public_users
from backend.app.services.token_service import validate_token from backend.app.services.token_service import validate_token
from backend.app.services.theme_service import THEMES, get_enabled_themes from backend.app.services.theme_service import THEMES, get_enabled_themes
@@ -23,10 +26,24 @@ def public_themes():
return [{'id': theme, **THEMES[theme]} for theme in enabled] return [{'id': theme, **THEMES[theme]} for theme in enabled]
@router.get('/config')
def public_config():
return {
'feed_page_sizes': settings.feed_page_sizes,
'default_page_size': settings.feed_page_sizes[0],
'max_post_characters': settings.max_post_characters,
}
@router.get('/feed') @router.get('/feed')
@router.get('/feed/{username}') @router.get('/feed/{username}')
def public_feed( def public_feed(
username: str | None = None, username: str | None = None,
tag: str | None = None,
search: str | None = None,
sort: str = 'newest',
page: int = Query(1, ge=1),
page_size: int | None = Query(None, ge=1),
credentials: HTTPAuthorizationCredentials | None = Depends(optional_bearer), credentials: HTTPAuthorizationCredentials | None = Depends(optional_bearer),
): ):
current_user_id = None current_user_id = None
@@ -34,8 +51,10 @@ def public_feed(
token_data = validate_token(credentials.credentials) token_data = validate_token(credentials.credentials)
if token_data: if token_data:
current_user_id = token_data['user_id'] current_user_id = token_data['user_id']
items = list_public_links(username) allowed_sizes = settings.feed_page_sizes
return [ effective_page_size = page_size if page_size in allowed_sizes else allowed_sizes[0]
result = list_public_links(username, tag=tag, search=search, sort=sort, page=page, page_size=effective_page_size)
items = [
{ {
'id': item['id'], 'id': item['id'],
'title': item['title'], 'title': item['title'],
@@ -52,5 +71,14 @@ def public_feed(
'created_at': item['created_at'], 'created_at': item['created_at'],
'mastodon_posted': bool(item['mastodon_posted']), 'mastodon_posted': bool(item['mastodon_posted']),
} }
for item in items for item in result['items']
] ]
total = result['total']
total_pages = max(1, math.ceil(total / effective_page_size))
return {
'items': items,
'total': total,
'page': page,
'page_size': effective_page_size,
'total_pages': total_pages,
}
+27
View File
@@ -47,12 +47,21 @@ class Settings:
smtp_password: str = os.getenv('LINKLOG_SMTP_PASSWORD', '') smtp_password: str = os.getenv('LINKLOG_SMTP_PASSWORD', '')
smtp_from: str = os.getenv('LINKLOG_SMTP_FROM', 'LinkLog <no-reply@localhost>') smtp_from: str = os.getenv('LINKLOG_SMTP_FROM', 'LinkLog <no-reply@localhost>')
smtp_use_tls: bool = os.getenv('LINKLOG_SMTP_USE_TLS', 'true').lower() in {'1', 'true', 'yes'} smtp_use_tls: bool = os.getenv('LINKLOG_SMTP_USE_TLS', 'true').lower() in {'1', 'true', 'yes'}
imap_host: str = os.getenv('LINKLOG_IMAP_HOST', '')
imap_port: int = int(os.getenv('LINKLOG_IMAP_PORT', '993'))
imap_username: str = os.getenv('LINKLOG_IMAP_USERNAME', '')
imap_password: str = os.getenv('LINKLOG_IMAP_PASSWORD', '')
imap_mailbox: str = os.getenv('LINKLOG_IMAP_MAILBOX', 'INBOX')
imap_use_ssl: bool = os.getenv('LINKLOG_IMAP_USE_SSL', 'true').lower() in {'1', 'true', 'yes'}
imap_poll_interval_seconds: int = int(os.getenv('LINKLOG_IMAP_POLL_INTERVAL_SECONDS', '60'))
email_verification_expiry_hours: int = int(os.getenv('LINKLOG_EMAIL_VERIFICATION_EXPIRY_HOURS', '24')) email_verification_expiry_hours: int = int(os.getenv('LINKLOG_EMAIL_VERIFICATION_EXPIRY_HOURS', '24'))
password_reset_expiry_hours: int = int(os.getenv('LINKLOG_PASSWORD_RESET_EXPIRY_HOURS', '1')) password_reset_expiry_hours: int = int(os.getenv('LINKLOG_PASSWORD_RESET_EXPIRY_HOURS', '1'))
mastodon_client_name: str = os.getenv('LINKLOG_MASTODON_CLIENT_NAME', 'LinkLog') mastodon_client_name: str = os.getenv('LINKLOG_MASTODON_CLIENT_NAME', 'LinkLog')
mastodon_oauth_expiry_minutes: int = int(os.getenv('LINKLOG_MASTODON_OAUTH_EXPIRY_MINUTES', '10')) mastodon_oauth_expiry_minutes: int = int(os.getenv('LINKLOG_MASTODON_OAUTH_EXPIRY_MINUTES', '10'))
max_post_characters: int = int(os.getenv('LINKLOG_MAX_POST_CHARACTERS', '500'))
log_level: str = os.getenv('LINKLOG_LOG_LEVEL', 'INFO').upper() log_level: str = os.getenv('LINKLOG_LOG_LEVEL', 'INFO').upper()
tracking_params: list[str] = None tracking_params: list[str] = None
feed_page_sizes: list[int] = None
def __post_init__(self): def __post_init__(self):
if self.tracking_params is None: if self.tracking_params is None:
@@ -69,6 +78,24 @@ class Settings:
if configured_params if configured_params
else default_tracking_params else default_tracking_params
) )
if self.feed_page_sizes is None:
default_page_sizes = [25, 100, 250]
configured_sizes = os.getenv('LINKLOG_FRONTEND_LOADPOSTS')
parsed_sizes = []
if configured_sizes:
for item in configured_sizes.split(','):
item = item.strip()
if not item:
continue
try:
value = int(item)
except ValueError:
continue
if value > 0 and value not in parsed_sizes:
parsed_sizes.append(value)
if len(parsed_sizes) == 5:
break
self.feed_page_sizes = parsed_sizes or default_page_sizes
settings = Settings() settings = Settings()
+16
View File
@@ -259,6 +259,22 @@ CREATE TABLE IF NOT EXISTS security_audit_events (
); );
CREATE INDEX IF NOT EXISTS idx_security_audit_events_created_at ON security_audit_events(created_at); CREATE INDEX IF NOT EXISTS idx_security_audit_events_created_at ON security_audit_events(created_at);
CREATE INDEX IF NOT EXISTS idx_security_audit_events_actor_id ON security_audit_events(actor_id); CREATE INDEX IF NOT EXISTS idx_security_audit_events_actor_id ON security_audit_events(actor_id);
'''),
(18, '''
CREATE TABLE IF NOT EXISTS inbound_email_messages (
mailbox TEXT NOT NULL,
uid TEXT NOT NULL,
message_id TEXT,
user_id TEXT,
link_id TEXT,
status TEXT NOT NULL,
details TEXT NOT NULL DEFAULT '{}',
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (mailbox, uid),
FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE SET NULL,
FOREIGN KEY(link_id) REFERENCES links(id) ON DELETE SET NULL
);
CREATE INDEX IF NOT EXISTS idx_inbound_email_messages_message_id ON inbound_email_messages(message_id);
''') ''')
] ]
+25 -6
View File
@@ -1,8 +1,10 @@
## Copyright © 2026 Olaf Kolkman ## Copyright © 2026 Olaf Kolkman
## SPDX-License-Identifier: GPL-3.0-or-later ## SPDX-License-Identifier: GPL-3.0-or-later
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request from fastapi import FastAPI, Request
import logging import logging
from threading import Event, Thread
from uuid import uuid4 from uuid import uuid4
from fastapi.responses import HTMLResponse from fastapi.responses import HTMLResponse
from fastapi.responses import RedirectResponse from fastapi.responses import RedirectResponse
@@ -20,12 +22,31 @@ from backend.app.api.setup import has_administrator
from backend.app.api.user_config import router as user_config_router from backend.app.api.user_config import router as user_config_router
from backend.app.core.config import settings, validate_configuration from backend.app.core.config import settings, validate_configuration
from backend.app.database import AVATARS_DIR from backend.app.database import AVATARS_DIR
from backend.app.services.link_service import get_public_profile, list_public_links from backend.app.services.inbound_email_service import run_imap_polling
from backend.app.services.link_service import get_public_profile
logging.basicConfig(level=getattr(logging, settings.log_level, logging.INFO)) logging.basicConfig(level=getattr(logging, settings.log_level, logging.INFO))
validate_configuration(settings) validate_configuration(settings)
app = FastAPI(title='LinkLog API', version=settings.version)
@asynccontextmanager
async def lifespan(_: FastAPI):
stop_event = Event()
worker = Thread(
target=run_imap_polling,
args=(stop_event, logging.getLogger('backend.app.services.inbound_email_service')),
name='linklog-imap-poller',
daemon=True,
)
worker.start()
try:
yield
finally:
stop_event.set()
worker.join(timeout=2)
app = FastAPI(title='LinkLog API', version=settings.version, lifespan=lifespan)
@app.middleware('http') @app.middleware('http')
@@ -53,8 +74,7 @@ templates.env.globals['app_version'] = settings.version
async def public_root(request: Request): async def public_root(request: Request):
if not has_administrator(): if not has_administrator():
return RedirectResponse('/setup') return RedirectResponse('/setup')
feed = list_public_links() return templates.TemplateResponse(request, 'feed.html', {})
return templates.TemplateResponse(request, 'feed.html', {'feed': feed})
@app.get('/admin', response_class=HTMLResponse) @app.get('/admin', response_class=HTMLResponse)
@@ -117,10 +137,9 @@ def health_check():
@app.get('/{username}', response_class=HTMLResponse) @app.get('/{username}', response_class=HTMLResponse)
@app.get('/{username}/', response_class=HTMLResponse) @app.get('/{username}/', response_class=HTMLResponse)
async def public_user_feed(request: Request, username: str): async def public_user_feed(request: Request, username: str):
feed = list_public_links(username)
profile = get_public_profile(username) profile = get_public_profile(username)
return templates.TemplateResponse( return templates.TemplateResponse(
request, request,
'feed.html', 'feed.html',
{'feed': feed, 'profile': profile, 'user_filter': username}, {'profile': profile, 'user_filter': username},
) )
@@ -0,0 +1,308 @@
## Copyright © 2026 Olaf Kolkman
## SPDX-License-Identifier: GPL-3.0-or-later
from email import policy
from email.header import decode_header, make_header
from email.parser import BytesParser
from email.utils import getaddresses
from html.parser import HTMLParser
import imaplib
import json
import logging
import re
from threading import Event
from backend.app.core.config import settings
from backend.app.database import get_connection
from backend.app.services.link_service import create_link, normalize_tags
from backend.app.services.secret_store import decrypt_secret, encrypt_secret
URL_PATTERN = re.compile(r'https?://[^\s<>()"\']+')
HASHTAG_PATTERN = re.compile(r'(?<!\w)#([A-Za-z0-9][\w-]*)')
class _HTMLTextExtractor(HTMLParser):
def __init__(self) -> None:
super().__init__()
self.text_parts: list[str] = []
self.hrefs: list[str] = []
def handle_data(self, data: str) -> None:
if data:
self.text_parts.append(data)
def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
if tag.lower() != 'a':
return
for name, value in attrs:
if name.lower() == 'href' and value:
self.hrefs.append(value)
def _decode_header_value(value: str | None) -> str:
if not value:
return ''
return str(make_header(decode_header(value))).strip()
def _extract_message_text(message) -> tuple[str, list[str]]:
plain_parts: list[str] = []
html_parts: list[str] = []
html_hrefs: list[str] = []
parts = message.walk() if message.is_multipart() else [message]
for part in parts:
if part.get_content_maintype() == 'multipart':
continue
content_type = part.get_content_type()
try:
content = part.get_content()
except (LookupError, UnicodeDecodeError):
continue
if not isinstance(content, str):
continue
if content_type == 'text/plain':
plain_parts.append(content)
elif content_type == 'text/html':
parser = _HTMLTextExtractor()
parser.feed(content)
html_parts.append(' '.join(parser.text_parts))
html_hrefs.extend(parser.hrefs)
text = '\n\n'.join(part.strip() for part in (plain_parts or html_parts) if part.strip())
urls = list(dict.fromkeys([*html_hrefs, *URL_PATTERN.findall(text)]))
return text, urls
def _extract_comment(text: str) -> str:
without_links = URL_PATTERN.sub(' ', text)
without_tags = HASHTAG_PATTERN.sub(' ', without_links)
lines = []
for raw_line in without_tags.splitlines():
line = ' '.join(raw_line.split()).strip()
if line:
lines.append(line)
return '\n'.join(lines)
def _extract_tags(*values: str) -> list[str]:
return normalize_tags([match.group(0) for value in values for match in HASHTAG_PATTERN.finditer(value or '')])
def _resolve_sender_email(message) -> str:
addresses = getaddresses(message.get_all('from', []))
for _, email in addresses:
if email:
return email.strip().lower()
return ''
def parse_incoming_email(raw_message: bytes) -> dict:
message = BytesParser(policy=policy.default).parsebytes(raw_message)
subject = _decode_header_value(message.get('Subject'))
text, urls = _extract_message_text(message)
subject_without_tags = HASHTAG_PATTERN.sub(' ', subject)
subject_without_link = URL_PATTERN.sub(' ', subject_without_tags)
title = ' '.join(subject_without_link.split()).strip()
tags = _extract_tags(subject, text)
return {
'message_id': _decode_header_value(message.get('Message-ID')),
'from_email': _resolve_sender_email(message),
'subject': subject,
'title': title,
'comment': _extract_comment(text),
'tags': tags,
'url': urls[0] if urls else None,
}
def get_imap_settings() -> dict:
values = {
'imap_host': settings.imap_host,
'imap_port': settings.imap_port,
'imap_username': settings.imap_username,
'imap_password': settings.imap_password,
'imap_mailbox': settings.imap_mailbox,
'imap_use_ssl': settings.imap_use_ssl,
'imap_poll_interval_seconds': settings.imap_poll_interval_seconds,
}
with get_connection() as conn:
row = conn.execute('SELECT value FROM app_settings WHERE name = ?', ('imap',)).fetchone()
if row:
values.update(json.loads(row['value']))
values['imap_password'] = decrypt_secret(values['imap_password'])
return values
def save_imap_settings(values: dict) -> None:
stored_values = {
**values,
'imap_password': encrypt_secret(values['imap_password']),
}
with get_connection() as conn:
conn.execute(
'''INSERT INTO app_settings (name, value, updated_at) VALUES (?, ?, CURRENT_TIMESTAMP)
ON CONFLICT(name) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP''',
('imap', json.dumps(stored_values)),
)
conn.commit()
def imap_configured(imap_values: dict | None = None) -> bool:
imap = imap_values or get_imap_settings()
return bool(imap['imap_host'] and imap['imap_username'] and imap['imap_password'] and imap['imap_mailbox'])
def _find_user_by_email(address: str) -> dict | None:
email = address.strip().lower()
if not email:
return None
with get_connection() as conn:
row = conn.execute(
'SELECT id, username FROM users WHERE lower(email) = ? AND email_verified = 1',
(email,),
).fetchone()
if row is None:
row = conn.execute(
'''SELECT users.id, users.username
FROM user_email_addresses
JOIN users ON users.id = user_email_addresses.user_id
WHERE lower(user_email_addresses.email) = ? AND user_email_addresses.verified = 1''',
(email,),
).fetchone()
return dict(row) if row else None
def _already_processed(mailbox: str, uid: str) -> bool:
with get_connection() as conn:
row = conn.execute(
'SELECT 1 FROM inbound_email_messages WHERE mailbox = ? AND uid = ? LIMIT 1',
(mailbox, uid),
).fetchone()
return row is not None
def _record_message(mailbox: str, uid: str, status: str, parsed: dict, user_id: str | None = None, link_id: str | None = None, details: dict | None = None) -> None:
payload = details or {}
with get_connection() as conn:
conn.execute(
'''INSERT INTO inbound_email_messages (mailbox, uid, message_id, user_id, link_id, status, details)
VALUES (?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(mailbox, uid) DO UPDATE SET
message_id = excluded.message_id,
user_id = excluded.user_id,
link_id = excluded.link_id,
status = excluded.status,
details = excluded.details''',
(mailbox, uid, parsed.get('message_id'), user_id, link_id, status, json.dumps(payload)),
)
conn.commit()
def ingest_message(mailbox: str, uid: str, raw_message: bytes) -> dict:
if _already_processed(mailbox, uid):
return {'status': 'duplicate', 'mailbox': mailbox, 'uid': uid}
parsed = parse_incoming_email(raw_message)
sender = parsed['from_email']
if not sender:
_record_message(mailbox, uid, 'ignored_missing_sender', parsed)
return {'status': 'ignored_missing_sender', 'mailbox': mailbox, 'uid': uid}
user = _find_user_by_email(sender)
if user is None:
_record_message(mailbox, uid, 'ignored_unknown_sender', parsed, details={'from_email': sender})
return {'status': 'ignored_unknown_sender', 'mailbox': mailbox, 'uid': uid, 'from_email': sender}
if not parsed['url']:
_record_message(mailbox, uid, 'ignored_no_link', parsed, user_id=user['id'])
return {'status': 'ignored_no_link', 'mailbox': mailbox, 'uid': uid, 'user_id': user['id']}
title = parsed['title'] or parsed['url']
record = create_link(user['id'], title, parsed['url'], parsed['comment'], None, parsed['tags'])
_record_message(mailbox, uid, 'stored', parsed, user_id=user['id'], link_id=record['id'])
return {
'status': 'stored',
'mailbox': mailbox,
'uid': uid,
'user_id': user['id'],
'link_id': record['id'],
'link': record,
}
def _open_imap_client(imap_values: dict):
client_class = imaplib.IMAP4_SSL if imap_values['imap_use_ssl'] else imaplib.IMAP4
return client_class(imap_values['imap_host'], imap_values['imap_port'])
def _fetch_message_bytes(response_data) -> bytes | None:
for item in response_data or []:
if isinstance(item, tuple) and len(item) > 1 and isinstance(item[1], (bytes, bytearray)):
return bytes(item[1])
return None
def poll_inbox_once(imap_values: dict | None = None, client_factory=None) -> dict:
values = imap_values or get_imap_settings()
if not imap_configured(values):
return {'status': 'not_configured', 'processed': 0, 'stored': 0, 'ignored': 0}
mailbox = values['imap_mailbox']
client = (client_factory or _open_imap_client)(values)
processed = 0
stored = 0
ignored = 0
try:
client.login(values['imap_username'], values['imap_password'])
status, _ = client.select(mailbox)
if status != 'OK':
raise RuntimeError(f'Could not select IMAP mailbox {mailbox}')
status, data = client.uid('search', None, 'UNSEEN')
if status != 'OK':
raise RuntimeError('Could not list unseen IMAP messages')
raw_uids = data[0].split() if data and data[0] else []
for uid in raw_uids:
uid_value = uid.decode('utf-8') if isinstance(uid, bytes) else str(uid)
status, message_data = client.uid('fetch', uid, '(BODY.PEEK[])')
if status != 'OK':
raise RuntimeError(f'Could not fetch IMAP message {uid_value}')
raw_message = _fetch_message_bytes(message_data)
if raw_message is None:
continue
result = ingest_message(mailbox, uid_value, raw_message)
processed += 1
if result['status'] == 'stored':
stored += 1
else:
ignored += 1
if result['status'] in {
'stored', 'duplicate', 'ignored_missing_sender', 'ignored_unknown_sender', 'ignored_no_link',
}:
client.uid('store', uid, '+FLAGS', '(\\Seen)')
return {'status': 'ok', 'processed': processed, 'stored': stored, 'ignored': ignored}
finally:
try:
client.logout()
except Exception:
pass
def run_imap_polling(stop_event: Event, logger: logging.Logger | None = None) -> None:
active_logger = logger or logging.getLogger(__name__)
while not stop_event.is_set():
values = get_imap_settings()
interval = max(5, int(values.get('imap_poll_interval_seconds', settings.imap_poll_interval_seconds or 60)))
if not imap_configured(values):
stop_event.wait(interval)
continue
try:
summary = poll_inbox_once(values)
if summary['processed']:
active_logger.info(
'IMAP poll processed=%s stored=%s ignored=%s mailbox=%s',
summary['processed'], summary['stored'], summary['ignored'], values['imap_mailbox'],
)
except Exception as error:
active_logger.warning('IMAP polling failed mailbox=%s error=%s', values.get('imap_mailbox'), error)
stop_event.wait(interval)
+77 -5
View File
@@ -3,6 +3,8 @@
from datetime import datetime, timezone from datetime import datetime, timezone
import json import json
import re
from urllib.parse import urlparse
from uuid import uuid4 from uuid import uuid4
from backend.app.core.security import clean_url from backend.app.core.security import clean_url
@@ -136,23 +138,93 @@ def find_owned_link_by_title(user_id: str, title: str) -> dict | None:
return record return record
def list_public_links(username: str | None = None): def _tokenize_search(value: str) -> list[str]:
return [group1 or group2 for group1, group2 in re.findall(r'"([^"]+)"|(\S+)', value or '')]
def _parse_search_query(value: str) -> dict:
groups = [[]]
excluded = []
sites = []
for token in _tokenize_search(value):
if token.upper() == 'OR':
groups.append([])
continue
is_excluded = token.startswith('-') and len(token) > 1
term = token[1:] if is_excluded else token
site_match = re.match(r'^site:(\S+)$', term, re.IGNORECASE)
if site_match and not is_excluded:
sites.append(site_match.group(1).lower())
continue
if is_excluded:
excluded.append(term.lower())
else:
groups[-1].append(term.lower())
return {'groups': [group for group in groups if group], 'excluded': excluded, 'sites': sites}
def _searchable_text(record: dict) -> str:
parts = [record.get('title'), record.get('url'), record.get('comment'), record.get('username'), *(record.get('tags') or [])]
return ' '.join(part for part in parts if part).lower()
def _matches_search(record: dict, query: str) -> bool:
if not query or not query.strip():
return True
parsed = _parse_search_query(query)
text = _searchable_text(record)
def site_matches(site: str) -> bool:
hostname = (urlparse(record.get('url') or '').hostname or '').lower()
return hostname == site or hostname.endswith(f'.{site}')
matches_site = all(site_matches(site) for site in parsed['sites'])
matches_group = not parsed['groups'] or any(all(term in text for term in group) for group in parsed['groups'])
excludes_term = any(term in text for term in parsed['excluded'])
return matches_site and matches_group and not excludes_term
def list_public_links(
username: str | None = None,
tag: str | None = None,
search: str | None = None,
sort: str = 'newest',
page: int = 1,
page_size: int | None = None,
) -> dict:
order = 'ASC' if sort == 'oldest' else 'DESC'
with get_connection() as conn: with get_connection() as conn:
rows = conn.execute( rows = conn.execute(
''' f'''
SELECT links.*, users.username, users.avatar_url, users.bio SELECT links.*, users.username, users.avatar_url, users.bio
FROM links FROM links
JOIN users ON users.id = links.user_id JOIN users ON users.id = links.user_id
WHERE links.is_public = 1 WHERE links.is_public = 1
AND (? IS NULL OR users.username = ?) AND (? IS NULL OR users.username = ?)
ORDER BY created_at DESC AND (
? IS NULL OR links.id IN (
SELECT link_tags.link_id FROM link_tags
JOIN tags ON tags.id = link_tags.tag_id
WHERE lower(tags.name) = lower(?)
)
)
ORDER BY links.created_at {order}
''', ''',
(username, username), (username, username, tag, tag),
).fetchall() ).fetchall()
records = [dict(row) for row in rows] records = [dict(row) for row in rows]
for record in records: for record in records:
record['tags'] = get_link_tags(conn, record['id']) record['tags'] = get_link_tags(conn, record['id'])
return records
if search:
records = [record for record in records if _matches_search(record, search)]
total = len(records)
if page_size:
start = max(page - 1, 0) * page_size
records = records[start:start + page_size]
return {'items': records, 'total': total}
def get_public_profile(username: str) -> dict | None: def get_public_profile(username: str) -> dict | None:
+2
View File
@@ -11,6 +11,8 @@ TEST_DATABASE_DIRECTORY = tempfile.TemporaryDirectory(prefix='linklog-tests-')
TEST_DATABASE_PATH = os.path.join(TEST_DATABASE_DIRECTORY.name, 'linklog.db') TEST_DATABASE_PATH = os.path.join(TEST_DATABASE_DIRECTORY.name, 'linklog.db')
os.environ['LINKLOG_DATABASE_PATH'] = TEST_DATABASE_PATH os.environ['LINKLOG_DATABASE_PATH'] = TEST_DATABASE_PATH
os.environ['LINKLOG_DATA_ENCRYPTION_KEY'] = 'L5M4sQYVjD1N7pT2Xk8R0aBcDeFgHiJkLmNoPqRsTuV=' os.environ['LINKLOG_DATA_ENCRYPTION_KEY'] = 'L5M4sQYVjD1N7pT2Xk8R0aBcDeFgHiJkLmNoPqRsTuV='
# Use a large page size so existing tests that expect the full feed keep working.
os.environ['LINKLOG_FRONTEND_LOADPOSTS'] = '1000'
@pytest.fixture(scope='session', autouse=True) @pytest.fixture(scope='session', autouse=True)
+116 -17
View File
@@ -15,6 +15,7 @@ from backend.app.main import app
from backend.app.core.config import settings from backend.app.core.config import settings
from backend.app.database import get_connection, hash_password from backend.app.database import get_connection, hash_password
from backend.app.services.email_service import get_smtp_settings from backend.app.services.email_service import get_smtp_settings
from backend.app.services.inbound_email_service import get_imap_settings, poll_inbox_once
from backend.app.services.login_throttle import clear_login_failures from backend.app.services.login_throttle import clear_login_failures
from backend.app.services.otp_service import current_code from backend.app.services.otp_service import current_code
from backend.app.services.password_reset import create_reset_token from backend.app.services.password_reset import create_reset_token
@@ -147,6 +148,8 @@ def test_configuration_requires_authentication_and_admin_role():
assert client.get('/api/admin/users', headers=login_headers('bob')).status_code == 403 assert client.get('/api/admin/users', headers=login_headers('bob')).status_code == 403
assert client.get('/api/admin/smtp').status_code == 401 assert client.get('/api/admin/smtp').status_code == 401
assert client.get('/api/admin/smtp', headers=login_headers('bob')).status_code == 403 assert client.get('/api/admin/smtp', headers=login_headers('bob')).status_code == 403
assert client.get('/api/admin/imap').status_code == 401
assert client.get('/api/admin/imap', headers=login_headers('bob')).status_code == 403
def test_admin_can_select_multiple_themes(): def test_admin_can_select_multiple_themes():
@@ -234,6 +237,105 @@ def test_admin_reports_smtp_validation_errors():
assert failed_validation.headers['X-Request-ID'] assert failed_validation.headers['X-Request-ID']
def test_admin_can_save_imap_settings():
headers = login_headers()
original = get_imap_settings()
with get_connection() as conn:
original_row = conn.execute('SELECT value FROM app_settings WHERE name = ?', ('imap',)).fetchone()
response = client.put('/api/admin/imap', headers=headers, json={
'imap_host': 'imap.example.com',
'imap_port': 993,
'imap_username': 'collector@example.com',
'imap_password': 'secret-imap-password',
'imap_mailbox': 'INBOX',
'imap_use_ssl': True,
'imap_poll_interval_seconds': 60,
})
assert response.status_code == 200
assert response.json()['imap_host'] == 'imap.example.com'
assert response.json()['password_configured'] is True
assert response.json()['configured'] is True
assert 'imap_password' not in response.json()
if original_row is None:
with get_connection() as conn:
conn.execute('DELETE FROM app_settings WHERE name = ?', ('imap',))
conn.commit()
else:
with get_connection() as conn:
conn.execute(
'UPDATE app_settings SET value = ?, updated_at = CURRENT_TIMESTAMP WHERE name = ?',
(original_row['value'], 'imap'),
)
conn.commit()
def test_poll_inbox_once_reads_unseen_messages_and_marks_them_seen():
class FakeImapClient:
def __init__(self):
self.actions = []
self.raw_message = (
b'From: Alice <alice@example.com>\n'
b'To: capture@linklog.example\n'
b'Subject: Polled inbox entry #AI\n'
b'Message-ID: <poll-1@example.com>\n'
b'Content-Type: text/plain; charset="utf-8"\n\n'
b'Collected from IMAP.\nhttps://example.com/polled\n'
)
def login(self, username, password):
self.actions.append(('login', username, password))
return 'OK', [b'Logged in']
def select(self, mailbox):
self.actions.append(('select', mailbox))
return 'OK', [b'1']
def uid(self, command, *args):
self.actions.append(('uid', command, *args))
if command == 'search':
return 'OK', [b'200']
if command == 'fetch':
return 'OK', [(b'200 (BODY[] {42}', self.raw_message), b')']
if command == 'store':
return 'OK', [b'200 (FLAGS (\\Seen))']
raise AssertionError(command)
def logout(self):
self.actions.append(('logout',))
return 'BYE', [b'Logged out']
summary = poll_inbox_once(
{
'imap_host': 'imap.example.com',
'imap_port': 993,
'imap_username': 'collector@example.com',
'imap_password': 'secret',
'imap_mailbox': 'INBOX',
'imap_use_ssl': True,
'imap_poll_interval_seconds': 60,
},
client_factory=lambda _: FakeImapClient(),
)
assert summary == {'status': 'ok', 'processed': 1, 'stored': 1, 'ignored': 0}
with get_connection() as conn:
link = conn.execute(
'SELECT title, url, comment, user_id FROM links WHERE url = ?',
('https://example.com/polled',),
).fetchone()
inbound = conn.execute(
'SELECT status FROM inbound_email_messages WHERE mailbox = ? AND uid = ?',
('INBOX', '200'),
).fetchone()
assert link['user_id'] == 'user-1'
assert link['title'] == 'Polled inbox entry'
assert link['comment'] == 'Collected from IMAP.'
assert inbound['status'] == 'stored'
def test_request_id_is_preserved_and_sensitive_error_text_is_not_returned(): def test_request_id_is_preserved_and_sensitive_error_text_is_not_returned():
headers = login_headers() headers = login_headers()
with get_connection() as conn: with get_connection() as conn:
@@ -607,7 +709,7 @@ def test_submit_link_stores_cleaned_url_and_public_feed():
data = response.json() data = response.json()
assert data['url'] == 'https://example.com/path?keep=yes' assert data['url'] == 'https://example.com/path?keep=yes'
feed = client.get('/api/public/feed').json() feed = client.get('/api/public/feed').json()['items']
matching = next(item for item in feed if item['id'] == data['id']) matching = next(item for item in feed if item['id'] == data['id'])
assert matching['comment'] == 'Interesting read' assert matching['comment'] == 'Interesting read'
assert matching['user']['username'] == 'alice' assert matching['user']['username'] == 'alice'
@@ -615,8 +717,8 @@ def test_submit_link_stores_cleaned_url_and_public_feed():
filtered_response = client.get('/api/public/feed/alice') filtered_response = client.get('/api/public/feed/alice')
assert filtered_response.status_code == 200 assert filtered_response.status_code == 200
assert all(item['user']['username'] == 'alice' for item in filtered_response.json()) assert all(item['user']['username'] == 'alice' for item in filtered_response.json()['items'])
assert client.get('/api/public/feed/does-not-exist').json() == [] assert client.get('/api/public/feed/does-not-exist').json()['items'] == []
users_response = client.get('/api/public/users') users_response = client.get('/api/public/users')
assert users_response.status_code == 200 assert users_response.status_code == 200
assert 'alice' in users_response.json() assert 'alice' in users_response.json()
@@ -645,7 +747,7 @@ def test_duplicate_link_updates_comment_tags_and_retriggers_plugins():
dispatch.assert_called_once() dispatch.assert_called_once()
assert dispatch.call_args.args[0]['comment'] == 'updated comment' assert dispatch.call_args.args[0]['comment'] == 'updated comment'
assert dispatch.call_args.args[0]['tags'] == ['#Second'] assert dispatch.call_args.args[0]['tags'] == ['#Second']
feed_item = next(item for item in client.get('/api/public/feed').json() if item['id'] == first.json()['id']) feed_item = next(item for item in client.get('/api/public/feed').json()['items'] if item['id'] == first.json()['id'])
assert feed_item['comment'] == 'updated comment' assert feed_item['comment'] == 'updated comment'
assert feed_item['tags'] == ['#Second'] assert feed_item['tags'] == ['#Second']
@@ -689,7 +791,7 @@ def test_links_support_tags_and_tag_filtering():
assert { assert {
'#Internet', '#Cybersecurity', '#Fediverse', '#Food', '#Photography', '#Music', '#AI' '#Internet', '#Cybersecurity', '#Fediverse', '#Food', '#Photography', '#Music', '#AI'
} <= set(tags) } <= set(tags)
tagged_feed = client.get('/api/public/feed').json() tagged_feed = client.get('/api/public/feed').json()['items']
tagged_item = next(item for item in tagged_feed if item['id'] == link_id) tagged_item = next(item for item in tagged_feed if item['id'] == link_id)
assert {tag.casefold() for tag in tagged_item['tags']} == {'#casepreserved', '#web'} assert {tag.casefold() for tag in tagged_item['tags']} == {'#casepreserved', '#web'}
@@ -725,12 +827,12 @@ def test_only_link_owner_can_edit_link():
}) })
assert unauthenticated.status_code == 401 assert unauthenticated.status_code == 401
anonymous_feed = client.get('/api/public/feed').json() anonymous_feed = client.get('/api/public/feed').json()['items']
anonymous_link = next(item for item in anonymous_feed if item['id'] == link_id) anonymous_link = next(item for item in anonymous_feed if item['id'] == link_id)
assert anonymous_link['is_owner'] is False assert anonymous_link['is_owner'] is False
assert anonymous_link['can_edit'] is False assert anonymous_link['can_edit'] is False
owner_feed = client.get('/api/public/feed', headers=owner_headers).json() owner_feed = client.get('/api/public/feed', headers=owner_headers).json()['items']
owner_link = next(item for item in owner_feed if item['id'] == link_id) owner_link = next(item for item in owner_feed if item['id'] == link_id)
assert owner_link['is_owner'] is True assert owner_link['is_owner'] is True
assert owner_link['can_edit'] is True assert owner_link['can_edit'] is True
@@ -830,17 +932,14 @@ def test_public_and_admin_pages_render_html():
assert 'class="panel-toggle-btn"' in profile_page assert 'class="panel-toggle-btn"' in profile_page
assert 'profile.js?v=6' in profile_page assert 'profile.js?v=6' in profile_page
feed_script = client.get('/static/feed.js?v=7').text feed_script = client.get('/static/feed.js?v=7').text
assert 'function parseSearchQuery(value)' in feed_script assert 'function loadFeed()' in feed_script
assert 'site:(\\S+)' in feed_script assert 'function renderPagination(page, totalPages)' in feed_script
assert 'token.toUpperCase() === \'OR\'' in feed_script
assert 'token.startsWith(\'-\')' in feed_script
assert 'matchesSearch(item, pref.search || \'\')' in feed_script
assert 'if (item.is_owner && !showIdentity)' in feed_script assert 'if (item.is_owner && !showIdentity)' in feed_script
assert 'deleteEntry(item, deleteButton)' in feed_script assert 'deleteEntry(item, deleteButton)' in feed_script
assert 'postToMastodon(item, mastodonButton)' in feed_script assert 'postToMastodon(item, mastodonButton)' in feed_script
assert 'tag.toLowerCase() === activeTag.toLowerCase()' in feed_script assert "params.set('tag', pref.tag)" in feed_script
assert 'loadFeed(event.target.value)' in feed_script assert 'currentPage = 1' in feed_script
assert 'Promise.all([loadUsers(), loadTags()]).then(() => loadFeed())' in feed_script assert "Promise.all([loadUsers(), loadTags()])" in feed_script
assert "fetch('/api/tags', {" in feed_script assert "fetch('/api/tags', {" in feed_script
assert 'Authorization: `Bearer ${accessToken}`' in feed_script assert 'Authorization: `Bearer ${accessToken}`' in feed_script
assert 'return `${date.getFullYear()} ${months[date.getMonth()]} ${date.getDate()} - ${hours}:${minutes}`' in feed_script assert 'return `${date.getFullYear()} ${months[date.getMonth()]} ${date.getDate()} - ${hours}:${minutes}`' in feed_script
@@ -899,8 +998,8 @@ def test_link_submission_posts_to_enabled_mastodon_plugin():
assert received['path'] == '/api/v1/statuses' assert received['path'] == '/api/v1/statuses'
assert received['authorization'] == 'Bearer test-token' assert received['authorization'] == 'Bearer test-token'
assert received['content_type'] == 'application/x-www-form-urlencoded' assert received['content_type'] == 'application/x-www-form-urlencoded'
assert received['body'] == {'status': ['From my #LinkLog:\n\nA useful page\n\nWorth sharing\n\nLogged on 2026 August 29 - 21:10 from: https://example.com/useful\n\n#python #web']} assert received['body'] == {'status': ['From my #LinkLog:\n\nA useful page\n\nWorth sharing\n\nLogged on 2026 August 29 - 21:10 UTC from: https://example.com/useful\n\n#python #web']}
posted_item = next(item for item in client.get('/api/public/feed/alice', headers=headers).json() if item['id'] == response.json()['id']) posted_item = next(item for item in client.get('/api/public/feed/alice', headers=headers).json()['items'] if item['id'] == response.json()['id'])
assert posted_item['mastodon_posted'] is True assert posted_item['mastodon_posted'] is True
finally: finally:
server.shutdown() server.shutdown()
@@ -0,0 +1,92 @@
## Copyright © 2026 Olaf Kolkman
## SPDX-License-Identifier: GPL-3.0-or-later
from email.message import EmailMessage
from backend.app.database import get_connection
from backend.app.services.inbound_email_service import ingest_message, parse_incoming_email
def _raw_message(sender: str, subject: str, body: str, message_id: str) -> bytes:
message = EmailMessage()
message['From'] = sender
message['To'] = 'capture@linklog.example'
message['Subject'] = subject
message['Message-ID'] = message_id
message.set_content(body)
return message.as_bytes()
def test_parse_incoming_email_extracts_title_comment_tags_and_link():
parsed = parse_incoming_email(_raw_message(
'Alice <alice@example.com>',
'A useful article #AI',
'Interesting summary about the protocol.\nhttps://example.com/posts/1\n#Security',
'<msg-1@example.com>',
))
assert parsed['from_email'] == 'alice@example.com'
assert parsed['title'] == 'A useful article'
assert parsed['url'] == 'https://example.com/posts/1'
assert parsed['comment'] == 'Interesting summary about the protocol.'
assert parsed['tags'] == ['#AI', '#Security']
def test_ingest_message_stores_link_for_primary_email_sender():
result = ingest_message(
'INBOX',
'101',
_raw_message(
'Alice <alice@example.com>',
'Email sourced link #Fediverse',
'A comment from the inbox.\nhttps://example.com/inbox-link',
'<msg-2@example.com>',
),
)
assert result['status'] == 'stored'
with get_connection() as conn:
link = conn.execute(
'SELECT title, url, comment, user_id FROM links WHERE id = ?',
(result['link_id'],),
).fetchone()
tags = conn.execute(
'''SELECT tags.name
FROM tags
JOIN link_tags ON link_tags.tag_id = tags.id
WHERE link_tags.link_id = ?
ORDER BY tags.name''',
(result['link_id'],),
).fetchall()
audit = conn.execute(
'SELECT status FROM inbound_email_messages WHERE mailbox = ? AND uid = ?',
('INBOX', '101'),
).fetchone()
assert link['user_id'] == 'user-1'
assert link['title'] == 'Email sourced link'
assert link['url'] == 'https://example.com/inbox-link'
assert link['comment'] == 'A comment from the inbox.'
assert [row['name'] for row in tags] == ['#Fediverse']
assert audit['status'] == 'stored'
def test_ingest_message_accepts_verified_additional_address_and_ignores_duplicates():
with get_connection() as conn:
conn.execute(
'INSERT INTO user_email_addresses (id, user_id, email, verified) VALUES (?, ?, ?, 1)',
('alt-email-test', 'user-1', 'alice-alt@example.com'),
)
conn.commit()
raw_message = _raw_message(
'Alice Alt <alice-alt@example.com>',
'Secondary sender #Links',
'https://example.com/secondary',
'<msg-3@example.com>',
)
first = ingest_message('INBOX', '102', raw_message)
second = ingest_message('INBOX', '102', raw_message)
assert first['status'] == 'stored'
assert second['status'] == 'duplicate'
+7
View File
@@ -20,6 +20,13 @@ services:
LINKLOG_SMTP_PASSWORD: ${LINKLOG_SMTP_PASSWORD:?Set LINKLOG_SMTP_PASSWORD in .env} LINKLOG_SMTP_PASSWORD: ${LINKLOG_SMTP_PASSWORD:?Set LINKLOG_SMTP_PASSWORD in .env}
LINKLOG_SMTP_FROM: ${LINKLOG_SMTP_FROM:-LinkLog <no-reply@example.com>} LINKLOG_SMTP_FROM: ${LINKLOG_SMTP_FROM:-LinkLog <no-reply@example.com>}
LINKLOG_SMTP_USE_TLS: ${LINKLOG_SMTP_USE_TLS:-true} LINKLOG_SMTP_USE_TLS: ${LINKLOG_SMTP_USE_TLS:-true}
LINKLOG_IMAP_HOST: ${LINKLOG_IMAP_HOST:-imap.example.com}
LINKLOG_IMAP_PORT: ${LINKLOG_IMAP_PORT:-993}
LINKLOG_IMAP_USERNAME: ${LINKLOG_IMAP_USERNAME:?Set LINKLOG_IMAP_USERNAME in .env}
LINKLOG_IMAP_PASSWORD: ${LINKLOG_IMAP_PASSWORD:?Set LINKLOG_IMAP_PASSWORD in .env}
LINKLOG_IMAP_MAILBOX: ${LINKLOG_IMAP_MAILBOX:-INBOX}
LINKLOG_IMAP_USE_SSL: ${LINKLOG_IMAP_USE_SSL:-true}
LINKLOG_IMAP_POLL_INTERVAL_SECONDS: ${LINKLOG_IMAP_POLL_INTERVAL_SECONDS:-60}
LINKLOG_EMAIL_VERIFICATION_EXPIRY_HOURS: ${LINKLOG_EMAIL_VERIFICATION_EXPIRY_HOURS:-24} LINKLOG_EMAIL_VERIFICATION_EXPIRY_HOURS: ${LINKLOG_EMAIL_VERIFICATION_EXPIRY_HOURS:-24}
LINKLOG_PASSWORD_RESET_EXPIRY_HOURS: ${LINKLOG_PASSWORD_RESET_EXPIRY_HOURS:-1} LINKLOG_PASSWORD_RESET_EXPIRY_HOURS: ${LINKLOG_PASSWORD_RESET_EXPIRY_HOURS:-1}
LINKLOG_MASTODON_CLIENT_NAME: ${LINKLOG_MASTODON_CLIENT_NAME:-LinkLog} LINKLOG_MASTODON_CLIENT_NAME: ${LINKLOG_MASTODON_CLIENT_NAME:-LinkLog}
+7
View File
@@ -19,6 +19,13 @@ services:
LINKLOG_PUBLIC_URL: ${LINKLOG_PUBLIC_URL:-http://localhost:8000} LINKLOG_PUBLIC_URL: ${LINKLOG_PUBLIC_URL:-http://localhost:8000}
LINKLOG_TOKEN_EXPIRY_MINUTES: ${LINKLOG_TOKEN_EXPIRY_MINUTES:-15} LINKLOG_TOKEN_EXPIRY_MINUTES: ${LINKLOG_TOKEN_EXPIRY_MINUTES:-15}
LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS: ${LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS:-30} LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS: ${LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS:-30}
LINKLOG_IMAP_HOST: ${LINKLOG_IMAP_HOST:-}
LINKLOG_IMAP_PORT: ${LINKLOG_IMAP_PORT:-993}
LINKLOG_IMAP_USERNAME: ${LINKLOG_IMAP_USERNAME:-}
LINKLOG_IMAP_PASSWORD: ${LINKLOG_IMAP_PASSWORD:-}
LINKLOG_IMAP_MAILBOX: ${LINKLOG_IMAP_MAILBOX:-INBOX}
LINKLOG_IMAP_USE_SSL: ${LINKLOG_IMAP_USE_SSL:-true}
LINKLOG_IMAP_POLL_INTERVAL_SECONDS: ${LINKLOG_IMAP_POLL_INTERVAL_SECONDS:-60}
LINKLOG_LOG_LEVEL: ${LINKLOG_LOG_LEVEL:-DEBUG} LINKLOG_LOG_LEVEL: ${LINKLOG_LOG_LEVEL:-DEBUG}
LINKLOG_TRACKING_PARAMS: ${LINKLOG_TRACKING_PARAMS:-} LINKLOG_TRACKING_PARAMS: ${LINKLOG_TRACKING_PARAMS:-}
restart: ${APP_RESTART_POLICY:-unless-stopped} restart: ${APP_RESTART_POLICY:-unless-stopped}
+7
View File
@@ -19,6 +19,13 @@ services:
LINKLOG_LOG_LEVEL: ${LINKLOG_LOG_LEVEL:-INFO} LINKLOG_LOG_LEVEL: ${LINKLOG_LOG_LEVEL:-INFO}
LINKLOG_TOKEN_EXPIRY_MINUTES: ${LINKLOG_TOKEN_EXPIRY_MINUTES:-15} LINKLOG_TOKEN_EXPIRY_MINUTES: ${LINKLOG_TOKEN_EXPIRY_MINUTES:-15}
LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS: ${LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS:-30} LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS: ${LINKLOG_REFRESH_TOKEN_EXPIRY_DAYS:-30}
LINKLOG_IMAP_HOST: ${LINKLOG_IMAP_HOST:-}
LINKLOG_IMAP_PORT: ${LINKLOG_IMAP_PORT:-993}
LINKLOG_IMAP_USERNAME: ${LINKLOG_IMAP_USERNAME:-}
LINKLOG_IMAP_PASSWORD: ${LINKLOG_IMAP_PASSWORD:-}
LINKLOG_IMAP_MAILBOX: ${LINKLOG_IMAP_MAILBOX:-INBOX}
LINKLOG_IMAP_USE_SSL: ${LINKLOG_IMAP_USE_SSL:-true}
LINKLOG_IMAP_POLL_INTERVAL_SECONDS: ${LINKLOG_IMAP_POLL_INTERVAL_SECONDS:-60}
LINKLOG_TRACKING_PARAMS: ${LINKLOG_TRACKING_PARAMS:-} LINKLOG_TRACKING_PARAMS: ${LINKLOG_TRACKING_PARAMS:-}
restart: ${APP_RESTART_POLICY:-unless-stopped} restart: ${APP_RESTART_POLICY:-unless-stopped}
healthcheck: healthcheck:
+86 -88
View File
@@ -6,10 +6,14 @@ const sortSelect = document.getElementById('sort-select');
const userFilter = document.getElementById('user-filter'); const userFilter = document.getElementById('user-filter');
const tagFilter = document.getElementById('tag-filter'); const tagFilter = document.getElementById('tag-filter');
const searchInput = document.getElementById('search-input'); const searchInput = document.getElementById('search-input');
const pageSizeSelect = document.getElementById('page-size-select');
const paginationEl = document.getElementById('pagination');
const cookieName = 'linklog-feed-preferences'; const cookieName = 'linklog-feed-preferences';
const accessToken = localStorage.getItem('linklogAccessToken'); const accessToken = localStorage.getItem('linklogAccessToken');
let availableTags = []; let availableTags = [];
let pageSizes = [25, 100, 250];
let currentPage = 1;
function createAvatar(user) { function createAvatar(user) {
const avatar = document.createElement('div'); const avatar = document.createElement('div');
@@ -52,70 +56,6 @@ function writePreferences(pref) {
document.cookie = `${cookieName}=${value}; path=/; max-age=31536000`; document.cookie = `${cookieName}=${value}; path=/; max-age=31536000`;
} }
function tokenizeSearch(value) {
const tokens = [];
const pattern = /"([^"]+)"|(\S+)/g;
let match;
while ((match = pattern.exec(value)) !== null) {
tokens.push(match[1] || match[2]);
}
return tokens;
}
function parseSearchQuery(value) {
const groups = [[]];
const excluded = [];
const sites = [];
tokenizeSearch(value).forEach((token) => {
if (token.toUpperCase() === 'OR') {
groups.push([]);
return;
}
const isExcluded = token.startsWith('-') && token.length > 1;
const term = isExcluded ? token.slice(1) : token;
const siteMatch = term.match(/^site:(\S+)$/i);
if (siteMatch && !isExcluded) {
sites.push(siteMatch[1].toLowerCase());
return;
}
if (isExcluded) {
excluded.push(term.toLowerCase());
} else {
groups[groups.length - 1].push(term.toLowerCase());
}
});
return {groups: groups.filter((group) => group.length), excluded, sites};
}
function searchableText(item) {
return [
item.title,
item.url,
item.comment,
item.user?.username,
...(item.tags || []),
].filter(Boolean).join(' ').toLowerCase();
}
function matchesSearch(item, query) {
if (!query.trim()) return true;
const parsed = parseSearchQuery(query);
const text = searchableText(item);
const matchesSite = parsed.sites.every((site) => {
try {
const hostname = new URL(item.url).hostname.toLowerCase();
return hostname === site || hostname.endsWith(`.${site}`);
} catch (error) {
return false;
}
});
const matchesGroup = !parsed.groups.length || parsed.groups.some((group) => group.every((term) => text.includes(term)));
const excludesTerm = parsed.excluded.some((term) => text.includes(term));
return matchesSite && matchesGroup && !excludesTerm;
}
function formatDate(value) { function formatDate(value) {
const date = new Date(value); const date = new Date(value);
if (Number.isNaN(date.getTime())) return value || 'updated recently'; if (Number.isNaN(date.getTime())) return value || 'updated recently';
@@ -128,6 +68,17 @@ function formatDate(value) {
return `${date.getFullYear()} ${months[date.getMonth()]} ${date.getDate()} - ${hours}:${minutes}`; return `${date.getFullYear()} ${months[date.getMonth()]} ${date.getDate()} - ${hours}:${minutes}`;
} }
async function loadConfig() {
const response = await fetch('/api/public/config');
if (!response.ok) throw new Error('Could not load config');
const config = await response.json();
pageSizes = config.feed_page_sizes?.length ? config.feed_page_sizes : pageSizes;
const pref = readPreferences();
const selected = pageSizes.includes(pref.pageSize) ? pref.pageSize : pageSizes[0];
pageSizeSelect.replaceChildren(...pageSizes.map((size) => new Option(`${size} per page`, String(size))));
pageSizeSelect.value = String(selected);
}
async function loadUsers() { async function loadUsers() {
const response = await fetch('/api/public/users'); const response = await fetch('/api/public/users');
if (!response.ok) throw new Error('Could not load users'); if (!response.ok) throw new Error('Could not load users');
@@ -237,6 +188,43 @@ function renderFeed(items, showIdentity = true) {
}); });
} }
function renderPagination(page, totalPages) {
paginationEl.innerHTML = '';
if (totalPages <= 1) return;
const goToPage = (target) => {
currentPage = Math.min(Math.max(target, 1), totalPages);
loadFeed();
};
const makeButton = (label, target, options = {}) => {
const button = document.createElement('button');
button.type = 'button';
button.textContent = label;
if (options.active) button.classList.add('active');
if (options.disabled) button.disabled = true;
button.addEventListener('click', () => goToPage(target));
return button;
};
paginationEl.appendChild(makeButton('Previous', page - 1, {disabled: page <= 1}));
const pageNumbers = new Set([1, totalPages, page, page - 1, page + 1]);
let previous = null;
[...pageNumbers].filter((num) => num >= 1 && num <= totalPages).sort((a, b) => a - b).forEach((num) => {
if (previous !== null && num - previous > 1) {
const ellipsis = document.createElement('span');
ellipsis.className = 'pagination-ellipsis';
ellipsis.textContent = '…';
paginationEl.appendChild(ellipsis);
}
paginationEl.appendChild(makeButton(String(num), num, {active: num === page}));
previous = num;
});
paginationEl.appendChild(makeButton('Next', page + 1, {disabled: page >= totalPages}));
}
async function postToMastodon(item, button) { async function postToMastodon(item, button) {
button.disabled = true; button.disabled = true;
const response = await fetch(`/api/links/${encodeURIComponent(item.id)}/mastodon`, { const response = await fetch(`/api/links/${encodeURIComponent(item.id)}/mastodon`, {
@@ -321,35 +309,30 @@ function showEditForm(article, item) {
article.appendChild(form); article.appendChild(form);
} }
async function loadFeed(selectedTag = null) { async function loadFeed() {
const routeUser = document.body.dataset.userFilter; const routeUser = document.body.dataset.userFilter;
const endpoint = routeUser const pref = readPreferences();
const pageSize = pageSizes.includes(pref.pageSize) ? pref.pageSize : pageSizes[0];
const params = new URLSearchParams();
if (pref.tag) params.set('tag', pref.tag);
if (pref.search) params.set('search', pref.search);
params.set('sort', pref.sort || 'newest');
params.set('page', String(currentPage));
params.set('page_size', String(pageSize));
if (pref.user && !routeUser) params.set('username', pref.user);
const path = routeUser
? `/api/public/feed/${encodeURIComponent(routeUser)}` ? `/api/public/feed/${encodeURIComponent(routeUser)}`
: '/api/public/feed'; : '/api/public/feed';
const response = await fetch(endpoint, { const response = await fetch(`${path}?${params.toString()}`, {
headers: accessToken ? {Authorization: `Bearer ${accessToken}`} : {}, headers: accessToken ? {Authorization: `Bearer ${accessToken}`} : {},
}); });
const data = await response.json(); const data = await response.json();
let items = data || []; currentPage = data.page || 1;
const pref = readPreferences(); renderFeed(data.items || [], !routeUser);
const activeTag = selectedTag ?? pref.tag; renderPagination(currentPage, data.total_pages || 1);
if (pref.user && !routeUser) {
items = items.filter((item) => (item.user?.username || '').toLowerCase() === pref.user.toLowerCase());
}
if (activeTag) {
items = items.filter((item) => item.tags?.some((tag) => tag.toLowerCase() === activeTag.toLowerCase()));
}
items = items.filter((item) => matchesSearch(item, pref.search || ''));
if (pref.sort === 'oldest') {
items = [...items].reverse();
}
renderFeed(items, !routeUser);
} }
function syncPreferences() { function syncPreferences() {
@@ -362,6 +345,7 @@ function syncPreferences() {
sortSelect.addEventListener('change', (event) => { sortSelect.addEventListener('change', (event) => {
const next = { ...readPreferences(), sort: event.target.value }; const next = { ...readPreferences(), sort: event.target.value };
writePreferences(next); writePreferences(next);
currentPage = 1;
loadFeed(); loadFeed();
}); });
@@ -375,15 +359,29 @@ function syncPreferences() {
tagFilter.addEventListener('change', (event) => { tagFilter.addEventListener('change', (event) => {
const next = { ...readPreferences(), tag: event.target.value }; const next = { ...readPreferences(), tag: event.target.value };
writePreferences(next); writePreferences(next);
loadFeed(event.target.value); currentPage = 1;
loadFeed();
}); });
let searchDebounce;
searchInput.addEventListener('input', (event) => { searchInput.addEventListener('input', (event) => {
const next = { ...readPreferences(), search: event.target.value }; const next = { ...readPreferences(), search: event.target.value };
writePreferences(next); writePreferences(next);
currentPage = 1;
clearTimeout(searchDebounce);
searchDebounce = setTimeout(() => loadFeed(), 300);
});
pageSizeSelect.addEventListener('change', (event) => {
const next = { ...readPreferences(), pageSize: Number(event.target.value) };
writePreferences(next);
currentPage = 1;
loadFeed(); loadFeed();
}); });
} }
syncPreferences(); syncPreferences();
Promise.all([loadUsers(), loadTags()]).then(() => loadFeed()).catch(() => loadFeed()); loadConfig()
.then(() => Promise.all([loadUsers(), loadTags()]))
.then(() => loadFeed())
.catch(() => loadFeed());
+69 -11
View File
@@ -16,11 +16,14 @@
const refetchTitleButton = document.getElementById('refetch-title-button'); const refetchTitleButton = document.getElementById('refetch-title-button');
const submitButton = document.getElementById('submit-button'); const submitButton = document.getElementById('submit-button');
const submitStatus = document.getElementById('submit-status'); const submitStatus = document.getElementById('submit-status');
const characterCount = document.getElementById('character-count');
const token = localStorage.getItem('linklogAccessToken'); const token = localStorage.getItem('linklogAccessToken');
let availableTags = []; let availableTags = [];
let selectedTags = new Set(); let selectedTags = new Set();
let currentUser = null; let currentUser = null;
let maxPostCharacters = 500;
let mastodonPostPrefix = 'From my #LinkLog: ';
// Utility function to add status messages; splits on \n into real <br> line breaks without using innerHTML. // Utility function to add status messages; splits on \n into real <br> line breaks without using innerHTML.
function setStatus(statusEl, message, isError = false) { function setStatus(statusEl, message, isError = false) {
@@ -53,7 +56,7 @@
.then((user) => { .then((user) => {
currentUser = user; currentUser = user;
entryForm.classList.remove('hidden'); entryForm.classList.remove('hidden');
Promise.all([loadTags(), loadMastodonPublishing()]); Promise.all([loadTags(), loadMastodonPublishing(), loadConfig()]).then(updateCharacterCount);
}) })
.catch(() => { .catch(() => {
localStorage.removeItem('linklogAccessToken'); localStorage.removeItem('linklogAccessToken');
@@ -61,6 +64,17 @@
entryForm.classList.add('hidden'); entryForm.classList.add('hidden');
}); });
async function loadConfig() {
try {
const response = await fetch('/api/public/config');
if (!response.ok) throw new Error('Could not load config');
const config = await response.json();
if (config.max_post_characters) maxPostCharacters = config.max_post_characters;
} catch (error) {
console.error('Could not load config:', error);
}
}
// Load available tags // Load available tags
async function loadTags() { async function loadTags() {
try { try {
@@ -82,11 +96,63 @@
const config = await response.json(); const config = await response.json();
mastodonEnabledCheckbox.checked = Boolean(config.configured); mastodonEnabledCheckbox.checked = Boolean(config.configured);
mastodonPublishing.classList.toggle('hidden', !config.configured); mastodonPublishing.classList.toggle('hidden', !config.configured);
if (config.post_prefix) {
mastodonPostPrefix = config.post_prefix;
} else if (config.hashtag) {
mastodonPostPrefix = `#${String(config.hashtag).trim().replace(/^#/, '')} `;
}
} catch (error) { } catch (error) {
console.error('Could not load Mastodon configuration:', error); console.error('Could not load Mastodon configuration:', error);
} }
} }
// Collect the selected checkbox tags plus any typed new tags, mirroring the submit-time logic.
function collectTags() {
const tags = Array.from(selectedTags);
const newTags = newTagsInput.value.trim();
if (newTags) {
tags.push(...newTags.split(',').map((t) => t.trim()).filter(Boolean));
}
return tags;
}
// Format a UTC timestamp the same way the Mastodon plugin does, so the estimated post length matches the server.
function formatMastodonTimestamp(date) {
const months = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December',
];
const pad = (value) => String(value).padStart(2, '0');
return `${date.getUTCFullYear()} ${months[date.getUTCMonth()]} ${pad(date.getUTCDate())} - ${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}`;
}
// Estimate the assembled Mastodon post length, mirroring backend/app/services/plugin_manager.py.
function estimatePostLength() {
const title = titleInput.value.trim();
const comment = commentInput.value.trim();
const url = removeKnownTrackingParams(urlInput.value.trim());
const parts = [mastodonPostPrefix.trim()];
if (title) parts.push(title);
if (comment) parts.push(comment);
if (title) parts.push(`Logged on ${formatMastodonTimestamp(new Date())} UTC from: ${url}`);
const tags = collectTags();
if (tags.length) parts.push(tags.join(' '));
return parts.join('\n\n').length;
}
function updateCharacterCount() {
const length = estimatePostLength();
const overLimit = length > maxPostCharacters;
characterCount.textContent = overLimit
? `${length}/${maxPostCharacters} characters - exceeds the Mastodon post limit by ${length - maxPostCharacters}`
: `${length}/${maxPostCharacters} characters`;
characterCount.classList.toggle('over-limit', overLimit);
}
[urlInput, titleInput, commentInput, newTagsInput].forEach((input) => {
input.addEventListener('input', updateCharacterCount);
});
// Render tag checkboxes // Render tag checkboxes
function renderTags() { function renderTags() {
existingTagsEl.innerHTML = ''; existingTagsEl.innerHTML = '';
@@ -104,6 +170,7 @@
} else { } else {
selectedTags.delete(tag); selectedTags.delete(tag);
} }
updateCharacterCount();
}); });
label.appendChild(checkbox); label.appendChild(checkbox);
@@ -224,22 +291,13 @@
const url = removeKnownTrackingParams(urlInput.value.trim()); const url = removeKnownTrackingParams(urlInput.value.trim());
const title = titleInput.value.trim(); const title = titleInput.value.trim();
const comment = commentInput.value.trim(); const comment = commentInput.value.trim();
const newTags = newTagsInput.value.trim();
if (!url || !title) { if (!url || !title) {
setStatus(submitStatus, 'URL and title are required', true); setStatus(submitStatus, 'URL and title are required', true);
return; return;
} }
// Combine selected tags and new tags const tags = collectTags();
const tags = Array.from(selectedTags);
if (newTags) {
const newTagsList = newTags
.split(',')
.map((t) => t.trim())
.filter((t) => t);
tags.push(...newTagsList);
}
submitButton.disabled = true; submitButton.disabled = true;
setStatus(submitStatus, 'Saving...', false); setStatus(submitStatus, 'Saving...', false);
+80
View File
@@ -847,6 +847,11 @@ button:disabled {
border-top: 1px solid var(--border); border-top: 1px solid var(--border);
} }
.edit-form textarea {
width: 100%;
}
.edit-tags { .edit-tags {
display: grid; display: grid;
gap: 8px; gap: 8px;
@@ -886,6 +891,53 @@ button:disabled {
padding-bottom: 40px; padding-bottom: 40px;
} }
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 4px;
max-width: 100%;
margin: 0 0 40px;
overflow-x: auto;
}
.pagination button {
min-width: 28px;
padding: 3px 7px;
background: transparent;
border: 1px solid transparent;
border-radius: 6px;
color: var(--muted);
font-size: 0.82rem;
line-height: 1.4;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
border-color: var(--border);
color: var(--text);
}
.pagination button:disabled {
opacity: 0.4;
cursor: default;
}
.pagination button.active {
background: var(--surface-1);
color: var(--text);
border-color: var(--border);
font-weight: 600;
}
.pagination .pagination-ellipsis {
padding: 3px 2px;
color: var(--muted);
font-size: 0.82rem;
opacity: 0.6;
}
.link-item { .link-item {
padding: 11px; padding: 11px;
background: var(--surface-0); background: var(--surface-0);
@@ -894,6 +946,21 @@ button:disabled {
box-shadow: var(--shadow); box-shadow: var(--shadow);
} }
.profile-summary summary {
color: var(--subtext);
cursor: pointer;
font-size: 0.9rem;
font-weight: 600;
}
.profile-summary[open] summary {
margin-bottom: 8px;
}
.profile-summary-content {
font-size: 0.95rem;
}
.about-content { .about-content {
display: grid; display: grid;
gap: 14px; gap: 14px;
@@ -960,6 +1027,7 @@ button:disabled {
.profile-summary p { .profile-summary p {
margin: 12px 0 0; margin: 12px 0 0;
color: var(--subtext); color: var(--subtext);
font-size: 0.95rem;
line-height: 1.65; line-height: 1.65;
} }
@@ -1195,6 +1263,18 @@ button:disabled {
display: none; display: none;
} }
.char-count {
margin: -8px 0 0;
color: var(--muted);
font-size: 0.82rem;
text-align: right;
}
.char-count.over-limit {
color: var(--red);
font-weight: 600;
}
@media (max-width: 600px) { @media (max-width: 600px) {
.container { .container {
padding: 0 14px; padding: 0 14px;
+1 -1
View File
@@ -60,7 +60,7 @@
<section class="link-item"> <section class="link-item">
<h2>Plugin</h2> <h2>Plugin</h2>
<p>Install the Firefox plugin to save links directly from your browser. <a <p>Install the Firefox plugin to save links directly from your browser. <a
href="https://git.kolkman.org/olaf/Link-Log/raw/branch/main/XPI/signed/LinkLog-0.2.0.xpi" href="https://git.kolkman.org/olaf/Link-Log/raw/branch/main/XPI/signed/LinkLog-0.3.0.xpi"
download>Download and install the Plugin</a>.</p> download>Download and install the Plugin</a>.</p>
</section> </section>
</main> </main>
+11 -3
View File
@@ -57,6 +57,10 @@
<option value="">All users</option> <option value="">All users</option>
</select> </select>
</label> </label>
<label>
Per page
<select id="page-size-select"></select>
</label>
<label class="search-control"> <label class="search-control">
Search Search
<input id="search-input" type="search" placeholder="Search links" autocomplete="off" aria-label="Search links" /> <input id="search-input" type="search" placeholder="Search links" autocomplete="off" aria-label="Search links" />
@@ -69,7 +73,9 @@
<main class="container"> <main class="container">
{% if profile %} {% if profile %}
<section class="link-item profile-summary"> <details class="link-item profile-summary">
<summary>Profile</summary>
<div class="profile-summary-content">
<div class="link-header"> <div class="link-header">
<div class="avatar"> <div class="avatar">
{% if profile.avatar_url %} {% if profile.avatar_url %}
@@ -81,15 +87,17 @@
<div class="user-name">{{ profile.username }}</div> <div class="user-name">{{ profile.username }}</div>
</div> </div>
<p>{{ profile.bio or 'No profile information provided.' }}</p> <p>{{ profile.bio or 'No profile information provided.' }}</p>
</section> </div>
</details>
{% endif %} {% endif %}
<section id="feed" class="feed" aria-live="polite"></section> <section id="feed" class="feed" aria-live="polite"></section>
<nav id="pagination" class="pagination" aria-label="Feed pages"></nav>
</main> </main>
<footer class="site-footer">LinkLog Version {{ app_version }}. Copyright © 2026 Olaf Kolkman · <a href="https://git.kolkman.org/olaf/Link-Log">git.kolkman.org/LinkLog</a></footer> <footer class="site-footer">LinkLog Version {{ app_version }}. Copyright © 2026 Olaf Kolkman · <a href="https://git.kolkman.org/olaf/Link-Log">git.kolkman.org/LinkLog</a></footer>
<script src="/static/auth-header.js?v=3"></script> <script src="/static/auth-header.js?v=3"></script>
<script src="/static/logout.js?v=3"></script> <script src="/static/logout.js?v=3"></script>
<script src="/static/theme.js?v=1"></script> <script src="/static/theme.js?v=1"></script>
<script src="/static/feed.js?v=13"></script> <script src="/static/feed.js?v=14"></script>
</body> </body>
</html> </html>
+3 -1
View File
@@ -71,6 +71,7 @@
<textarea id="comment-input" name="comment" rows="4" placeholder="Optional comment about this link"></textarea> <textarea id="comment-input" name="comment" rows="4" placeholder="Optional comment about this link"></textarea>
</label> </label>
</div> </div>
<div id="character-count" class="char-count" aria-live="polite">0/500 characters</div>
<fieldset class="form-section"> <fieldset class="form-section">
<legend>Tags</legend> <legend>Tags</legend>
@@ -89,6 +90,7 @@
</label> </label>
</fieldset> </fieldset>
<div class="form-actions"> <div class="form-actions">
<button id="submit-button" type="submit">Save Entry</button> <button id="submit-button" type="submit">Save Entry</button>
<a href="/" class="secondary button">Cancel</a> <a href="/" class="secondary button">Cancel</a>
@@ -103,6 +105,6 @@
</footer> </footer>
<script src="/static/auth-header.js"></script> <script src="/static/auth-header.js"></script>
<script src="/static/new-entry.js?v=8"></script> <script src="/static/new-entry.js?v=9"></script>
</body> </body>
</html> </html>
+1 -1
View File
@@ -1,3 +1,3 @@
{ {
"version": "0.2.1 "version": "0.3.0"
} }
+179
View File
@@ -0,0 +1,179 @@
#!/usr/bin/env python3
## Copyright © 2026 Olaf Kolkman
## SPDX-License-Identifier: GPL-3.0-or-later
"""One-off script: seed the running LinkLog API with random users and links.
Uses the HTTP API exclusively for user/link creation. The only direct
database access is flipping `email_verified` for freshly created accounts,
since there is no mailbox available in this environment to click the real
verification link that the API would otherwise send.
"""
import random
import string
import subprocess
import sys
from datetime import datetime, timedelta, timezone
import requests
BASE_URL = 'http://localhost:5469'
ADMIN_EMAIL = 'bootstrap_admin@example.invalid'
ADMIN_PASSWORD = 'Bootstrap-Admin-Pass1!'
CONTAINER_NAME = 'testlog-app'
NUM_USERS = 5
LINKS_PER_USER = 500
FIRST_NAMES = ['ava', 'liam', 'noah', 'emma', 'olivia', 'mia', 'ethan', 'sofia', 'lucas', 'zoe']
SITES = [
('https://news.ycombinator.com', 'Hacker News'),
('https://www.theguardian.com', 'The Guardian'),
('https://arstechnica.com', 'Ars Technica'),
('https://www.wired.com', 'Wired'),
('https://github.com', 'GitHub'),
('https://www.nature.com', 'Nature'),
('https://www.bbc.com', 'BBC'),
('https://techcrunch.com', 'TechCrunch'),
('https://www.nytimes.com', 'NY Times'),
('https://www.reddit.com', 'Reddit'),
('https://stackoverflow.com', 'Stack Overflow'),
('https://www.smithsonianmag.com', 'Smithsonian'),
('https://www.economist.com', 'The Economist'),
('https://www.nationalgeographic.com', 'Nat Geo'),
('https://www.theverge.com', 'The Verge'),
]
PATH_WORDS = ['article', 'story', 'post', 'thread', 'blog', 'notes', 'guide', 'review', 'update', 'deep-dive']
HASHTAG_POOL = ['#tech', '#science', '#news', '#opensource', '#ai', '#climate', '#music',
'#photography', '#food', '#travel', '#fediverse', '#security', '#culture', '#space']
COMMENT_TEMPLATES = [
"Interesting take on {topic}.",
"Worth a read if you're into {topic}.",
"Not sure I agree with this on {topic}, but good points.",
"Bookmarking this for later - {topic}.",
"Great deep dive into {topic}.",
"", # some links have no comment
]
session = requests.Session()
def rand_suffix(n=6):
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=n))
def create_bootstrap_admin_if_needed():
resp = session.post(f'{BASE_URL}/api/auth/login', json={'email': ADMIN_EMAIL, 'password': ADMIN_PASSWORD})
if resp.status_code == 200:
return resp.json()['access_token']
raise RuntimeError(f'Bootstrap admin login failed: {resp.status_code} {resp.text}')
def mark_email_verified(user_id: str):
code = (
"from backend.app.database import get_connection\n"
f"with get_connection() as conn:\n"
f" conn.execute('UPDATE users SET email_verified = 1 WHERE id = ?', ('{user_id}',))\n"
" conn.commit()\n"
)
subprocess.run(
['docker', 'exec', '-w', '/app', CONTAINER_NAME, 'python3', '-c', code],
check=True, capture_output=True, text=True,
)
def create_user(admin_token: str, index: int) -> dict:
name = f'{random.choice(FIRST_NAMES)}{index}_{rand_suffix()}'
email = f'{name}@example-seed.invalid'
password = f'Passw0rd-{rand_suffix(8)}!'
resp = session.post(
f'{BASE_URL}/api/admin/users',
headers={'Authorization': f'Bearer {admin_token}'},
json={'username': name, 'email': email, 'password': password, 'is_admin': False},
)
if resp.status_code == 201:
user = resp.json()
elif resp.status_code == 503:
# User row was created but the verification email failed to send (no SMTP egress here).
list_resp = session.get(f'{BASE_URL}/api/admin/users', headers={'Authorization': f'Bearer {admin_token}'})
list_resp.raise_for_status()
user = next(u for u in list_resp.json() if u['username'] == name)
else:
raise RuntimeError(f'Failed to create user {name}: {resp.status_code} {resp.text}')
mark_email_verified(user['id'])
return {'id': user['id'], 'username': name, 'email': email, 'password': password}
def login_user(email: str, password: str) -> str:
resp = session.post(f'{BASE_URL}/api/auth/login', json={'email': email, 'password': password})
resp.raise_for_status()
return resp.json()['access_token']
def random_link_payload():
base_url, site_name = random.choice(SITES)
url = f'{base_url}/{random.choice(PATH_WORDS)}/{rand_suffix(8)}'
title = f'{site_name}: {random.choice(PATH_WORDS).replace("-", " ").title()} #{random.randint(1000, 9999)}'
topic = random.choice(HASHTAG_POOL).lstrip('#')
comment = random.choice(COMMENT_TEMPLATES).format(topic=topic)
tags = random.sample(HASHTAG_POOL, k=random.randint(1, 4))
timestamp = (datetime.now(timezone.utc) - timedelta(days=random.randint(0, 730),
seconds=random.randint(0, 86400))).isoformat()
return {
'title': title,
'url': url,
'comment': comment,
'tags': tags,
'timestamp': timestamp,
'post_to_mastodon': False,
}
def create_links_for_user(token: str, username: str, count: int):
headers = {'Authorization': f'Bearer {token}'}
created = 0
for i in range(count):
payload = random_link_payload()
resp = session.post(f'{BASE_URL}/api/links', headers=headers, json=payload)
if resp.status_code == 401:
# access token expired mid-run; caller handles refresh via re-login
raise PermissionError('token_expired')
if resp.status_code not in (200, 201):
print(f' ! link {i} failed for {username}: {resp.status_code} {resp.text[:200]}', file=sys.stderr)
continue
created += 1
if created % 100 == 0:
print(f' {username}: {created}/{count} links created')
return created
def main():
print('Logging in as bootstrap admin...')
admin_token = create_bootstrap_admin_if_needed()
users = []
print(f'Creating {NUM_USERS} users...')
for i in range(1, NUM_USERS + 1):
user = create_user(admin_token, i)
users.append(user)
print(f' created user: {user["username"]} <{user["email"]}>')
for user in users:
print(f'Seeding {LINKS_PER_USER} links for {user["username"]}...')
token = login_user(user['email'], user['password'])
try:
total = create_links_for_user(token, user['username'], LINKS_PER_USER)
except PermissionError:
print(f' token expired, re-logging in for {user["username"]}')
token = login_user(user['email'], user['password'])
total = create_links_for_user(token, user['username'], LINKS_PER_USER)
print(f' done: {total}/{LINKS_PER_USER} links created for {user["username"]}')
print('\nSummary:')
for user in users:
print(f' {user["username"]} / {user["email"]} / password: {user["password"]}')
if __name__ == '__main__':
main()
+3 -1
View File
@@ -53,5 +53,7 @@
"loginFailed": {"message": "Anmeldung fehlgeschlagen"}, "loginFailed": {"message": "Anmeldung fehlgeschlagen"},
"loggedInSuccessfully": {"message": "Erfolgreich angemeldet"}, "loggedInSuccessfully": {"message": "Erfolgreich angemeldet"},
"unableToLogIn": {"message": "Anmeldung nicht möglich. Überprüfe Backend-URL und Zugangsdaten."}, "unableToLogIn": {"message": "Anmeldung nicht möglich. Überprüfe Backend-URL und Zugangsdaten."},
"signedOut": {"message": "Abgemeldet"} "signedOut": {"message": "Abgemeldet"},
"characterCount": {"message": "$USED$/$LIMIT$ Zeichen", "placeholders": {"used": {"content": "$1"}, "limit": {"content": "$2"}}},
"characterCountOverLimit": {"message": "$USED$/$LIMIT$ Zeichen - überschreitet das Mastodon-Beitragslimit um $OVER$", "placeholders": {"used": {"content": "$1"}, "limit": {"content": "$2"}, "over": {"content": "$3"}}}
} }
+25
View File
@@ -181,5 +181,30 @@
}, },
"signedOut": { "signedOut": {
"message": "Signed out" "message": "Signed out"
},
"characterCount": {
"message": "$USED$/$LIMIT$ characters",
"placeholders": {
"used": {
"content": "$1"
},
"limit": {
"content": "$2"
}
}
},
"characterCountOverLimit": {
"message": "$USED$/$LIMIT$ characters - exceeds the Mastodon post limit by $OVER$",
"placeholders": {
"used": {
"content": "$1"
},
"limit": {
"content": "$2"
},
"over": {
"content": "$3"
}
}
} }
} }
+3 -1
View File
@@ -53,5 +53,7 @@
"loginFailed": {"message": "Error de inicio de sesión"}, "loginFailed": {"message": "Error de inicio de sesión"},
"loggedInSuccessfully": {"message": "Sesión iniciada correctamente"}, "loggedInSuccessfully": {"message": "Sesión iniciada correctamente"},
"unableToLogIn": {"message": "No se pudo iniciar sesión. Comprueba la URL y las credenciales."}, "unableToLogIn": {"message": "No se pudo iniciar sesión. Comprueba la URL y las credenciales."},
"signedOut": {"message": "Sesión cerrada"} "signedOut": {"message": "Sesión cerrada"},
"characterCount": {"message": "$USED$/$LIMIT$ caracteres", "placeholders": {"used": {"content": "$1"}, "limit": {"content": "$2"}}},
"characterCountOverLimit": {"message": "$USED$/$LIMIT$ caracteres: supera el límite de publicación de Mastodon en $OVER$", "placeholders": {"used": {"content": "$1"}, "limit": {"content": "$2"}, "over": {"content": "$3"}}}
} }
+3 -1
View File
@@ -53,5 +53,7 @@
"loginFailed": {"message": "Échec de la connexion"}, "loginFailed": {"message": "Échec de la connexion"},
"loggedInSuccessfully": {"message": "Connexion réussie"}, "loggedInSuccessfully": {"message": "Connexion réussie"},
"unableToLogIn": {"message": "Connexion impossible. Vérifiez l’URL du serveur et vos identifiants."}, "unableToLogIn": {"message": "Connexion impossible. Vérifiez l’URL du serveur et vos identifiants."},
"signedOut": {"message": "Déconnecté"} "signedOut": {"message": "Déconnecté"},
"characterCount": {"message": "$USED$/$LIMIT$ caractères", "placeholders": {"used": {"content": "$1"}, "limit": {"content": "$2"}}},
"characterCountOverLimit": {"message": "$USED$/$LIMIT$ caractères : dépasse la limite de publication Mastodon de $OVER$", "placeholders": {"used": {"content": "$1"}, "limit": {"content": "$2"}, "over": {"content": "$3"}}}
} }
+3 -1
View File
@@ -53,5 +53,7 @@
"loginFailed": {"message": "Inloggen mislukt"}, "loginFailed": {"message": "Inloggen mislukt"},
"loggedInSuccessfully": {"message": "Succesvol ingelogd"}, "loggedInSuccessfully": {"message": "Succesvol ingelogd"},
"unableToLogIn": {"message": "Inloggen mislukt. Controleer de backend-URL en inloggegevens."}, "unableToLogIn": {"message": "Inloggen mislukt. Controleer de backend-URL en inloggegevens."},
"signedOut": {"message": "Uitgelogd"} "signedOut": {"message": "Uitgelogd"},
"characterCount": {"message": "$USED$/$LIMIT$ tekens", "placeholders": {"used": {"content": "$1"}, "limit": {"content": "$2"}}},
"characterCountOverLimit": {"message": "$USED$/$LIMIT$ tekens - overschrijdt de Mastodon-postlimiet met $OVER$", "placeholders": {"used": {"content": "$1"}, "limit": {"content": "$2"}, "over": {"content": "$3"}}}
} }
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "__MSG_extensionName__", "name": "__MSG_extensionName__",
"version": "0.2.0", "version": "0.3.0",
"description": "__MSG_extensionDescription__", "description": "__MSG_extensionDescription__",
"default_locale": "en-US", "default_locale": "en-US",
"permissions": [ "permissions": [
+12
View File
@@ -149,6 +149,18 @@ button {
color: #f38ba8; color: #f38ba8;
} }
.char-count {
margin: -6px 0 10px;
color: #a6adc8;
font-size: 0.75rem;
text-align: right;
}
.char-count.over-limit {
color: #f38ba8;
font-weight: 600;
}
.auth-session { .auth-session {
margin-bottom: 10px; margin-bottom: 10px;
border: 1px solid #585b70; border: 1px solid #585b70;
+1
View File
@@ -37,6 +37,7 @@
<span data-i18n="commentLabel">Comment</span> <span data-i18n="commentLabel">Comment</span>
<textarea id="comment" name="comment" rows="3" data-i18n-placeholder="commentPlaceholder" placeholder="Your comment"></textarea> <textarea id="comment" name="comment" rows="3" data-i18n-placeholder="commentPlaceholder" placeholder="Your comment"></textarea>
</label> </label>
<div id="character-count" class="char-count" aria-live="polite"></div>
<fieldset> <fieldset>
<legend data-i18n="tagsLabel">Tags</legend> <legend data-i18n="tagsLabel">Tags</legend>
+82 -1
View File
@@ -14,10 +14,14 @@ const authWarning = document.getElementById('auth-warning');
const warningSettingsButton = document.getElementById('warning-settings'); const warningSettingsButton = document.getElementById('warning-settings');
const authSession = document.getElementById('auth-session'); const authSession = document.getElementById('auth-session');
const refetchTitleButton = document.getElementById('refetch-title'); const refetchTitleButton = document.getElementById('refetch-title');
const characterCountEl = document.getElementById('character-count');
const sessionStore = browser.storage.session; const sessionStore = browser.storage.session;
const t = window.linklogI18n; const t = window.linklogI18n;
let maxPostCharacters = 500;
let mastodonPostPrefix = 'From my #LinkLog: ';
function normalizeBackendOrigin(backendUrl) { function normalizeBackendOrigin(backendUrl) {
try { try {
const url = new URL(backendUrl); const url = new URL(backendUrl);
@@ -192,9 +196,11 @@ async function loadExistingTags() {
const checkbox = document.createElement('input'); const checkbox = document.createElement('input');
checkbox.type = 'checkbox'; checkbox.type = 'checkbox';
checkbox.value = tag; checkbox.value = tag;
checkbox.addEventListener('change', updateCharacterCount);
label.append(checkbox, document.createTextNode(` ${tag}`)); label.append(checkbox, document.createTextNode(` ${tag}`));
return label; return label;
})); }));
updateCharacterCount();
} }
function getTags() { function getTags() {
@@ -203,6 +209,79 @@ function getTags() {
return [...new Set([...selected, ...newTags])].slice(0, 10); return [...new Set([...selected, ...newTags])].slice(0, 10);
} }
// Load public app settings (e.g. the Mastodon post length limit) once a backend is configured.
async function loadConfig() {
const settings = await getSettings();
if (!settings.backendUrl || !(await hasBackendPermission(settings.backendUrl))) return;
try {
const response = await fetch(`${settings.backendUrl}/api/public/config`);
if (!response.ok) return;
const config = await response.json();
if (config.max_post_characters) maxPostCharacters = config.max_post_characters;
} catch (error) {
// Character-count warning is advisory; ignore config load failures.
}
updateCharacterCount();
}
// Load the user's configured Mastodon post prefix, so the estimated post length matches the server.
async function loadMastodonPrefix() {
const settings = await getSettings();
if (!settings.backendUrl || !settings.accessToken || !(await hasBackendPermission(settings.backendUrl))) return;
try {
const response = await fetch(`${settings.backendUrl}/api/user/plugins/mastodon`, {
headers: {'Authorization': `Bearer ${settings.accessToken}`},
});
if (!response.ok) return;
const config = await response.json();
if (config.post_prefix) {
mastodonPostPrefix = config.post_prefix;
} else if (config.hashtag) {
mastodonPostPrefix = `#${String(config.hashtag).trim().replace(/^#/, '')} `;
}
} catch (error) {
// Character-count warning is advisory; ignore config load failures.
}
updateCharacterCount();
}
// Format a UTC timestamp the same way the Mastodon plugin does, so the estimated post length matches the server.
function formatMastodonTimestamp(date) {
const months = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December',
];
const pad = (value) => String(value).padStart(2, '0');
return `${date.getUTCFullYear()} ${months[date.getUTCMonth()]} ${pad(date.getUTCDate())} - ${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}`;
}
// Estimate the assembled Mastodon post length, mirroring backend/app/services/plugin_manager.py.
function estimatePostLength() {
const title = titleInput.value.trim();
const comment = commentInput.value.trim();
const url = removeKnownTrackingParams(urlInput.value.trim());
const parts = [mastodonPostPrefix.trim()];
if (title) parts.push(title);
if (comment) parts.push(comment);
if (title) parts.push(`Logged on ${formatMastodonTimestamp(new Date())} UTC from: ${url}`);
const tags = getTags();
if (tags.length) parts.push(tags.join(' '));
return parts.join('\n\n').length;
}
function updateCharacterCount() {
const length = estimatePostLength();
const overLimit = length > maxPostCharacters;
characterCountEl.textContent = overLimit
? t('characterCountOverLimit', [String(length), String(maxPostCharacters), String(length - maxPostCharacters)])
: t('characterCount', [String(length), String(maxPostCharacters)]);
characterCountEl.classList.toggle('over-limit', overLimit);
}
[titleInput, urlInput, commentInput, newTagsInput].forEach((input) => {
input.addEventListener('input', updateCharacterCount);
});
function removeKnownTrackingParams(urlString) { function removeKnownTrackingParams(urlString) {
try { try {
const url = new URL(urlString); const url = new URL(urlString);
@@ -361,6 +440,8 @@ refetchTitleButton.addEventListener('click', (e) => {
titleInput.value = ''; titleInput.value = '';
fetchTitle(url, { force: true }); fetchTitle(url, { force: true });
}); });
populateCurrentTab().then(checkExistingLink); populateCurrentTab().then(checkExistingLink).then(updateCharacterCount);
loadExistingTags(); loadExistingTags();
updateFeedLink(); updateFeedLink();
loadConfig();
loadMastodonPrefix();
+10
View File
@@ -2,6 +2,16 @@
"addons": { "addons": {
"linklog@kolkman.org": { "linklog@kolkman.org": {
"updates": [ "updates": [
{
"version": "0.3.0",
"update_link": "https://git.kolkman.org/olaf/Link-Log/raw/branch/main/XPI/signed/LinkLog-0.3.0.xpi",
"update_hash": "sha256:c4cc16a7e96885caa759c803dca90dd43fdf0befc43457655f6eeb6fd51a4e7f",
"applications": {
"gecko": {
"strict_min_version": "142.0"
}
}
},
{ {
"version": "0.2.0", "version": "0.2.0",
"update_link": "https://git.kolkman.org/olaf/Link-Log/raw/branch/main/XPI/signed/LinkLog-0.2.0.xpi", "update_link": "https://git.kolkman.org/olaf/Link-Log/raw/branch/main/XPI/signed/LinkLog-0.2.0.xpi",