1 | import * as wmill from "npm:windmill-client@1"; |
2 | import * as nc from "https://raw.githubusercontent.com/marcelklehr/nextcloud-client-deno/c57692db56e9292b252c9b8aca7516753881409c/core/index.ts"; |
3 |
|
4 |
|
5 |
|
6 |
|
7 | export async function main( |
8 | nextcloudResource: string, |
9 | userId: string | null = null, |
10 | taskId: string, |
11 | useAppApiAuth: boolean = false, |
12 | ) { |
13 | const ncResource = await wmill.getResource( |
14 | nextcloudResource, |
15 | ); |
16 | const config = new nc.Configuration({ |
17 | username: userId || ncResource.username, |
18 | password: ncResource.password, |
19 | basePath: ncResource.baseUrl, |
20 | middleware: [{ |
21 | async pre(context) { |
22 | if (!context.url.includes("?")) { |
23 | context.url += "?"; |
24 | } else { |
25 | context.url += "&"; |
26 | } |
27 | context.url += "format=json"; |
28 | return context; |
29 | }, |
30 | }], |
31 | ...(useAppApiAuth && ({ |
32 | headers: { |
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 | const api = new nc.TaskProcessingApiApi(config); |
43 |
|
44 | const res = await api.taskProcessingApiGetTaskRaw({ |
45 | id: taskId, |
46 | oCSAPIRequest: true, |
47 | }); |
48 | return await res.raw.json() |
49 | } |
50 |
|
51 |
|