File size: 1,859 Bytes
594c998
 
728516e
594c998
 
 
9b93964
4b3cdf7
 
594c998
 
 
 
 
 
 
a6bb0df
594c998
 
 
 
 
 
 
a2a82a3
a6bb0df
4085b1a
594c998
4085b1a
a6bb0df
594c998
4085b1a
594c998
4085b1a
594c998
 
a6bb0df
594c998
 
a2a82a3
594c998
 
 
 
 
 
 
 
 
a47847b
594c998
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const express = require('express');
const { chromium } = require('playwright');
const fs = require('fs');
const path = require('path');

const app = express();
const PORT = 7860;
const TEMP_DIR = '/tmp';
if (!fs.existsSync(TEMP_DIR)) fs.mkdirSync(TEMP_DIR, { recursive: true });
app.get('/sswebvid', async (req, res) => {
  const url = req.query.url;
  if (!url) return res.status(400).send('Parameter ?url= wajib');

  const browser = await chromium.launch();
  const context = await browser.newContext({
    recordVideo: {
      dir: '/tmp',
      size: { width: 1280, height: 720 }
    }
  });

  const page = await context.newPage();

  try {
    await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 15000 });
    await page.waitForTimeout(5000);
    const videoPath = await page.video().path();

    await browser.close();

    res.setHeader('Content-Type', 'video/webm');
    const stream = fs.createReadStream(videoPath);
    stream.pipe(res);
    stream.on('end', () => fs.unlink(videoPath, () => {})); // hapus setelah dikirim
  } catch (err) {
    await browser.close();
    res.status(500).send('Gagal rekam video: ' + err.message);
  }
});

// Endpoint: Screenshot sebagai foto (gambar)
app.get('/ssweb', async (req, res) => {
  const url = req.query.url;
  if (!url) return res.status(400).send('Parameter ?url= wajib');

  const browser = await chromium.launch();
  const page = await browser.newPage();

  try {
    await page.goto(url, { waitUntil: 'load', timeout: 15000 });

    const buffer = await page.screenshot({ fullPage: true });

    res.setHeader('Content-Type', 'image/png');
    res.send(buffer);
  } catch (err) {
    res.status(500).send('Gagal screenshot foto: ' + err.message);
  } finally {
    await browser.close();
  }
});

app.listen(PORT, () => {
  console.log(`Server jalan di http://localhost:${PORT}`);
});