1 |
|
2 | type Adhook = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Adhook, |
8 | id: string, |
9 | deleteInPlatform: string | undefined, |
10 | Origin: string |
11 | ) { |
12 | const url = new URL(`https://app.adhook.io/v1/posts/${id}`) |
13 |
|
14 | for (const [k, v] of [['deleteInPlatform', deleteInPlatform]]) { |
15 | if (v !== undefined && v !== '' && k !== undefined) { |
16 | url.searchParams.append(k, v) |
17 | } |
18 | } |
19 |
|
20 | const response = await fetch(url, { |
21 | method: 'DELETE', |
22 | headers: { |
23 | Authorization: `Bearer ${auth.token}`, |
24 | Origin: Origin |
25 | }, |
26 | body: undefined |
27 | }) |
28 |
|
29 | if (!response.ok) { |
30 | const text = await response.text() |
31 | throw new Error(`${response.status} ${text}`) |
32 | } |
33 |
|
34 | return await response.text() |
35 | } |
36 |
|