termai commited on
Commit
aaa04de
·
verified ·
1 Parent(s): 4358f3a

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +17 -18
index.js CHANGED
@@ -14,18 +14,30 @@ const uploadFile = async (file) => {
14
  formData.append('file', file, { filename: 'file.png'});
15
 
16
  try {
17
- const response = await axios.post(`${domain}/api/upload?uploader=drive&key=`+key, formData, {
18
- headers: {
19
- 'Content-Type': 'multipart/form-data',
20
- },
21
  });
22
 
23
- return response.data
24
  } catch (error) {
25
  console.error('Error uploading file', error.response?.data || error.message);
 
26
  }
27
  };
28
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  app.all("/", async (req, res) => {
30
  const code = req.body?.code || req.query?.code;
31
  if (!code) return res.status(400).json({ error: "No code provided" });
@@ -33,17 +45,6 @@ app.all("/", async (req, res) => {
33
  let browser;
34
  const images = [];
35
 
36
- const patchScreenshot = (target) => {
37
- const orig = target.screenshot;
38
- target.screenshot = async function (...args) {
39
- const buffer = await orig.apply(this, args);
40
- const url = await uploadFile(buffer);
41
- delete url.status
42
- images.push(url);
43
- return buffer;
44
- };
45
- };
46
-
47
  const chromium = {
48
  ...origChromium,
49
  launch: async (...args) => {
@@ -51,8 +52,6 @@ app.all("/", async (req, res) => {
51
  const origNewPage = browser.newPage;
52
  browser.newPage = async (...a) => {
53
  const page = await origNewPage.apply(browser, a);
54
- patchScreenshot(page);
55
- const origElemScreenshot = page.locator("").screenshot;
56
  patchScreenshot(page);
57
  return page;
58
  };
 
14
  formData.append('file', file, { filename: 'file.png'});
15
 
16
  try {
17
+ const response = await axios.post(`${domain}/api/upload?uploader=drive&key=` + key, formData, {
18
+ headers: formData.getHeaders(),
19
+ maxBodyLength: Infinity,
 
20
  });
21
 
22
+ return response.data || {};
23
  } catch (error) {
24
  console.error('Error uploading file', error.response?.data || error.message);
25
+ return {};
26
  }
27
  };
28
 
29
+ const patchScreenshot = (page) => {
30
+ const orig = page.screenshot;
31
+ page.screenshot = async function (options = {}) {
32
+ const buffer = await orig.apply(this, [options]);
33
+ const url = await uploadFile(buffer);
34
+ if (url && url.path) {
35
+ images.push(url.path);
36
+ }
37
+ return buffer;
38
+ };
39
+ };
40
+
41
  app.all("/", async (req, res) => {
42
  const code = req.body?.code || req.query?.code;
43
  if (!code) return res.status(400).json({ error: "No code provided" });
 
45
  let browser;
46
  const images = [];
47
 
 
 
 
 
 
 
 
 
 
 
 
48
  const chromium = {
49
  ...origChromium,
50
  launch: async (...args) => {
 
52
  const origNewPage = browser.newPage;
53
  browser.newPage = async (...a) => {
54
  const page = await origNewPage.apply(browser, a);
 
 
55
  patchScreenshot(page);
56
  return page;
57
  };