Skip to content

Commit a46ec03

Browse files
committed
Revert "Updating Drive Activity v2 quickstart formatting."
This reverts commit 38849b1.
1 parent 38849b1 commit a46ec03

1 file changed

Lines changed: 75 additions & 75 deletions

File tree

drive/activity-v2/index.js

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,42 @@
1515
* limitations under the License.
1616
*/
1717
// [START drive_activity_v2_quickstart]
18-
const fs = require('fs')
19-
const readline = require('readline')
20-
const { google } = require('googleapis')
18+
const fs = require('fs');
19+
const readline = require('readline');
20+
const {google} = require('googleapis');
2121

2222
// If modifying these scopes, delete token.json.
23-
const SCOPES = ['https://www.googleapis.com/auth/drive.activity.readonly']
23+
const SCOPES = ['https://www.googleapis.com/auth/drive.activity.readonly'];
2424
// The file token.json stores the user's access and refresh tokens, and is
2525
// created automatically when the authorization flow completes for the first
2626
// time.
27-
const TOKEN_PATH = 'token.json'
27+
const TOKEN_PATH = 'token.json';
2828

2929
// Load client secrets from a local file.
3030
fs.readFile('credentials.json', (err, content) => {
31-
if (err) return console.log('Error loading client secret file:', err)
31+
if (err) return console.log('Error loading client secret file:', err);
3232
// Authorize a client with credentials, then call the Google Drive Activity
3333
// API.
34-
authorize(JSON.parse(content), listDriveActivity)
35-
})
34+
authorize(JSON.parse(content), listDriveActivity);
35+
});
3636

3737
/**
3838
* Create an OAuth2 client with the given credentials, and then execute the
3939
* given callback function.
4040
* @param {Object} credentials The authorization client credentials.
4141
* @param {function} callback The callback to call with the authorized client.
4242
*/
43-
function authorize (credentials, callback) {
44-
const { clientSecret, clientId, redirectUris } = credentials.installed
43+
function authorize(credentials, callback) {
44+
const {client_secret, client_id, redirect_uris} = credentials.installed;
4545
const oAuth2Client = new google.auth.OAuth2(
46-
clientId, clientSecret, redirectUris[0])
46+
client_id, client_secret, redirect_uris[0]);
4747

4848
// Check if we have previously stored a token.
4949
fs.readFile(TOKEN_PATH, (err, token) => {
50-
if (err) return getNewToken(oAuth2Client, callback)
51-
oAuth2Client.setCredentials(JSON.parse(token))
52-
callback(oAuth2Client)
53-
})
50+
if (err) return getNewToken(oAuth2Client, callback);
51+
oAuth2Client.setCredentials(JSON.parse(token));
52+
callback(oAuth2Client);
53+
});
5454
}
5555

5656
/**
@@ -59,124 +59,124 @@ function authorize (credentials, callback) {
5959
* @param {google.auth.OAuth2} oAuth2Client The OAuth2 client to get token for.
6060
* @param {getEventsCallback} callback The callback for the authorized client.
6161
*/
62-
function getNewToken (oAuth2Client, callback) {
62+
function getNewToken(oAuth2Client, callback) {
6363
const authUrl = oAuth2Client.generateAuthUrl({
6464
access_type: 'offline',
65-
scope: SCOPES
66-
})
67-
console.log('Authorize this app by visiting this url:', authUrl)
65+
scope: SCOPES,
66+
});
67+
console.log('Authorize this app by visiting this url:', authUrl);
6868
const rl = readline.createInterface({
6969
input: process.stdin,
70-
output: process.stdout
71-
})
70+
output: process.stdout,
71+
});
7272
rl.question('Enter the code from that page here: ', (code) => {
73-
rl.close()
73+
rl.close();
7474
oAuth2Client.getToken(code, (err, token) => {
75-
if (err) return console.error('Error retrieving access token', err)
76-
oAuth2Client.setCredentials(token)
75+
if (err) return console.error('Error retrieving access token', err);
76+
oAuth2Client.setCredentials(token);
7777
// Store the token to disk for later program executions
7878
fs.writeFile(TOKEN_PATH, JSON.stringify(token), (err) => {
79-
if (err) console.error(err)
80-
console.log('Token stored to', TOKEN_PATH)
81-
})
82-
callback(oAuth2Client)
83-
})
84-
})
79+
if (err) console.error(err);
80+
console.log('Token stored to', TOKEN_PATH);
81+
});
82+
callback(oAuth2Client);
83+
});
84+
});
8585
}
8686

8787
/**
8888
* Lists the recent activity in your Google Drive.
8989
*
9090
* @param {google.auth.OAuth2} auth An authorized OAuth2 client.
9191
*/
92-
function listDriveActivity (auth) {
93-
const service = google.driveactivity({ version: 'v2', auth })
92+
function listDriveActivity(auth) {
93+
const service = google.driveactivity({version: 'v2', auth});
9494
const params = {
95-
'pageSize': 10
96-
}
97-
service.activity.query({ requestBody: params }, (err, res) => {
98-
if (err) return console.error('The API returned an error: ' + err)
99-
const activities = res.data.activities
95+
'pageSize': 10,
96+
};
97+
service.activity.query({requestBody:params}, (err, res) => {
98+
if (err) return console.error('The API returned an error: ' + err);
99+
const activities = res.data.activities;
100100
if (activities) {
101-
console.log('Recent activity:')
101+
console.log('Recent activity:');
102102
activities.forEach((activity) => {
103-
var time = getTimeInfo(activity)
104-
var action = getActionInfo(activity['primaryActionDetail'])
105-
var actors = activity.actors.map(getActorInfo)
106-
var targets = activity.targets.map(getTargetInfo)
103+
var time = getTimeInfo(activity);
104+
var action = getActionInfo(activity['primaryActionDetail']);
105+
var actors = activity.actors.map(getActorInfo);
106+
var targets = activity.targets.map(getTargetInfo);
107107
console.log(`${time}: ${truncated(actors)}, ${action}, ` +
108-
`${truncated(targets)}`)
109-
})
108+
`${truncated(targets)}`);
109+
});
110110
} else {
111-
console.log('No activity.')
111+
console.log('No activity.');
112112
}
113-
})
113+
});
114114
}
115115

116116
/** Returns a string representation of the first elements in a list. */
117-
function truncated (array, limit = 2) {
118-
var contents = array.slice(0, limit).join(', ')
119-
var more = array.length > limit ? ', ...' : ''
120-
return `[${contents}${more}]`
117+
function truncated(array, limit = 2) {
118+
var contents = array.slice(0, limit).join(', ');
119+
var more = array.length > limit ? ', ...' : '';
120+
return `[${contents}${more}]`;
121121
}
122122

123123
/** Returns the name of a set property in an object, or else "unknown". */
124-
function getOneOf (object) {
124+
function getOneOf(object) {
125125
for (var key in object) {
126-
return key
126+
return key;
127127
}
128-
return 'unknown'
128+
return 'unknown';
129129
}
130130

131131
/** Returns a time associated with an activity. */
132-
function getTimeInfo (activity) {
132+
function getTimeInfo(activity) {
133133
if ('timestamp' in activity) {
134-
return activity.timestamp
134+
return activity.timestamp;
135135
}
136136
if ('timeRange' in activity) {
137-
return activity.timeRange.endTime
137+
return activity.timeRange.endTime;
138138
}
139-
return 'unknown'
139+
return 'unknown';
140140
}
141141

142142
/** Returns the type of action. */
143-
function getActionInfo (actionDetail) {
144-
return getOneOf(actionDetail)
143+
function getActionInfo(actionDetail) {
144+
return getOneOf(actionDetail);
145145
}
146146

147147
/** Returns user information, or the type of user if not a known user. */
148-
function getUserInfo (user) {
148+
function getUserInfo(user) {
149149
if ('knownUser' in user) {
150-
var knownUser = user['knownUser']
151-
var isMe = knownUser['isCurrentUser'] || false
152-
return isMe ? 'people/me' : knownUser['personName']
150+
var knownUser = user['knownUser'];
151+
var isMe = knownUser['isCurrentUser'] || false;
152+
return isMe ? 'people/me' : knownUser['personName'];
153153
}
154-
return getOneOf(user)
154+
return getOneOf(user);
155155
}
156156

157157
/** Returns actor information, or the type of actor if not a user. */
158-
function getActorInfo (actor) {
158+
function getActorInfo(actor) {
159159
if ('user' in actor) {
160160
return getUserInfo(actor['user'])
161161
}
162-
return getOneOf(actor)
162+
return getOneOf(actor);
163163
}
164164

165165
/** Returns the type of a target and an associated title. */
166-
function getTargetInfo (target) {
166+
function getTargetInfo(target) {
167167
if ('driveItem' in target) {
168-
var itemTitle = target.driveItem.title || 'unknown'
169-
return `driveItem:"${itemTitle}"`
168+
var title = target.driveItem.title || 'unknown';
169+
return `driveItem:"${title}"`;
170170
}
171171
if ('teamDrive' in target) {
172-
var driveTitle = target.teamDrive.title || 'unknown'
173-
return `teamDrive:"${driveTitle}"`
172+
var title = target.teamDrive.title || 'unknown';
173+
return `teamDrive:"${title}"`;
174174
}
175175
if ('fileComment' in target) {
176-
var parent = target.fileComment.parent || {}
177-
var parentTitle = parent.title || 'unknown'
178-
return `fileComment:"${parentTitle}"`
176+
var parent = target.fileComment.parent || {};
177+
var title = parent.title || 'unknown';
178+
return `fileComment:"${title}"`;
179179
}
180-
return `${getOneOf(target)}:unknown`
180+
return `${getOneOf(target)}:unknown`;
181181
}
182182
// [END drive_activity_v2_quickstart]

0 commit comments

Comments
 (0)