Edits history of script submission #11451 for ' Nextcloud WebDAV: Copy a file or folder (nextcloud)'

  • bun
    import axios from "axios";
    
    export async function main(
        nextcloud: RT.Nextcloud,
        sourcePath: string,
        destinationPath: string,
    ) {
    
        try {
            const res = await axios.request(
                {
                    method: "COPY",
                    url: `/remote.php/dav/files/${nextcloud.userId}/${sourcePath}`,
                    baseURL: nextcloud.baseUrl,
                    headers: {
                        Authorization: `Basic ${btoa(`${nextcloud.userId}:${nextcloud.token}`)
                        }`,
                        Destination: `${nextcloud.baseUrl}/remote.php/dav/files/${nextcloud.userId}/${destinationPath}`,
                    },
                },
            );
    
            return res.data;
        } catch (e) {
            console.log(e.response.data);
        }
    }

    Submitted by nextcloud 86 days ago

  • bun
    import * as wmill from "windmill-client@1";
    import axios from "axios";
    
    type Nextcloud = {
      baseUrl: string,
      password: string,
      username: string
    };
    
    export async function main(
      ncResource: Nextcloud,
      userId: string | null = null,
      sourcePath: string,
      destinationPath: string,
      useAppApiAuth: boolean = false,
    ) {
    
      try {
        console.log("Test");
        console.log(`${ncResource.baseUrl}/remote.php/dav/files/${userId || ncResource.username}/${destinationPath}`);
        const res = await axios.request(
          {
            method: "COPY",
            url: `/remote.php/dav/files/${userId || ncResource.username}/${sourcePath}`,
            baseURL: ncResource.baseUrl,
            headers: {
              Authorization: `Basic ${btoa(`${userId || ncResource.username}:${ncResource.password}`)
                }`,
              Destination: `${ncResource.baseUrl}/remote.php/dav/files/${userId || ncResource.username}/${destinationPath}`,
            },
            ...(useAppApiAuth && ({
              headers: {
                "AA-VERSION": ncResource.aa_version,
                "EX-APP-ID": ncResource.app_id,
                "EX-APP-VERSION": ncResource.app_version,
                "AUTHORIZATION-APP-API": btoa(
                  `${userId || ncResource.username}:${ncResource.password}`,
                ),
                "Destination": `${ncResource.baseUrl}/remote.php/dav/files/${userId || ncResource.username}/${destinationPath}`,
              },
            })),
          },
        );
        
        return res.data;
      } catch (e) {
        console.log(e.response.data);
      }
    }

    Submitted by nextcloud 444 days ago