Coder Social home page Coder Social logo

Javascript examples about nextcloud-node-client HOT 4 CLOSED

hobigo avatar hobigo commented on August 16, 2024
Javascript examples

from nextcloud-node-client.

Comments (4)

hobigo avatar hobigo commented on August 16, 2024

Hi michimau,
what is JavaScript? :-)
I would strongly recommend to switch to TypeScript.
However, import and require with defaults is a mess - I will fix that in Version 2.

Remove the typings in the example code and use this line to get the client
const Client = require("nextcloud-node-client").Client;

Find the js example example below.
Regards Holger

// tslint:disable:no-console
// get files recursively

const Client = require("nextcloud-node-client").Client;

(async () => {
    const client = new Client();

    const sourceFolder = await client.getFolder("/Borstenson/Company Information");
    if (!sourceFolder) {
        console.log("source folder not found");
        process.exit(1);
    }

    // only pdfs and jpg should be listed
    const fileFilterFunction = (file) => {
        if (file.mime === "application/pdf" || file.mime === "image/jpeg") {
            return file;
        }
        return null;
    }

    const options = {
        sourceFolder,
        filterFile: fileFilterFunction,
    };

    const command = new GetFilesRecursivelyCommand(client, options);
    // get files asynchronously (will not throw exceptions!)
    command.execute();

    // check the processing status as long as the command is running
    while (command.isFinished() !== true) {
        // wait one second
        await (async () => { return new Promise(resolve => setTimeout(resolve, 1000)) })();
        console.log(command.getPercentCompleted() + "%");
    }

    // use the result to do the needful
    const commandResult = command.getResultMetaData();

    if (command.getStatus() === CommandStatus.success) {
        console.log(commandResult.messages);
        for (const file of command.getFiles()) {
            console.log(file.name);
        }
    } else {
        console.log(commandResult.errors);
    }

})();





from nextcloud-node-client.

michimau avatar michimau commented on August 16, 2024

thank you 1000: https://gist.github.com/michimau/5b8deb6a2c98a6a9c68d4ea4c3d5b9a0

I cannot make this to work tho:
const client = new Client("http://localhost:8002", { username: "admin", password: "changemeXX" } );

what is wrong there?

from nextcloud-node-client.

hobigo avatar hobigo commented on August 16, 2024

Hi,
here's the info: https://github.com/hobigo/nextcloud-node-client#creating-a-client

replace line 11 with the following code

  const server: Server = new Server(
            { basicAuth:
                { password: "<your password>",
                  username: "<your user name>",
                },
                url: "https://<your nextcloud host>",
            });

  const client = new Client(server);

from nextcloud-node-client.

michimau avatar michimau commented on August 16, 2024

Brilliant, thanks!

from nextcloud-node-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.