]> source.dussan.org Git - nextcloud-server.git/commitdiff
show animated gifs on public sharing page
authorGeorg Ehrke <developer@georgehrke.com>
Sat, 17 Jan 2015 11:11:52 +0000 (12:11 +0100)
committerGeorg Ehrke <developer@georgehrke.com>
Mon, 19 Jan 2015 15:20:06 +0000 (16:20 +0100)
apps/files_sharing/js/public.js
apps/files_sharing/lib/controllers/sharecontroller.php
apps/files_sharing/templates/public.php
apps/files_sharing/tests/controller/sharecontroller.php
config/config.sample.php

index cbd135028f1a379d4b635d6d622cfdc1be981aa7..bec43a4fb5709ceba594982baebe3a644708d495 100644 (file)
@@ -97,7 +97,17 @@ OCA.Sharing.PublicApp = {
                };
 
                var img = $('<img class="publicpreview" alt="">');
-               if (previewSupported === 'true' || mimetype.substr(0, mimetype.indexOf('/')) === 'image' && mimetype !== 'image/svg+xml') {
+
+               var fileSize = parseInt($('#filesize').val(), 10);
+               var maxGifSize = parseInt($('#maxSizeAnimateGif').val(), 10);
+
+               if (mimetype === 'image/gif' &&
+                       (maxGifSize === -1 || fileSize <= (maxGifSize * 1024 * 1024))) {
+                       img.attr('src', $('#downloadURL').val());
+                       img.appendTo('#imgframe');
+               } else if (previewSupported === 'true' ||
+                       mimetype.substr(0, mimetype.indexOf('/')) === 'image' &&
+                       mimetype !== 'image/svg+xml') {
                        img.attr('src', OC.filePath('files_sharing', 'ajax', 'publicpreview.php') + '?' + OC.buildQueryString(params));
                        img.appendTo('#imgframe');
                } else if (mimetype.substr(0, mimetype.indexOf('/')) !== 'video') {
index 69de717611c446f3700569620c089a88b9a83698..1d8eabc198497b2fd88329321b4cd76ec2f618fc 100644 (file)
@@ -176,7 +176,9 @@ class ShareController extends Controller {
                $shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled();
                $shareTmpl['protected'] = isset($linkItem['share_with']) ? 'true' : 'false';
                $shareTmpl['dir'] = '';
-               $shareTmpl['fileSize'] = \OCP\Util::humanFileSize(\OC\Files\Filesystem::filesize($originalSharePath));
+               $nonHumanFileSize = \OC\Files\Filesystem::filesize($originalSharePath);
+               $shareTmpl['nonHumanFileSize'] = $nonHumanFileSize;
+               $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($nonHumanFileSize);
 
                // Show file list
                if (Filesystem::is_dir($originalSharePath)) {
@@ -202,6 +204,7 @@ class ShareController extends Controller {
                }
 
                $shareTmpl['downloadURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.downloadShare', array('token' => $token));
+               $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
 
                return new TemplateResponse($this->appName, 'public', $shareTmpl, 'base');
        }
index 0384d9a60aa54ef87434dcc3736248f7ba3e5f95..4ec4d264b317e4d4c443fced41db9ae6e689095e 100644 (file)
@@ -40,6 +40,8 @@ $previewSupported = OC\Preview::isMimeSupported($_['mimetype']) ? 'true' : 'fals
 <input type="hidden" name="mimetype" value="<?php p($_['mimetype']) ?>" id="mimetype">
 <input type="hidden" name="previewSupported" value="<?php p($previewSupported); ?>" id="previewSupported">
 <input type="hidden" name="mimetypeIcon" value="<?php p(OC_Helper::mimetypeIcon($_['mimetype'])); ?>" id="mimetypeIcon">
+<input type="hidden" name="filesize" value="<?php p($_['nonHumanFileSize']); ?>" id="filesize">
+<input type="hidden" name="maxSizeAnimateGif" value="<?php p($_['maxSizeAnimateGif']); ?>" id="maxSizeAnimateGif">
 
 
 <header><div id="header" class="<?php p((isset($_['folder']) ? 'share-folder' : 'share-file')) ?>">
index f13e5b2e4974c46fb011f56479a6bebb730886c3..931cd506d43926e81b89fe158358efb6b731c322 100644 (file)
@@ -155,7 +155,9 @@ class ShareControllerTest extends \PHPUnit_Framework_TestCase {
                        'protected' => 'true',
                        'dir' => '',
                        'downloadURL' => null,
-                       'fileSize' => '33 B'
+                       'fileSize' => '33 B',
+                       'nonHumanFileSize' => 33,
+                       'maxSizeAnimateGif' => 10,
                );
                $expectedResponse = new TemplateResponse($this->container['AppName'], 'public', $sharedTmplParams, 'base');
                $this->assertEquals($expectedResponse, $response);
index 98da8aed356694f13c27adfb6ed6a8692dbc3ffa..ae22f3b13550c05d8c0d69fbe605a7eaceeef597 100644 (file)
@@ -943,6 +943,16 @@ $CONFIG = array(
  */
 'forwarded_for_headers' => array('HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR'),
 
+/**
+ * max file size for animating gifs on public-sharing-site.
+ * If the gif is bigger, it'll show a static preview
+ *
+ * Value represents the maximum filesize in megabytes
+ * Default is 10
+ * Set to -1 for no limit
+ */
+'max_filesize_animated_gifs_public_sharing' => 10,
+
 /**
  * This entry is just here to show a warning in case somebody copied the sample
  * configuration. DO NOT ADD THIS SWITCH TO YOUR CONFIGURATION!