Skip to content
Permalink
Browse files

Init the project

  • Loading branch information...
int64ago committed Feb 3, 2016
0 parents commit 24f5ff523b79fcddcf22198dbec137d8337cfdcb
Showing with 404 additions and 0 deletions.
  1. +27 −0 .gitignore
  2. +2 −0 README.md
  3. +36 −0 app.js
  4. +5 −0 config.js
  5. +28 −0 package.json
  6. +49 −0 public/index.html
  7. +69 −0 public/loading.css
  8. +101 −0 public/main.css
  9. +39 −0 public/main.js
  10. +48 −0 utils.js
@@ -0,0 +1,27 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
node_modules
@@ -0,0 +1,2 @@
302@ - A Cool URL Shortener
---
36 app.js
@@ -0,0 +1,36 @@
var express = require('express');
var bodyParser = require('body-parser');
var config = require('./config');
var utils = require('./utils');
var app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.use('/', express.static(__dirname + '/public'));

app.get('/404', function(req, res) {
res.send('<p>/* 404 */</p>');
});

app.post('/', function(req, res) {
var longUrl = req.body.longUrl;
utils.set(longUrl, function(result) {
if (result.is_url) {
res.json(result);
} else {
res.json({
err: 'Not a URL'
});
}
});
});

app.get('/:shortId', function(req, res) {
var shortId = req.params.shortId;
utils.get(shortId, function(result) {
res.redirect(result);
});
});

app.listen(config.PORT);
@@ -0,0 +1,5 @@
module.exports = {
PORT: process.env.VCAP_APP_PORT || 3000,
APP_ID: process.env.APP_ID || '<APP_ID>',
APP_KEY: process.env.APP_KEY || '<APP_KEY>'
};
@@ -0,0 +1,28 @@
{
"name": "302.at",
"version": "1.0.0",
"description": "A Cool URL Shortener",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/int64ago/302.at.git"
},
"keywords": [
"URL-Shortener"
],
"author": "Cody Chan <int64ago@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/int64ago/302.at/issues"
},
"homepage": "https://github.com/int64ago/302.at#readme",
"dependencies": {
"avoscloud-sdk": "^0.6.8",
"body-parser": "^1.14.2",
"express": "^4.13.4",
"short-url-generator": "0.0.12"
}
}
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>

<head>
<title>302@</title>
<link href="//dn-getlink.qbox.me/ptorq5gmk7qfr.ico" rel="shortcut icon">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Architects+Daughter" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" type="text/css" href="loading.css">
</head>

<body>
<div class="container">
<div class="header">
<a href="/">302@ - A Cool URL Shortener</a>
</div>
<div class="content">
<div class="input">
<input placeholder="Please enter the URL" />
<button disabled>Go</button>
</div>
<div class="output">
<a href="#" target="_blank"></a>
<button data-clipboard-text="">Copy</button>
</div>
<img width="150" />
<div id="load">
<div>G</div>
<div>N</div>
<div>I</div>
<div>D</div>
<div>A</div>
<div>O</div>
<div>L</div>
</div>
</div>
<div class="footer">
<a href="https://github.com/int64ago/302.at.git" target="_blank">/* GitHub */</a>
</div>
</div>
<script src="//dn-cdnjs-cn.qbox.me/ajax/libs/jquery/2.2.0/jquery.js"></script>
<script src="//dn-cdnjs-cn.qbox.me/ajax/libs/clipboard.js/1.5.5/clipboard.min.js"></script>
<script src="main.js"></script>
</body>

</html>
@@ -0,0 +1,69 @@
#load {
display: none;
position: absolute;
width: 600px;
height: 36px;
left: 50%;
top: 40%;
margin-left: -300px;
overflow: visible;
user-select: none;
cursor: default;
}

#load div {
position: absolute;
width: 20px;
height: 36px;
opacity: 0;
font-family: Helvetica, Arial, sans-serif;
animation: move 2s linear infinite;
transform: rotate(180deg);
color: #35C4F0;
}

#load div:nth-child(2) {
animation-delay: 0.2s;
}

#load div:nth-child(3) {
animation-delay: 0.4s;
}

#load div:nth-child(4) {
animation-delay: 0.6s;
}

#load div:nth-child(5) {
animation-delay: 0.8s;
}

#load div:nth-child(6) {
animation-delay: 1s;
}

#load div:nth-child(7) {
animation-delay: 1.2s;
}

@keyframes move {
0% {
left: 0;
opacity: 0;
}
35% {
left: 41%;
transform: rotate(0deg);
opacity: 1;
}
65% {
left: 59%;
transform: rotate(0deg);
opacity: 1;
}
100% {
left: 100%;
transform: rotate(-180deg);
opacity: 0;
}
}
@@ -0,0 +1,101 @@
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}

.container {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
flex: 1;
}

.header {
padding: 10px;
}

.header a {
font-family: 'Architects Daughter', cursive;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #20B8DF;
cursor: pointer;
}

.content {
display: flex;
flex-direction: column;
flex: 1;
justify-content: center;
align-items: center;
}

.input input {
height: 48px;
width: 250px;
padding-left: 10px;
border-color: transparent;
background: #F2F2F2;
border-radius: 1px;
box-sizing: border-box;
}

.input button {
height: 48px;
width: 48px;
color: white;
background-color: #20B8DF;
border-radius: 1px;
cursor: pointer;
border-color: transparent;
}

.input button:active {
background-color: #0996BA;
}

.input button:disabled {
background-color: rgba(32, 184, 223, 0.4);
}

.output {
display: none;
margin-top: 20px;
}

.output a {
color: #9E9E9E;
font-size: 14px;
}

.output button {
color: white;
background-color: #20B8DF;
border-radius: 1px;
cursor: pointer;
border-color: transparent;
}

.output button:active {
background-color: #0996BA;
}

.footer {
align-self: flex-end;
padding: 10px;
margin-top: 200px;
}

.footer a {
color: #9E9E9E;
text-decoration: none;
}

* {
outline: none;
}
@@ -0,0 +1,39 @@
$(function() {
new Clipboard('.output button');

var validateUrl = function() {
var reg = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
$('.input input').on('input', function() {
if (reg.test($(this).val())) {
$('.input button').prop('disabled', false);
} else {
$('.input button').prop('disabled', true);
}
});
};

validateUrl();

var setOutput = function(shortId) {
var url = location.protocol + '//' + location.host + '/' + shortId;
$('.output a').attr('href', url).text(url);
$('.output button').attr('data-clipboard-text', url);
$('.content img').attr('src', '//qr.302.at/chart?chs=150x150&cht=qr&choe=UTF-8&chl=' + url);
};
$('.input button').on('click', function() {
$('.output').hide();
$('.content img').hide();
$('#load').show();
var longUrl = $('.input input').val();
$.post('/', {
longUrl: longUrl
}, function(data) {
$('#load').hide();
if (data && data.is_url) {
setOutput(data.short);
$('.output').show();
$('.content img').show();
}
});
});
});

0 comments on commit 24f5ff5

Please sign in to comment.
You can’t perform that action at this time.