-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmega.js
More file actions
27 lines (25 loc) · 878 Bytes
/
mega.js
File metadata and controls
27 lines (25 loc) · 878 Bytes
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
const mega = require("megajs");
const auth = {
email: 'EnterYourMegaEmail',
password: 'EnterYourMegaPassword',
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 {
const storage = new mega.Storage(auth, () => {
data.pipe(storage.upload({name: name, allowUploadBuffering: true}));
storage.on("add", (file) => {
file.link((err, url) => {
if (err) throw err;
storage.close()
resolve(url);
});
});
});
} catch (err) {
reject(err);
}
});
};
module.exports = { upload };