Pepguy commited on
Commit
473c03c
·
verified ·
1 Parent(s): c4786c3

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +21 -11
app.js CHANGED
@@ -12,17 +12,27 @@ const SCOPES = ["https://www.googleapis.com/auth/drive.file"];
12
  const TOKEN_PATH = "token.json";
13
  const CREDENTIALS_PATH = "credentials.json";
14
 
15
- async function getAuthClient() {
16
- const credentials = JSON.parse(fs.readFileSync(CREDENTIALS_PATH));
17
- const token = JSON.parse(fs.readFileSync(TOKEN_PATH));
18
-
19
- const auth = new google.auth.OAuth2(
20
- credentials.installed.client_id,
21
- credentials.installed.client_secret,
22
- credentials.installed.redirect_uris[0]
23
- );
24
- auth.setCredentials(token);
25
- return auth;
 
 
 
 
 
 
 
 
 
 
26
  }
27
 
28
  async function getAllRedisData() {
 
12
  const TOKEN_PATH = "token.json";
13
  const CREDENTIALS_PATH = "credentials.json";
14
 
15
+
16
+ const auth = new google.auth.GoogleAuth({
17
+ keyFile: 'credentials.json',
18
+ scopes: ['https://www.googleapis.com/auth/drive.file'],
19
+ });
20
+
21
+ const drive = google.drive({ version: 'v3', auth });
22
+
23
+ async function uploadBackup(filePath, fileName) {
24
+ const res = await drive.files.create({
25
+ requestBody: {
26
+ name: fileName,
27
+ parents: ['FOLDER_ID'], // optional: set your shared folder
28
+ },
29
+ media: {
30
+ mimeType: 'application/json',
31
+ body: fs.createReadStream(filePath),
32
+ },
33
+ });
34
+
35
+ console.log('File uploaded to Google Drive:', res.data);
36
  }
37
 
38
  async function getAllRedisData() {