當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript dropbox.Dropbox類代碼示例

本文整理匯總了TypeScript中dropbox.Dropbox的典型用法代碼示例。如果您正苦於以下問題:TypeScript Dropbox類的具體用法?TypeScript Dropbox怎麽用?TypeScript Dropbox使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Dropbox類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: before

 before(function() {
     this.timeout(5000);
     dbx = new Dropbox({ accessToken, fetch });
     store = new DropboxStore(dbx, testRoot, Response);
     return dbx.filesGetMetadata({ path: "/" + testRoot }).then(() => {
         return dbx.filesDelete({ path: "/" + testRoot });
     }).catch(() => true);
 });
開發者ID:jsebrech,項目名稱:minisync,代碼行數:8,代碼來源:dropbox.spec.ts

示例2: expect

 }).then((result) => {
     expect(result).to.equal(true);
     // download file and check contents
     dbx.filesDownload({
         path: "/" + testRoot + "/path/file2"
     }).then((f: any) => { // DropboxTypes.files.FileMetadata
         // in node it returns a fileBinary
         if (f.fileBinary) {
             return f.fileBinary;
         // in browser it returns a fileBlob
         } else if (f.fileBlob) {
             return (new Response((f as any).fileBlob as Blob)).text();
         } else {
             throw new Error("no fileBinary or fileBlob in response");
         }
     }).then((t: string) => {
         expect(t).to.equal("bar");
         done();
     });
 }).catch((e) => done(new Error(e)));
開發者ID:jsebrech,項目名稱:minisync,代碼行數:20,代碼來源:dropbox.spec.ts

示例3: authenticate

function authenticate() {
  const client = new Dropbox({ clientId: CLIENT_ID });
  const authUrl = client.getAuthenticationUrl("http://localhost:3030/auth");
  const app = express();
  app.use(jsonBodyParser());
  let server: Server;

  app.get('/auth', function(req, res) {
    res.status(200);
    // Write code that POST's code to server from client.
    res.write(Buffer.from(`<!DOCTYPE html>
<html>
  <head>
    <title>BrowserFS Dropbox Authentication</title>
  </head>
  <body>
    <h1 id="status">Sending access token to BrowserFS...</h1>

    <p id="details">Please wait one moment...</p>

    <script type="text/javascript">
      (function() {
        var status = document.getElementById('status');
        var detail = document.getElementById('detail');
        // Send full URL, including #, to server.
        var xhr = new XMLHttpRequest();
        xhr.onload = function() {
          var statusCode = xhr.status;
          var statusText = xhr.statusText;
          if (statusCode >= 200 && statusCode < 300) {
            document.title = "Success!";
            status.innerText = "Success!";
            details.innerText = xhr.responseText;
          } else {
            document.title = "Failed";
            status.innerText = "Failed";
            details.innerText = xhr.responseText;
          }
        };
        xhr.open('POST', 'http://localhost:3030/authurl');
        xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        xhr.send(JSON.stringify({url: window.location.href}));
      })();
    </script>
  </body>
</html>`, 'utf8'));
    res.end();
  });

  app.post('/authurl', function(req, res) {
    if (!req.body || !req.body.url) {
      console.error(`Unable to retrieve Dropbox access token.`);
      res.status(400);
      res.send();
      server.close(() => process.exit(1));
    } else {
      const rawUrl = req.body.url;
      // Dropbox URLs use query params, but use # instead of ? to denote them.
      // Switch to '?' so the url package can parse them.
      const url = parseUrl(rawUrl.replace("#", "?"), true);
      console.log(req.url);
      console.log(url);
      const token = url.query['access_token'];
      if (token) {
        res.status(200);
        writeFileSync(tokenPath, Buffer.from(`{ "accessToken": "${token}" }`, 'utf8'));
        const successMsg = `Successfully saved Dropbox token to ${tokenPath}. You may now close your browser.`;
        console.log(successMsg);
        res.write(Buffer.from(successMsg, 'utf8'));
      } else {
        res.status(400);
        const failureMsg = `Unable to retrieve Dropbox token. Please try again.`;
        console.log(failureMsg);
        res.write(Buffer.from(failureMsg, 'utf8'));
      }
      res.end();
      setTimeout(() => {
        server.close(function() {
          // Exit w/ error if failed to get token.
          process.exit(token ? 0 : 1);
        });
      }, 500);
    }
  });

  server = app.listen(3030, function() {
    console.log(`Navigate to ${authUrl} and log in to Dropbox.`);
  });
}
開發者ID:jvilk,項目名稱:BrowserFS,代碼行數:89,代碼來源:get_db_credentials.ts

示例4: readFileSync

}

// Check if there are some credentials already stored
let token: any = null
if (existsSync(tokenPath)) {
  const tokenData = readFileSync(tokenPath, 'utf8')
  try {
    token = JSON.parse(tokenData)
  } catch (e) {
    // Do nothing.
  }
}

// Use them to authenticate if there are
if (token) {
  const client = new Dropbox(token);
  client.usersGetCurrentAccount(undefined).then((res) => {
    console.log(`Token authenticates to ${res.name.display_name}'s Dropbox.`);
  }).catch((e) => {
    console.log(`Invalid / outdated token found on disk at ${tokenPath}; re-authenticating...`);
    authenticate();
  });
} else {
  authenticate();
}

function authenticate() {
  const client = new Dropbox({ clientId: CLIENT_ID });
  const authUrl = client.getAuthenticationUrl("http://localhost:3030/auth");
  const app = express();
  app.use(jsonBodyParser());
開發者ID:jvilk,項目名稱:BrowserFS,代碼行數:31,代碼來源:get_db_credentials.ts

示例5: putFile

 function putFile(path: string, file: string, contents: any) {
     return dbx.filesUpload({
         path: "/" + testRoot + "/" + path + "/" + file,
         contents,
         mode: { ".tag": "overwrite" }
     });
 }
開發者ID:jsebrech,項目名稱:minisync,代碼行數:7,代碼來源:dropbox.spec.ts

示例6:

 return dbx.filesGetMetadata({ path: "/" + testRoot }).then(() => {
     return dbx.filesDelete({ path: "/" + testRoot });
 }).catch(() => true);
開發者ID:jsebrech,項目名稱:minisync,代碼行數:3,代碼來源:dropbox.spec.ts


注:本文中的dropbox.Dropbox類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。