Get Nextcloud TaskProcessing Task

Script nextcloud Verified

by marcel klehr12 · 9/5/2024

The script

Submitted by nextcloud Bun
Verified 86 days ago
1
import createClient, { type Middleware } from "openapi-fetch";
2

3

4
export async function main(
5
  nextcloud: RT.Nextcloud,
6
  taskId: string,
7
) {
8

9
  const client = createClient<paths>({ baseUrl: nextcloud.baseUrl });
10
  const authMiddleware: Middleware = {
11
    async onRequest({ request, options }) {
12
      // fetch token, if it doesn’t exist
13
      // add Authorization header to every request
14
      request.headers.set("Authorization", `Basic ${btoa((nextcloud.userId) + ':' + nextcloud.token)}`);
15
      return request;
16
    },
17
  };
18
  client.use(authMiddleware);
19

20
  const res = await client.GET("/ocs/v2.php/taskprocessing/task/{id}", {
21
    params: {
22
      header: {
23
        "OCS-APIRequest": true,
24
      },
25
      query: {
26
        format: "json",
27
      },
28
      path: {
29
        id: taskId,
30
      },
31

32
    },
33
  });
34
  return res.data;
35
}
Other submissions
  • Submitted by marcel klehr12 Deno
    Created 568 days ago
    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
    // fill the type, or use the +Resource type to get a type-safe reference to a resource
    5
    // type Postgresql = object
    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