aliyun-pds-js-sdk 是PDS官方的推出的js sdk,提供PDS資源的基本操作方法,開發人員可以很方便的開發PDS網盤應用。除了上傳,下載,複製,移動,刪除等檔案基本操作外,還提供了Drive,Share,Group等資源的基本操作,同時支援瀏覽器和Node.js(electron或node服務)端。
github 開源地址: https://github.com/aliyun/aliyun-pds-js-sdk。
重要
注意:從 1.0.0 開始,不再支援 HostingMode(託管模式)相關功能。說明
node版本依賴:>=16.15.0
PDS資源說明
Domain下的資源:
Domain/
|-- Group # 分組或團隊
|-- User # 使用者
|-- Account # 帳號
|-- Drive # 雲端硬碟(網盤)
|-- ShareLink # 分享連結
|-- File # 檔案相關(新版共用許可權,資源回收筒)一個
User綁定多個Account,一個Account即一種登入方式,如:DingTalk登入。Group下可以嵌套Group或者User(通過Membership)。
Group/
|-- Group
|-- UserDrive的Owner可以為一個Group或者User。
File必屬於一個Drive。
Drive/ # 雲端硬碟
|-- File安裝
執行以下命令安裝:
npm i -S aliyun-pds-js-sdk注意:請先確保已經安裝 Node.js >= 16.15.0。
引入
(1) 在 Vue 或 React 專案中使用
import {PDSClient} from 'aliyun-pds-js-sdk/browser' (2) 在 Node.js 中使用
const { PDSClient } = require('aliyun-pds-js-sdk')(3) 在瀏覽器中以 script 標籤引入
npm 安裝後,在 node_modules/aliyun-pds-js-sdk/dist/browser/ 目錄下,有打包好的 aliyun-pds-js-sdk.umd.cjs 檔案,可以複製到你自己的靜態服務或CDN上,然後以 script 標籤引入。
<script src="/path/to/dist/browser/aliyun-pds-js-sdk.umd.cjs"></script>const { PDSClient } = window.PDS_SDK調用舉例
PDS API 的功能都整合在 PDSClient 類執行個體方法上,使用時只需 new 一個 PDSClient 執行個體,即可通過該執行個體的方法來調用 PDS 的各種 API。
const domain_id = "您的domainID" // 如:bj123
const config = {
token_info: {...},
api_endpoint: `https://${domain_id}.api.aliyunpds.com`,
}
const pds = new PDSClient(config)
let { items=[], next_marker } = await pds.listDrives({ limit:10 })
關於構造參數
config詳解,請看這裡:PDSClient類。