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 | tableId: number, |
11 | limit: number | null = null, |
12 | offset: number | null = null, |
13 | useAppApiAuth: boolean = false, |
14 | ) { |
15 | const ncResource = await wmill.getResource( |
16 | nextcloudResource, |
17 | ); |
18 | const config = new tb.Configuration({ |
19 | username: userId || ncResource.username, |
20 | password: ncResource.password, |
21 | basePath: ncResource.baseUrl, |
22 | middleware: [{ |
23 | async pre(context) { |
24 | if (!context.url.includes("?")) { |
25 | context.url += "?"; |
26 | } else { |
27 | context.url += "&"; |
28 | } |
29 | context.url += "format=json"; |
30 | return context; |
31 | }, |
32 | }], |
33 | ...(useAppApiAuth && ({ |
34 | headers: { |
35 | "AA-VERSION": "2.3.0", |
36 | "EX-APP-ID": "windmill_app", |
37 | "EX-APP-VERSION": "1.0.0", |
38 | "AUTHORIZATION-APP-API": btoa( |
39 | `${userId || ncResource.username}:${ncResource.password}`, |
40 | ), |
41 | }, |
42 | })), |
43 | }); |
44 | const api = new tb.Api1Api(config); |
45 |
|
46 | return await api.api1ListTableColumns({ |
47 | tableId, |
48 | ...(limit && ({ limit })), |
49 | ...(offset && ({ offset })), |
50 | }); |
51 | } |
52 |
|