1.1.1 • Published 3 years ago

@lucafont2/onedrive-api v1.1.1

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

How to use:

(async function() {
     var onedrive = new OnedriveApi(YOUR_REFRESH_TOKEN,async function (error,userInfo) {
         if (error) {
             throw error;
         }  
     })
})();

The application provides you with a pre-built platform to get your refresh token Go to https://lucaservers.com/onedrivetoken/ authorize and get the token. In the future, you can revoke your token by going to https://account.live.com/consent/Manage

Functions

Methoddescparamsresponse
getDrives()Gives you all drives in your accountnonearray of drive objects
getDrive(id)Gives you all info of one driveid: drive id got from getDrives()info object
getDirChildren(id,path)Gives you all children folders and files in pathid: drive id, path: absolute path in the drivearray of files and folders info objects
fileInfoByPath(id,filePath)Gives file info by giving his pathid: drive id, filePath absolute path of file in the drivefile object
fileInfoById(id, fileId)Gives file info by giving his idid: drive id, fileId uniqId of the file got from getDirChildren() or fileInfoByPath()file object
downloadFileById(id,fileId,dir)Download file by the idid: drive id, fileId: uniqId of the file, dir: directory to place the downloadtrue if success
deleteFileById(id,fileId)Delete file by the idid: drive id, fileId: uniqId of the filetrue if success
moveFileById(id,fileId,newDir,newName)Move a file in the driveid: drive id, fileId: uniqId of the file, newDir: absolute path of the new foldertrue if success
copyFileById(id,fileId,newDir,newName)Copy a file in the driveid: drive id, fileId: uniqId of the file, newDir: absolute path of the new foldertrue if success
createDirectory(id,dir,name)Create a dir in the driveid: drive id, dir: directory to place the folder, name: name of the new dirInfo object of the new folder
uploadFile(id,dir,name,localFile)Upload a fileid: drive id, dir: directory to place the file, name: name of the file, localFile: string of the file path to uploadtrue if success
getFileShareLink(id,fileId,props)Get file share linkid: drive id, fileId: uniqId of the file, props: props objectlink String

#Objects

###Drive object Key | Value | Description --- | --- | --- | id | String | Drive uniqId type | String | personal / business / documentLibrary owner | String | Name of owner

###File or folder object Key | Value | Description --- | --- | --- | id | String | Element uniqId name | Sting | Element name size | Int | Element bytes lastModified | String | Last Modified parent | String | Parent path type | String | File / Folder typeInfo | Object | if type is File contains mime and sha1

###Props object Key | Value | Description --- | --- | --- | type | String | Permission type view/edit/embed password | OPTIONAL - String | Password protected link scope | OPTIONAL - String | anonymous / organization expirationDateTime | OPTIONAL - String | Link exipiration

#Functions All functions work with async - promise

(async function() {
 var onedrive = new OnedriveApi(token,async function (error,userInfo) {
     try {
         if (error) {
             throw error;
         }
         console.log("Logged in with", userInfo.displayName);
         var drives = await onedrive.getDrives();
         console.log(drives);
         var drive = await onedrive.getDrive(drives[0]["id"]);
         console.log(drive);
     }catch (e) {
         console.log(e)
     }
 })

})();
1.1.1

3 years ago

1.0.1

3 years ago