1 | |
2 |
|
3 | type Gdrive = { |
4 | token: string; |
5 | }; |
6 | export async function main( |
7 | gdrive_auth: Gdrive, |
8 | drive_id: string, |
9 | webhook_address: string, |
10 | channelId: any, |
11 | ) { |
12 | const SUPPORT_ALL_DRIVES = true; |
13 | const SUPPORT_TEAM_DRIVES = true; |
14 | const INCLUDE_ITEMS_FROM_ALL_DRIVES = true; |
15 | const START_PAGE_URL = `https://www.googleapis.com/drive/v3/changes/startPageToken/?driveId=${drive_id}&supportsAllDrives=${SUPPORT_ALL_DRIVES}`; |
16 |
|
17 | const token = gdrive_auth["token"]; |
18 |
|
19 | const response_sp = await fetch(START_PAGE_URL, { |
20 | method: "GET", |
21 | headers: { |
22 | Authorization: "Bearer " + token, |
23 | "Content-Type": "application/json", |
24 | }, |
25 | }); |
26 |
|
27 | const start_page_result = await response_sp.json(); |
28 | const START_PAGE_TOKEN = start_page_result["startPageToken"]; |
29 |
|
30 | const WATCH_URL = `https://www.googleapis.com/drive/v3/changes/watch/?pageToken=${START_PAGE_TOKEN}&supportsAllDrives=${SUPPORT_ALL_DRIVES}&supportsTeamDrives=${SUPPORT_TEAM_DRIVES}&includeItemsFromAllDrives=${INCLUDE_ITEMS_FROM_ALL_DRIVES}`; |
31 |
|
32 | const requestBody = { |
33 | kind: "api#channel", |
34 | type: "webhook", |
35 | address: webhook_address, |
36 | id: channelId, |
37 | }; |
38 |
|
39 | const response = await fetch(WATCH_URL, { |
40 | method: "POST", |
41 | body: JSON.stringify(requestBody), |
42 | headers: { |
43 | Authorization: "Bearer " + token, |
44 | "Content-Type": "application/json", |
45 | }, |
46 | }); |
47 |
|
48 | const message = await response.json(); |
49 |
|
50 | return message; |
51 | } |
52 |
|