Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appinfo/application.php2
-rw-r--r--appinfo/routes.php8
-rw-r--r--controller/configcontroller.php36
-rw-r--r--controller/previewcontroller.php14
-rw-r--r--controller/publicconfigcontroller.php4
-rw-r--r--controller/publicpreviewcontroller.php11
-rw-r--r--js/app.js13
-rw-r--r--js/gallery.js17
-rw-r--r--js/galleryconfig.js23
-rw-r--r--js/galleryfileaction.js17
-rw-r--r--service/configparser.php8
-rw-r--r--service/configservice.php2
-rw-r--r--service/previewservice.php15
13 files changed, 81 insertions, 89 deletions
diff --git a/appinfo/application.php b/appinfo/application.php
index 538890af..6b38651d 100644
--- a/appinfo/application.php
+++ b/appinfo/application.php
@@ -79,6 +79,7 @@ class Application extends App {
$c->query('AppName'),
$c->query('Request'),
$c->query('ConfigService'),
+ $c->query('PreviewService'),
$c->query('Logger')
);
}
@@ -89,6 +90,7 @@ class Application extends App {
$c->query('AppName'),
$c->query('Request'),
$c->query('ConfigService'),
+ $c->query('PreviewService'),
$c->query('Logger')
);
}
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 76e3a8e6..9ed88ccf 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -65,18 +65,12 @@ return [
/**
* Services
*/
- // Gallery config
+ // Gallery config, as well as supported media types
[
'name' => 'config#get_config',
'url' => '/config',
'verb' => 'GET'
],
- // Supported media types. Only called by the slideshow
- [
- 'name' => 'preview#get_media_types',
- 'url' => '/mediatypes',
- 'verb' => 'GET'
- ],
// All the images of which a preview can be generated
[
'name' => 'files#get_files',
diff --git a/controller/configcontroller.php b/controller/configcontroller.php
index 828deb30..689fa2e0 100644
--- a/controller/configcontroller.php
+++ b/controller/configcontroller.php
@@ -19,6 +19,7 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCA\GalleryPlus\Service\ConfigService;
+use OCA\GalleryPlus\Service\PreviewService;
/**
* Class ConfigController
@@ -34,6 +35,10 @@ class ConfigController extends Controller {
*/
private $configService;
/**
+ * @var PreviewService
+ */
+ private $previewService;
+ /**
* @var ILogger
*/
private $logger;
@@ -44,17 +49,20 @@ class ConfigController extends Controller {
* @param string $appName
* @param IRequest $request
* @param ConfigService $configService
+ * @param PreviewService $previewService
* @param ILogger $logger
*/
public function __construct(
$appName,
IRequest $request,
ConfigService $configService,
+ PreviewService $previewService,
ILogger $logger
) {
parent::__construct($appName, $request);
$this->configService = $configService;
+ $this->previewService = $previewService;
$this->logger = $logger;
}
@@ -63,21 +71,35 @@ class ConfigController extends Controller {
*
* Returns an app configuration array
*
+ * @param bool $slideshow
+ *
* @return array
*/
- public function getConfig() {
- return $this->getFeaturesList();
+ public function getConfig($slideshow = false) {
+ $features = $this->configService->getFeaturesList();
+ $nativeSvgSupport = $this->isNativeSvgActivated($features);
+ $mediaTypes = $this->previewService->getSupportedMediaTypes($slideshow, $nativeSvgSupport);
+
+ return ['features' => $features, 'mediatypes' => $mediaTypes];
}
/**
- * @NoAdminRequired
+ * Determines if the native SVG feature has been activated
*
- * Returns a list of supported features
+ * @param array $features
*
- * @return array
+ * @return bool
*/
- private function getFeaturesList() {
- return $this->configService->getFeaturesList();
+ private function isNativeSvgActivated($features) {
+ $nativeSvgSupport = false;
+ if (!empty($features)
+ && array_key_exists('native_svg', $features)
+ && $features['native_svg'] === 'yes'
+ ) {
+ $nativeSvgSupport = true;
+ }
+
+ return $nativeSvgSupport;
}
}
diff --git a/controller/previewcontroller.php b/controller/previewcontroller.php
index 22f290f2..e4843b41 100644
--- a/controller/previewcontroller.php
+++ b/controller/previewcontroller.php
@@ -103,20 +103,6 @@ class PreviewController extends Controller {
/**
* @NoAdminRequired
*
- * Sends back a list of all media types supported by the system, as well as the name of their
- * icon
- *
- * @param bool $slideshow
- *
- * @return array <string,string>|null
- */
- public function getMediaTypes($slideshow = false) {
- return $this->previewService->getSupportedMediaTypes($slideshow);
- }
-
- /**
- * @NoAdminRequired
- *
* Generates thumbnails
*
* Uses EventSource to send thumbnails back as soon as they're created
diff --git a/controller/publicconfigcontroller.php b/controller/publicconfigcontroller.php
index 71a738f1..fa1506d6 100644
--- a/controller/publicconfigcontroller.php
+++ b/controller/publicconfigcontroller.php
@@ -29,8 +29,8 @@ class PublicConfigController extends ConfigController {
*
* @inheritDoc
*/
- public function getConfig() {
- return parent::getConfig();
+ public function getConfig($slideshow = false) {
+ return parent::getConfig($slideshow);
}
}
diff --git a/controller/publicpreviewcontroller.php b/controller/publicpreviewcontroller.php
index 6686e89e..66f4e790 100644
--- a/controller/publicpreviewcontroller.php
+++ b/controller/publicpreviewcontroller.php
@@ -24,17 +24,6 @@ class PublicPreviewController extends PreviewController {
/**
* @PublicPage
- *
- * @inheritDoc
- *
- * @param bool $slideshow
- */
- public function getMediaTypes($slideshow = false) {
- return parent::getMediaTypes($slideshow);
- }
-
- /**
- * @PublicPage
* @UseSession
*
* Generates thumbnails for public galleries
diff --git a/js/app.js b/js/app.js
index ba377a3e..0c3068cd 100644
--- a/js/app.js
+++ b/js/app.js
@@ -21,16 +21,9 @@ $(document).ready(function () {
$.getJSON(Gallery.utility.buildGalleryUrl('config', '', {}))
.then(function (config) {
Gallery.config = new Gallery.Config(config);
- $.getJSON(Gallery.utility.buildGalleryUrl('mediatypes', '', {}))
- .then(function (mediaTypes) {
- //console.log('mediaTypes', mediaTypes);
- Gallery.mediaTypes = mediaTypes;
- })
- .then(function () {
- Gallery.getFiles().then(function () {
- window.onhashchange();
- });
- });
+ Gallery.getFiles().then(function () {
+ window.onhashchange();
+ });
});
$('#openAsFileListButton').click(function () {
diff --git a/js/gallery.js b/js/gallery.js
index fb4079ed..6ae54ed6 100644
--- a/js/gallery.js
+++ b/js/gallery.js
@@ -1,6 +1,5 @@
/* global OC, $, t, Album, GalleryImage, SlideShow, oc_requesttoken */
var Gallery = {};
-Gallery.mediaTypes = {};
Gallery.images = [];
Gallery.currentAlbum = null;
Gallery.config = {};
@@ -11,20 +10,6 @@ Gallery.appName = 'galleryplus';
Gallery.token = undefined;
/**
- * Returns a list of supported media types
- *
- * @returns {string}
- */
-Gallery.getMediaTypes = function () {
- var types = '';
- for (var i = 0, keys = Object.keys(Gallery.mediaTypes); i < keys.length; i++) {
- types += keys[i] + ';';
- }
-
- return types.slice(0, -1);
-};
-
-/**
* Builds a map of the albums located in the current folder
*
* @param {string} path
@@ -84,7 +69,7 @@ Gallery.getFiles = function () {
}
var params = {
location: currentLocation,
- mediatypes: Gallery.getMediaTypes(),
+ mediatypes: Gallery.config.getMediaTypes(),
features: Gallery.config.galleryFeatures,
etag: albumEtag
};
diff --git a/js/galleryconfig.js b/js/galleryconfig.js
index b76bd670..ae8d57a8 100644
--- a/js/galleryconfig.js
+++ b/js/galleryconfig.js
@@ -7,11 +7,14 @@
* @constructor
*/
var Config = function (config) {
- this.galleryFeatures = this.setGalleryFeatures(config);
+ this.galleryFeatures = this.setGalleryFeatures(config.features);
+ this.mediaTypes = config.mediatypes;
};
Config.prototype = {
galleryFeatures: [],
+ mediaTypes: {},
+ cachedMediaTypesString: '',
albumPermissions: null,
albumInfo: null,
albumSorting: null,
@@ -39,6 +42,24 @@
},
/**
+ * Returns the list of supported media types in a string
+ *
+ * @returns {string}
+ */
+ getMediaTypes: function () {
+ if (this.cachedMediaTypesString === '') {
+ var types = '';
+ for (var i = 0, keys = Object.keys(this.mediaTypes); i < keys.length; i++) {
+ types += keys[i] + ';';
+ }
+
+ this.cachedMediaTypesString = types.slice(0, -1);
+ }
+
+ return this.cachedMediaTypesString;
+ },
+
+ /**
* Stores the configuration about the current album
*
* @param albumConfig
diff --git a/js/galleryfileaction.js b/js/galleryfileaction.js
index 30a71a81..7ff9d3bf 100644
--- a/js/galleryfileaction.js
+++ b/js/galleryfileaction.js
@@ -63,10 +63,10 @@ var galleryFileAction = {
var height = Math.floor(screen.height * window.devicePixelRatio);
/* Find value of longest edge. */
- var longEdge = Math.max( width, height );
+ var longEdge = Math.max(width, height);
/* Find the next larger image size. */
- if ( longEdge % 100 !== 0 ){
+ if (longEdge % 100 !== 0) {
longEdge = ( longEdge + 100 ) - ( longEdge % 100 );
}
@@ -118,14 +118,13 @@ $(document).ready(function () {
return true;
}
- var url = galleryFileAction.buildGalleryUrl('config', '', {});
+ // We're also asking for a list of supported media types.
+ // Media files are retrieved through the Files context
+ var url = galleryFileAction.buildGalleryUrl('config', '', {slideshow: 1});
$.getJSON(url).then(function (config) {
- if (config) {
- galleryFileAction.config = config;
+ if (!$.isEmptyObject(config.features)) {
+ galleryFileAction.config = config.features;
}
- url = galleryFileAction.buildGalleryUrl('mediatypes', '', {slideshow: 1});
- // We're asking for a list of supported media types.
- // Media files are retrieved through the Files context
- $.getJSON(url, {}, galleryFileAction.register);
+ galleryFileAction.register(config.mediatypes);
});
});
diff --git a/service/configparser.php b/service/configparser.php
index 92ca90a0..6305d029 100644
--- a/service/configparser.php
+++ b/service/configparser.php
@@ -32,15 +32,15 @@ class ConfigParser {
*
* @return null|array
*/
- public function getGlobalConfig($folder, $configName) {
- $config = [];
+ public function getFeaturesList($folder, $configName) {
+ $featuresList = [];
$parsedConfig = $this->parseConfig($folder, $configName);
$key = 'features';
if (array_key_exists('features', $parsedConfig)) {
- $config = [$key => $parsedConfig[$key]];
+ $featuresList = $parsedConfig[$key];
}
- return $config;
+ return $featuresList;
}
/**
diff --git a/service/configservice.php b/service/configservice.php
index 1efafc67..b450fd11 100644
--- a/service/configservice.php
+++ b/service/configservice.php
@@ -75,7 +75,7 @@ class ConfigService extends FilesService {
if ($rootFolder && $rootFolder->nodeExists($this->configName)) {
try {
$featuresList =
- $this->configParser->getGlobalConfig($rootFolder, $this->configName);
+ $this->configParser->getFeaturesList($rootFolder, $this->configName);
} catch (ServiceException $exception) {
$featuresList = $this->buildErrorMessage($exception, $rootFolder);
}
diff --git a/service/previewservice.php b/service/previewservice.php
index 825b0980..f17f089e 100644
--- a/service/previewservice.php
+++ b/service/previewservice.php
@@ -85,10 +85,11 @@ class PreviewService extends Service {
* @todo Native SVG could be disabled via admin settings
*
* @param bool $slideshow
+ * @param bool $nativeSvgSupport
*
- * @return string[] all supported media types
+ * @return \string[] all supported media types
*/
- public function getSupportedMediaTypes($slideshow) {
+ public function getSupportedMediaTypes($slideshow, $nativeSvgSupport) {
$supportedMimes = [];
$wantedMimes = $this->baseMimeTypes;
if ($slideshow) {
@@ -102,7 +103,7 @@ class PreviewService extends Service {
$pathToIcon; // We add it to the list of supported media types
}
}
- $supportedMimes = $this->addSvgSupport($supportedMimes);
+ $supportedMimes = $this->addSvgSupport($supportedMimes, $nativeSvgSupport);
//$this->logger->debug("Supported Mimes: {mimes}", ['mimes' => $supportedMimes]);
return $supportedMimes;
@@ -208,12 +209,12 @@ class PreviewService extends Service {
* preview. If it's disabled, we support it via the browser's native support
*
* @param string[] $supportedMimes
+ * @param bool $nativeSvgSupport
*
- * @return string[]
+ * @return \string[]
*/
- private function addSvgSupport($supportedMimes) {
-
- if (!in_array('image/svg+xml', $supportedMimes)) {
+ private function addSvgSupport($supportedMimes, $nativeSvgSupport) {
+ if (!in_array('image/svg+xml', $supportedMimes) && $nativeSvgSupport) {
$supportedMimes['image/svg+xml'] = Template::mimetype_icon('image/svg+xml');
}