Giter VIP home page Giter VIP logo

onedrive-api's People

Contributors

alexanderhentzsch avatar dasheck0 avatar dependabot[bot] avatar dkatavic avatar evaliyev avatar gdraganic avatar mhd3v avatar msimundza avatar namdien177 avatar nilswsr avatar paradix avatar steffanhalv avatar theashraf avatar yamyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

onedrive-api's Issues

Partial Download feature

Feature request

  • Partial range downloads

Brief

  • Allow the user to download the large files partially by providing custom range to the header request.

References


This feature is related to the current download() function, however, as the docs stated, we have to use the actual @microsoft.graph.downloadUrl (which I believe can only be taken from the list item API or meta API?).
Also, since the response will be 206 - partial content so the implementation must be different from the current download() function.

Btw, request was deprecated, do you have any plan to replace with other libraries? (fetch, axios, ...)

help with getting token.

Hi
THis may be a dumb question but im struggling to get a valid token.

I setup an app registration in app registrations. use the cleint ID and key and send a request to https://login.microsoftonline.com/common/oauth2/v2.0/token'; to generate a token. I use the token for a request in the onedrive-api and get this response.

{ code: 'BadRequest',
message:
'Current authenticated context is not valid for this request. This occurs when a request is made to an endpoint that requires user sign-in. For example, /me requires a signed-in user. Acquire a token on behalf of a user to make requests to these endpoints. Use the OAuth 2.0 authorization code flow for mobile and native apps and the OAuth 2.0 implicit flow for single-page web apps.',

Please can you give me a direction to go to troubleshoot further?

Regards
Shaun

Migrate `request` package to another alternative package.

Since request was deprecated so I suggest we should move on with a new HTTP request package.

There are plenty of packages for HTTP requests out there and we can look at what request suggested to replace itself here. I would suggest using node-fetch as a replacement because:

  • It's the lightest in the list.
  • Promise/stream-based, we can now migrate all APIs to promise to have a standard.

However, I also want to promote a new option as it is very promising - got. Their comparison to other package seems very good.

List all files

Hi,
This is not necessarily an issue with this library. The method listChildren lists immediate children to given item id. Though, Microsoft does not seem to provide a way to get children regardless of "depth" (as far as I can see in the documentation). In other words, in order to get all children, one needs to do make recursive calls to get all files.

Through the Graph Explorer, I experimented with expand parameter but it does not seem to result in desired outcome. Neither does it work to search with asterisk.

Is the Graph API this un-evolved or have I missed a lot of documentation?

Thanks in advance

Getting Setup

Can someone help on getting started? How to get the AccessToken ?

Integrate code formatter and linter

Integrate code formatter (prettier?) and linter into the project. I'm open to suggestions, the only requirement is that the tool used is considered best practice and that it is maintained

StatusCodeError: 400 with uploadSession

Hi, I'm trying to implement a file upload using this library, uploadSimple works great, but most of the files I want to upload will be over 10mb, and when I use uploadSession with the same parameters (and added fileSize), I get the following error:

Unhandled rejection StatusCodeError: 400 - [object Object]
    at new StatusCodeError (/Users/jonas/Projects/personal/pipeline/uploader/node_modules/request-promise/lib/errors.js:26:15)
    at Request.RP$callback [as _callback] (/Users/jonas/Projects/personal/pipeline/uploader/node_modules/request-promise/lib/rp.js:68:32)
    at Request.self.callback (/Users/jonas/Projects/personal/pipeline/uploader/node_modules/request/request.js:185:22)
    at Request.emit (events.js:189:13)
    at Request.<anonymous> (/Users/jonas/Projects/personal/pipeline/uploader/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:189:13)
    at IncomingMessage.<anonymous> (/Users/jonas/Projects/personal/pipeline/uploader/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:277:13)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

I haven't really used streams before so I'm not sure if I'm doing everything correctly, I do it as follows:

  • I get the stats object for the file I want to upload and use stats.size to determine the fileSize
  • I use fs.createReadStream(localPath) to create the readable stream

Do you have any idea what could be going wrong? The access token and path is for sure correct, since uploadSimple works just fine with the same parameters.
Here is the full parameter object I use to call uploadSession:

{ fileSize: 16805688,
  accessToken:'<my-token>',
  filename: 'test5.png',
  parentPath: '/pipeline/',
  readableStream:
   ReadStream {
     _readableState:
      ReadableState {
        objectMode: false,
        highWaterMark: 65536,
        buffer: BufferList { head: [Object], tail: [Object], length: 1 },
        length: 65536,
        pipes: null,
        pipesCount: 0,
        flowing: null,
        ended: false,
        endEmitted: false,
        reading: false,
        sync: false,
        needReadable: true,
        emittedReadable: true,
        readableListening: false,
        resumeScheduled: false,
        paused: true,
        emitClose: false,
        destroyed: false,
        defaultEncoding: 'utf8',
        awaitDrain: 0,
        readingMore: false,
        decoder: null,
        encoding: null },
     readable: true,
     _events: [Object: null prototype] { end: [Function] },
     _eventsCount: 1,
     _maxListeners: undefined,
     path:
      '<absolute path to this image>/697DD.png',
     fd: 21,
     flags: 'r',
     mode: 438,
     start: undefined,
     end: Infinity,
     autoClose: true,
     pos: undefined,
     bytesRead: 65536,
     closed: false } }

Dowloading several files

Hi ,

Downloading several files as script , i get the below error. is the timeout on onedrive side or script side ?
Any parameters to overcome ..?

Please advise.

events.js:352
throw er; // Unhandled 'error' event
^

RequestError: connect ETIMEDOUT 20.190.169.24:443
at ClientRequest. (C:\onedrive\node_modules\got\dist\source\core\index.js:959:25)
at Object.onceWrapper (events.js:482:26)
at ClientRequest.emit (events.js:387:35)
at ClientRequest.origin.emit (C:\onedrive\node_modules@szmarczak\http-timer\dist\source\index.js:43:20)
at TLSSocket.socketErrorListener (_http_client.js:475:9)
at TLSSocket.emit (events.js:375:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1148:16)
Emitted 'error' event on Request instance at:
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
code: 'ETIMEDOUT',
timings: {
start: 1642074390106,
socket: 1642074390138,
lookup: 1642074390147,
connect: undefined,
secureConnect: undefined,
upload: undefined,
response: undefined,
end: undefined,
error: 1642074411185,
abort: undefined,
phases: {
wait: 32,
dns: 9,
tcp: undefined,
tls: undefined,
request: undefined,
firstByte: undefined,
download: undefined,
total: 21079
}
}
}

Depending on vulnerable version of `got`

As the HTTP request library got is pure ESM since v12, the version of got can't be bumped, meaning the onedrive-api module depends on a vulnarable version.

As far as I see it, there are three options:

  1. Convert to ESM as well
  2. Try and use a dynamic import (requires async context)
  3. Change request library

What is your take on this?
I would be willing to work on this.

uploadSimple()'s param filename that contains '(' character will return 400

I found one issue, but I am not sure whether this is onedrive-api bug or Microsoft oneDrive API bug.

Issue: call uploadSimple() with filename that contains '(' character, Microsoft Graph return 400

oneDriveAPI.items.uploadSimple({
  accessToken: accessToken,
  filename: '10-testing(2).png',
  readableStream: readableStream
}).then((item) => {
  // console.log(item);
  // returns body of https://dev.onedrive.com/items/upload_put.htm#response
});

Delete not working

Unfortunately, I do not understand the delete function.

What exactly do I need to provide data to delete individual files that are located in a subfolder.
Here is an example of how I would have to delete it.

File to delete: /testDir/file.txt

oneDriveAPI.items .delete({ accessToken: 'xxxxxxxxxxxxx', itemId: 'testDir/file.txt', }) .then(() => { console.log('file deleted') }) .catch((error) => { console.log('file not deleted: ' + error.response.statusMessage) console.log('file not deleted: ' + JSON.stringify(error)) });

Populating a tree grid

Is there any way to list all the file objects and children in one single method in order to populate the data within the grid?

'Authentication failed' | Unhandled rejection StatusCodeError: 401 - [object Object]

So i was trying to use this API wrapper for a personal project and i needed to interact with OneDrive files, only problem that i keep getting this error message

Unhandled rejection StatusCodeError: 401 - [object Object]
    at new StatusCodeError (/root/CloudRAID/node_modules/request-promise/lib/errors.js:26:15)
    at Request.RP$callback [as _callback] (/root/CloudRAID/node_modules/request-promise/lib/rp.js:68:32)
    at Request.self.callback (/root/CloudRAID/node_modules/request/request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/root/CloudRAID/node_modules/request/request.js:1171:10)
    at emitOne (events.js:96:13)
    at Request.emit (events.js:188:7)
    at IncomingMessage.<anonymous> (/root/CloudRAID/node_modules/request/request.js:1091:12)
    at IncomingMessage.g (events.js:292:16)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

And catching the error gives a long log in witch i found this

...
name: 'StatusCodeError',
  statusCode: 401,
  message: '401 - [object Object]',
  error: { error: { code: 'unauthenticated', message: 'Authentication failed' } },
  options: 
   { method: 'GET',
     uri: 'https://api.onedrive.com/v1.0/drive/items/root/children',
     headers: 
      { 'Content-Type': 'application/json',
...

I know the project hasn't been update since a year and maybe OneDrive's API has changed too since, but it's the only API for OneDrive on npm so i gave it a shot anyway
Hoping i can get some help

Upload writeStream

.uploadSession should return a write stream instead of / or in addition to having a callback.

This will make it easier to work with piping of readStreams, ex. to integrate with multer.

uploadSimple not working in nodejs 16

Below is a sample code, which works under nodejs 14, but not nodejs 16.
There seem to be an issue when passing a stream created by createReadStream() in nodejs 16.

const fs = require('fs')
const oneDriveAPI = require('onedrive-api')

const testRun = () => {
  const accessToken = '***insert access token here***'
  const filePath = './test.txt'
  const stream = fs.createReadStream(filePath)
  const fileName = 'test-file.txt';

  return oneDriveAPI.items.uploadSimple({
    accessToken: accessToken,
    filename: fileName,
    readableStream: stream
  })
    .then((item) => {
      console.log(item)
      stream.destroy();
    })
    .catch((error) => {
      console.log(error)
      stream.destroy();
    })
};

testRun().then(() => process.exit());

edit:

additional info: I'm using node v16.13.1 on windows 10.

uploadSimple stalls for a few minute before timing out with the following error:

RequestError: read ECONNRESET
    at ClientRequest.<anonymous> (C:\test\node_modules\got\dist\source\core\index.js:957:25)
    at Object.onceWrapper (node:events:510:26)
    at ClientRequest.emit (node:events:402:35)
    at ClientRequest.origin.emit (C:\test\node_modules\@szmarczak\http-timer\dist\source\index.js:43:20)
    at TLSSocket.socketErrorListener (node:_http_client:447:9)
    at TLSSocket.emit (node:events:390:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20) {
  code: 'ECONNRESET',
  timings: {
    start: 1639767749393,
    socket: 1639767749398,
    lookup: 1639767749413,
    connect: 1639767749448,
    secureConnect: 1639767749511,
    upload: undefined,
    response: undefined,
    end: undefined,
    error: 1639767870576,
    abort: undefined,
    phases: {
      wait: 5,
      dns: 15,
      tcp: 35,
      tls: 63,
      request: undefined,
      firstByte: undefined,
      download: undefined,
      total: 121183
    }
  }
}

Add support to auth/move/copy

I find there are copy and move api
https://docs.microsoft.com/ja-jp/onedrive/developer/rest-api/api/driveitem_move?view=odsp-graph-online
https://docs.microsoft.com/ja-jp/onedrive/developer/rest-api/api/driveitem_copy?view=odsp-graph-online

please add these apis

And, I fount it difficult to get the access token, After trying, Please also add auth.
I try to use refresh_token to get access_token and succeed. But I didn't find easy way to get the refresh_token.

async function odauth(client_id, client_secret, refresh_token){
var res=null;
try {
res = await axios.post("https://login.microsoftonline.com/common/oauth2/v2.0/token" , new URLSearchParams({
client_id: client_id,
client_secret: client_secret,
refresh_token: refresh_token,
grant_type: "refresh_token"
}).toString(), {
headers : {
"Content-Type": "application/x-www-form-urlencoded"
},
})
} catch(e){
console.log("odauth error!")
console.log(e)
}
return res
}

Cannot list activities using list activities

Whenever i try to list activities from y drive I get this error:
Unexpected token { in JSON at position 1 in "https://graph.microsoft.com/v1.0//drives/11acf151067914b5/items/11ACF151067914B5!11408/activities\
here's my code


`exports.listActivities = async (req, res) => {
  let accessToken = await check_auth(req, res);
  let { drive_id, item_id } = req.body;
  oneDriveAPI.items
    .customEndpoint({
      accessToken: accessToken,
      url: `/drives/${drive_id}/items/${item_id}/activities`,
      method: 'GET',
      // body: {}
    })
    .then((r) => {
      res.status(200).send({ activities: r });
    })
    .catch((e) => {
      res.status(500).send({ error: e.message });
    });
};`

image

and if itry to use this URL : GET /me/drive/activities
it returns 400 BAD request I couldn't understand why
image

does any one have any suggestion?

Problem with download

I tried to download a file and I got this error, I copied the example only different I added the right itemid
I am able to list the file with the same token

node:events:491
throw er; // Unhandled 'error' event
^

HTTPError: Response code 401 (Unauthorized)
at Request._onResponseBase (/Users/XXXXXX/node_modules/got/dist/source/core/index.js:905:31)
at Request._onResponse (/Users/XXXXXX/node_modules/got/dist/source/core/index.js:940:24)
at ClientRequest. (/Users/XXXXXX/node_modules/got/dist/source/core/index.js:954:23)
at Object.onceWrapper (node:events:628:26)
at ClientRequest.emit (node:events:525:35)
at origin.emit (/Users/XXXXXX/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20)
at HTTPParser.parserOnIncomingClient (node:_http_client:693:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:117:17)
at TLSSocket.socketOnData (node:_http_client:534:22)
at TLSSocket.emit (node:events:513:28)
Emitted 'error' event on Request instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'ERR_NON_2XX_3XX_RESPONSE',
timings: {
start: 1670752196547,
socket: 1670752196548,
lookup: 1670752196622,
connect: 1670752196658,
secureConnect: 1670752196780,
upload: 1670752196780,
response: 1670752196907,
end: 1670752196926,
error: undefined,
abort: undefined,
phases: {
wait: 1,
dns: 74,
tcp: 36,
tls: 122,
request: 0,
firstByte: 127,
download: 19,
total: 379
}
}
}

However, using postman with the same URI and the same token I am able to download the file

I am new on node, probably I did something wrong

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.