Zhofang commited on
Commit
5475b91
·
verified ·
1 Parent(s): 2ba30ac

Update temp.js

Browse files
Files changed (1) hide show
  1. temp.js +7 -3
temp.js CHANGED
@@ -1,7 +1,6 @@
1
  const express = require('express');
2
  const fs = require('fs');
3
  const path = require('path');
4
- const { v6: uuidv6 } = require('uuid');
5
  const multer = require('multer');
6
 
7
  const app = express();
@@ -12,13 +11,18 @@ if (!fs.existsSync(uploadDir)) {
12
  fs.mkdirSync(uploadDir);
13
  }
14
 
 
 
 
 
 
15
  // Configure multer for file storage
16
  const storage = multer.diskStorage({
17
  destination: function (req, file, cb) {
18
  cb(null, uploadDir);
19
  },
20
  filename: function (req, file, cb) {
21
- const shortId = uuidv6().slice(0, 5);
22
  cb(null, `${shortId}-${file.originalname}`);
23
  }
24
  });
@@ -237,7 +241,7 @@ app.post('/upload', upload.single('file'), (req, res) => {
237
 
238
  // Route for upload via PUT (like bashupload)
239
  app.put('/:filename', (req, res) => {
240
- const shortId = uuidv6().slice(0, 5);
241
  const filename = req.params.filename;
242
  const filepath = path.join(uploadDir, `${shortId}-${filename}`);
243
  const fileStream = fs.createWriteStream(filepath);
 
1
  const express = require('express');
2
  const fs = require('fs');
3
  const path = require('path');
 
4
  const multer = require('multer');
5
 
6
  const app = express();
 
11
  fs.mkdirSync(uploadDir);
12
  }
13
 
14
+ // Function to generate a short random ID (alphanumeric)
15
+ function generateShortId() {
16
+ return Math.random().toString(36).substring(2, 7); // Generates a random string of length 5
17
+ }
18
+
19
  // Configure multer for file storage
20
  const storage = multer.diskStorage({
21
  destination: function (req, file, cb) {
22
  cb(null, uploadDir);
23
  },
24
  filename: function (req, file, cb) {
25
+ const shortId = generateShortId();
26
  cb(null, `${shortId}-${file.originalname}`);
27
  }
28
  });
 
241
 
242
  // Route for upload via PUT (like bashupload)
243
  app.put('/:filename', (req, res) => {
244
+ const shortId = generateShortId();
245
  const filename = req.params.filename;
246
  const filepath = path.join(uploadDir, `${shortId}-${filename}`);
247
  const fileStream = fs.createWriteStream(filepath);