Minimalistic url shortener written in Python3 using flask, MySQL and clipboard.js
You can paste, drag and type in (+ return) URLs to shorten them
- URL gets posted to /a
- verify URL
- add URL to database, get base 10 ID (insert id)
- convert base 10 ID to base 62
- convert base 62 ID to string ID using (alphabet) hashmap and return it
- /{string_id} is opened
- revert {string_id} using (alphabet) hashmap back to base 62 ID
- revert base 62 ID back to base 10 ID
- get record from database with base 10 ID
- redirect to associated URL
- make a copy of .env.example named .env
- change variables in .env (they're self-explanatory)
- git submodule init
- git submodule update
- create database, user and tables
- run it like any other flask app
Database schema:
CREATE DATABASE urlshortener;
CREATE USER `mistershort`@`localhost` IDENTIFIED BY 'topsecret';
GRANT ALL ON urlshortener.* TO `mistershort`@`localhost`;
USE urlshortener;
CREATE TABLE urls(
id iNT NOT NULL AUTO_INCREMENT PRIMARY KEY,
url VARCHAR(2000) NOT NULL
);
ALTER TABLE urls AUTO_INCREMENT=1;
Auto increment is offset by one because the first possible id 'a' is used as a POST endpoint (/a - shorthand for /add) for shortening urls