Edits history of script submission #11428 for ' Schedule a TaskProcessing AI task in Nextcloud (nextcloud)'

  • bun
    // This must be an approval script!
    
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    export async function main(
      nextcloud: RT.Nextcloud,
      taskType: string,
      input: object,
    ) {
    
      const client = createClient<paths>({ baseUrl: nextcloud.baseUrl });
      const authMiddleware: Middleware = {
        async onRequest({ request, options }) {
          // fetch token, if it doesn’t exist
          // add Authorization header to every request
          request.headers.set("Authorization", `Basic ${btoa((nextcloud.userId) + ':' + nextcloud.token)}`);
          return request;
        },
      };
      client.use(authMiddleware);
    
      const resumeUrls = await wmill.getResumeUrls()
    
      const res = await client.POST("/ocs/v2.php/taskprocessing/schedule", {
        params: {
          header: {
            "OCS-APIRequest": true,
          },
          query: {
            format: "json",
          },
    
        },
        body: {
          type: taskType,
          input: input,
          appId: 'windmill',
          webhookUri: resumeUrls.resume,
          webhookMethod: 'HTTP:POST',
        }
      });
      return {
        urls: resumeUrls,
        task: await res.data,
      }
    }

    Submitted by nextcloud 104 days ago

  • bun
    import caldav
    import base64
    import datetime
    
    # You can import any PyPi package.
    # See here for more info: https://www.windmill.dev/docs/advanced/dependencies_in_python
    
    # you can use typed resources by doing a type alias to dict
    nextcloud = dict
    datetime = dict
    
    
    def main(
        Nextcloud: nextcloud,
        calendarName: str,
        event_start: datetime,
        event_end: datetime,
    ):
        headers = {}
    
        with caldav.DAVClient(
            url=Nextcloud["baseUrl"] + "/remote.php/dav/calendars/" + Nextcloud["userId"] + "/",
            username=Nextcloud["userId"],
            password=Nextcloud["token"],
            headers=headers,
        ) as client:
            my_principal = client.principal()
            calendar = next(
                filter(
                    lambda calendar: calendar.name == calendarName, my_principal.calendars()
                )
            )
            if calendar is None:
                raise ValueError("Could not find calendar by the name you provided")
    
            my_event = calendar.save_event(
                dtstart=event_start,
                dtend=event_end,
                summary="Do the needful",
            )
            return my_event
    
    

    Submitted by nextcloud 104 days ago

  • bun
    // This must be an approval script!
    
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    export async function main(
      nextcloud: RT.Nextcloud,
      taskType: string,
      input: object,
    ) {
    
      const client = createClient<paths>({ baseUrl: nextcloud.baseUrl });
      const authMiddleware: Middleware = {
        async onRequest({ request, options }) {
          // fetch token, if it doesn’t exist
          // add Authorization header to every request
          request.headers.set("Authorization", `Basic ${btoa((nextcloud.userId) + ':' + nextcloud.token)}`);
          return request;
        },
      };
      client.use(authMiddleware);
    
      const resumeUrls = await wmill.getResumeUrls()
    
      const res = await client.POST("/ocs/v2.php/taskprocessing/schedule", {
        params: {
          header: {
            "OCS-APIRequest": true,
          },
          query: {
            format: "json",
          },
    
        },
        body: {
          type: taskType,
          input: input,
          appId: 'windmill',
          webhookUri: resumeUrls.resume,
          webhookMethod: 'HTTP:POST',
        }
      });
      return {
        urls: resumeUrls,
        task: await res.data,
      }
    }

    Submitted by nextcloud 112 days ago

  • bun
    // This must be an approval script!
    
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    type Nextcloud = {
      baseUrl: string,
      password: string,
      username: string
    };
    
    export async function main(
      ncResource: Nextcloud,
      userId: string | null = null,
      taskType: string,
      input: object,
      useAppApiAuth: boolean = false,
    ) {
    
      const client = createClient<paths>({ baseUrl: ncResource.baseUrl });
      const authMiddleware: Middleware = {
        async onRequest({ request, options }) {
          // fetch token, if it doesn’t exist
          // add Authorization header to every request
          request.headers.set("Authorization", `Basic ${btoa((ncResource.username) + ':' + ncResource.password)}`);
          if (useAppApiAuth) {
            request.headers.set("AA-VERSION", ncResource.aa_version,);
            request.headers.set("EX-APP-ID", ncResource.app_id,);
            request.headers.set("EX-APP-VERSION", ncResource.app_version,);
            request.headers.set("AUTHORIZATION-APP-API", btoa(
              `${userId || ncResource.username}:${ncResource.password}`,
            ));
          }
          return request;
        },
      };
      client.use(authMiddleware);
    
      const resumeUrls = await wmill.getResumeUrls()
    
      const res = await client.POST("/ocs/v2.php/taskprocessing/schedule", {
        params: {
          header: {
            "OCS-APIRequest": true,
          },
          query: {
            format: "json",
          },
    
        },
        body: {
          type: taskType,
          input: input,
          appId: 'windmill',
          webhookUri: resumeUrls.resume,
          webhookMethod: 'HTTP:POST',
        }
      });
      return {
        urls: resumeUrls,
        task: await res.data,
      }
    }

    Submitted by nextcloud 501 days ago

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    // This must be an approval script!
    
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    type Nextcloud = {
      baseUrl: string,
      password: string,
      username: string
    };
    
    export async function main(
      ncResource: Nextcloud,
      userId: string | null = null,
      taskType: string,
      input: object,
      useAppApiAuth: boolean = false,
    ) {
    
      const client = createClient<paths>({ baseUrl: ncResource.baseUrl });
      const authMiddleware: Middleware = {
        async onRequest({ request, options }) {
          // fetch token, if it doesn’t exist
          // add Authorization header to every request
          request.headers.set("Authorization", `Basic ${btoa((userId || ncResource.username) + ':' + ncResource.password)}`);
          if (useAppApiAuth) {
            request.headers.set("AA-VERSION", "2.3.0",);
            request.headers.set("EX-APP-ID", "flow",);
            request.headers.set("EX-APP-VERSION", "1.0.1",);
            request.headers.set("AUTHORIZATION-APP-API", btoa(
              `${userId || ncResource.username}:${ncResource.password}`,
            ));
          }
          return request;
        },
      };
      client.use(authMiddleware);
    
      const resumeUrls = await wmill.getResumeUrls()
    
      const res = await client.POST("/ocs/v2.php/taskprocessing/schedule", {
        params: {
          header: {
            "OCS-APIRequest": true,
          },
          query: {
            format: "json",
          },
    
        },
        body: {
          type: taskType,
          input: input,
          appId: 'windmill',
          webhookUri: resumeUrls.resume,
          webhookMethod: 'HTTP:POST',
        }
      });
      return {
        urls: resumeUrls,
        task: await res.data,
      }
    }

    Submitted by nextcloud 512 days ago

  • bun
    // This must be an approval script!
    
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    type Nextcloud = {
      baseUrl: string,
      password: string,
      username: string
    };
    
    export async function main(
      ncResource: Nextcloud,
      userId: string | null = null,
      taskType: string,
      input: object,
      useAppApiAuth: boolean = false,
    ) {
    
      const client = createClient<paths>({ baseUrl: ncResource.baseUrl });
      const authMiddleware: Middleware = {
        async onRequest({ request, options }) {
          // fetch token, if it doesn’t exist
          // add Authorization header to every request
          request.headers.set("Authorization", `Basic ${btoa((userId || ncResource.username) + ':' + ncResource.password)}`);
          if (useAppApiAuth) {
            request.headers.set("AA-VERSION", "2.3.0",);
            request.headers.set("EX-APP-ID", "flow",);
            request.headers.set("EX-APP-VERSION", "1.0.1",);
            request.headers.set("AUTHORIZATION-APP-API", btoa(
              `${userId || ncResource.username}:${ncResource.password}`,
            ));
          }
          return request;
        },
      };
      client.use(authMiddleware);
    
      const resumeUrls = await wmill.getResumeUrls()
    
      const res = await client.POST("/ocs/v2.php/taskprocessing/schedule", {
        params: {
          header: {
            "OCS-APIRequest": true,
          },
          query: {
            format: "json",
          },
    
        },
        body: {
          type: taskType,
          input: input,
          appId: 'windmill',
          webhookUri: resumeUrls.resume,
          webhookMethod: 'HTTP:POST',
        }
      });
      return {
        urls: resumeUrls,
        task: await res.data,
      }
    }

    Submitted by nextcloud 512 days ago

  • bun
    // This must be an approval script!
    
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    export async function main(
      ncResource: Nextcloud,
      userId: string | null = null,
      taskType: string,
      input: object,
      useAppApiAuth: boolean = false,
    ) {
    
      const client = createClient<paths>({ baseUrl: ncResource.baseUrl });
      const authMiddleware: Middleware = {
        async onRequest({ request, options }) {
          // fetch token, if it doesn’t exist
          // add Authorization header to every request
          request.headers.set("Authorization", `Basic ${btoa((userId || ncResource.username) + ':' + ncResource.password)}`);
          if (useAppApiAuth) {
            request.headers.set("AA-VERSION", "2.3.0",);
            request.headers.set("EX-APP-ID", "flow",);
            request.headers.set("EX-APP-VERSION", "1.0.1",);
            request.headers.set("AUTHORIZATION-APP-API", btoa(
              `${userId || ncResource.username}:${ncResource.password}`,
            ));
          }
          return request;
        },
      };
      client.use(authMiddleware);
    
      const resumeUrls = await wmill.getResumeUrls()
    
      const res = await client.POST("/ocs/v2.php/taskprocessing/schedule", {
        params: {
          header: {
            "OCS-APIRequest": true,
          },
          query: {
            format: "json",
          },
    
        },
        body: {
          type: taskType,
          input: input,
          appId: 'windmill',
          webhookUri: resumeUrls.resume,
          webhookMethod: 'HTTP:POST',
        }
      });
      return {
        urls: resumeUrls,
        task: await res.data,
      }
    }

    Submitted by nextcloud 513 days ago

  • bun
    // This must be an approval script!
    
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    export async function main(
      nextcloudResource: string,
      userId: string | null = null,
      taskType: string,
      input: object,
      useAppApiAuth: boolean = false,
    ) {
      const ncResource = await wmill.getResource(
        nextcloudResource,
      );
    
      const client = createClient<paths>({ baseUrl: ncResource.baseUrl });
      const authMiddleware: Middleware = {
        async onRequest({ request, options }) {
          // fetch token, if it doesn’t exist
          // add Authorization header to every request
          request.headers.set("Authorization", `Basic ${btoa((userId || ncResource.username) + ':' + ncResource.password)}`);
          if (useAppApiAuth) {
            request.headers.set("AA-VERSION", "2.3.0",);
            request.headers.set("EX-APP-ID", "flow",);
            request.headers.set("EX-APP-VERSION", "1.0.1",);
            request.headers.set("AUTHORIZATION-APP-API", btoa(
              `${userId || ncResource.username}:${ncResource.password}`,
            ));
          }
          return request;
        },
      };
      client.use(authMiddleware);
    
      const resumeUrls = await wmill.getResumeUrls()
    
      const res = await client.POST("/ocs/v2.php/taskprocessing/schedule", {
        params: {
          header: {
            "OCS-APIRequest": true,
          },
          query: {
            format: "json",
          },
    
        },
        body: {
          type: taskType,
          input: input,
          appId: 'windmill',
          webhookUri: resumeUrls.resume,
          webhookMethod: 'HTTP:POST',
        }
      });
      return {
        urls: resumeUrls,
        task: await res.data,
      }
    }

    Submitted by nextcloud 517 days ago