Fix file revisions
This commit is contained in:
parent
a5f6569591
commit
9bb400714c
@ -118,7 +118,7 @@ var documentsMain = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud)
|
// WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud)
|
||||||
var wopiurl = window.location.protocol + '//' + window.location.host + OC.generateUrl('apps/richdocuments/wopi/files/{file_id}_{instanceId}', {file_id: fileId, instanceId: instanceId});
|
var wopiurl = window.location.protocol + '//' + window.location.host + OC.generateUrl('apps/richdocuments/wopi/files/{file_id}', {file_id: fileId});
|
||||||
var wopisrc = encodeURIComponent(wopiurl);
|
var wopisrc = encodeURIComponent(wopiurl);
|
||||||
|
|
||||||
// urlsrc - the URL from discovery xml that we access for the particular
|
// urlsrc - the URL from discovery xml that we access for the particular
|
||||||
@ -162,7 +162,6 @@ var documentsMain = {
|
|||||||
if (version === 0) {
|
if (version === 0) {
|
||||||
formattedTimestamp = t('richdocuments', 'Latest revision');
|
formattedTimestamp = t('richdocuments', 'Latest revision');
|
||||||
downloadUrl = OC.generateUrl('apps/files/download'+ documentPath);
|
downloadUrl = OC.generateUrl('apps/files/download'+ documentPath);
|
||||||
fileId = fileId.replace(/_.*/, '');
|
|
||||||
} else {
|
} else {
|
||||||
downloadUrl = OC.generateUrl('apps/files_versions/download.php?file={file}&revision={revision}',
|
downloadUrl = OC.generateUrl('apps/files_versions/download.php?file={file}&revision={revision}',
|
||||||
{file: documentPath, revision: version});
|
{file: documentPath, revision: version});
|
||||||
|
@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
namespace OCA\Richdocuments\Controller;
|
namespace OCA\Richdocuments\Controller;
|
||||||
|
|
||||||
|
use OC\Files\View;
|
||||||
use OCA\Richdocuments\Db\Wopi;
|
use OCA\Richdocuments\Db\Wopi;
|
||||||
|
use OCA\Richdocuments\Helper;
|
||||||
use OCA\Richdocuments\WOPI\Parser;
|
use OCA\Richdocuments\WOPI\Parser;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
@ -50,29 +52,6 @@ class WopiController extends Controller {
|
|||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $fileId
|
|
||||||
* @return array
|
|
||||||
* @throws \Exception
|
|
||||||
*/
|
|
||||||
private function parseFileId($fileId) {
|
|
||||||
$arr = explode('_', $fileId, 2);
|
|
||||||
if (count($arr) === 2) {
|
|
||||||
list($fileId, $instanceId) = $arr;
|
|
||||||
$version = '0';
|
|
||||||
} else if (count($arr) === 3) {
|
|
||||||
list($fileId, $instanceId, $version) = $arr;
|
|
||||||
} else {
|
|
||||||
throw new \Exception('$fileId has not the expected format');
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
$fileId,
|
|
||||||
$instanceId,
|
|
||||||
$version,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns general info about a file.
|
* Returns general info about a file.
|
||||||
*
|
*
|
||||||
@ -86,12 +65,9 @@ class WopiController extends Controller {
|
|||||||
public function checkFileInfo($fileId) {
|
public function checkFileInfo($fileId) {
|
||||||
$token = $this->request->getParam('access_token');
|
$token = $this->request->getParam('access_token');
|
||||||
|
|
||||||
list($fileId, , $version) = $this->parseFileId($fileId);
|
list($fileId, , $version) = Helper::parseFileId($fileId);
|
||||||
|
$db = new Wopi();
|
||||||
$row = new Wopi();
|
$res = $db->getPathForToken($fileId, $token);
|
||||||
$row->loadBy('token', $token);
|
|
||||||
|
|
||||||
$res = $row->getPathForToken($fileId, $version, $token);
|
|
||||||
if ($res === false) {
|
if ($res === false) {
|
||||||
return new JSONResponse([], Http::STATUS_FORBIDDEN);
|
return new JSONResponse([], Http::STATUS_FORBIDDEN);
|
||||||
}
|
}
|
||||||
@ -136,18 +112,32 @@ class WopiController extends Controller {
|
|||||||
*/
|
*/
|
||||||
public function getFile($fileId,
|
public function getFile($fileId,
|
||||||
$access_token) {
|
$access_token) {
|
||||||
list($fileId, , $version) = $this->parseFileId($fileId);
|
list($fileId, , $version) = Helper::parseFileId($fileId);
|
||||||
|
|
||||||
$row = new Wopi();
|
$row = new Wopi();
|
||||||
$row->loadBy('token', $access_token);
|
$row->loadBy('token', $access_token);
|
||||||
|
$res = $row->getPathForToken($fileId, $access_token);
|
||||||
$res = $row->getPathForToken($fileId, $version, $access_token);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/** @var File $file */
|
/** @var File $file */
|
||||||
$userFolder = $this->rootFolder->getUserFolder($res['owner']);
|
$userFolder = $this->rootFolder->getUserFolder($res['owner']);
|
||||||
$file = $userFolder->getById($fileId)[0];
|
$file = $userFolder->getById($fileId)[0];
|
||||||
|
|
||||||
|
if ($version !== '0')
|
||||||
|
{
|
||||||
|
$view = new View('/' . $res['owner'] . '/files');
|
||||||
|
$relPath = $view->getRelativePath($file->getPath());
|
||||||
|
$versionPath = '/files_versions/' . $relPath . '.v' . $version;
|
||||||
|
$view = new View('/' . $res['owner']);
|
||||||
|
if ($view->file_exists($versionPath)){
|
||||||
|
$response = new StreamResponse($view->fopen($versionPath, 'rb'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$response->setStatus(Http::STATUS_NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$response = new StreamResponse($file->fopen('rb'));
|
$response = new StreamResponse($file->fopen('rb'));
|
||||||
|
}
|
||||||
$response->addHeader('Content-Disposition', 'attachment');
|
$response->addHeader('Content-Disposition', 'attachment');
|
||||||
$response->addHeader('Content-Type', 'application/octet-stream');
|
$response->addHeader('Content-Type', 'application/octet-stream');
|
||||||
return $response;
|
return $response;
|
||||||
@ -169,12 +159,12 @@ class WopiController extends Controller {
|
|||||||
*/
|
*/
|
||||||
public function putFile($fileId,
|
public function putFile($fileId,
|
||||||
$access_token) {
|
$access_token) {
|
||||||
list($fileId, , $version) = $this->parseFileId($fileId);
|
list($fileId, , $version) = Helper::parseFileId($fileId);
|
||||||
|
|
||||||
$row = new Wopi();
|
$row = new Wopi();
|
||||||
$row->loadBy('token', $access_token);
|
$row->loadBy('token', $access_token);
|
||||||
|
|
||||||
$res = $row->getPathForToken($fileId, $version, $access_token);
|
$res = $row->getPathForToken($fileId, $access_token);
|
||||||
if (!$res['canwrite']) {
|
if (!$res['canwrite']) {
|
||||||
return new JSONResponse([], Http::STATUS_FORBIDDEN);
|
return new JSONResponse([], Http::STATUS_FORBIDDEN);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
namespace OCA\Richdocuments;
|
namespace OCA\Richdocuments;
|
||||||
|
|
||||||
use OC\Share\Constants;
|
use OC\Share\Constants;
|
||||||
|
use OCA\Richdocuments\Helper;
|
||||||
use OCA\Richdocuments\Db\Wopi;
|
use OCA\Richdocuments\Db\Wopi;
|
||||||
use OCA\Richdocuments\WOPI\Parser;
|
use OCA\Richdocuments\WOPI\Parser;
|
||||||
use OCP\Files\File;
|
use OCP\Files\File;
|
||||||
@ -64,12 +65,7 @@ class TokenManager {
|
|||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function getToken($fileId, $shareToken = null) {
|
public function getToken($fileId, $shareToken = null) {
|
||||||
$arr = explode('_', $fileId, 2);
|
list($fileId,, $version) = Helper::parseFileId($fileId);
|
||||||
$version = '0';
|
|
||||||
if (count($arr) === 2) {
|
|
||||||
list($fileId, $version) = $arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the user is not logged-in do use the sharers storage
|
// if the user is not logged-in do use the sharers storage
|
||||||
if($shareToken !== null) {
|
if($shareToken !== null) {
|
||||||
/** @var File $file */
|
/** @var File $file */
|
||||||
|
@ -56,7 +56,7 @@ class Wopi extends \OCA\Richdocuments\Db{
|
|||||||
* constructs and validates the path.
|
* constructs and validates the path.
|
||||||
* Returns the path, if valid, else false.
|
* Returns the path, if valid, else false.
|
||||||
*/
|
*/
|
||||||
public function getPathForToken($fileId, $version, $token){
|
public function getPathForToken($fileId, $token){
|
||||||
|
|
||||||
$wopi = new Wopi();
|
$wopi = new Wopi();
|
||||||
$row = $wopi->loadBy('token', $token)->getData();
|
$row = $wopi->loadBy('token', $token)->getData();
|
||||||
@ -75,11 +75,6 @@ class Wopi extends \OCA\Richdocuments\Db{
|
|||||||
//$wopi->deleteBy('id', $row['id']);
|
//$wopi->deleteBy('id', $row['id']);
|
||||||
//return false;
|
//return false;
|
||||||
}
|
}
|
||||||
if ($row['fileid'] !== $fileId || $row['version'] !== $version){
|
|
||||||
// File unknown / user unauthorized (for the requested file).
|
|
||||||
http_response_code(404);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'owner' => $row['owner_uid'],
|
'owner' => $row['owner_uid'],
|
||||||
|
@ -14,6 +14,33 @@ namespace OCA\Richdocuments;
|
|||||||
class Helper {
|
class Helper {
|
||||||
const APP_ID = 'richdocuments';
|
const APP_ID = 'richdocuments';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $fileId
|
||||||
|
* @return array
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public static function parseFileId($fileId) {
|
||||||
|
$arr = explode('_', $fileId);
|
||||||
|
if (count($arr) === 1) {
|
||||||
|
$fileId = $arr[0];
|
||||||
|
$version = '0';
|
||||||
|
} else if (count($arr) === 2) {
|
||||||
|
list($fileId, $instanceId) = $arr;
|
||||||
|
$version = '0';
|
||||||
|
} else if (count($arr) === 3) {
|
||||||
|
list($fileId, $instanceId, $version) = $arr;
|
||||||
|
} else {
|
||||||
|
throw new \Exception('$fileId has not the expected format');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
$fileId,
|
||||||
|
$instanceId,
|
||||||
|
$version,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function getNewFileName($view, $path, $prepend = ' '){
|
public static function getNewFileName($view, $path, $prepend = ' '){
|
||||||
$fileNum = 1;
|
$fileNum = 1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user