Copy genesis to storage

pull/1/head
Victor Dubiniuk 11 years ago committed by Tobias Hintze
parent 354f059d92
commit 5b165331df

@ -13,8 +13,8 @@ namespace OCA\Office;
\OCP\User::checkLoggedIn();
$session = Session::getSession($_SERVER['QUERY_STRING']);
$filename = isset($session['genesis_url']) ? $session['genesis_url'] : '';
$session = Session::getSession(@$_SERVER['QUERY_STRING']);
$filename = isset($session['genesis_url']) ? $session['genesis_url'] : '';
$download = new Download($filename);
$download->sendResponse();

@ -6,10 +6,19 @@ namespace OCA\Office;
\OCP\User::checkLoggedIn();
$genesis = @$_POST['genesis'];
if ($genesis){
$session = Session::getSessionByUrl($genesis);
$uid = \OCP\User::getUser();
$officeView = View::initOfficeView($uid);
if (!$officeView->file_exists($genesis)){
$genesisPath = View::storeDocument($uid, $genesis);
} else {
$genesisPath = $genesis;
}
if ($genesisPath){
$session = Session::getSessionByPath($genesisPath);
if (!$session){
$session = Session::addSession($genesis);
$session = Session::addSession($genesisPath);
}
\OCP\JSON::success($session);
exit();

@ -33,7 +33,7 @@ OCP\App::addNavigationEntry(array(
'name' => 'Office')
);
OC::$CLASSPATH['OCA\Office\Storage'] = 'office/lib/storage.php';
OC::$CLASSPATH['OCA\Office\Genesis'] = 'office/lib/genesis.php';
OC::$CLASSPATH['OCA\Office\Download\Simple'] = 'office/lib/download/simple.php';
OC::$CLASSPATH['OCA\Office\Download\Range'] = 'office/lib/download/range.php';

@ -0,0 +1,10 @@
<?php
$this->create('office_genesis', 'ajax/genesis/{es_id}')
->post()
->action('\OCA\Office\Genesis', 'serve')
;
$this->create('office_genesis', 'ajax/genesis/{es_id}')
->get()
->action('\OCA\Office\Genesis', 'serve')
;

@ -98,7 +98,7 @@ var webodfEditor = (function () {
server = serverFactory.createServer({url: "./office/ajax/otpoll.php"});
server.getGenesisUrl = function(sid) {
// what a dirty hack :)
return window.officeMain.doclocation;
return OC.Router.generate('office_genesis')+'/' +sid;
};
server.connect(8000, callback);
});

@ -83,13 +83,13 @@ var officeMain = {
});
});
},
registerSession : function(dir, file){
registerSession : function(filepath){
"use strict";
if (officeMain.initialized === undefined) {
alert("WebODF Editor not yet initialized...");
return;
}
var filepath = fileDownloadPath(dir, file);
$.post(OC.filePath('office', 'ajax', 'session.php'),
{ 'genesis' : filepath },
officeMain.onView
@ -135,7 +135,7 @@ var officeMain = {
$(document).ready(function() {
$('.documentslist tr').click(function(event) {
event.preventDefault();
officeMain.registerSession('', $(this).attr('data-file'));
officeMain.registerSession($(this).attr('data-file'));
});
$('#odf_close').live('click', officeMain.onClose);
OC.addScript('office', 'dojo-amalgamation', officeMain.onStartup);

@ -3,7 +3,7 @@
namespace OCA\Office;
class Download {
protected $view;
// File to be served
protected $filepath;
@ -11,6 +11,7 @@ class Download {
public function __construct($filepath){
$this->filepath = $filepath;
if (isset($_SERVER['HTTP_RANGE'])) {
$this->instance = new Download\Range($filepath);
} else {
@ -20,6 +21,7 @@ class Download {
public function sendResponse(){
\OCP\Response::disableCaching();
$this->view = View::initOfficeView(\OCP\User::getUser());
if (!$this->fileExists()){
$this->sendNotFound();
@ -34,15 +36,15 @@ class Download {
}
protected function getFilesize(){
return \OC\Files\Filesystem::filesize($this->filepath);
return $this->view->filesize($this->filepath);
}
protected function getMimeType(){
return \OC\Files\Filesystem::getMimeType($this->filepath);
return $this->view->getMimeType($this->filepath);
}
protected function fileExists(){
return \OC\Files\Filesystem::file_exists($this->filepath);
return $this->view->file_exists($this->filepath);
}
protected function sendNotFound(){

@ -1,7 +1,7 @@
<?php
namespace OCA\Office\Download;
use OCA\Office\View;
class Range extends \OCA\Office\Download {
// Start of the range
@ -14,6 +14,7 @@ class Range extends \OCA\Office\Download {
}
public function sendResponse(){
$this->view = View::initOfficeView(\OCP\User::getUser());
if (!preg_match('/^bytes=\d*-\d*(,\d*-\d*)*$/', $_SERVER['HTTP_RANGE'])){
$this->sendNotSatisfiable();
}
@ -28,7 +29,7 @@ class Range extends \OCA\Office\Download {
$this->sendNotSatisfiable();
}
$handle = \OC\Files\Filesystem::fopen($this->filepath, 'rb');
$handle = $this->view->fopen($this->filepath, 'rb');
\fseek($handle, $start);
$buffer = \fread($handle, $end - $start);
$md5Sum = md5($buffer);

@ -1,6 +1,7 @@
<?php
namespace OCA\Office\Download;
use OCA\Office\View;
class Simple extends \OCA\Office\Download {
@ -9,6 +10,7 @@ class Simple extends \OCA\Office\Download {
}
public function sendResponse(){
$this->view = View::initOfficeView(\OCP\User::getUser());
header( 'Content-Type:' . $this->getMimeType() );
$encodedName = rawurlencode($this->getFilename());
@ -21,10 +23,10 @@ class Simple extends \OCA\Office\Download {
. '; filepath="' . $encodedName . '"');
}
header('Content-Length: ' . \OC\Files\Filesystem::filesize($this->filepath));
header('Content-Length: ' . $this->view->filesize($this->filepath));
\OC_Util::obEnd();
\OC\Files\Filesystem::readfile($this->filepath);
$this->view->readfile($this->filepath);
}
}

@ -0,0 +1,17 @@
<?php
namespace OCA\Office;
class Genesis {
public static function serve($args){
\OCP\User::checkLoggedIn();
$session = Session::getSession(@$args['es_id']);
$filename = isset($session['genesis_url']) ? $session['genesis_url'] : '';
$download = new Download($filename);
$download->sendResponse();
}
}

@ -16,7 +16,7 @@ class Session {
return $result->fetchRow();
}
public static function getSessionByUrl($url){
public static function getSessionByPath($url){
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ?');
$result = $query->execute(array($url));
return $result->fetchRow();

@ -0,0 +1,31 @@
<?php
namespace OCA\Office;
class View extends \OC\Files\View{
const OFFICE_DIRNAME='/office';
protected static $officeView;
public static function initOfficeView($uid){
$view = new \OC\Files\View('/' . $uid);
if (!$view->is_dir(self::OFFICE_DIRNAME)) {
$view->mkdir(self::OFFICE_DIRNAME);
}
if (!self::$officeView){
self::$officeView = new \OC\Files\View('/' . $uid . self::OFFICE_DIRNAME);
}
return self::$officeView;
}
public static function storeDocument($uid, $path){
$view = new \OC\Files\View('/' . $uid);
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$view->copy('/files' . $path, self::OFFICE_DIRNAME . $path);
\OC_FileProxy::$enabled = $proxyStatus;
return $path;
}
}

@ -4,7 +4,7 @@
<?php } else { ?>
<table class="documentslist" >
<?php foreach($_['list'] as $entry) { ?>
<tr data-file="<?php p($entry['path']) ?>">
<tr data-file="<?php \OCP\Util::encodePath(p($entry['path'])) ?>">
<td width="1">
<img align="left" src="<?php p(\OCP\Util::linkToAbsolute('office','ajax/thumbnail.php').'?filepath='.urlencode($entry['url'])) ?>" />
</td>

Loading…
Cancel
Save