diff --git a/appinfo/info.xml b/appinfo/info.xml
index 21b3d3a98..6c38c603b 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -34,7 +34,7 @@
files app and adds a gallery view to public links.
Compatible with Firefox, Chrome and Internet Explorer 11
- 18.3.0
+ 18.3.1
agpl
Olivier Paroz, Robin Appelman
Gallery
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 7c968905c..0941b53d7 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -96,6 +96,16 @@
'url' => '/preview/{fileId}',
'verb' => 'GET'
],
+ [
+ 'name' => 'preview#get_modifications',
+ 'url' => '/preview/modifications/{fileId}',
+ 'verb' => 'GET'
+ ],
+ [
+ 'name' => 'preview#set_modifications',
+ 'url' => '/preview/modifications/{fileId}',
+ 'verb' => 'POST'
+ ],
/**
* Public services
*/
diff --git a/js/slideshow.js b/js/slideshow.js
index 576ce70be..177f9bb7f 100644
--- a/js/slideshow.js
+++ b/js/slideshow.js
@@ -26,6 +26,7 @@
zoomablePreviewContainer: null,
controls: null,
imageCache: {},
+ imageModificationsCache: {},
/** {Image} */
currentImage: null,
errorLoadingImage: false,
@@ -36,6 +37,7 @@
// We need 6 hexas for comparison reasons
darkBackgroundColour: '#000000',
lightBackgroundColour: '#ffffff',
+ currentRotation: 0,
/**
* Initialises the slideshow
@@ -135,6 +137,7 @@
* @returns {*}
*/
show: function (index) {
+ this.currentImageIndex = index;
this.hideErrorNotification();
this.active = true;
this.container.show();
@@ -143,7 +146,9 @@
this._hideImage();
this.container.find('.icon-loading-dark').show();
var currentImageId = index;
- return this.loadImage(this.images[index]).then(function (img) {
+ return this.loadImage(this.images[index]).then(function (results) {
+ var img = results[0];
+ var params = results[1];
this.container.css('background-position', '-10000px 0');
// check if we moved along while we were loading
@@ -162,6 +167,13 @@
}
this.zoomablePreview.startBigshot(img, this.currentImage, image.mimeType);
+ this.currentRotation = 0;
+ for (var i=0;iregisterService(
+ 'FilePropertiesService', function (IContainer $c) {
+ return new FilePropertiesService(
+ $c->query('AppName'),
+ $c->query('Environment'),
+ $c->query('Logger'),
+ $c->query('FilePropertiesMapper')
+ );
+ }
+ );
+ $container->registerService(
+ 'FilePropertiesMapper', function (IContainer $c) {
+ return new FilePropertiesMapper(
+ $c->query('ServerContainer')->getDatabaseConnection()
+ );
+ }
+ );
$container->registerService(
'PageController', function (IContainer $c) {
return new PageController(
@@ -169,6 +188,7 @@ public function __construct(array $urlParams = []) {
$c->query('ThumbnailService'),
$c->query('PreviewService'),
$c->query('DownloadService'),
+ $c->query('FilePropertiesService'),
$c->query('EventSource'),
$c->query('Logger')
);
diff --git a/lib/Controller/Preview.php b/lib/Controller/Preview.php
index 06f4cbcd4..361cb16fd 100644
--- a/lib/Controller/Preview.php
+++ b/lib/Controller/Preview.php
@@ -83,7 +83,7 @@ private function getThumbnail($fileId, $square, $scale) {
/** @type File $file */
list($file, $preview, $status) =
$this->getData(
- $fileId, $width, $height, $aspect, $animatedPreview, $base64Encode
+ $fileId, null, $width, $height, $aspect, $animatedPreview, $base64Encode
);
if ($preview === null) {
$preview = $this->prepareEmptyThumbnail($file, $status);
@@ -107,17 +107,19 @@ private function getThumbnail($fileId, $square, $scale) {
* @throws NotFoundServiceException
*/
private function getData(
- $fileId, $width, $height, $keepAspect = true, $animatedPreview = true, $base64Encode = false
+ $fileId, $etag, $width, $height, $keepAspect = true, $animatedPreview = true, $base64Encode = false
) {
/** @type File $file */
list($file, $status) = $this->getFile($fileId);
try {
- if (!is_null($file)) {
+ if (is_null($file)) {
+ $data = $this->getErrorData($status);
+ } else if (!is_null($etag) && $etag === $file->getEtag()) {
+ $data = [null, Http::STATUS_NOT_MODIFIED];
+ } else {
$data = $this->getPreviewData(
$file, $animatedPreview, $width, $height, $keepAspect, $base64Encode
);
- } else {
- $data = $this->getErrorData($status);
}
} catch (ServiceException $exception) {
$data = $this->getExceptionData($exception);
diff --git a/lib/Controller/PreviewApiController.php b/lib/Controller/PreviewApiController.php
index 51f7eb43b..34f05d00a 100644
--- a/lib/Controller/PreviewApiController.php
+++ b/lib/Controller/PreviewApiController.php
@@ -123,7 +123,7 @@ public function getThumbnails($ids, $square, $scale) {
*/
public function getPreview($fileId, $width, $height, $nativesvg = false) {
/** @type File $file */
- list($file, $preview, $status) = $this->getData($fileId, $width, $height);
+ list($file, $preview, $status) = $this->getData($fileId, null, $width, $height);
if (!$preview) {
return new JSONResponse(
diff --git a/lib/Controller/PreviewController.php b/lib/Controller/PreviewController.php
index 576f7a8f8..aef996f67 100644
--- a/lib/Controller/PreviewController.php
+++ b/lib/Controller/PreviewController.php
@@ -27,6 +27,7 @@
use OCA\Gallery\Service\ThumbnailService;
use OCA\Gallery\Service\PreviewService;
use OCA\Gallery\Service\DownloadService;
+use OCA\Gallery\Service\FilePropertiesService;
use OCA\Gallery\Utility\EventSource;
/**
@@ -62,6 +63,7 @@ public function __construct(
ThumbnailService $thumbnailService,
PreviewService $previewService,
DownloadService $downloadService,
+ FilePropertiesService $filePropertiesService,
EventSource $eventSource,
ILogger $logger
) {
@@ -72,6 +74,7 @@ public function __construct(
$this->thumbnailService = $thumbnailService;
$this->previewService = $previewService;
$this->downloadService = $downloadService;
+ $this->filePropertiesService = $filePropertiesService;
$this->eventSource = $eventSource;
$this->logger = $logger;
}
@@ -127,13 +130,12 @@ public function getThumbnails($ids, $square, $scale) {
*/
public function getPreview($fileId, $width, $height) {
/** @type File $file */
- list($file, $status) = $this->getFile($fileId);
- if ($this->request->getHeader('If-None-Match') === $file->getEtag()) {
- return new DataResponse([], Http::STATUS_NOT_MODIFIED);
- }
- list($file, $preview, $status) = $this->getData($fileId, $width, $height);
+ list($file, $preview, $status) = $this->getData($fileId, $this->request->getHeader('If-None-Match'), $width, $height);
if (!$preview) {
+ if ($status === Http::STATUS_NOT_MODIFIED) {
+ return new DataResponse([], Http::STATUS_NOT_MODIFIED);
+ }
return new JSONResponse(
[
'message' => "I'm truly sorry, but we were unable to generate a preview for this file",
@@ -152,4 +154,13 @@ public function getPreview($fileId, $width, $height) {
return $response;
}
+ public function setModifications($fileId) {
+ $requestBody = file_get_contents('php://input');
+ $this->filePropertiesService->setModifications($fileId, $requestBody);
+ }
+
+ public function getModifications($fileId) {
+ return new DataResponse(json_decode($this->filePropertiesService->getModifications($fileId)), 200);
+ }
+
}
diff --git a/lib/Db/FileProperties.php b/lib/Db/FileProperties.php
new file mode 100644
index 000000000..b16b35305
--- /dev/null
+++ b/lib/Db/FileProperties.php
@@ -0,0 +1,8 @@
+findEntity($sql, [$id]);
+ }
+
+ public function findAll($limit=null, $offset=null) {
+ $sql = 'SELECT * FROM `*PREFIX*gallery_file_properties`';
+ return $this->findEntities($sql, $limit, $offset);
+ }
+}
diff --git a/lib/Migration/Version1803Date20181208221653.php b/lib/Migration/Version1803Date20181208221653.php
new file mode 100644
index 000000000..8891576cf
--- /dev/null
+++ b/lib/Migration/Version1803Date20181208221653.php
@@ -0,0 +1,54 @@
+hasTable('gallery_file_properties')) {
+ $table = $schema->createTable('gallery_file_properties');
+ $table->addColumn('id', 'integer', [
+ 'notnull' => true,
+ ]);
+ $table->addColumn('modifications', 'string', [
+ 'notnull' => false,
+ ]);
+ }
+ return $schema;
+ }
+
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ */
+ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
+ }
+}
diff --git a/lib/Service/FilePropertiesService.php b/lib/Service/FilePropertiesService.php
new file mode 100644
index 000000000..b9c14db17
--- /dev/null
+++ b/lib/Service/FilePropertiesService.php
@@ -0,0 +1,43 @@
+mapper = $mapper;
+ }
+
+ public function getModifications($fileId) {
+ try {
+ $entity = $this->mapper->find($fileId);
+ return $entity->getModifications();
+ } catch (DoesNotExistException $ex) {
+ return "{}";
+ }
+ }
+
+ public function setModifications($fileId, $modificationsJson) {
+ try {
+ $entity = $this->mapper->find($fileId);
+ $entity->setModifications($modificationsJson);
+ $this->mapper->update($entity);
+ } catch (DoesNotExistException $ex) {
+ $entity = new FileProperties();
+ $entity->setId($fileId);
+ $entity->setModifications($modificationsJson);
+ $this->mapper->insert($entity);
+ }
+ }
+}
diff --git a/templates/slideshow.php b/templates/slideshow.php
index 4115cb103..bdc20b0d6 100644
--- a/templates/slideshow.php
+++ b/templates/slideshow.php
@@ -7,6 +7,10 @@