Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit 6da3038

Browse files
committed
fix
1 parent 8c36067 commit 6da3038

1 file changed

Lines changed: 7 additions & 50 deletions

File tree

  • lib/osf-components/addon/components/google-file-picker-widget

lib/osf-components/addon/components/google-file-picker-widget/component.ts

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Intl from 'ember-intl/services/intl';
1313

1414
const {
1515
GOOGLE_FILE_PICKER_SCOPES,
16-
GOOGLE_FILE_PICKER_CLIENT_ID,
1716
GOOGLE_FILE_PICKER_API_KEY,
1817
GOOGLE_FILE_PICKER_APP_ID,
1918
} = config.OSF.googleFilePicker;
@@ -68,12 +67,9 @@ export default class GoogleFilePickerWidget extends Component<Args> {
6867
@tracked openGoogleFilePicker = false;
6968
@tracked visible = false;
7069
pickerInited = false;
71-
gisInited = false;
7270
selectFolder: any = undefined;
73-
tokenClient: any = undefined;
7471
accessToken!: string;
7572
scopes = GOOGLE_FILE_PICKER_SCOPES;
76-
clientId = GOOGLE_FILE_PICKER_CLIENT_ID;
7773
apiKey = GOOGLE_FILE_PICKER_API_KEY;
7874
appId = GOOGLE_FILE_PICKER_APP_ID;
7975
mimeTypes = '';
@@ -137,12 +133,12 @@ export default class GoogleFilePickerWidget extends Component<Args> {
137133
* @param file - The file object selected (format determined by external API)
138134
*/
139135
@action
140-
filePickerCallback(file: any) {
136+
filePickerCallback(data: any) {
141137
if (this.selectFolder !== undefined) {
142-
this.folderName = file.name;
138+
this.folderName = data.name;
143139
this.selectFolder({
144-
itemName: file.name,
145-
itemId: file.id,
140+
itemName: data.name,
141+
itemId: data.id,
146142
});
147143
} else {
148144
this.args.manager.reload();
@@ -166,9 +162,7 @@ export default class GoogleFilePickerWidget extends Component<Args> {
166162

167163
willDestroy() {
168164
super.willDestroy();
169-
delete this.tokenClient;
170165
this.pickerInited = false;
171-
this.gisInited = false;
172166
}
173167

174168

@@ -184,31 +178,15 @@ export default class GoogleFilePickerWidget extends Component<Args> {
184178
* discovery doc to initialize the API.
185179
*/
186180
async initializePicker() {
187-
await window.gapi.client.load('https://www.googleapis.com/discovery/v1/apis/drive/v3/rest');
188181
this.pickerInited = true;
189182
this.maybeEnableButtons();
190183
}
191184

192-
/**
193-
* Callback after Google Identity Services are loaded.
194-
*/
195-
gisLoaded() {
196-
if (!this.tokenClient) {
197-
this.tokenClient = window.google?.accounts?.oauth2.initTokenClient({
198-
client_id: this.clientId,
199-
scope: this.scopes,
200-
callback: '', // defined later
201-
});
202-
}
203-
this.gisInited = true;
204-
this.maybeEnableButtons();
205-
}
206-
207185
/**
208186
* Enables user interaction after all libraries are loaded.
209187
*/
210188
maybeEnableButtons() {
211-
if (this.pickerInited && this.gisInited && this.isFolderPicker) {
189+
if (this.pickerInited && this.isFolderPicker) {
212190
this.visible = true;
213191
}
214192
}
@@ -218,21 +196,7 @@ export default class GoogleFilePickerWidget extends Component<Args> {
218196
*/
219197
@action
220198
handleAuthClick() {
221-
this.tokenClient.callback = async (response: any) => {
222-
if (response.error !== undefined) {
223-
throw (response);
224-
}
225-
await this.createPicker();
226-
};
227-
228-
if (this.accessToken === null) {
229-
// Prompt the user to select a Google Account and ask for consent to share their data
230-
// when establishing a new session.
231-
this.tokenClient?.requestAccessToken({prompt: 'consent'});
232-
} else {
233-
// Skip display of account chooser and consent dialog for an existing session.
234-
this.tokenClient?.requestAccessToken({prompt: ''});
235-
}
199+
this.createPicker();
236200
}
237201

238202
/**
@@ -263,14 +227,7 @@ export default class GoogleFilePickerWidget extends Component<Args> {
263227
*/
264228
async pickerCallback(data: any) {
265229
if (data.action === window.google.picker.Action.PICKED) {
266-
const document = data[window.google.picker.Response.DOCUMENTS][0];
267-
const fileId = document[window.google.picker.Document.ID];
268-
const res = await window.gapi.client.drive.files.get({
269-
fileId,
270-
fields: '*',
271-
});
272-
// Correctly call the Ember method
273-
this.filePickerCallback(res.result);
230+
this.filePickerCallback(data.docs[0]);
274231
}
275232
}
276233
}

0 commit comments

Comments
 (0)