1
Create an approval link with the approve_links app
One script reply has been approved by the moderators Verified
Created by marcel klehr12 136 days ago Viewed 362 times
0
Submitted by nextcloud Bun
Verified 10 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
  userId: string | null = null,
13
  approveCallbackUri: string,
14
  rejectCallbackUri: string,
15
  description: string,
16
  useAppApiAuth: boolean = false,
17
) {
18

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

38
  const data = {
39
    approveCallbackUri,
40
    rejectCallbackUri,
41
    description,
42
  }
43

44
  try {
45
    const resp = await await client.POST("/ocs/v2.php/apps/approve_links/api/v1/link", {
46
      params: {
47
        header: {
48
          "OCS-APIRequest": true,
49
        },
50
        query: {
51
          format: "json",
52
        },
53

54
      },
55
      body: data,
56
    });
57
    console.debug('RESPONSE', resp.data)
58
    return {
59
      link: resp.data.ocs.data.link,
60
    }
61
  } catch (e) {
62
    console.debug('error', e)
63
  }
64

65

66
  return {}
67

68
}
Other submissions