0
Get Nextcloud TaskProcessing Task
One script reply has been approved by the moderators Verified
Created by marcel klehr12 135 days ago Viewed 355 times
0
Submitted by nextcloud Bun
Verified 9 days ago
1
import * as wmill from "windmill-client";
2
import createClient, { type Middleware } from "openapi-fetch";
3

4
type Nextcloud = {
5
  baseUrl: string,
6
  password: string,
7
  username: string
8
};
9

10
export async function main(
11
  ncResource: Nextcloud,
12

13
  userId: string | null = null,
14

15
  taskId: string,
16

17
  useAppApiAuth: boolean = false,
18
) {
19

20
  const client = createClient<paths>({ baseUrl: ncResource.baseUrl });
21
  const authMiddleware: Middleware = {
22
    async onRequest({ request, options }) {
23
      // fetch token, if it doesn’t exist
24
      // add Authorization header to every request
25
      request.headers.set("Authorization", `Basic ${btoa((userId || ncResource.username) + ':' + ncResource.password)}`);
26
      if (useAppApiAuth) {
27
        request.headers.set("AA-VERSION", "2.3.0",);
28
        request.headers.set("EX-APP-ID", "flow",);
29
        request.headers.set("EX-APP-VERSION", "1.0.1",);
30
        request.headers.set("AUTHORIZATION-APP-API", btoa(
31
          `${userId || ncResource.username}:${ncResource.password}`,
32
        ));
33
      }
34
      return request;
35
    },
36
  };
37
  client.use(authMiddleware);
38

39
  const res = await client.GET("/ocs/v2.php/taskprocessing/task/{id}", {
40
    params: {
41
      header: {
42
        "OCS-APIRequest": true,
43
      },
44
      query: {
45
        format: "json",
46
      },
47
      path: {
48
        id: taskId,
49
      },
50

51
    },
52
  });
53
  return res.data;
54
}
Other submissions