TheRealToxicDev revised this gist . Go to revision
1 file changed, 63 insertions
stream.js(file created)
@@ -0,0 +1,63 @@ | |||
1 | + | import newSqlQuery from '@/utils/functions/sqlQuery'; | |
2 | + | import { downloadStream, readStream } from '@/utils/functions/readStream'; | |
3 | + | const fs = require('fs'); | |
4 | + | ||
5 | + | /** | |
6 | + | * API ROUTE FOR VIEWING OR DOWNLOADING | |
7 | + | * A USERS SHAREX CONFIG BASED ON THEIR ID | |
8 | + | */ | |
9 | + | export default async function handler(req, res) { | |
10 | + | ||
11 | + | let user = req.query.userId; | |
12 | + | let method = req.query.method; | |
13 | + | let protocol = process.env.NODE_ENV === 'development' ? 'http://' : 'https://' | |
14 | + | let domain = process.env.NODE_ENV === 'development' ? 'localhost:3000' : req.headers.host | |
15 | + | ||
16 | + | const userData = await newSqlQuery({ query: `SELECT * FROM users WHERE folder="${user}"` }).then((u) => u); | |
17 | + | ||
18 | + | if (method == 'stream') { | |
19 | + | ||
20 | + | await readStream({ | |
21 | + | url: `${protocol}${domain}/api/upload`, | |
22 | + | user: `${user[0].userid}`, | |
23 | + | secret: `${user[0].secret}`, | |
24 | + | res: res | |
25 | + | }); | |
26 | + | ||
27 | + | setTimeout(async () => { | |
28 | + | ||
29 | + | res.end(); | |
30 | + | ||
31 | + | fs.unlink('./public/u/CordX.sxcu', function (err) { | |
32 | + | ||
33 | + | if (err) return console.log(`STREAM_ERROR: ${err.stack}`) | |
34 | + | }) | |
35 | + | }, 10000) | |
36 | + | ||
37 | + | } else if (method === 'download') { | |
38 | + | ||
39 | + | await downloadStream({ | |
40 | + | url: `${protocol}${domain}/api/upload`, | |
41 | + | user: `${user[0].userid}`, | |
42 | + | secret: `${user[0].secret}`, | |
43 | + | res: res | |
44 | + | }) | |
45 | + | ||
46 | + | setTimeout(async () => { | |
47 | + | ||
48 | + | res.end(); | |
49 | + | ||
50 | + | fs.unlink('./public/u/CordX.sxcu', function (err) { | |
51 | + | ||
52 | + | if (err) return console.log(`STREAM_ERROR: ${err.stack}`) | |
53 | + | }) | |
54 | + | }, 10000) | |
55 | + | ||
56 | + | } else if (!method) { | |
57 | + | ||
58 | + | return res.status(400).send({ | |
59 | + | message: 'Please provide a valid method query', | |
60 | + | status: 400 | |
61 | + | }) | |
62 | + | } | |
63 | + | } |
Newer
Older