Edits history of script submission #11415 for ' Create a group folder in Nextcloud (nextcloud)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    /*
     * We expect that the group comes from a Nextcloud Table where you can
     * define a datatype "Users and groups". The result is a list of groups,
     * each list item consist of the fields "id", "type" and "displayName". 
     * This script uses the "id" value of each list item.
     */
    import createClient, { type Middleware } from "openapi-fetch";
    
    export async function main(
      nextcloud: RT.Nextcloud,
      folderName: string,
      groups: Array<{
        id: string,
        key: string,
        type: number,
        displayName: string,
      }>,
      quota: number,
    ) {
    
      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);
    
    
      try {
        const resp = await client.POST("/index.php/apps/groupfolders/folders", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
          },
          body: {
            mountpoint: folderName
          },
        });
    
        const tableId = resp.data.ocs.data.id;
    
        for (const group of groups) {
            await client.POST("/index.php/apps/groupfolders/folders/{id}/groups", {
              params: {
                header: {
                  "OCS-APIRequest": true,
                },
                query: {
                  format: "json",
                },
                path: {
                  id: tableId,
                }
              },
              body: {
                group: group.id
              },
            });
        }
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/quota", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            quota: quota
          },
        });
    
      } catch (e) {
        console.debug('error', e)
      }
    }
    

    Submitted by nextcloud 86 days ago

  • bun
    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,
      folderName: string,
      groupName: string,
      quota: number,
      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);
    
    
      try {
        const resp = await client.POST("/index.php/apps/groupfolders/folders", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
          },
          body: {
            mountpoint: folderName
          },
        });
    
        const tableId = resp.data.ocs.data.id;
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/groups", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            group: groupName
          },
        });
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/quota", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            quota: quota
          },
        });
    
      } catch (e) {
        console.debug('error', e)
      }
    }

    Submitted by nextcloud 476 days ago

  • bun
    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,
      folderName: string,
      groupName: string,
      quota: number,
      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);
    
    
      try {
        const resp = await client.POST("/index.php/apps/groupfolders/folders", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
          },
          body: {
            mountpoint: folderName
          },
        });
    
        const tableId = resp.data.ocs.data.id;
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/groups", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            group: groupName
          },
        });
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/quota", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            quota: quota
          },
        });
    
      } catch (e) {
        console.debug('error', e)
      }
    }

    Submitted by nextcloud 485 days ago

  • bun
    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,
      folderName: string,
      groupName: string,
      quota: number,
      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);
    
    
      try {
        const resp = await client.POST("/index.php/apps/groupfolders/folders", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
          },
          body: {
            mountpoint: folderName
          },
        });
    
        const tableId = resp.data.ocs.data.id;
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/groups", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            group: groupName
          },
        });
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/quota", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            quota: quota
          },
        });
    
      } catch (e) {
        console.debug('error', e)
      }
    }

    Submitted by nextcloud 485 days ago

  • bun
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    export async function main(
      ncResource: Nextcloud,
      userId: string | null = null,
      folderName: string,
      groupName: string,
      quota: number,
      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);
    
    
      try {
        const resp = await client.POST("/index.php/apps/groupfolders/folders", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
          },
          body: {
            mountpoint: folderName
          },
        });
    
        const tableId = resp.data.ocs.data.id;
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/groups", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            group: groupName
          },
        });
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/quota", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            quota: quota
          },
        });
    
      } catch (e) {
        console.debug('error', e)
      }
    }

    Submitted by nextcloud 486 days ago

  • bun
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    export async function main(
      nextcloudResource: string,
      userId: string | null = null,
      folderName: string,
      groupName: string,
      quota: number,
      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);
    
    
      try {
        const resp = await client.POST("/index.php/apps/groupfolders/folders", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
          },
          body: {
            mountpoint: folderName
          },
        });
    
        const tableId = resp.data.ocs.data.id;
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/groups", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            group: groupName
          },
        });
    
        await client.POST("/index.php/apps/groupfolders/folders/{id}/quota", {
          params: {
            header: {
              "OCS-APIRequest": true,
            },
            query: {
              format: "json",
            },
            path: {
              id: tableId,
            }
          },
          body: {
            quota: quota
          },
        });
    
      } catch (e) {
        console.debug('error', e)
      }
    }

    Submitted by nextcloud 490 days ago

  • bun
    import * as wmill from "windmill-client";
    import createClient, { type Middleware } from "openapi-fetch";
    
    export async function main(
      nextcloudResource: string,
      userId: string | null = null,
      notificationUserId: string,
      subject: string,
      message: string,
      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 {
        data, // only present if 2XX response
        error, // only present if 4XX or 5XX response
      } = await client.POST("/ocs/v2.php/apps/notifications/api/{apiVersion3}/admin_notifications/{userId}", {
        params: {
          header: {
            "OCS-APIRequest": true,
          },
          query: {
            format: "json",
          },
          path: {
            apiVersion3: "v3",
            userId: notificationUserId,
          },
    
        },
        body: {
          subject: subject,
          message: message,
        },
      });
    }

    Submitted by nextcloud 491 days ago