cloudsuite: Implement the document loading via CloudSuite.

In order to work, we need a group that is shared between wwwrun (for owncloud)
and loolwsd; let's call it loolwww.  Then:

cd <www>/owncloud/apps/documents
mkdir documents-tmp
chown chown wwwrun:loolwww documents-tmp
chmod g+ws documents-tmp

ownCloud takes care of copying the files to this shared location, and back (in
the future).  It will also need to take care of the cleanup, at the moment the
files are leaked.
pull/1/head
Jan Holesovsky 9 years ago
parent 4cdae43fc8
commit 3bed81b4a9

@ -33,6 +33,8 @@ $application->registerRoutes($this, [
['name' => 'document#listAll', 'url' => 'ajax/documents/list', 'verb' => 'GET'],
['name' => 'document#download', 'url' => 'ajax/download.php', 'verb' => 'GET'],
['name' => 'document#showLOleaflet', 'url' => '/loleaflet', 'verb' => 'GET'],
//documents - for CloudSuite access
['name' => 'document#localLoad', 'url' => 'ajax/documents/load/{esId}', 'verb' => 'POST'],
//settings
['name' => 'settings#savePersonal', 'url' => 'ajax/personal.php', 'verb' => 'POST'],
['name' => 'settings#setUnstable', 'url' => 'ajax/config/unstable', 'verb' => 'POST'],

@ -37,6 +37,7 @@ class DocumentController extends Controller{
private $urlGenerator;
const ODT_TEMPLATE_PATH = '/assets/new.odt';
const CLOUDSUITE_TMP_PATH = '/documents-tmp/';
public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, IURLGenerator $urlGenerator, $uid){
parent::__construct($appName, $request);
@ -111,6 +112,47 @@ class DocumentController extends Controller{
return $response;
}
/**
* @NoAdminRequired
* @PublicPage
* Copy the file to a temporary location that is shared between the
* cloudsuite server part and owncloud.
*/
public function localLoad($esId){
$session = new Db\Session();
$session->load($esId);
$member = new Db\Member();
$member->load($this->uid);
try {
if ($member->getIsGuest()){
$file = File::getByShareToken($member->getToken());
} else {
$file = new File($session->getFileId());
}
$view = $file->getOwnerView(true);
$path = $file->getPath(true);
} catch (\Exception $e){
return array(
'status' => 'error',
'message' => (string) $this->l10n->t('Unable to copy document for CloudSuite access.')
);
}
$content = $view->file_get_contents($path);
$filename = tempnam(dirname(__DIR__) . self::CLOUDSUITE_TMP_PATH, 'ccs-');
file_put_contents($filename, $content);
chmod($filename, 0660);
return array(
'status' => 'success', 'filename' => $filename,
'basename' => basename($filename)
);
}
/**
* @NoAdminRequired
* @PublicPage

@ -153,6 +153,8 @@ var documentsMain = {
esId : false,
ready :false,
fileName: null,
baseName: null,
url: null,
canShare : false,
toolbar : '<div id="ocToolbar"><div id="ocToolbarInside"></div><span id="toolbar" class="claro"></span></div>',
@ -179,8 +181,8 @@ var documentsMain = {
$('title').text(title + ' - ' + documentsMain.UI.mainTitle);
var viewer = window.location.protocol + '//' + window.location.host + '/cloudsuite/cloudsuite.html?' +
'file_path=' + 'file:///local/home/kendy/Downloads/ODT-test.odt' +
'&host=' + 'ws://localhost:9980' +
'file_path=' + documentsMain.url +
'&host=' + 'ws://' + window.location.hostname + ':9980' +
'&edit=' + 'false' +
'&timestamp=' + '';
@ -346,15 +348,16 @@ var documentsMain = {
documentsMain.fileId = response.file_id;
documentsMain.fileName = response.title;
documentsMain.UI.showEditor(documentsMain.fileName || response.title);
documentsMain.esId = response.es_id;
documentsMain.memberId = response.member_id;
documentsMain.loadDocument();
if (documentsMain.isGuest){
$('#odf-close').text(t('documents', 'Save') );
$('#odf-close').removeClass('icon-view-close');
}
//var serverFactory = new ServerFactory();
documentsMain.esId = response.es_id;
documentsMain.memberId = response.member_id;
/*
// TODO: set webodf translation system, by passing a proper function translate(!string):!string in "runtime.setTranslator(translate);"
documentsMain.webodfServerInstance = serverFactory.createServer({
@ -518,6 +521,28 @@ var documentsMain = {
input.selectRange(0, name.length);
},
loadDocument: function() {
var url = OC.generateUrl('apps/documents/ajax/documents/load/{es_id}', {es_id: documentsMain.esId});
$.post(
url,
{},
function(result) {
if (result && result.status === 'error') {
if (result.message){
documentsMain.IU.notify(result.message);
}
documentsMain.onEditorShutdown(t('documents', 'Failed to load this document. Please check if it can be opened with an external odt editor. This might also mean it has been unshared or deleted recently.'));
return;
}
documentsMain.url = 'file://' + result.filename;
documentsMain.baseName = result.basename;
documentsMain.UI.showEditor(documentsMain.fileName);
}
);
},
renameDocument: function(name) {
var url = OC.generateUrl('apps/documents/ajax/documents/rename/{file_id}', {file_id: documentsMain.fileId});
$.post(

Loading…
Cancel
Save