使用 JavaScript 从 Dropbox 位置读取 Discord 上的文件

Read file on Discord from Dropbox location using JavaScript

我目前正在努力让 Discord 机器人连接到 Dropbox 内的目录,我正在使用 Discord.js 和 Dropbox JavaScript SDK,我已经完成了以下操作:

module.exports = {
  name: "dropbox",
  description: "Commands for interacting with a dropbox folder",
  execute(message, args) {
    var iso = require("isomorphic-fetch");
    var Dropbox = require("dropbox").Dropbox;
    var dbx = new Dropbox({ accessToken: "ACCESS_TOKEN", fetch: iso });
    dbx
      .filesListFolder({ path: "" })
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      });
    dbx
      .filesDownload({ path: "/test.json" })
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      });
  },
};

我得到以下响应数据:

{
  name: 'test.json',
  path_lower: '/test.json',
  path_display: '/test.json',
  id: 'id:rXD9HpHY8HAAAAAAAAAOEw',
  client_modified: '2020-08-24T20:29:51Z',
  server_modified: '2020-08-24T20:29:51Z',
  rev: '015ada572d4487c00000001e8da14d0',
  size: 45,
  is_downloadable: true,
  content_hash: '8864f0de005b2729263a68f88c1f2201049c0a37e5d4f033b3821d590d3a9f71',
  fileBinary: <Buffer 7b 0d 0a 20 20 22 76 61 6c 75 65 22 3a 20 22 54 68 69 73 20 69 73 20 61 20 74 65 73 74 20 4a 53 4f 4e 20 66 69 6c 65 22 0d 0a 7d 0d 0a>
}

但我不确定如何处理这些数据,是否需要将内容哈希转换回 json 文件?还是我需要使用 Node.js file streamer (fs) 来访问它?当我可以使用 API 时,我觉得这会破坏使用 Dropbox SDK 的目的,还是有另一种方法来读取我需要下载包的文件?

很抱歉,如果这是一个我没有得到的明显解决方案,我找不到任何关于如何继续的明确信息,我们将不胜感激。

The Dropbox API JavaScript SDK does the work of communicating with the Dropbox API servers for you. In the case of downloading a file using filesDownload from the Dropbox SDK in Node, it makes the resulting file data available to you in the fileBinary field. You can read the data out from that Buffer, like in this example.

content_hash 字段是文件数据的“散列”,而不是文件数据本身。您可以在 here 上找到相关信息。)