Kyouka commited on
Commit
9a1b38d
·
verified ·
1 Parent(s): bd13fd7

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +3 -38
index.js CHANGED
@@ -40,41 +40,6 @@ app.use((req, res, next) => {
40
  next()
41
  })
42
 
43
- const DOWNLOAD_DIR = path.join(__dirname, 'downloads');
44
-
45
-
46
- // Buat folder downloads jika belum ada
47
- if (!fs.existsSync(DOWNLOAD_DIR)) {
48
- fs.mkdirSync(DOWNLOAD_DIR, { recursive: true });
49
- }
50
-
51
- // Fungsi pembersih file lama (> 24 jam)
52
- function cleanupDownloads() {
53
- console.log('Running cleanup...');
54
- fs.readdir(DOWNLOAD_DIR, (err, files) => {
55
- if (err) throw err;
56
-
57
- const now = Date.now();
58
- const oneDay = 24 * 60 * 60 * 1000;
59
-
60
- files.forEach(file => {
61
- const filePath = path.join(DOWNLOAD_DIR, file);
62
- fs.stat(filePath, (err, stat) => {
63
- if (err) return console.error(err);
64
-
65
- if (now - stat.mtime.getTime() > oneDay) {
66
- fs.unlink(filePath, err => {
67
- if (err) console.error(`Error deleting ${filePath}:`, err);
68
- else console.log(`Deleted old file: ${filePath}`);
69
- });
70
- }
71
- });
72
- });
73
- });
74
- }
75
-
76
- // Jadwalkan cleanup setiap hari pukul 00:00
77
- cron.schedule('0 0 * * *', cleanupDownloads);
78
 
79
  // Fungsi buat nama file unik
80
  function generateUniqueFilename() {
@@ -114,7 +79,7 @@ app.get('/douyin', async (req, res) => {
114
 
115
  // Step 2: Download videonya
116
  const filename = generateUniqueFilename();
117
- const filePath = path.join(DOWNLOAD_DIR, filename);
118
 
119
  const videoResponse = await axios({
120
  method: 'get',
@@ -151,7 +116,7 @@ app.get('/douyin', async (req, res) => {
151
  // Route publik file video: http://node.shiaori.xyz:19141/filename.mp4
152
  app.get('/:filename', (req, res) => {
153
  const filename = req.params.filename;
154
- const filePath = path.join(DOWNLOAD_DIR, filename);
155
 
156
  if (!fs.existsSync(filePath)) {
157
  return res.status(404).send('File not found');
@@ -162,7 +127,7 @@ app.get('/:filename', (req, res) => {
162
 
163
  // Route debugging (opsional)
164
  app.get('/files', (req, res) => {
165
- fs.readdir(DOWNLOAD_DIR, (err, files) => {
166
  if (err) {
167
  return res.status(500).send('Error reading directory');
168
  }
 
40
  next()
41
  })
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  // Fungsi buat nama file unik
45
  function generateUniqueFilename() {
 
79
 
80
  // Step 2: Download videonya
81
  const filename = generateUniqueFilename();
82
+ const filePath = path.join(tmpFolder, filename);
83
 
84
  const videoResponse = await axios({
85
  method: 'get',
 
116
  // Route publik file video: http://node.shiaori.xyz:19141/filename.mp4
117
  app.get('/:filename', (req, res) => {
118
  const filename = req.params.filename;
119
+ const filePath = path.join(tmpFolder, filename);
120
 
121
  if (!fs.existsSync(filePath)) {
122
  return res.status(404).send('File not found');
 
127
 
128
  // Route debugging (opsional)
129
  app.get('/files', (req, res) => {
130
+ fs.readdir(tmpFolder, (err, files) => {
131
  if (err) {
132
  return res.status(500).send('Error reading directory');
133
  }