1 | import * as wmill from "npm:windmill-client@1" |
2 | import axios from "npm:axios" |
3 |
|
4 | export async function main( |
5 | nextcloudResource: string, |
6 | userId: string|null = null, |
7 | rowId: number, |
8 | columnId: number, |
9 | value: string, |
10 | useAppApiAuth: boolean = false, |
11 | ) { |
12 | const ncResource = await wmill.getResource( |
13 | nextcloudResource, |
14 | ); |
15 |
|
16 | const data = { |
17 | data: { |
18 | [columnId]: value, |
19 | } |
20 | } |
21 | const url = ncResource.baseUrl + '/index.php/apps/tables/api/1/rows/' + rowId |
22 | const config = { |
23 | ...(!useAppApiAuth && ({ |
24 | auth: { |
25 | username: ncResource.username, |
26 | password: ncResource.password, |
27 | }, |
28 | })), |
29 | headers: { |
30 | 'content-type': 'application/json', |
31 | 'ocs-apirequest': true, |
32 | ...(useAppApiAuth && ({ |
33 | "AA-VERSION": "2.3.0", |
34 | "EX-APP-ID": "flow", |
35 | "EX-APP-VERSION": "1.0.0", |
36 | "AUTHORIZATION-APP-API": btoa( |
37 | `${userId || ncResource.username}:${ncResource.password}`, |
38 | ), |
39 | })), |
40 | }, |
41 | } |
42 | console.debug('config', config) |
43 | try { |
44 | const resp = await axios.put(url, data, config) |
45 | console.debug('RESPONSE', resp.data) |
46 | return { |
47 | data |
48 | } |
49 | } catch(e) { |
50 | console.debug('error', e) |
51 | } |
52 | |
53 | |
54 | return {} |
55 | } |