-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
137 lines (118 loc) Β· 4.43 KB
/
server.js
File metadata and controls
137 lines (118 loc) Β· 4.43 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const express = require("express");
const app = express();
function randomLetter() {
const alphabet = 'abcdefghijklmnopqrstuvwxyz'
return alphabet.charAt(Math.floor(Math.random() * alphabet.length))
}
function randomOnesNumber() {
return ~~(Math.random() * 10)
}
//useragent to spoof request (this value is extracted from my iPhone)
const ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Mobile/15E148 Safari/604.1"
// get random image
app.get("/", (request, response) => {
const domain = 'https://prnt.sc/'
const randomShit = randomLetter() + randomLetter() + randomOnesNumber() + randomOnesNumber() + randomOnesNumber() + randomOnesNumber()
const url = domain + randomShit
console.log(url)
const fetch = require('node-fetch');
fetch(url, {
headers: {
Host: "prnt.sc",
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"User-Agent": ua,
"Accept-Language": "en-us",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
}
})
.then(res => res.text())
.then(body => {
try {
let img = body.split('<img class="no-click screenshot-image" src="')[1].split('"')[0]
console.log(img)
if (img.indexOf('http') !== -1) {
const image2base64 = require('image-to-base64');
image2base64(img)
.then(
(imgres) => {
response.json({
img: imgres,
tryagain: false,
id: randomShit,
url: url
})
}
)
.catch(
(error) => {
console.log(error);
}
)
} else {
response.json({
tryagain: true,
reason: 'image is deleted',
id: randomShit,
})
}
} catch (err) {
console.log('image does not exist')
response.json({
tryagain: true,
reason: 'image does not exist',
id: randomShit,
})
}
});
});
//get image by ID
app.get("/id/:id", (request, response) => {
const domain = 'https://prnt.sc/'
const url = domain + request.params.id
console.log(url)
const fetch = require('node-fetch');
fetch(url)
.then(res => res.text())
.then(body => {
try {
let img = body.split('<img class="no-click screenshot-image" src="')[1].split('"')[0]
console.log(img)
if (img.indexOf('http') !== -1) {
const image2base64 = require('image-to-base64');
image2base64(img)
.then(
(imgres) => {
response.json({
img: imgres,
tryagain: false,
id: request.params.id,
url: url
})
}
)
.catch(
(error) => {
console.log(error);
}
)
} else {
response.json({
tryagain: true,
reason: 'image is deleted',
id: randomShit,
})
}
} catch (err) {
console.log('image does not exist')
response.json({
tryagain: true,
reason: 'image does not exist',
id: randomShit,
})
}
});
});
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});