-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmega.js
37 lines (32 loc) · 1.25 KB
/
mega.js
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
const mega = require("megajs");
const auth = {
email: '[email protected]', //use your real vaild mega account email
password: 'meganz@432#SS', ////use your real vaild mega account password
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
};
const upload = (data, name) => {
return new Promise((resolve, reject) => {
try {
if (!auth.email || !auth.password || !auth.userAgent) {
throw new Error("Missing required authentication fields");
}
console.log("Using auth:", auth); // Debugging line
const storage = new mega.Storage(auth, () => {
data.pipe(storage.upload({ name: name, allowUploadBuffering: true }));
storage.on("add", (file) => {
file.link((err, url) => {
if (err) {
reject(err);
return;
}
storage.close();
resolve(url);
});
});
});
} catch (err) {
reject(err);
}
});
};
module.exports = { upload };