Subscribe to Watch Changes ( gdrive)
One script reply has been approved by the moderators Verified

Created by rossmccrann 241 days ago Viewed 58 times 1 Point

No comments yet

Login to be able to comment
Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import * as wmill from "https://deno.land/x/windmill@v1.70.1/mod.ts";

export async function main(
  gdrive_auth: wmill.Resource<"gdrive">,
  drive_id: string,
  webhook_address: string,
  channelId: any,
) {
  const SUPPORT_ALL_DRIVES = true;
  const SUPPORT_TEAM_DRIVES = true;
  const INCLUDE_ITEMS_FROM_ALL_DRIVES = true;
  const START_PAGE_URL =
    `https://www.googleapis.com/drive/v3/changes/startPageToken/?driveId=${drive_id}&supportsAllDrives=${SUPPORT_ALL_DRIVES}`;

  const token = gdrive_auth["token"];

  const response_sp = await fetch(START_PAGE_URL, {
    method: "GET",
    headers: {
      Authorization: "Bearer " + token,
      "Content-Type": "application/json",
    },
  });

  const start_page_result = await response_sp.json();
  const START_PAGE_TOKEN = start_page_result["startPageToken"];

  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}`;

  const requestBody = {
    kind: "api#channel",
    "type": "webhook",
    address: webhook_address,
    id: channelId,
  };

  const response = await fetch(WATCH_URL, {
    method: "POST",
    body: JSON.stringify(requestBody),
    headers: {
      Authorization: "Bearer " + token,
      "Content-Type": "application/json",
    },
  });

  const message = await response.json();

  return message;
}

Submitted by rossmccrann 241 days ago

Edited 24 days ago

No comments yet

Login to be able to comment