Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add support for generating private urls with "private=1" #6

Merged
merged 1 commit into from

2 participants

Nathan Rajlich Guillermo Rauch
Nathan Rajlich
Collaborator

Closes #5.

Guillermo Rauch
Owner

Great

Nathan Rajlich TooTallNate merged commit e94c537 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 1 deletion.
  1. +12 −1 app.js
13 app.js
View
@@ -8,6 +8,7 @@ var express = require('express')
, sio = require('socket.io')
, base60 = require('./base60')
, jadevu = require('jadevu')
+ , crypto = require('crypto')
, url = require('url')
, nib = require('nib')
, fs = require('fs')
@@ -131,6 +132,7 @@ app.get('/', function (req, res, next) {
app.post('/', validate, exists, function (req, res, next) {
var url = req.body.url
, parsed = req.body.parsed
+ , private = req.body.private
, length
, short
, obj
@@ -141,7 +143,12 @@ app.post('/', validate, exists, function (req, res, next) {
function onLenth (err, len) {
if (err) return next(500);
length = len;
- short = base60.toString(length ? length + 1 : 0);
+
+ if (private) {
+ short = crypto.randomBytes(20).toString('hex');
+ } else {
+ short = base60.toString(length ? length + 1 : 0);
+ }
// next save the short url with the original url to the "urls" hash
redis.hset('urls', short, url, onUrlsSet);
@@ -209,6 +216,10 @@ function accept(type) {
*/
function exists (req, res, next) {
+ if (req.body.private) {
+ // for "private" links, always return a new one
+ return next();
+ }
redis.hget('urls-hash', req.body.url, function (err, val) {
if (err) return next(err);
if (val) return res.send({ short: 'https://' + app.set('domain') + '/' + val });
Something went wrong with that request. Please try again.