apinew / post /ship /upfile.js
sjsjd's picture
hello
59485cb
const { writeFileSync, readFileSync} = require('fs-extra');
exports.name = "/upfile";
exports.index = (req, res) => {
let { data, type, id } = req.body;
if (!data)
return res.json({
status: false,
message: "Không có dữ liệu"
});
if (!type) type = "text";
else type = type;
const character = 'ABCDKCCzwKyY9rmBJGu48FrkNMro4AWtCkc1flmnopqrstuvwxyz0123456789';
let random = '';
const number = 32;
for (let i = 0; i < number; i++) {
random += character.charAt(Math.floor(Math.random() * character.length));
}
/*const d = readFileSync(__dirname+`/cache/t5uB188CccrB988twr5fmYCuKAf88pm2.txt`,"utf-8");*/
writeFileSync(`${__dirname}/cache/${random}.txt`, data);
return res.send({
status: 200,
code: random
});
};