Copy genesis to storage
This commit is contained in:
parent
354f059d92
commit
5b165331df
@ -13,8 +13,8 @@ namespace OCA\Office;
|
|||||||
|
|
||||||
\OCP\User::checkLoggedIn();
|
\OCP\User::checkLoggedIn();
|
||||||
|
|
||||||
$session = Session::getSession($_SERVER['QUERY_STRING']);
|
$session = Session::getSession(@$_SERVER['QUERY_STRING']);
|
||||||
$filename = isset($session['genesis_url']) ? $session['genesis_url'] : '';
|
|
||||||
|
|
||||||
|
$filename = isset($session['genesis_url']) ? $session['genesis_url'] : '';
|
||||||
$download = new Download($filename);
|
$download = new Download($filename);
|
||||||
$download->sendResponse();
|
$download->sendResponse();
|
@ -6,10 +6,19 @@ namespace OCA\Office;
|
|||||||
\OCP\User::checkLoggedIn();
|
\OCP\User::checkLoggedIn();
|
||||||
|
|
||||||
$genesis = @$_POST['genesis'];
|
$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){
|
if (!$session){
|
||||||
$session = Session::addSession($genesis);
|
$session = Session::addSession($genesisPath);
|
||||||
}
|
}
|
||||||
\OCP\JSON::success($session);
|
\OCP\JSON::success($session);
|
||||||
exit();
|
exit();
|
||||||
|
@ -33,7 +33,7 @@ OCP\App::addNavigationEntry(array(
|
|||||||
'name' => 'Office')
|
'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\Simple'] = 'office/lib/download/simple.php';
|
||||||
OC::$CLASSPATH['OCA\Office\Download\Range'] = 'office/lib/download/range.php';
|
OC::$CLASSPATH['OCA\Office\Download\Range'] = 'office/lib/download/range.php';
|
||||||
|
|
||||||
|
10
appinfo/routes.php
Normal file
10
appinfo/routes.php
Normal file
@ -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 = serverFactory.createServer({url: "./office/ajax/otpoll.php"});
|
||||||
server.getGenesisUrl = function(sid) {
|
server.getGenesisUrl = function(sid) {
|
||||||
// what a dirty hack :)
|
// what a dirty hack :)
|
||||||
return window.officeMain.doclocation;
|
return OC.Router.generate('office_genesis')+'/' +sid;
|
||||||
};
|
};
|
||||||
server.connect(8000, callback);
|
server.connect(8000, callback);
|
||||||
});
|
});
|
||||||
|
@ -83,13 +83,13 @@ var officeMain = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
registerSession : function(dir, file){
|
registerSession : function(filepath){
|
||||||
"use strict";
|
"use strict";
|
||||||
if (officeMain.initialized === undefined) {
|
if (officeMain.initialized === undefined) {
|
||||||
alert("WebODF Editor not yet initialized...");
|
alert("WebODF Editor not yet initialized...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var filepath = fileDownloadPath(dir, file);
|
|
||||||
$.post(OC.filePath('office', 'ajax', 'session.php'),
|
$.post(OC.filePath('office', 'ajax', 'session.php'),
|
||||||
{ 'genesis' : filepath },
|
{ 'genesis' : filepath },
|
||||||
officeMain.onView
|
officeMain.onView
|
||||||
@ -135,7 +135,7 @@ var officeMain = {
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('.documentslist tr').click(function(event) {
|
$('.documentslist tr').click(function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
officeMain.registerSession('', $(this).attr('data-file'));
|
officeMain.registerSession($(this).attr('data-file'));
|
||||||
});
|
});
|
||||||
$('#odf_close').live('click', officeMain.onClose);
|
$('#odf_close').live('click', officeMain.onClose);
|
||||||
OC.addScript('office', 'dojo-amalgamation', officeMain.onStartup);
|
OC.addScript('office', 'dojo-amalgamation', officeMain.onStartup);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
namespace OCA\Office;
|
namespace OCA\Office;
|
||||||
|
|
||||||
class Download {
|
class Download {
|
||||||
|
protected $view;
|
||||||
// File to be served
|
// File to be served
|
||||||
protected $filepath;
|
protected $filepath;
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ class Download {
|
|||||||
|
|
||||||
public function __construct($filepath){
|
public function __construct($filepath){
|
||||||
$this->filepath = $filepath;
|
$this->filepath = $filepath;
|
||||||
|
|
||||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||||
$this->instance = new Download\Range($filepath);
|
$this->instance = new Download\Range($filepath);
|
||||||
} else {
|
} else {
|
||||||
@ -20,6 +21,7 @@ class Download {
|
|||||||
|
|
||||||
public function sendResponse(){
|
public function sendResponse(){
|
||||||
\OCP\Response::disableCaching();
|
\OCP\Response::disableCaching();
|
||||||
|
$this->view = View::initOfficeView(\OCP\User::getUser());
|
||||||
|
|
||||||
if (!$this->fileExists()){
|
if (!$this->fileExists()){
|
||||||
$this->sendNotFound();
|
$this->sendNotFound();
|
||||||
@ -34,15 +36,15 @@ class Download {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function getFilesize(){
|
protected function getFilesize(){
|
||||||
return \OC\Files\Filesystem::filesize($this->filepath);
|
return $this->view->filesize($this->filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getMimeType(){
|
protected function getMimeType(){
|
||||||
return \OC\Files\Filesystem::getMimeType($this->filepath);
|
return $this->view->getMimeType($this->filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function fileExists(){
|
protected function fileExists(){
|
||||||
return \OC\Files\Filesystem::file_exists($this->filepath);
|
return $this->view->file_exists($this->filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function sendNotFound(){
|
protected function sendNotFound(){
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace OCA\Office\Download;
|
namespace OCA\Office\Download;
|
||||||
|
use OCA\Office\View;
|
||||||
class Range extends \OCA\Office\Download {
|
class Range extends \OCA\Office\Download {
|
||||||
|
|
||||||
// Start of the range
|
// Start of the range
|
||||||
@ -14,6 +14,7 @@ class Range extends \OCA\Office\Download {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function sendResponse(){
|
public function sendResponse(){
|
||||||
|
$this->view = View::initOfficeView(\OCP\User::getUser());
|
||||||
if (!preg_match('/^bytes=\d*-\d*(,\d*-\d*)*$/', $_SERVER['HTTP_RANGE'])){
|
if (!preg_match('/^bytes=\d*-\d*(,\d*-\d*)*$/', $_SERVER['HTTP_RANGE'])){
|
||||||
$this->sendNotSatisfiable();
|
$this->sendNotSatisfiable();
|
||||||
}
|
}
|
||||||
@ -28,7 +29,7 @@ class Range extends \OCA\Office\Download {
|
|||||||
$this->sendNotSatisfiable();
|
$this->sendNotSatisfiable();
|
||||||
}
|
}
|
||||||
|
|
||||||
$handle = \OC\Files\Filesystem::fopen($this->filepath, 'rb');
|
$handle = $this->view->fopen($this->filepath, 'rb');
|
||||||
\fseek($handle, $start);
|
\fseek($handle, $start);
|
||||||
$buffer = \fread($handle, $end - $start);
|
$buffer = \fread($handle, $end - $start);
|
||||||
$md5Sum = md5($buffer);
|
$md5Sum = md5($buffer);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace OCA\Office\Download;
|
namespace OCA\Office\Download;
|
||||||
|
use OCA\Office\View;
|
||||||
|
|
||||||
class Simple extends \OCA\Office\Download {
|
class Simple extends \OCA\Office\Download {
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ class Simple extends \OCA\Office\Download {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function sendResponse(){
|
public function sendResponse(){
|
||||||
|
$this->view = View::initOfficeView(\OCP\User::getUser());
|
||||||
header( 'Content-Type:' . $this->getMimeType() );
|
header( 'Content-Type:' . $this->getMimeType() );
|
||||||
|
|
||||||
$encodedName = rawurlencode($this->getFilename());
|
$encodedName = rawurlencode($this->getFilename());
|
||||||
@ -21,10 +23,10 @@ class Simple extends \OCA\Office\Download {
|
|||||||
. '; filepath="' . $encodedName . '"');
|
. '; filepath="' . $encodedName . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
header('Content-Length: ' . \OC\Files\Filesystem::filesize($this->filepath));
|
header('Content-Length: ' . $this->view->filesize($this->filepath));
|
||||||
|
|
||||||
\OC_Util::obEnd();
|
\OC_Util::obEnd();
|
||||||
\OC\Files\Filesystem::readfile($this->filepath);
|
$this->view->readfile($this->filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
17
lib/genesis.php
Normal file
17
lib/genesis.php
Normal file
@ -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();
|
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`= ?');
|
$query = \OCP\DB::prepare('SELECT * FROM `*PREFIX*office_session` WHERE `genesis_url`= ?');
|
||||||
$result = $query->execute(array($url));
|
$result = $query->execute(array($url));
|
||||||
return $result->fetchRow();
|
return $result->fetchRow();
|
||||||
|
31
lib/view.php
Normal file
31
lib/view.php
Normal file
@ -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 { ?>
|
<?php } else { ?>
|
||||||
<table class="documentslist" >
|
<table class="documentslist" >
|
||||||
<?php foreach($_['list'] as $entry) { ?>
|
<?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">
|
<td width="1">
|
||||||
<img align="left" src="<?php p(\OCP\Util::linkToAbsolute('office','ajax/thumbnail.php').'?filepath='.urlencode($entry['url'])) ?>" />
|
<img align="left" src="<?php p(\OCP\Util::linkToAbsolute('office','ajax/thumbnail.php').'?filepath='.urlencode($entry['url'])) ?>" />
|
||||||
</td>
|
</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user