This is the "WHAT YOU DO" part repo. Refer "WHAT USERS SEE" part repo at https://github.com/dwaidatta/your-links-worker
Your own custom link service!
Store your links and corresponding URLs. Share as custom links. Enable or disable when needed. Change the underlying URLs without breaking your shared link.
This setup is for "WHAT YOU DO" part.
- Python 3.12 installed
- SQLite3 installed
- Upstash account
- Cloudflare account (Needed for "WHAT USERS SEE" part)
Kindly run the equivalent commands for different systems. Those given here are mainly for Windows and Bash.
- Clone the repo and go to the project folder
python3.12 -m venv .venv
.\.venv\Scripts\activate
pip install -r requirements.txtsqlite3You must in something like:
SQLite version ...
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> TYPE HERE...Continue the below commands inside sqlite>
.open links.db
CREATE TABLE links (
id TEXT PRIMARY KEY,
url TEXT NOT NULL,
description TEXT,
enabled BOOLEAN NOT NULL DEFAULT 1,
action TEXT DEFAULT 'SET' CHECK (action IN ('SET', 'DEL') OR action IS NULL)
);
CREATE TRIGGER links_change_action_on_update AFTER UPDATE ON links
FOR EACH ROW WHEN new.id = old.id
AND (old.action IS NULL OR old.action = 'DEL')
AND new.action NOT IN ('DEL', 'SET')
BEGIN
UPDATE links SET action = 'SET' WHERE id = new.id;
END;
CREATE INDEX idx_sync_pending ON links(action) WHERE action IS NOT NULL;-
Now using any SQLite DB viewer or editor you can edit your DB. One such is https://marketplace.visualstudio.com/items?itemName=yy0931.vscode-sqlite3-editor
-
Now in your DB you can add or modify the link records.
-
Do NOT manually delete rows which are synced. You must change "action" to "DEL" for that row.
-
Supported actions are
SET,DELand NULL.SETis by default and triggered on updates.DELis to be manually. NULL means the row is in sync with cloud DB.
- Create a
.envfile - Get the tokens from Upstash (NOT the read-only token)
- The
.envfile will look like:
UPSTASH_REDIS_REST_URL="..."
UPSTASH_REDIS_REST_TOKEN="..."
- Open a new terminal in the project folder
- Activate python environment (if not already active)
.\.venv\Scripts\activate- Run the following command
python sync.py- After the program runs successfully your latest data is updated in the cloud.
You can now look into the "WHAT USERS SEE" part repo.
