1 | |
2 |
|
3 | |
4 | * Add Comment |
5 | * Add a comment to a file. The comment is unanchored (it applies to the whole file, not a text selection); mention someone by writing +email@example.com in the content. |
6 | */ |
7 | export async function main(auth: RT.Gdrive, file_id: string, content: string) { |
8 | const url = new URL( |
9 | `https://www.googleapis.com/drive/v3/files/${file_id}/comments` |
10 | ) |
11 | url.searchParams.append("fields", "*") |
12 |
|
13 | const response = await fetch(url, { |
14 | method: "POST", |
15 | headers: { |
16 | Authorization: `Bearer ${auth.token}`, |
17 | "Content-Type": "application/json", |
18 | Accept: "application/json", |
19 | }, |
20 | body: JSON.stringify({ content }), |
21 | }) |
22 |
|
23 | if (!response.ok) { |
24 | throw new Error(`${response.status} ${await response.text()}`) |
25 | } |
26 |
|
27 | return await response.json() |
28 | } |
29 |
|