Skip to content
Snippets Groups Projects
wopiapi-iframe.js 1011 B
Newer Older
  • Learn to ignore specific revisions
  • Alexey Lunin's avatar
    Alexey Lunin committed
    const axios = require("axios");
    
    function WopiAPI() {}
    
    
    Alexey Lunin's avatar
    Alexey Lunin committed
    WopiAPI.prototype.getPassports = function(fileID) {
      const {
        publicKey,
        uuid,
        token,
        deviceHash
      } = window.viamApi.getConfig().headers;
    
      const requestConfig = {
    
        url: `${window.WOPI_URL}getPassports`,
    
    Alexey Lunin's avatar
    Alexey Lunin committed
        method: "POST",
    
        headers: {
    
          publicKey,
          uuid,
          token,
          deviceHash,
    
    Alexey Lunin's avatar
    Alexey Lunin committed
          fileID: encodeURI(fileID)
    
    Markin Igor's avatar
    Markin Igor committed
      return axios(requestConfig);
    
    Alexey Lunin's avatar
    Alexey Lunin committed
    WopiAPI.prototype.putDocument = function(path, accessToken, file) {
      const {
        publicKey,
        uuid,
        token,
        deviceHash
      } = window.viamApi.getConfig().headers;
    
      path = path[0] === "/" ? path : `/${path}`;
    
    Alexey Lunin's avatar
    Alexey Lunin committed
      path = encodeURI(path);
    
    Alexey Lunin's avatar
    Alexey Lunin committed
      const requestConfig = {
    
        url: `${window.WOPI_URL}files${path}/contents`,
    
    Alexey Lunin's avatar
    Alexey Lunin committed
        method: "POST",
    
    Alexey Lunin's avatar
    Alexey Lunin committed
        headers: {
          publicKey,
          uuid,
          token,
          deviceHash
        },
        params: {
          access_token: accessToken
        },
        data: file
      };
    
      return axios(requestConfig);
    };
    
    
    module.exports = WopiAPI;