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 | formHash: string, |
8 | submissionId: number, |
9 | useAppApiAuth: boolean = false, |
10 | ) { |
11 | const ncResource = await wmill.getResource( |
12 | nextcloudResource, |
13 | ); |
14 |
|
15 | const url = ncResource.baseUrl + '/ocs/v2.php/apps/forms/api/v2/submissions/' + formHash |
16 | console.debug('url', url) |
17 | const config = { |
18 | ...(!useAppApiAuth && ({ |
19 | auth: { |
20 | username: ncResource.username, |
21 | password: ncResource.password, |
22 | }, |
23 | })), |
24 | headers: { |
25 | |
26 | 'content-type': 'application/json', |
27 | 'ocs-apirequest': true, |
28 | ...(useAppApiAuth && ({ |
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 | console.debug('config', config) |
39 | try { |
40 | const resp = await axios.get(url, config) |
41 | console.debug('RESPONSE', resp.data) |
42 | const submission = resp.data.ocs.data.submissions.find(s => s.id === submissionId) |
43 | |
44 | return { |
45 | submission, |
46 | } |
47 | } catch(e) { |
48 | console.debug('error', e) |
49 | } |
50 | } |