1.1.1 • Published 4 months ago

onedrive-tree v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

OD Tree

List all files in onedrive as a file tree.

Usage

Easiest way: OdTree

The clientId, clientSecret and tenantId can be found in the Azure Active Directory page of your onedrive account.

import OdTree from "onedrive-tree";
await OdTree(clientId, clientSecret, tenantId);

If you have got the token, you can use

import {buildTree} from "onedrive-tree";
await buildTree(token)

The token is DriveToken type, which is defined in src/types/odTree.d.ts.

API

Data Structure

refer to src/types/odTree.d.ts

export type FileNode = {
    name: string,
    size: number,
    downloadUrl: string,
    type: FileNodeType.File,
}

export type DirectoryNode = {
    name: string,
    type: FileNodeType.Directory,
    size?: number,
    children: (FileNode | DirectoryNode)[]
}

export type FileTree = DirectoryNode;

The token's type is

export type DriveToken = {
    driveId: string,
    accessToken: string,
}

Auth

  • getAccessToken(clientId: string, clientSecret: string, tenantId: string): Promise<string>
  • getOneDriveDriveId(accessToken: string): Promise<string>

Request But not Parse

  • requestList(directoryId: string, token: DriveToken): Promise<(FileResponse | DirectoryResponse)[]>

Request and Parse

  • recursiveBuildDirectory(directoryId: string, token: DriveToken, name: string, size?: number): Promise<DirectoryNode>
  • buildFileTree(directoryId: string, token: DriveToken): Promise<FileTree>
1.1.1

4 months ago

1.0.0

4 months ago