npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hanzoz/onedrive-js-sdk

v1.1.0

Published

Js SDK for OneDrive

Downloads

11

Readme

OneDrive JS SDK

ts npm version license

本项目封装了 OneDrive 的一小部分 API,仅用于上传文件并生成分享链接。

可以用来搞个网页,比如 OneDrive 图床

创建应用

打开 应用注册 页面,点击新注册,然后需要填写以下项目:

  • 名称

  • 受支持的账户类型

    仅 Microsoft 个人帐户 就够用了

  • 重定向 URI

    比如 https://localhost:3000/

注册完成之后,点击左边目录中的身份验证,选中访问令牌(用于隐式流)并保存。

应用一旦注册完成,就会生成 应用程序(客户端) ID,不过不能直接用,还得先验证应用。点击左边的品牌打造,然后跟着页面上的指引做就是了。

使用

授权

这里使用令牌流验证。使用工具函数 generateAuthUrl 生成授权链接。

import { generateAuthUrl } from '@harrisoff/onedrive-js-sdk'

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

实际上在原始的 OneDrive API 中还需要一个 scope 参数 这个值没有必要修改,所以直接设置为了 openid https://graph.microsoft.com/Files.ReadWrite.All

重定向回自己的网站后,如果授权成功,url 的 hash 中会有 access_token,否则会有错误信息。

调用 API

有两种方式

可以直接调用原始的 API:

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

也可以使用封装了原始 API 的构造函数:

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

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

开发文档