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