An open API service indexing awesome lists of open source software.

https://github.com/alttiri/meganz-api

Unfinished Mega.nz API library. Only some of methods are implemented.
https://github.com/alttiri/meganz-api

javascript

Last synced: 2 months ago
JSON representation

Unfinished Mega.nz API library. Only some of methods are implemented.

Awesome Lists containing this project

README

          

# meganz-api

**Uncomplited, demo Mega.nz JS library.**

It works, but supports only some features:
- listing,
- thumbnails/previews downloading.

---

- `npm ci`
- `npm run build`

To open a web demo run a http server in the root folder, then open a html file from `_examples-browser` directory.

Or try to use a Node.js demo from `_examples-node` directory. (Note: remove `import * as URLS from "./test-urls-private.js";` first and use your own Mega URL.)

---

### The example usage

Downloading of thumbnails:

https://github.com/AlttiRi/meganz-api/blob/master/_examples-node/ex-3.3-ok.js:
```js
import {saveFile} from "./util-node.js";
import {Nodes} from "../src/mega.js";

const nodeArray = await Nodes.nodes("https://mega.nz/..."); // Use your own URL

const promises = [];
let i = 0;
for (const node of nodeArray) {
if (Nodes.isMediaNode(node)) {
const index = (++i).toString().padStart(3, "0");
console.log(`${index} ${node.name}`);
const filename = `thumbnail-${index}-${node.id}.jpg`;
const downloaded = node.getThumbnail()
.then(thumb => {
void saveFile(thumb, filename, node.mtime);
});
promises.push(downloaded);
}
}
await Promise.all(promises);
```

- Multiple API requests are grouped within one API request when it's possible.
- Multiple thumbnails data are downloaded within one download request when it's possible.
- All similar HTTP connections are performed concurrently, but not more that 16 at one moment. See `Semaphore` class.
- Also it uses custom (much faster (up to x9 times)) convertation from `ArrayBuffer` to `WordArray` of CryptoJS library. See `/src/crypto.js`.

---

- 2022.02.20: This private repo was turned into public one.