WOPI GetFile and PutFile added and document loader updated
This commit is contained in:
parent
be97780451
commit
30a22ef7e7
@ -36,6 +36,10 @@ $application->registerRoutes($this, [
|
|||||||
['name' => 'document#localLoad', 'url' => 'load/{fileId}', 'verb' => 'POST'],
|
['name' => 'document#localLoad', 'url' => 'load/{fileId}', 'verb' => 'POST'],
|
||||||
['name' => 'document#localSave', 'url' => 'save/{fileId}', 'verb' => 'POST'],
|
['name' => 'document#localSave', 'url' => 'save/{fileId}', 'verb' => 'POST'],
|
||||||
['name' => 'document#localClose', 'url' => 'close/{fileId}', 'verb' => 'POST'],
|
['name' => 'document#localClose', 'url' => 'close/{fileId}', 'verb' => 'POST'],
|
||||||
|
//documents - for WOPI access
|
||||||
|
['name' => 'document#wopiGetToken', 'url' => 'wopi/token/{fileId}', 'verb' => 'GET'],
|
||||||
|
['name' => 'document#wopiGetFile', 'url' => 'wopi/files/{fileId}/contents', 'verb' => 'GET'],
|
||||||
|
['name' => 'document#wopiPutFile', 'url' => 'wopi/files/{fileId}/contents', 'verb' => 'POST'],
|
||||||
//settings
|
//settings
|
||||||
['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'],
|
['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'],
|
||||||
['name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'],
|
['name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'],
|
||||||
|
@ -265,6 +265,70 @@ class DocumentController extends Controller{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates and returns an access token for a given fileId.
|
||||||
|
* Only for authenticated users!
|
||||||
|
*/
|
||||||
|
public function wopiGetToken($fileId){
|
||||||
|
\OC::$server->getLogger()->debug('Generating WOPI Token for file {fileId}.', [ 'app' => $this->appName, 'fileId' => $fileId ]);
|
||||||
|
|
||||||
|
$row = new Db\Wopi();
|
||||||
|
$token = $row->generateFileToken($fileId);
|
||||||
|
|
||||||
|
// Return the token.
|
||||||
|
return array(
|
||||||
|
'status' => 'success',
|
||||||
|
'token' => $token
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
* @PublicPage
|
||||||
|
* Given an access token and a fileId, returns the contents of the file.
|
||||||
|
* Expects a valid token in access_token parameter.
|
||||||
|
*/
|
||||||
|
public function wopiGetFile($fileId){
|
||||||
|
$token = $this->request->getParam('access_token');
|
||||||
|
|
||||||
|
\OC::$server->getLogger()->debug('Getting contents of file {fileId} by token {token}.', [ 'app' => $this->appName, 'fileId' => $fileId, 'token' => $token ]);
|
||||||
|
|
||||||
|
$row = new Db\Wopi();
|
||||||
|
$row->loadBy('token', $token);
|
||||||
|
|
||||||
|
//TODO: Support X-WOPIMaxExpectedSize header.
|
||||||
|
$res = $row->getPathForToken($fileId, $token);
|
||||||
|
return new DownloadResponse($this->request, $res['user'], $res['path']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
* @NoCSRFRequired
|
||||||
|
* @PublicPage
|
||||||
|
* Given an access token and a fileId, replaces the files with the request body.
|
||||||
|
* Expects a valid token in access_token parameter.
|
||||||
|
*/
|
||||||
|
public function wopiPutFile($fileId){
|
||||||
|
$token = $this->request->getParam('access_token');
|
||||||
|
|
||||||
|
\OC::$server->getLogger()->debug('Putting contents of file {fileId} by token {token}.', [ 'app' => $this->appName, 'fileId' => $fileId, 'token' => $token ]);
|
||||||
|
|
||||||
|
$row = new Db\Wopi();
|
||||||
|
$row->loadBy('token', $token);
|
||||||
|
|
||||||
|
$res = $row->getPathForToken($token);
|
||||||
|
$view = new \OC\Files\View('/' . $res['user'] . '/');
|
||||||
|
|
||||||
|
// Read the contents of the file from the POST body and store.
|
||||||
|
$content = file_get_contents('php://input');
|
||||||
|
$view->file_put_contents($res['path'], $content);
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'status' => 'success'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @PublicPage
|
* @PublicPage
|
||||||
|
@ -180,27 +180,38 @@ var documentsMain = {
|
|||||||
|
|
||||||
$('title').text(title + ' - ' + documentsMain.UI.mainTitle);
|
$('title').text(title + ' - ' + documentsMain.UI.mainTitle);
|
||||||
|
|
||||||
// TODO. wopiurl = get from discovery xml
|
$.get(OC.generateUrl('apps/richdocuments/wopi/token/{fileId}', { fileId: documentsMain.fileId }),
|
||||||
var wopiurl = $('#wopi-url').val() + '/loleaflet/dist/loleaflet.html';
|
function (result) {
|
||||||
var wopisrc = documentsMain.url;
|
if (!result || result.status === 'error') {
|
||||||
var action = wopiurl + '?' + wopisrc;
|
if (result && result.message){
|
||||||
var token = oc_requesttoken;
|
documentsMain.IU.notify(result.message);
|
||||||
|
}
|
||||||
|
documentsMain.onEditorShutdown(t('richdocuments', 'Failed to aquire access token. Please re-login and try again.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var form = '<form id="loleafletform" name="loleafletform" target="loleafletframe" action="' + action + '" method="post">' +
|
//TODO: Get WOPISrc from the discovery XML.
|
||||||
'<input name="access_token" value="' + token + '" type="hidden"/></form>';
|
var url = OC.generateUrl('apps/richdocuments/wopi/files/{file_id}/contents?access_token={token}',
|
||||||
var frame = '<iframe id="loleafletframe" name= "loleafletframe" allowfullscreen style="width:100%;height:100%;position:absolute;"/>';
|
{file_id: documentsMain.fileId, token: encodeURIComponent(result.token)});
|
||||||
|
documentsMain.url = window.location.protocol + '//' + window.location.host + url;
|
||||||
|
|
||||||
|
var viewer = window.location.protocol + '//' + window.location.host + '/loleaflet/dist/loleaflet.html?' +
|
||||||
|
'file_path=' + encodeURIComponent(documentsMain.url) +
|
||||||
|
'&host=' + 'ws://' + window.location.hostname + ':9980' +
|
||||||
|
'&permission=' + 'view' +
|
||||||
|
'×tamp=' + '';
|
||||||
|
|
||||||
|
var frame = '<iframe id="loleafletframe" allowfullscreen style="width:100%;height:100%;position:absolute;" src="' + viewer + '" sandbox="allow-scripts allow-same-origin allow-popups allow-modals"/>';
|
||||||
|
$('#mainContainer').append(frame);
|
||||||
|
});
|
||||||
|
|
||||||
$('#mainContainer').append(form);
|
|
||||||
$('#mainContainer').append(frame);
|
|
||||||
documentsMain.overlay.documentOverlay('hide');
|
documentsMain.overlay.documentOverlay('hide');
|
||||||
$('#loleafletframe').load(function(){
|
$('#loleafletframe').load(function(){
|
||||||
// avoid Blocked a frame with origin different domains
|
var iframe = $('#loleafletframe').contents();
|
||||||
|
|
||||||
/*var iframe = $('#loleafletframe').contents();
|
|
||||||
iframe.find('#tb_toolbar-up_item_close').click(function() {
|
iframe.find('#tb_toolbar-up_item_close').click(function() {
|
||||||
documentsMain.onClose();
|
documentsMain.onClose();
|
||||||
});*/
|
});
|
||||||
/*var frameWindow = $('#loleafletframe')[0].contentWindow;
|
var frameWindow = $('#loleafletframe')[0].contentWindow;
|
||||||
(function() {
|
(function() {
|
||||||
cloudSuiteOnClick = frameWindow.onClick;
|
cloudSuiteOnClick = frameWindow.onClick;
|
||||||
frameWindow.onClick = function() {
|
frameWindow.onClick = function() {
|
||||||
@ -209,9 +220,8 @@ var documentsMain = {
|
|||||||
cloudSuiteOnClick.apply(this, arguments);
|
cloudSuiteOnClick.apply(this, arguments);
|
||||||
frameWindow.map.options.doc = documentsMain.url;
|
frameWindow.map.options.doc = documentsMain.url;
|
||||||
};
|
};
|
||||||
})();*/
|
})();
|
||||||
});
|
});
|
||||||
$('#loleafletform').submit();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
hideEditor : function(){
|
hideEditor : function(){
|
||||||
@ -506,11 +516,6 @@ var documentsMain = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
loadDocument: function() {
|
loadDocument: function() {
|
||||||
// Provides access to information about a file and allows
|
|
||||||
// for file-level operations.
|
|
||||||
// HTTP://server/<...>/wopi*/files/<id>
|
|
||||||
var url = window.location.protocol + '//' + window.location.host + OC.generateUrl('apps/documents/wopi/files/{file_id}', {file_id: documentsMain.fileId}, false);
|
|
||||||
documentsMain.url = 'WOPISrc=' + encodeURIComponent(url);
|
|
||||||
documentsMain.UI.showEditor(documentsMain.fileName);
|
documentsMain.UI.showEditor(documentsMain.fileName);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user