DANK keeps its sources in one of two places, and you choose which:
config.toml, as thesourceslist, for running DANK from a file you edit, copy or keep under your own version control. This is the default.- Postgres, where you add and edit them in the reader and changes apply without a restart.
Both are supported for good. This page covers the sources_in_database
switch that chooses between them, the command that copies a file's sources
into Postgres, the reader's screens for editing sources, the sources table
and the API behind it.
sources_in_database is a top-level key in config.toml, so it goes before
any [section]. It decides where every source comes from:
sources_in_database |
Sources come from |
|---|---|
false, as the example configs have it, or no such line |
sources in config.toml, read when DANK starts |
true |
The sources table only, even when it's empty. DANK doesn't use sources in config.toml, though it still checks it at startup, so remove it or keep it valid |
Changing it needs a restart: make web ARGS='--force-recreate dank' with
Docker, which copies config.toml in when the container starts. Switching
keeps both the table and the list, so you can switch back later.
Set the switch off and list your sources in the same file:
sources_in_database = false
sources = ["blog.codinghorror.com"]The README and each platform's page show what an entry can hold. Edits to the list need a restart, and the list has no way to turn a source off without removing it.
The reader's Manage screen edits the table, not the file. While the
switch is off it says DANK is collecting from config.toml, and what you save
there isn't collected.
With the switch on:
- Edits apply without a restart. Each reader request, refresh and command
reads the table as it starts. That covers the sidebar and its counts, tags,
configured YouTube channels, which source icons the reader serves,
scrape,processandtrain. - Submitted work keeps its sources. A queued or running refresh collects the sources it was submitted with. A refresh asked for after an edit uses the new ones; asking again for the same refresh joins the active job only while the sources it selects are unchanged.
- Disabled sources stop new collection only. Their posts stay in the sidebar, readable, searchable and processable, and so do a disabled account's or feed's.
- Other tabs catch up within five seconds. A reader tab in the foreground checks the source list every five seconds, and again when you come back to it, and reloads its sidebar when the list changed.
- An empty table means no sources. The reader shows its empty state, and
scrape,processandtrainstop withNo sources in the database. Run make sources-import, or add one in the app.and exit 1. - Postgres has to be up. An outage never falls back to
config.toml: reader requests that need sources answer503, and commands stop withsources_in_database is on, but the sources couldn't be read from Postgres:and the reason, and exit 1. Commands also need the schema at head, and never migrate. Scrape modes that name their own posts, such as--x-post, read no sources and run without Postgres. - It needs Postgres turned on. With
[postgres] enabled = false, DANK refuses the config:sources_in_database needs Postgres, which is turned off ([postgres] enabled = false).To run without Postgres, setsources_in_database = falsetoo.
GET /api/reader/sources, the sidebar's request, has an
in_database flag that mirrors the switch, so the reader knows whether to watch
for edits.
To move from the file to the reader, copy the list across:
make sources-import # Docker
make sources-import MODE=native # nativeThe command saves every source in config.toml in Postgres, in the same order,
and prints how many it imported:
Imported 14 sources into Postgres database dank.
DANK is set to use the sources in config.toml. To use the ones in Postgres instead, set this near the top of config.toml, before any [section], replacing any sources_in_database line already there, and restart DANK:
sources_in_database = true
With the switch already on, the last line says DANK uses these sources now.
The list stays in config.toml, so you can go back to it by switching off.
- It runs once per database. Once any source exists, it says
Sources were already imported, so nothing changed.and exits 1. Two runs started together import once. - It's all or nothing. If one source can't be imported, nothing is, and the
command lists each problem with the source's domain and its place, counting
from 0, such as
sources.3.domain. The count leaves out entriesconfig.tomlitself ignores, such as one without a domain. - It's stricter than
config.toml. A domain must be a host name, such asexample.comrather thanhttps://example.com, and its feed URLs must be ones that platform collects. - Exact duplicates are saved once, and the command says how many it skipped. An account listed twice in one source is kept once, whitespace around it is removed, and a blank one is left out.
- An empty list imports nothing, so you can import later.
- It needs the schema at head and never migrates. Start the web app, or run
make db-upgrade, first. - It never edits
config.toml.
To start again while the data doesn't matter, empty the table and import again. With Docker:
docker compose exec postgres psql --username=dank --dbname=dank -c 'TRUNCATE sources'
make sources-importEach worktree has its own database, and imports from its own config.toml.
Open Sources and choose Manage. Collected is the list of sources with saved posts, as before; choosing one there filters your reading.
-
Add a source takes one thing you paste or type and works out what it is, then saves it and starts collecting it:
You paste DANK saves A domain, or a link to any page of a site The site, finding its feed itself A link to a feed The site, with that feed @handle, or an x.com or twitter.com profile linkAn X account r/community, or any Reddit link inside oneA Reddit community A YouTube channel or playlist link That channel or playlist A news.ycombinator.com link Hacker News A bare
@handleis read as an X account; choose YouTube beneath the field when it is a channel. A video link is refused, since only channels and playlists are collected. An account, community or channel joins the source of its platform that is on, or starts one. Something saved but turned off is turned back on, and something already collected is left alone and says so. If collection can't start, what you added stays saved. -
More options opens a full form for each platform: a site and its feeds, X accounts, Reddit communities and how to sort them, YouTube channels and links, or which Hacker News stories. The Site field takes a pasted link as well as a domain.
-
Each source has a switch, in the list and in its form, and so does each account, feed and community. Turning one off stops new collection and keeps everything already saved. Sources can't be deleted.
-
Each row is titled by what it collects, such as
r/rust, r/python, with its platform and options beneath. -
Search and filter appear once there are six sources: by platform when there is more than one, and by on or off when something is off.
-
Save sends the whole source and returns to the list, which says what was saved. Save and collect also starts a refresh, and is the main action for a new source. When this save added one account or community, only that is collected; otherwise the source's platform is. If the refresh can't start, the source stays saved and the list says so.
-
Problems appear beside their field, with the server's own message, and nothing you typed is lost.
-
A duplicate links to the source that already has those settings, and says when that one is turned off.
-
An unconfirmed save, after an outage or a lost connection, offers Try again. Sending it again is safe.
-
Unsaved edits are kept while you look elsewhere in the reader, and the list marks that source Unsaved changes. They last until the page reloads, and the browser asks before it does. When another tab saves the same source meanwhile, the form says so and keeps your edits; saving replaces the other version.
-
Advanced: adapters is for the few sources that combine them: a publisher read through several RSS adapters with their own feeds, or Hacker News with RSS feeds. Adding RSS feeds to Hacker News writes out the adapters it needs.
-
Every source and form has its own link, such as
/?view=sources&manage=1&source=<id>.
Save what's on screen. An X account's page, a Reddit community's, a
YouTube channel's and a discovered site's each have a Save action beside
Refresh. It adds what you're looking at to a source of that platform, or
makes one. With several sources on that platform it asks which, since they
differ in their options. Something saved but turned off is offered as Turn
on, and something already collected shows Saved, which opens its
source. These actions appear only while sources_in_database is on.
While the switch is off, Manage still lists and edits the sources in the
table, and says DANK is collecting from config.toml instead.
Two limits to know about:
- Reddit communities that differ only in letter case, such as
r/Rustandr/rust, count as different across sources, so both can be saved. - Two tabs editing the same source don't merge: the last save wins.
A source has the fields of a config.toml source, plus an ID the server gives it
and an enabled flag on the source and on each account and feed.
| Field | Holds |
|---|---|
id |
A UUID, given by the server and never changed |
enabled |
Whether DANK collects it; disabled sources stay readable |
domain |
The canonical domain: www.reddit.com, hckrnews.com and similar spellings are folded |
accounts |
X accounts or YouTube channels, each {value, enabled} |
feeds |
Feed URLs, Reddit communities or YouTube listings, each {value, enabled}, stored normalized |
tags |
Lowercase, without repeats |
adapters |
null for the domain's default, or a list of {kind, feeds}; only RSS adapters have feeds, and null there means the source's own |
reddit |
{sort, time_filter} for Reddit, otherwise null |
hacker_news |
{filter} for Hacker News, otherwise null |
The rules are config.toml's, from the same functions: Reddit takes
communities, not accounts; X takes accounts, not feeds; RSS adapters only work
for publishers and Hacker News; and Hacker News feeds need an RSS adapter. Two
sources can share a domain when their settings differ, but two sources with
identical settings can't exist, whichever is enabled.
Turning targets off never collects more. DANK reads an empty list as "everything": an X source with no accounts means For You, and a publisher with no feeds means feed discovery. So when every account or feed in a list is off, that way of collecting is removed rather than run without them, and a source with nothing left isn't collected.
dank.sources.model.compile_sources turns sources into the SourceConfig
values the collectors already use. Sources imported from config.toml compile
back to exactly what the TOML gave, which tests/sources/test_model.py checks.
sources holds one row per source: id, position (the order sources were
added in, which the import takes from config.toml), enabled, and config,
the rest as JSON. A unique index on a hash of config refuses duplicates.
A save changes one row in one short transaction. There's no version history,
so an edit can't be undone in the app; back up with make postgres-dump. When
two tabs edit different sources, both edits stick. When they edit the same one,
the last save wins.
Under /api/reader/source-settings. See
the API conventions.
| Method | Path | Does |
|---|---|---|
GET |
/api/reader/source-settings |
{sources: [...], in_database}: every source in order, disabled ones too, and whether DANK uses them, which is false while the switch is off |
GET |
/api/reader/source-settings/{id} |
One source |
POST |
/api/reader/source-settings |
Add a source, sent without an ID. Answers 201 with the saved source |
PUT |
/api/reader/source-settings/{id} |
Replace a source, including whether it and each target are enabled |
Every write sends the whole source; a missing field is an error, not a way to
clear it. The answer has the values normalized, so r/LocalLLaMA comes back as
https://www.reddit.com/r/LocalLLaMA/. Sources can't be deleted yet; disable
them instead.
| Status | code |
When |
|---|---|---|
| 400 | invalid_request |
The body has the wrong shape, an unknown key or a list over its limit |
| 400 | invalid_source |
A rule is broken. fields lists each problem at its path in the source, such as feeds.0.value |
| 404 | not_found |
No source has this ID |
| 409 | duplicate_source |
Another source has identical settings, enabled or not |
| 503 | unavailable |
Postgres is unreachable, or a stored row can't be read. Logged |
Retrying is always safe. Repeating an edit changes nothing further, and a
repeated add answers duplicate_source, which means the first one worked.
Everything except the ID and enabled flag lives in the config column, so
changing what a source holds needs no change to the table.
-
A new field with a default: change the model, and let
decode_sourceread rows saved without it, which it otherwise refuses. The next save writes the field. Or add it to every row with a data migration, as below. -
A breaking change while the data doesn't matter: change the model, empty the table, and import again.
-
A breaking change once other people have data: change the model and write a data migration by hand, for example:
make db-atlas ARGS='migrate new rename_feeds --env dank'UPDATE sources SET config = (config - 'feeds') || jsonb_build_object('feed_urls', config -> 'feeds');
make db-atlas ARGS='migrate hash --env dank'
Rows are read strictly: a missing or unknown key, or a value of the wrong type,
answers 503 rather than being skipped. The web app migrates before it starts and
CLIs refuse a schema that isn't at head, so code never meets a row in an old
shape. Update sources_from_settings with the model; the parity tests fail if
it no longer matches.
Project heuristics far above a real source, in dank/sources/model.py: 1,000
targets in a list, 32 tags, 16 adapters and 2,048 characters in a value,
measured after normalizing. The API also refuses request bodies over 1 MiB with
413; see API errors.