Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/satyamsundaram/url-shortener

a simple url-shortener with cool features.
https://github.com/satyamsundaram/url-shortener

Last synced: about 1 month ago
JSON representation

a simple url-shortener with cool features.

Awesome Lists containing this project

README

        

## a simple url-shortener
[under development]

### Features
- storing mappings between shorturl -> originalurl
- validating originalurl for correctness
- generating shorturls using a hash of the originalurl to ensure uniqueness

### Tech stack
- currently using local redis server mysql server
- nodejs, express

### Upcoming features
- add more robust url validation (if possible)
- add functionality to set expiry for shorturl depending on maxVisits or validUntil
- add functionality to track number of visits to shorturl
- might need to use a database for this (might not if we map shorturl with [originalurl, visits, maxvisits, validuntil])
- add functionality to allow custom shorturl

### Mysql
```
CREATE TABLE IF NOT EXISTS users {
google_id VARCHAR(100) NOT NULL PRIMARY KEY,
email VARCHAR(512) NOT NULL UNIQUE,
username VARCHAR(100) NOT NULL,
}

CREATE TABLE IF NOT EXISTS urls (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
short_url VARCHAR(100) NOT NULL,
original_url VARCHAR(512) NOT NULL UNIQUE,
creation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
valid_until TIMESTAMP,
visit_count INT NOT NULL DEFAULT 0,
max_visits INT,
user_id VARCHAR(100) NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(google_id)
);

// valid_until TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + INTERVAL 30 DAY
// unable to create original_url of VARCHAR(1024) or VARCHAR(2048) with UNIQUE constraint on it

INSERT INTO urls (short_url, original_url) VALUES ('a23bde', 'https://www.facebook.com');
INSERT INTO urls (short_url, original_url, valid_until) VALUES ('3h2h2d', 'https://www.twitter.com', '2024-03-29 00:00:00');
INSERT INTO urls (short_url, original_url, max_visits) VALUES ('4h2h22', 'https://www.pinterest.com', 10);
```

### todo
- create separate files for different functionalities
- create separate functions wherever possible

### Notes
- table CSS borrowed from [this](https://codepen.io/AllThingsSmitty/pen/MyqmdM) codepen