1
Get Changes
One script reply has been approved by the moderators Verified
Created by rossmccrann 849 days ago Viewed 10021 times
0
Submitted by rossmccrann Deno
Verified 849 days ago
1
import * as wmill from "https://deno.land/x/windmill@v1.85.0/mod.ts";
2

3
type Gdrive = {
4
  token: string;
5
};
6
export async function main(gdrive_auth: Gdrive) {
7
  const START_PAGE_URL = `https://www.googleapis.com/drive/v3/changes/startPageToken/`;
8

9
  let last_start_page_token: string | undefined =
10
    await wmill.getInternalState();
11

12
  const token = gdrive_auth["token"];
13

14
  if (last_start_page_token == undefined) {
15
    const START_PAGE_URL = `https://www.googleapis.com/drive/v3/changes/startPageToken`;
16

17
    const response_sp = await fetch(START_PAGE_URL, {
18
      method: "GET",
19
      headers: {
20
        Authorization: "Bearer " + token,
21
        "Content-Type": "application/json",
22
      },
23
    });
24
    const start_page_result = await response_sp.json();
25

26
    last_start_page_token = start_page_result["startPageToken"];
27
  }
28

29
  const CHECK_CHANGES_URL = `https://www.googleapis.com/drive/v3/changes/?pageToken=${last_start_page_token}`;
30

31
  const changes_response = await fetch(CHECK_CHANGES_URL, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + token,
35
      "Content-Type": "application/json",
36
    },
37
  });
38

39
  const result_changes = await changes_response.json();
40

41
  await wmill.setInternalState(result_changes["newStartPageToken"]);
42

43
  return result_changes["changes"];
44
}
45