Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YOUR LINKS

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.


Workflow Diagram

Workflow Diagram


Setting Up

This setup is for "WHAT YOU DO" part.

Checks

  • Python 3.12 installed
  • SQLite3 installed
  • Upstash account
  • Cloudflare account (Needed for "WHAT USERS SEE" part)

Commands to Run

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

Virtual environment setup for Python

python3.12 -m venv .venv
.\.venv\Scripts\activate
pip install -r requirements.txt

SQLite3 Database Setup

sqlite3

You 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, DEL and NULL. SET is by default and triggered on updates. DEL is to be manually. NULL means the row is in sync with cloud DB.

Setting up environment for Upstash Redis and sync

  • Create a .env file
  • Get the tokens from Upstash (NOT the read-only token)
  • The .env file will look like:
UPSTASH_REDIS_REST_URL="..."
UPSTASH_REDIS_REST_TOKEN="..."

Syncing Local DB to Cloud Redis

  • 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.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages