1 | import * as wmill from "npm:windmill-client@1"; |
2 | import * as tb from "https://raw.githubusercontent.com/marcelklehr/nextcloud-client-deno/1629b11dc919b99d8dfadf2870a02128a24333fa/tables/index.ts"; |
3 |
|
4 | |
5 | |
6 |
|
7 | export async function main( |
8 | nextcloudResource: string, |
9 | userId: string | null = null, |
10 | useAppApiAuth: boolean = false, |
11 | ) { |
12 | const ncResource = await wmill.getResource( |
13 | nextcloudResource, |
14 | ); |
15 | const config = new tb.Configuration({ |
16 | username: userId || ncResource.username, |
17 | password: ncResource.password, |
18 | basePath: ncResource.baseUrl, |
19 | middleware: [{ |
20 | async pre(context) { |
21 | if (!context.url.includes("?")) { |
22 | context.url += "?"; |
23 | } else { |
24 | context.url += "&"; |
25 | } |
26 | context.url += "format=json"; |
27 | return context; |
28 | }, |
29 | }], |
30 | ...(useAppApiAuth && ({ |
31 | headers: { |
32 | "AA-VERSION": "2.3.0", |
33 | "EX-APP-ID": "flow", |
34 | "EX-APP-VERSION": "1.0.0", |
35 | "AUTHORIZATION-APP-API": btoa( |
36 | `${userId || ncResource.username}:${ncResource.password}`, |
37 | ), |
38 | }, |
39 | })), |
40 | }); |
41 | const api = new tb.Api1Api(config); |
42 |
|
43 | return await api.api1List(); |
44 | } |
45 |
|