-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
43 lines (39 loc) · 1.37 KB
/
script.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
38
39
40
41
42
43
require('dotenv').config()
const fetch = require('node-fetch');
fetch(`https://login.microsoftonline.com/${process.env.TENANTID}/oauth2/v2.0/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `client_id=${process.env.CLIENTID}&scope=openid&username=${process.env.USERNAME}&password=${process.env.PASSWORD}&grant_type=password`
}).then((res) => {
return res.json();
}).then((res) => {
const fs = require('fs');
fs.readdir(process.cwd(), function (err, files) {
if (err) {
console.log(err);
return;
}
const filePath = files.find(x => x.includes('.sql'));
if (filePath) {
const stats = fs.statSync(filePath).size;
const stream = fs.createReadStream(filePath);
fetch(`https://graph.microsoft.com/v1.0/me/drive/items/${process.env.FOLDERID}:/${filePath}:/content`, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${res.access_token}`,
"Content-length": stats
},
body: stream
})
.then(function(res) {
return res.json();
}).then(function(json) {
console.log(json);
});
} else {
console.log('REEEEEE')
}
});
});