Skip to content
github-actions[bot] edited this page Nov 3, 2026 · 3 revisions

Cloud | Learn how to get cloud data with Litedirecte.

The Cloud module gives you full access to EcoleDirecte's personal cloud storage.


🚀 Getting Started

Let's fetch the contents of the student's personal cloud and traverse the folder structure.

import { Litedirecte } from "litedirecte";

const ld = new Litedirecte();
await ld.auth.login("your_username", "your_password");

// Retrieve the files and folders up to a depth of 3 folders deep
const cloudItems = await ld.cloud.getCloud({ depth: 3 });

console.log(`You have ${cloudItems.length} top-level files or folders.`);

cloudItems.forEach(item => {
  if (item.type === "folder") {
    console.log(`📁 Folder: ${item.libelle} (contains ${item.children?.length ?? 0} items)`);
  } else {
    console.log(`📄 File: ${item.libelle} (${(item.taille / 1024).toFixed(1)} KB)`);
  }
});

📖 API Reference

ld.cloud.getCloud

Fetches all files and folders available in the student's personal space.

ld.cloud.getCloud(options?: GetCloudOptions): Promise<CloudEntry[]>

Parameters

  • options (optional):
    • depth (number): How many folders deep the SDK should scan and build children arrays for. Defaults to 3. Must be an integer between 1 and 10, otherwise an EdValidationError is thrown and nothing is requested.

ld.cloud.createFolder

Creates a new folder under a parent directory.

ld.cloud.createFolder(
  name: string,
  parentNode: CloudNode,
): Promise<CloudNode>

Parameters

  • name (string): The name for your new folder.
  • parentNode (CloudNode): The folder node where your new folder should be created.

Example

import { Litedirecte } from "litedirecte";

const ld = new Litedirecte();
await ld.auth.login("your_username", "your_password");

const tree = await ld.cloud.getCloud();
const myParentFolder = tree.find(node => node.type === "folder" && node.libelle === "My Documents");

if (myParentFolder) {
  const newFolder = await ld.cloud.createFolder("Math Homework", myParentFolder);
  console.log(`Successfully created folder: ${newFolder.libelle}`);
}

ld.cloud.deleteNodes

Moves files or folders to the Recycle Bin / Trash.

ld.cloud.deleteNodes(
  nodes: CloudNode[],
): Promise<{ success: boolean }>

Parameters

  • nodes (CloudNode[]): An array of file or folder nodes to delete.

Example

import { Litedirecte } from "litedirecte";

const ld = new Litedirecte();
await ld.auth.login("your_username", "your_password");

const tree = await ld.cloud.getCloud();
const oldFile = tree.find(node => node.type === "file" && node.libelle === "temporary_draft.txt");

if (oldFile) {
  const result = await ld.cloud.deleteNodes([oldFile]);
  if (result.success) {
    console.log("File successfully moved to trash!");
  }
}

ld.cloud.uploadFile

Uploads a file to a parent folder in the cloud (POST /televersement.awp?verbe=post&mode=CLOUD&dest=..., multipart field file).

ld.cloud.uploadFile(
  file: Blob,
  parentNode: CloudNode,
  filename?: string,
  options?: UploadCloudFileOptions,
): Promise<CloudNode>

Parameters

  • file (Blob): The file or blob to upload.
  • parentNode (CloudNode): The destination folder node where the file should be uploaded.
  • filename (string, optional): Custom filename. Defaults to file.name if file is a File instance.
  • options (UploadCloudFileOptions, optional):
    • mockMode (boolean): Run in mock mode.

Example

import { Litedirecte } from "litedirecte";

const ld = new Litedirecte();
await ld.auth.login("your_username", "your_password");

const tree = await ld.cloud.getCloud();
const folder = tree.find(node => node.type === "folder" && node.libelle === "Documents");

if (folder) {
  const file = new File(["Hello world"], "hello.txt");
  const uploaded = await ld.cloud.uploadFile(file, folder);
  console.log(`Successfully uploaded: ${uploaded.libelle} (${uploaded.taille} bytes)`);
}

ld.cloud.uploadTextFile / ld.cloud.createTextFile

Creates and uploads a plain-text file to a parent folder in the cloud.

ld.cloud.uploadTextFile(
  content: string,
  filename: string,
  parentNode: CloudNode,
  options?: UploadCloudFileOptions,
): Promise<CloudNode>

Example

const fileNode = await ld.cloud.createTextFile("Hello, World!", "notes.txt", folder);

ld.cloud.updateTextFile / ld.cloud.editTextFile

Updates (overwrites) an existing text file in the cloud with new text content.

ld.cloud.updateTextFile(
  content: string,
  fileNode: CloudFileNode,
  options?: UploadCloudFileOptions,
): Promise<CloudNode>

Example

const updatedNode = await ld.cloud.editTextFile("Updated note content!", fileNode);

🗂️ Type Definitions

CloudNode

Represents either a folder or a file inside the EcoleDirecte cloud:

interface CloudNode {
  id: string;               // Unique string ID of the file or folder
  type: "file" | "folder";  // Node type
  libelle: string;          // Name of the file or folder (raw key)
  date: string;             // Date string when created or updated
  taille: number;           // File size in bytes (raw key)
  readonly: boolean;        // True if the node is write-protected (raw key)
  hidden: boolean;          // True if the item is hidden (raw key)
  isTrash: boolean;         // True if the item is currently in the trash
  isLoaded?: boolean;       // Indicates if subfolders have been loaded
  quota?: number;           // Space limit in bytes (usually present on top folder)
  displayText?: string;     // Friendly display string
  children?: CloudNode[];   // Child nodes (if a folder)
  proprietaire?: {          // Owner metadata object (raw key)
    id: number;
    type: string;
    nom: string;
    prenom: string;
    particule: string;
  };
}

CloudEntry

A simple union representing the entries returned:

type CloudEntry = CloudFolderNode | CloudFileNode;

interface CloudFolderNode extends CloudNode {
  type: "folder";
  children: CloudNode[];
}

interface CloudFileNode extends CloudNode {
  type: "file";
}

💾 Caching

getCloud() at the default depth is maintained; other depths are manual entries. Reads accept { force: true } to skip the cache. See Cache & sync.

Clone this wiki locally