forked from mustcodes/reddit-api-random-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (45 loc) · 2.19 KB
/
app.js
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
const express = require('express');
const ejs = require('ejs');
const app = express();
const snekfetch = require('node-fetch');
// EJS
app.set('view engine', 'ejs');
/*app.get('/', (req, res) => res.render('index'));
*/
app.get('/', async(req, res) => {
var facts = ["burdurland", "TurkeyJerky", "KGBTR", "bgy", "duznamemes", "kucukinsanlaryoutube", "lanetliyorumlar", "ShitpostTC", "tamamahbapengelli", "Turkey"];
var fact = Math.floor(Math.random() * (facts.length - 0 + 1 ) + 0 )
var facts1 = ["hot", "new", "top"];
var fact1 = Math.floor(Math.random() * (facts.length - 0 + 1 ) + 0 )
var facts2 = ["hour", "day", "week", "month", "year", "all"];
var fact2 = Math.floor(Math.random() * (facts.length - 0 + 1 ) + 0 )
const body = await snekfetch(`https://www.reddit.com/r/${facts[fact]}.json?sort=${facts1[fact1]}&t=${facts2[fact2]}`)
.then(response => response.json());
const allowed = body.data.children
const randomnumber = Math.floor(Math.random() * allowed.length)
console.log(allowed[randomnumber].data.url)
res.render('index', {
Resim: `${allowed[randomnumber].data.url}`,
boy: `${allowed[randomnumber].height}`,
wile: `${allowed[randomnumber].width}`
});
});
app.get('/:sub', async(req, res) => {
var subs = req.params.sub
var facts1 = ["hot", "new", "top"];
var fact1 = Math.floor(Math.random() * (facts1.length - 0 + 1 ) + 0 )
var facts2 = ["hour", "day", "week", "month", "year", "all"];
var fact2 = Math.floor(Math.random() * (facts2.length - 0 + 1 ) + 0 )
const body = await snekfetch(`https://www.reddit.com/r/${subs}.json?sort=${facts1[fact1]}&t=${facts2[fact2]}`)
.then(response => response.json());
const allowed = body.data.children
const randomnumber = Math.floor(Math.random() * allowed.length)
res.render('index', {
Resim: `${allowed[randomnumber].data.url}`,
boy: `${allowed[randomnumber].height}`,
wile: `${allowed[randomnumber].width}`
});
});
//width=<%- wile ? wile :`1000`%> height=<%- boy ? boy :`600`%>
const port = 3000;
app.listen(port, () => console.log(`Port: ${port}`));