]> source.dussan.org Git - nextcloud-server.git/commitdiff
Initial work on shorter links
authorkondou <kondou@ts.unde.re>
Mon, 7 Apr 2014 21:16:25 +0000 (23:16 +0200)
committerkondou <kondou@ts.unde.re>
Thu, 4 Sep 2014 13:23:53 +0000 (15:23 +0200)
core/ajax/share.php
core/js/share.js
lib/private/share/constants.php
public.php
s.php [new file with mode: 0644]

index c6da79a8a42599b8b91b2ecaa4450eb810760be0..536f0e2ebd82b52a4025dfd6a87dac5bd8529aea 100644 (file)
@@ -46,6 +46,8 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo
                                                (!empty($_POST['expirationDate']) ? new \DateTime($_POST['expirationDate']) : null)
                                        );
 
+                                       $token = base_convert($token, 16, 36);
+
                                        if (is_string($token)) {
                                                OC_JSON::success(array('data' => array('token' => $token)));
                                        } else {
index f1652370d352ea2ddcc89e0f19734f1ab658c12e..d00b5f1ccf9fb6514a1614b98f7e2925a605665c 100644 (file)
@@ -663,6 +663,8 @@ OC.Share={
                        // TODO: use oc webroot ?
                        var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service=files&'+type+'='+encodeURIComponent(file);
                } else {
+                       // convert the token to base36
+                       //token = parseInt(token, 16).toString(36);
                        //TODO add path param when showing a link to file in a subfolder of a public link share
                        var service='';
                        if(linkSharetype === 'folder' || linkSharetype === 'file'){
@@ -672,8 +674,11 @@ OC.Share={
                        }
 
                        // TODO: use oc webroot ?
-                       var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service='+service+'&t='+token;
-
+                       if (service !== 'files') {
+                               var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 'public.php')+'?service='+service+'&t='+token;
+                       } else {
+                               var link = parent.location.protocol+'//'+location.host+OC.linkTo('', 's.php')+'?t='+token;
+                       }
                }
                $('#linkText').val(link);
                $('#linkText').show('blind');
index 4c398c43c2d62806b04eff866e04326d354e2643..cf935bd4c0e1e273393e9ddb805e20092375a061 100644 (file)
@@ -34,7 +34,7 @@ class Constants {
        const FORMAT_STATUSES = -2;
        const FORMAT_SOURCES = -3;  // ToDo Check if it is still in use otherwise remove it
 
-       const TOKEN_LENGTH = 32; // see db_structure.xml
+       const TOKEN_LENGTH = 16; // old length is 32, thus 32 in db_structure.xml
 
        protected static $shareTypeUserAndGroups = -1;
        protected static $shareTypeGroupUserUnique = 2;
index 0e04db66da79c6ada33e45b12f58363afb3e3082..b4578d991c821a2b72c84f241d252e8672ce293c 100644 (file)
@@ -36,6 +36,8 @@ try {
        \OC::$REQUESTEDAPP = $app;
        OC_App::loadApps(array('authentication'));
        OC_App::loadApps(array('filesystem', 'logging'));
+       print_r($_GET);
+       print_r($parts);
 
        OC_Util::checkAppEnabled($app);
        OC_App::loadApp($app);
diff --git a/s.php b/s.php
new file mode 100644 (file)
index 0000000..9223fd7
--- /dev/null
+++ b/s.php
@@ -0,0 +1,41 @@
+<?php
+
+try {
+
+       require_once 'lib/base.php';
+       OC::checkMaintenanceMode();
+       OC::checkSingleUserMode();
+       $file = OCP\CONFIG::getAppValue('core', 'public_files');
+       if(is_null($file)) {
+               header('HTTP/1.0 404 Not Found');
+               exit;
+       }
+
+       // convert the token to hex, if it's base36
+       if (strlen((string)$_GET['t']) != 16 && strlen((string)$_GET['t']) != 32) {
+               $_GET['t'] = base_convert($_GET['t'], 36, 16);
+
+               // the token should have leading zeroes and needs to be padded
+               if (strlen((string)$_GET['t']) != 16) {
+                       $padding = '';
+                       for ($i = 0; $i < (16 - strlen((string)$_GET['t'])); $i++) {
+                               $padding .= '0';
+                       }
+                       $_GET['t'] = $padding . $_GET['t'];
+               }
+       }
+
+       print($_GET['t']);
+
+       OC_Util::checkAppEnabled('files_sharing');
+       OC_App::loadApp('files_sharing');
+       OC_User::setIncognitoMode(true);
+
+       require_once OC_App::getAppPath('files_sharing') .'/public.php';
+
+} catch (Exception $ex) {
+       //show the user a detailed error page
+       OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR);
+       \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL);
+       OC_Template::printExceptionErrorPage($ex);
+}