forked from Furtsy/node.js-link-shortening
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
81 lines (65 loc) · 2.08 KB
/
server.js
File metadata and controls
81 lines (65 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const express = require("express");
const app = express();
const router = express.Router();
const path = require('path');
const bodyParser = require('body-parser')
const moment = require('moment');
moment.locale("tr");
require('dotenv/config');
const firebase = require('firebase/app');
const FieldValue = require('firebase-admin').firestore.FieldValue;
const admin = require('firebase-admin');
const servis = require('./servis.json');
const randomstring = require("randomstring");
const urls = require('is-url');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static('./public'));
app.use('/public', express.static(path.join(__dirname, 'public')))
const ejs = require('ejs');
app.set('view engine', 'ejs');
admin.initializeApp({
credential: admin.credential.cert(servis)
});
let data = admin.firestore();
app.get('/kisalt', function(req, res) {
data.collection("link").get().then(function(querySnapshot) {
res.render('linq.ejs', {
sayi: querySnapshot.size
})
})
});
app.post('/yonlendirme', async(req, res) => {
let body = req.body;
const ips = req.clientIp;
if (!urls(body.link)) return res.send('Link gir')
let random = randomstring.generate({
length: 5,
charset: 'alphanumeric'
})
if(body.link.includes('furtsy')) return res.redirect('https://www.youtube.com/watch?v=oHg5SJYRHA0')
const linqs = data.collection('link');
const sikis = await linqs.get();
sikis.forEach(doc => {
var linkA = doc.data().link
if(linkA.includes(body.link)) return res.redirect('https://www.youtube.com/watch?v=oHg5SJYRHA0')
})
data.collection('link').doc(`${random}`).set({
'kod': random,
'link': body.link,
'zaman': moment(Date.now()).add(3, 'hours').format('LLLL'),
})
res.render('links.ejs', {
link: `https://furtsy.wtf/link/${random}`
})
});
app.get('/link/:string', function(req, res) {
const linqs = req.params.string
data.collection('link').doc(linqs).get().then((am) => {
if (!am.exists) return res.send('düştün hacı')
res.redirect(am.data().link)
})
});
console.log('başladım')
app.listen(process.env.PORT)