ya-disk
This library provides methods for working with Yandex.Disk service API. Each method present with each own independent function. Example:
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas'; async { try const total_space used_space = await ; console; catch error console; };
Starting from v4.x ya-disk moved from callback to Promise. If you still wish to use callbacks, pls switch to v3.x.
Installation
npm install --save ya-disk
Authorization
Each method requires an OAuth token. You can receive one manually or use one of OAuth library, i.e. passport-yandex-token.
Promises
Each returned Promise is being resolved with deserialized response body or rejected with an error. Except copy and move methods which return value extended by status code.
List of available methods
download
Downloading a file from the user drive.
link(token, path)
Getting the download link. See details. Example:
;// This lib is necessary, because Yandex Disk// returns a 302 header when you try to download file// using provided link;;; const API_TOKEN = '1982jhk12h31iad7a(*&kjas';const file = 'disk:/Зима.jpg'; async { try const href = await downloadlinkAPI_TOKEN file; const output = ; const req = https; req; req; catch err console; };
info(token)
Getting common info about user drive. See details. Example:
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas'; async { try const total_space used_space = await ; console; catch error console; };
list(token, [options={}])
Getting a flat list of the user files on the drive. See details.
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas'; async { try const items = await ; items; catch error console; };
meta
get(token, path, [options={}])
Getting meta-information about the resource (file or directory). See details. Example:
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas'; async { try const metaGet = await meta; console; Object; catch error console; };
add(token, path, properties)
Append meta information to the resource (file or directory). See details. Example:
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas'; async { try await meta; catch error console; };
operations
Getting operation status. See details. Example:
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas';const operationId = 'MqeRNE6wJFJuKAo7nGAYatqjbUcYo3Hj'; async { try const status = await ; console; catch error console; };
recent(token, [options={}])
Getting a flat list of recently changed files. See details.
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas'; async { try const items = await ; items; catch error console; };
upload
Tool for uploading a file to the user drive.
link(token, path, [overwrite = false])
Getting link for uploaded file. See details. Example:
;;; ; const API_TOKEN = '1982jhk12h31iad7a(*&kjas';const fileToUpload = './file.txt';const remotePath = 'disk:/file.txt'; async { try const href method = await uploadlinkAPI_TOKEN remotePath true; const fileStream = ; const uploadStream = ; fileStream; fileStream; catch error console; };
remoteFile(token, url, path)
Upload remote file to the disk by its url. See details. Example:
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas';const url = 'https://tech.yandex.com/disk/doc/dg/yandex-disk-dg.pdf';const path = 'disk:/Приложения/ya-disk-api/yandex-disk-dg.pdf'; upload;
File and Folder Actions
copy(token, from, path, overwrite)
Copy file or folder from from
to path
. See details.
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas';const from = 'disk:/Зима.png';const to = 'disk:/new_folder/Зима.png'; async { try await resources; catch error console; };
create(token, path)
Create folder. See details.
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas'; async { try await resources; catch error console; };
move(token, from, path, overwrite)
Move file or folder from from
to path
. See details.
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas';const from = 'disk:/Зима.png';const to = 'disk:/new_folder/Зима.png'; async { try await resources; catch error console; };
remove(token, path, permanently)
Delete file or folder. See details.
; const API_TOKEN = '1982jhk12h31iad7a(*&kjas'; resources;