Add admin setting for configuring screeenly

If configured, use screeenly as a fallback to the default preview
service
This commit is contained in:
Marcel Klehr 2018-07-21 16:18:05 +02:00
parent abb11ae0b5
commit d5a894796f
9 changed files with 238 additions and 16 deletions

View File

@ -85,6 +85,7 @@ class Application extends App {
$c->query('ServerContainer')->getUserManager(),
$c->query('ServerContainer')->query(DefaultPreviewService::class),
$c->query('ServerContainer')->query(FaviconPreviewService::class),
$c->query('ServerContainer')->query(ScreenlyPreviewService::class),
$c->query('ServerContainer')->query(ITimeFactory::class)
);
});

View File

@ -8,7 +8,7 @@
This app allows you to store and organize your favorite places on the web in one spot, while allowing you to sync them with your various devices and browsers.
Check out the third-party clients listed here: https://github.com/nextcloud/bookmarks#third-party-clients
]]></description>
<version>0.12.0-rc2</version>
<version>0.12.0-rc3</version>
<licence>agpl</licence>
<author mail="blizzz@arthur-schiwon.de" homepage="https://www.arthur-schiwon.de">Arthur Schiwon</author>
<author mail="mklehr@gmx.net">Marcel Klehr</author>
@ -22,9 +22,8 @@ Check out the third-party clients listed here: https://github.com/nextcloud/book
<dependencies>
<nextcloud min-version="12" max-version="14" />
</dependencies>
<repair-steps>
<pre-migration>
<step>OCA\Bookmarks\Migration\RecreateAllBookmarks</step>
</pre-migration>
</repair-steps>
<settings>
<admin>OCA\Bookmarks\Settings\AdminSettings</admin>
<admin-section>OCA\Bookmarks\Settings\AdminSection</admin-section>
</settings>
</info>

View File

@ -21,6 +21,7 @@ namespace OCA\Bookmarks\Controller\Lib\Previews;
use Wnx\ScreeenlyClient\Screenshot;
use OCP\ICache;
use OCP\IConfig;
use OCP\ICacheFactory;
class ScreenlyPreviewService implements IPreviewService {
@ -29,6 +30,9 @@ class ScreenlyPreviewService implements IPreviewService {
private $apiKey;
/** @var IConfig */
private $config;
/** @var ICache */
private $cache;
@ -39,9 +43,10 @@ class ScreenlyPreviewService implements IPreviewService {
/**
* @param ICacheFactory $cacheFactory
*/
public function __construct(ICacheFactory $cacheFactory) {
$this->apiUrl = 'http://screeenly.com/api/v1/fullsize';
$this->apiKey = 'xxx';
public function __construct(ICacheFactory $cacheFactory, IConfig $config) {
$this->config = $config;
$this->apiUrl = $config->getAppValue('bookmarks', 'previews.screenly.url', 'http://screeenly.com/api/v1/fullsize');
$this->apiKey = $config->getAppValue('bookmarks', 'previews.screenly.token', '');
$this->cache = $cacheFactory->create('bookmarks.ScreenlyPreviewService');
}
@ -57,6 +62,9 @@ class ScreenlyPreviewService implements IPreviewService {
if (!isset($bookmark)) {
return null;
}
if ('' === $this->apiKey) {
return null;
}
$url = $bookmark['url'];
$key = $this->buildKey($url);

View File

@ -46,6 +46,7 @@ class InternalBookmarkController extends ApiController {
Manager $userManager,
IPreviewService $previewService,
IPreviewService $faviconService,
IPreviewService $screenshotService,
ITimeFactory $timeFactory
) {
parent::__construct($appName, $request);
@ -54,6 +55,7 @@ class InternalBookmarkController extends ApiController {
$this->libBookmarks = $bookmarks;
$this->previewService = $previewService;
$this->faviconService = $faviconService;
$this->screenshotService = $screenshotService;
$this->timeFactory = $timeFactory;
}
@ -206,11 +208,16 @@ class InternalBookmarkController extends ApiController {
public function getBookmarkImage($id) {
$bookmark = $this->libBookmarks->findUniqueBookmark($id, $this->userId);
$image = $this->previewService->getImage($bookmark);
if (!isset($image)) {
return new NotFoundResponse();
if (isset($image)) {
return $this->doImageResponse($image);
}
return $this->doImageResponse($image);
$image = $this->screenshotService->getImage($bookmark);
if (isset($image)) {
return $this->doImageResponse($image);
}
return new NotFoundResponse();
}
/**

View File

@ -191,10 +191,12 @@ button span,
background-color: rgb(210, 210, 210);
background-size: cover;
background-position: center;
box-shadow: inset 0 0 150px rgba(0, 0, 0, 0.65);
}
.bookmark-card:hover {
box-shadow: 0 1px 10px rgba(77, 77, 77, 0.75);
box-shadow: inset 0 0 150px rgba(0, 0, 0, 0.75) 0 1px 10px
rgba(77, 77, 77, 0.75);
opacity: 1;
}
@ -229,27 +231,30 @@ button span,
bottom: 0;
left: 0;
right: 0;
padding: 0.5cm 0.5cm 0.2cm;
padding: 1cm 0.5cm 0.2cm 0.5cm;
background: -moz-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.4) 40%,
rgba(0, 0, 0, 0.65) 100%
);
background: -webkit-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.4) 40%,
rgba(0, 0, 0, 0.65) 100%
);
background: linear-gradient(
to bottom,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.4) 40%,
rgba(0, 0, 0, 0.65) 100%
);
}
.bookmark-card .popovermenu {
position: absolute;
top: 1.5cm;
top: 2cm;
right: 0.1cm;
margin-right: -4px;
}
@ -258,7 +263,7 @@ button span,
background-color: transparent;
border: none;
position: absolute;
top: 0.6cm;
top: 1.1cm;
right: 0.1cm;
}

68
img/bookmarks-black.svg Normal file
View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="32"
width="32"
viewBox="0 0 32 32"
version="1.1"
id="svg10"
sodipodi:docname="bookmarks-black.svg"
inkscape:version="0.92.3 (2405546, 2018-03-11)">
<metadata
id="metadata16">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs14" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="792"
inkscape:window-height="480"
id="namedview12"
showgrid="false"
inkscape:zoom="7.375"
inkscape:cx="16"
inkscape:cy="16"
inkscape:window-x="477"
inkscape:window-y="184"
inkscape:window-maximized="0"
inkscape:current-layer="g8" />
<g
transform="translate(0,16)"
fill="#fff"
id="g8">
<path
d="m16-14c0.94487 0 3.9911 7.9919 4.7555 8.5752 0.76441 0.5833 8.9427 1.1565 9.2346 2.1003 0.29198 0.9438-6.0036 6.4562-6.2956 7.4-0.29198 0.9438 2.3984 9.2899 1.6339 9.8732-0.764 0.583-8.383-4.002-9.328-4.002-0.94487 0-8.5641 4.585-9.3285 4.0017-0.7644-0.584 1.9259-8.9297 1.6339-9.8735s-6.5875-6.4562-6.2956-7.4c0.292-0.9438 8.4702-1.517 9.2342-2.1003 0.765-0.5833 3.811-8.5752 4.756-8.5752z"
id="path2"
style="fill:#000000" />
<path
opacity=".3"
d="m88-14c0.94487 0 3.9911 7.9919 4.7555 8.5752 0.76441 0.5833 8.9427 1.1565 9.2346 2.1003 0.29198 0.9438-6.0036 6.4562-6.2956 7.4-0.29198 0.9438 2.3984 9.2899 1.6339 9.8732-0.764 0.583-8.383-4.002-9.328-4.002-0.94487 0-8.5641 4.585-9.3285 4.0017-0.76441-0.5833 1.9259-8.9294 1.6339-9.8732-0.29198-0.9438-6.5875-6.4562-6.2956-7.4 0.29198-0.9438 8.4702-1.517 9.2346-2.1003 0.76441-0.5833 3.8106-8.5752 4.7555-8.5752z"
id="path4" />
<path
opacity=".7"
d="m34.344 13.406c-0.172 0.088-0.315 0.187-0.344 0.282-0.28187 0.91113 5.5814 6.0441 6.25 7.25 0.06311-0.4005 0.10474-0.73846 0.0625-0.875-0.24735-0.79953-4.7593-4.8544-5.9688-6.6562zm27.312 0c-1.2095 1.8019-5.7214 5.8567-5.9688 6.6562-0.04224 0.13654-0.00061 0.4745 0.0625 0.875 0.66855-1.2059 6.5319-6.3389 6.25-7.25-0.0292-0.09438-0.17213-0.1939-0.34375-0.28125zm-13.656 12.532c-0.94487 0-8.5793 4.5833-9.3438 4-0.03185-0.0243-0.04218-0.07484-0.0625-0.125-0.06113 0.57179-0.08345 1.0136 0.0625 1.125 0.76442 0.5833 8.3989-4 9.3438-4 0.94487 0 8.5793 4.5833 9.3438 4 0.14595-0.11137 0.12363-0.55321 0.0625-1.125-0.02032 0.05016-0.03065 0.1007-0.0625 0.125-0.76441 0.5833-8.3989-4-9.3438-4z"
transform="translate(0,-16)"
id="path6" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

47
settings/adminsection.php Normal file
View File

@ -0,0 +1,47 @@
<?php
namespace OCA\Bookmarks\Settings;
use OCP\IL10N;
use OCP\Settings\IIconSection;
class AdminSection implements IIconSection {
/** @var IL10N */
private $l;
public function __construct(IL10N $l) {
$this->l = $l;
}
/**
* returns the ID of the section. It is supposed to be a lower case string
*
* @returns string
*/
public function getID() {
return 'bookmarks';
}
/**
* returns the translated name as it should be displayed, e.g. 'LDAP / AD
* integration'. Use the L10N service to translate it.
*
* @return string
*/
public function getName() {
return $this->l->t('Bookmarks');
}
public function getIcon() {
return '/custom_apps/bookmarks/img/bookmarks-black.svg';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the settings navigation. The sections are arranged in ascending order of
* the priority values. It is required to return a value between 0 and 99.
*/
public function getPriority() {
return 80;
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace OCA\Bookmarks\Settings;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\Settings\ISettings;
class AdminSettings implements ISettings {
/** @var IConfig */
private $config;
/** @var IL10N */
private $l;
/**
* Admin constructor.
*
* @param IConfig $config
* @param IL10N $l
*/
public function __construct(
IConfig $config,
IL10N $l
) {
$this->config = $config;
$this->l = $l;
}
/**
* @return TemplateResponse
*/
public function getForm() {
$parameters = [
'previews.screenly.url' => $this->config->getAppValue('bookmarks', 'previews.screenly.url', 'http://screeenly.com/api/v1/fullsize'),
'previews.screenly.token' => $this->config->getAppValue('bookmarks', 'previews.screenly.token', '')
];
return new TemplateResponse('bookmarks', 'admin', $parameters);
}
/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'bookmarks';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*/
public function getPriority() {
return 50;
}
}

30
templates/admin.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/** @var $l \OCP\IL10N */
/** @var $_ array */
script('bookmarks', 'admin');
?>
<div id="bookmarks" class="section">
<h2><?php p($l->t('Previews')); ?></h2>
<p>
<?php p($l->t('In order to display real screenshots of your bookmarked websites, Bookmarks can use a third-party service to generate those.')); ?>
</p>
<p>
<?php print($l->t('You can either sign up for free at <a href="https://screeenly.com">screeenly.com</a> or <a href="https://github.com/stefanzweifel/screeenly">setup your own server</a>.')); ?>
</p>
<p>
<label for="bookmarks_previews_screenly_url"><?php p($l->t('Screenly API URL')); ?></label>
<input id="bookmarks_previews_screenly_url" name="bookmarks_previews_screenly_url"
type="text" style="width: 250px;" value="<?php p($_['previews.screenly.url']); ?>" />
<span class="error-status icon-error-color" style="display: inline-block"></span>
<span class="success-status icon-checkmark-color" style="display: inline-block"></span>
</p>
<p>
<label for="bookmarks_previews_screenly_token"><?php p($l->t('Screenly API key')); ?></label>
<input id="bookmarks_previews_screenly_token" name="bookmarks_previews_screenly_token"
type="text" style="width: 250px;" value="<?php p($_['previews.screenly.token']); ?>" />
<span class="error-status icon-error-color" style="display: inline-block"></span>
<span class="success-status icon-checkmark-color" style="display: inline-block"></span>
</p>
</div>