🔌 Simple magnet uri shortener!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0 KiB

const express = require('express');
const router = express.Router();
const db = require('../modules/db');
const magnet = require('./magnet');
template = (magnet, meta) => (`
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>${meta.title}</title>
<meta http-equiv="refresh" content="0; url=${magnet}">
<link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
<h1> :magnet:</h1>
<pre>${magnet}</pre>
</p>
</body>
</html>
`)
router.get('/:shortlink', (req, res, next) => {
db.get(req.params.shortlink)
.then(record => {
const r = String(record);
const [ magnet, title ] = r.split('@@title@@');
const meta = {
title: title ? '⚡ ' + title : '⚡ :magnet:'
}
res.send(template(magnet, meta))
})
.catch(e => {
console.log(`[ERR!] Occured while retrieving shortlink`, e.stack);
res.end('Invalid shortlink')
});
})
7 years ago
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: ':magnet: ⚡️' });
7 years ago
});
router.use('/api', magnet);
7 years ago
module.exports = router;