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