- Migrated from https://github.com/Yetangitu/owncloud-apps
- substantial bit rot accrued in 4 years of non-maintenance which made Reader unusable - Reader now works reliably on public pages - or at least it _Works For Me™_ - Refactored a substantial part of the code to comply to the "current" (ha ha) Nextcloud API - Dropped Owncloud compatibility for lack of a testing installation - Dropped IE (<11) support - Dropped compatibility with older (<20) Nextcloud versions - Dropped app-specific ajax code, now handled by SettingsController - Updated dependencies where applicable
This commit is contained in:
parent
16afbe45fe
commit
b190e180ef
137 changed files with 30984 additions and 2 deletions
113
lib/Service/BookmarkService.php
Normal file
113
lib/Service/BookmarkService.php
Normal file
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2017 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Service;
|
||||
|
||||
|
||||
use OCA\Files_Reader\Db\BookmarkMapper;
|
||||
|
||||
class BookmarkService extends Service {
|
||||
|
||||
// "bookmark" name to use for the cursor (current reading position)
|
||||
const CURSOR = '__CURSOR__';
|
||||
const bookmark_type = 'bookmark';
|
||||
|
||||
private $bookmarkMapper;
|
||||
private $userId;
|
||||
|
||||
public function __construct(BookmarkMapper $bookmarkMapper, $UserId) {
|
||||
parent::__construct($bookmarkMapper);
|
||||
$this->bookmarkMapper = $bookmarkMapper;
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get bookmark
|
||||
*
|
||||
* bookmark type is format-dependent, eg CFI for epub, page number for CBR/CBZ, etc
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get($fileId, $name=null, $type=null) {
|
||||
$result = $this->bookmarkMapper->get($fileId, $name, $type);
|
||||
return array_map(
|
||||
function($entity) {
|
||||
return $entity->toService();
|
||||
}, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief write bookmark
|
||||
*
|
||||
* position type is format-dependent, eg CFI for epub, page number for CBR/CBZ, etc
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function set($fileId, $name, $value, $type=null, $content=null) {
|
||||
return $this->bookmarkMapper->set($fileId, $name, $value, $type, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get cursor (current position in book)
|
||||
*
|
||||
* @param int $fileId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCursor($fileId) {
|
||||
$result = $this->get($fileId, static::CURSOR);
|
||||
if (count($result) === 1) {
|
||||
return $result[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set cursor (current position in book)
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setCursor($fileId, $value) {
|
||||
return $this->bookmarkMapper->set($fileId, static::CURSOR, $value, static::bookmark_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief delete bookmark
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
*
|
||||
*/
|
||||
public function delete($fileId, $name, $type=null) {
|
||||
foreach ($this->bookmarkMapper->get($fileId, $name, $type) as $bookmark) {
|
||||
$this->bookmarkMapper->delete($bookmark);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief delete cursor
|
||||
*
|
||||
* @param int $fileId
|
||||
*
|
||||
*/
|
||||
public function deleteCursor($fileId) {
|
||||
$this->delete($fileId, static::CURSOR, static::bookmark_type);
|
||||
}
|
||||
}
|
||||
|
75
lib/Service/MetadataService.php
Normal file
75
lib/Service/MetadataService.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2017 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Service;
|
||||
|
||||
use OCP\App\IAppManager;
|
||||
|
||||
class MetadataService {
|
||||
|
||||
private $appManager;
|
||||
|
||||
/**
|
||||
* @param IAppManager $appManager
|
||||
*/
|
||||
public function __construct(IAppManager $appManager) {
|
||||
$this->appManager = $appManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get metadata item(s)
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get($fileId, $name=null) {
|
||||
if ($this->appManager->isInstalled('files_opds')) {
|
||||
if ($meta = \OCA\Files_Opds\Meta::get($fileId)) {
|
||||
if (!empty($name) && array_key_exists($name, $meta)) {
|
||||
return [$item => $meta[$name]];
|
||||
} else {
|
||||
return $meta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief write metadata to database
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param array $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setAll($fileId, $value) {
|
||||
// no-op for now
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief write metadata item to database
|
||||
*
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
* @param array $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function set($fileId, $name, $value) {
|
||||
// no-op for now
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
117
lib/Service/PreferenceService.php
Normal file
117
lib/Service/PreferenceService.php
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2017 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Service;
|
||||
|
||||
use OCA\Files_Reader\Db\PreferenceMapper;
|
||||
|
||||
class PreferenceService extends Service {
|
||||
|
||||
// (ab)use the fact that $fileId never goes below 1 by using the
|
||||
// value 0 to indicate a default preference
|
||||
const DEFAULTS = 0;
|
||||
|
||||
private $preferenceMapper;
|
||||
|
||||
/**
|
||||
* @param PreferenceMapper $preferenceMapper
|
||||
*/
|
||||
public function __construct(PreferenceMapper $preferenceMapper) {
|
||||
parent::__construct($preferenceMapper);
|
||||
$this->preferenceMapper = $preferenceMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get preference
|
||||
*
|
||||
* scope identifies preference source, i.e. which renderer the preference applies to
|
||||
* preference type is format-dependent, eg CFI for epub, page number for CBR/CBZ, etc
|
||||
*
|
||||
* @param string $scope
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get($scope, $fileId, $name=null) {
|
||||
$result = $this->preferenceMapper->get($scope, $fileId, $name);
|
||||
return array_map(
|
||||
function($entity) {
|
||||
return $entity->toService();
|
||||
}, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief write preference
|
||||
*
|
||||
* scope identifies preference source, i.e. which renderer the preference applies to
|
||||
* position type is format-dependent, eg CFI for epub, page number for CBR/CBZ, etc
|
||||
*
|
||||
* @param string $scope
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function set($scope, $fileId, $name, $value) {
|
||||
return $this->preferenceMapper->set($scope, $fileId, $name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get default preference
|
||||
*
|
||||
* @param string $scope
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefault($scope, $name=null) {
|
||||
return $this->get($scope, static::DEFAULTS, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set default preference
|
||||
*
|
||||
* @param string $scope
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setDefault($scope, $name, $value) {
|
||||
return $this->preferenceMapper->set($scope, static::DEFAULTS, $name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief delete preference
|
||||
*
|
||||
* @param string $scope
|
||||
* @param int $fileId
|
||||
* @param string $name
|
||||
*
|
||||
*/
|
||||
public function delete($scope, $fileId, $name) {
|
||||
foreach($this->preferenceMapper->get($scope, $fileId, $name) as $preference) {
|
||||
$this->preferenceMapper->delete($preference);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief delete default
|
||||
*
|
||||
* @param string $scope
|
||||
* @param string $name
|
||||
*
|
||||
*/
|
||||
public function deleteDefault($scope, $name) {
|
||||
$this->delete($scope, static::DEFAULTS, $name);
|
||||
}
|
||||
}
|
25
lib/Service/Service.php
Normal file
25
lib/Service/Service.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Frank de Lange
|
||||
* @copyright 2017 Frank de Lange
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Reader\Service;
|
||||
|
||||
use OCA\Files_Reader\Db\ReaderMapper;
|
||||
|
||||
abstract class Service {
|
||||
|
||||
protected $mapper;
|
||||
|
||||
public function __construct(ReaderMapper $mapper){
|
||||
$this->mapper = $mapper;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue