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 | taskType: string, |
11 | input: object, |
12 | useAppApiAuth: boolean = false, |
13 | ) { |
14 | const ncResource = await wmill.getResource( |
15 | nextcloudResource, |
16 | ); |
17 | const config = new nc.Configuration({ |
18 | username: userId || ncResource.username, |
19 | password: ncResource.password, |
20 | basePath: ncResource.baseUrl, |
21 | middleware: [{ |
22 | async pre(context) { |
23 | if (!context.url.includes("?")) { |
24 | context.url += "?"; |
25 | } else { |
26 | context.url += "&"; |
27 | } |
28 | context.url += "format=json"; |
29 | return context; |
30 | }, |
31 | }], |
32 | ...(useAppApiAuth && ({ |
33 | headers: { |
34 | "AA-VERSION": "2.3.0", |
35 | "EX-APP-ID": "windmill_app", |
36 | "EX-APP-VERSION": "1.0.0", |
37 | "AUTHORIZATION-APP-API": btoa( |
38 | `${userId || ncResource.username}:${ncResource.password}`, |
39 | ), |
40 | }, |
41 | })), |
42 | }); |
43 | const api = new nc.TaskProcessingApiApi(config); |
44 |
|
45 | const resumeUrls = await wmill.getResumeUrls() |
46 |
|
47 | const res = await api.taskProcessingApiScheduleRaw({ |
48 | taskProcessingApiScheduleRequest: { |
49 | type: taskType, |
50 | input, |
51 | appId: 'windmill', |
52 | webhookUri: resumeUrls.resume, |
53 | webhookMethod: 'HTTP:POST', |
54 | }, |
55 | oCSAPIRequest: true, |
56 | }); |
57 | return { |
58 | urls: resumeUrls, |
59 | task: await res.raw.json() |
60 | } |
61 | } |
62 |
|
63 |
|