1.0.3 • Published 3 years ago

@harrisoff/onedrive-api v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

OneDrive API

ts npm version license

This is the core lib of OneDrive Image Hosting.

This project wraps a small part of OneDrive's APIs, only for uploading files and creating sharing links.

Usage

Setting up Application

First, setting up your application here, clientId and redirectUri will be used later.

Authentication

Here we use token flow in authentication. Use helper function generateAuthUrl to generate an auth url and open it.

import { generateAuthUrl } from '@harrisoff/onedrive-api'

const authUrl = generateAuthUrl('your-client-id', 'your-redirect-uri')

Actually there's another field scope is required in the auth url. This value is set to openid https://graph.microsoft.com/Files.ReadWrite.All and is unnecessary to be changed.

After redirecting back to your site, access_token will be presented in the url.

API calls

There are two ways to call APIs.

The original APIs are exported so you can use them directly:

import { uploadSmall, createUploadSession, uploadLargeChunk, share, getShareUrl } from '@harrisoff/onedrive-api'

Or you can use constructor to create a client instance, which wraps the original APIs:

import OneDriveAPI, { getShareUrl } from '@harrisoff/onedrive-api'

const client = new OneDriveApi({ accessToken })
const { id: fileId } = await client.upload(file, filePath)
const { shareId } = await client.share(fileId)
const sharingLink = getShareUrl(shareId)

TODO List

  • more details about setting up application
  • progress callback
  • test suite
  • standardize error code

Development

For more details, see:

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago