Skip to content

Commit

Permalink
feat: set app id in google picker
Browse files Browse the repository at this point in the history
  • Loading branch information
abuaboud committed May 9, 2024
1 parent d61b2ed commit 0057da8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/ui/common/src/lib/service/google-file-picker.service.ts
@@ -1,14 +1,15 @@
import { GoogleFilePickerPropertyValueSchema } from '@activepieces/pieces-framework';
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Observable, switchMap } from 'rxjs';
import { Observable, switchMap, map } from 'rxjs';
import { AppConnectionsService } from './app-connections.service';
import { AppConnectionType } from '@activepieces/shared';
import { HttpClient } from '@angular/common/http';

@Injectable({ providedIn: 'root' })
export class GoogleFilePickerService {
private isPickerApiLoaded$ = new BehaviorSubject<boolean>(false);
constructor(private appConnectionsService: AppConnectionsService) {}
constructor(private appConnectionsService: AppConnectionsService, private httpClient: HttpClient) { }
loadGapiScript() {
if (!this.isPickerApiLoaded$.value) {
const script = document.createElement('script');
Expand Down Expand Up @@ -52,20 +53,22 @@ export class GoogleFilePickerService {
userDriveView.setIncludeFolders(true);
const sharedDriveView = new google.picker.DocsView(viewId);
sharedDriveView.setEnableDrives(true).setIncludeFolders(true);
const appId = connection.value.client_id.split("-")[0]
const picker = new google.picker.PickerBuilder()
.addView(userDriveView)
.addView(sharedDriveView)
.setAppId(appId)
.setOAuthToken(connection.value.access_token)
.setCallback((data: Record<string, any>) => {
if (
data[google.picker.Response.ACTION] ==
google.picker.Action.PICKED ||
google.picker.Action.PICKED ||
data[google.picker.Response.ACTION] ==
google.picker.Action.CANCEL
google.picker.Action.CANCEL
) {
const formattedData =
data[google.picker.Response.ACTION] ==
google.picker.Action.CANCEL
google.picker.Action.CANCEL
? null
: this.pickerCallback(data);
observer.next(formattedData);
Expand Down Expand Up @@ -109,4 +112,12 @@ export class GoogleFilePickerService {
backdrop.addEventListener('click', callback);
}
}

getFileName({ fileId, accessToken }: { fileId: string, accessToken: string }) {
return this.httpClient.get<{ name: string }>(`https://www.googleapis.com/drive/v3/files/${fileId}`, {
headers: {
Authorization: `Bearer ${accessToken}`
}
}).pipe(map(f => f.name))
}
}

0 comments on commit 0057da8

Please sign in to comment.