Epikcoder
commited on
Commit
·
1694ab1
1
Parent(s):
c15005b
varo gendeng
Browse files
beta.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
// Just additional code for https://github.com/rkwyu/scribd-dl
|
2 |
|
3 |
-
import { exec } from 'child_process';
|
4 |
import { promisify } from 'util';
|
5 |
import cors from 'cors'
|
6 |
import express from 'express'
|
7 |
-
import {config} from 'dotenv'
|
8 |
config()
|
9 |
import path from 'path';
|
10 |
import { fileURLToPath } from 'url';
|
@@ -14,12 +14,12 @@ const execPromise = promisify(exec);
|
|
14 |
|
15 |
async function executeCommand(command) {
|
16 |
try {
|
17 |
-
const { stdout, stderr } = await execPromise(command);
|
18 |
if (stderr) {
|
19 |
throw new Error(`Stderr: ${stderr}`);
|
20 |
}
|
21 |
|
22 |
-
return stdout;
|
23 |
} catch (error) {
|
24 |
throw new Error(`Error executing command: ${error.message}`);
|
25 |
}
|
@@ -27,7 +27,7 @@ async function executeCommand(command) {
|
|
27 |
|
28 |
function checkIfGenerated(output) {
|
29 |
const logs = output.trim().split('\n');
|
30 |
-
const lastLog = logs[logs.length - 1];
|
31 |
if (lastLog.includes('Generated: ')) {
|
32 |
return { result: true, path: lastLog.split(" output/")[1] }
|
33 |
} else {
|
@@ -38,14 +38,14 @@ function checkIfGenerated(output) {
|
|
38 |
async function main(url) {
|
39 |
return new Promise(async (resolve, reject) => {
|
40 |
try {
|
41 |
-
const command = `npm start '${url}'`;
|
42 |
-
const output = await executeCommand(command);
|
43 |
-
resolve(checkIfGenerated(output));
|
44 |
} catch (error) {
|
45 |
-
if(error.toString().includes("Unsupported UR")) {
|
46 |
-
reject({error: "Not supported URL"})
|
47 |
-
}else{
|
48 |
-
reject({error: error})
|
49 |
}
|
50 |
}
|
51 |
})
|
@@ -59,15 +59,21 @@ app.get("/", (req, res) => {
|
|
59 |
res.send("/down?url=<scribd>")
|
60 |
})
|
61 |
|
62 |
-
app.all("/down", async(req,res) => {
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
})
|
72 |
app.use(express.static(path.join(__dirname, 'output')));
|
73 |
|
|
|
1 |
// Just additional code for https://github.com/rkwyu/scribd-dl
|
2 |
|
3 |
+
import { exec } from 'child_process';
|
4 |
import { promisify } from 'util';
|
5 |
import cors from 'cors'
|
6 |
import express from 'express'
|
7 |
+
import { config } from 'dotenv'
|
8 |
config()
|
9 |
import path from 'path';
|
10 |
import { fileURLToPath } from 'url';
|
|
|
14 |
|
15 |
async function executeCommand(command) {
|
16 |
try {
|
17 |
+
const { stdout, stderr } = await execPromise(command);
|
18 |
if (stderr) {
|
19 |
throw new Error(`Stderr: ${stderr}`);
|
20 |
}
|
21 |
|
22 |
+
return stdout;
|
23 |
} catch (error) {
|
24 |
throw new Error(`Error executing command: ${error.message}`);
|
25 |
}
|
|
|
27 |
|
28 |
function checkIfGenerated(output) {
|
29 |
const logs = output.trim().split('\n');
|
30 |
+
const lastLog = logs[logs.length - 1];
|
31 |
if (lastLog.includes('Generated: ')) {
|
32 |
return { result: true, path: lastLog.split(" output/")[1] }
|
33 |
} else {
|
|
|
38 |
async function main(url) {
|
39 |
return new Promise(async (resolve, reject) => {
|
40 |
try {
|
41 |
+
const command = `npm start '${url}'`;
|
42 |
+
const output = await executeCommand(command);
|
43 |
+
resolve(checkIfGenerated(output));
|
44 |
} catch (error) {
|
45 |
+
if (error.toString().includes("Unsupported UR")) {
|
46 |
+
reject({ error: "Not supported URL" })
|
47 |
+
} else {
|
48 |
+
reject({ error: error })
|
49 |
}
|
50 |
}
|
51 |
})
|
|
|
59 |
res.send("/down?url=<scribd>")
|
60 |
})
|
61 |
|
62 |
+
app.all("/down", async (req, res) => {
|
63 |
+
const browserStartAttempts = 5;
|
64 |
+
for (let i = 0; i < browserStartAttempts; i++) {
|
65 |
+
try {
|
66 |
+
const { url } = req.query;
|
67 |
+
if (!url) return res.json({ error: "invalid url/nourl" })
|
68 |
+
return res.json(await main(url))
|
69 |
+
} catch (e) {
|
70 |
+
|
71 |
+
console.log(e)
|
72 |
+
// return res.json(e)
|
73 |
+
}
|
74 |
+
}
|
75 |
+
return res.json({error: "TIMEOUT"})
|
76 |
+
|
77 |
})
|
78 |
app.use(express.static(path.join(__dirname, 'output')));
|
79 |
|