From: Florian <7305144-fm-sys@users.noreply.gitlab.com> Date: Sat, 30 Aug 2025 12:13:45 +0000 (+0000) Subject: add short link support X-Git-Tag: 4.7.0~4^2 X-Git-Url: https://git.p6c8.net/jirafeau/jirafeau.git/commitdiff_plain/97971a35ce678939f577c4fc44c054ef98c72f0b add short link support --- diff --git a/.gitignore b/.gitignore index 4c13bde..02ef59e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ composer.phar .* !.gitlab-ci.yml !.gitignore -!.dockerignore \ No newline at end of file +!.dockerignore +!.htaccess.sample \ No newline at end of file diff --git a/.htaccess.sample b/.htaccess.sample new file mode 100644 index 0000000..98d1d80 --- /dev/null +++ b/.htaccess.sample @@ -0,0 +1,7 @@ + + RewriteEngine On + + # Match URLs with an 8-character alphanumeric ID + RewriteRule ^([a-zA-Z0-9_-]{8})$ f.php?h=$1 [L,QSA] + + diff --git a/lib/config.original.php b/lib/config.original.php index 8aec857..876ddba 100644 --- a/lib/config.original.php +++ b/lib/config.original.php @@ -34,6 +34,13 @@ $cfg['web_root'] = ''; */ $cfg['var_root'] = ''; +/* Activating 'use_shortlinks' will allow you to use shortened download links + * This requires a web server that supports URL rewriting, like Apache with mod_rewrite. + * If you are using Apache, copy the provided '.htaccess.sample' file in the root directory of + * Jirafeau and store it as '.htaccess'. For other web servers, manual configuration is required. + */ +$cfg['use_shortlinks'] = false; + /* Language - choose between 'auto' or any language located in the /lib/locales/ folder. * The mode »auto« will cause the script to detect the user's browser information * and offer a matching language, or use »en« if it is not available. diff --git a/lib/functions.js.php b/lib/functions.js.php index b8888a6..29d50c1 100644 --- a/lib/functions.js.php +++ b/lib/functions.js.php @@ -25,7 +25,9 @@ function template_js_preview_link() if (!!document.getElementById('preview_link')) { document.getElementById('upload_finished_preview').style.display = 'none'; - var preview_link_href = 'f.php?h=' + reference + '&p=1'; + var preview_link_href = use_shortlinks ? '' : 'f.php?h='; + preview_link_href += reference; + preview_link_href += use_shortlinks ? '?p=1' : '&p=1'; if (crypt_key.length > 0) { preview_link_href += '&k=' + crypt_key; @@ -50,10 +52,12 @@ function template_js_download_page() { ?> // Download page - var download_link_href = 'f.php?h=' + reference; + var download_link_href = use_shortlinks ? '' : 'f.php?h='; + download_link_href += reference; if (crypt_key.length > 0) { - download_link_href += '&k=' + crypt_key; + download_link_href += use_shortlinks ? '?k=' : '&k=' + download_link_href += crypt_key; } if (!!document.getElementById('upload_finished_download_page')) { @@ -79,7 +83,10 @@ function template_js_delete_link() { ?> // Delete link - var delete_link_href = 'f.php?h=' + reference + '&d=' + delete_code; + var delete_link_href = use_shortlinks ? '' : 'f.php?h='; + delete_link_href += reference; + delete_link_href += use_shortlinks ? '?d=' : '&d='; + delete_link_href += delete_code; document.getElementById('delete_link').href = delete_link_href; document.getElementById('delete_link_text').innerHTML = web_root + delete_link_href; // Direct download link - var direct_download_link_href = 'f.php?h=' + reference + '&d=1'; + //var direct_download_link_href = 'f.php?h=' + reference + '&d=1'; + var direct_download_link_href = use_shortlinks ? '' : 'f.php?h='; + direct_download_link_href += reference; + direct_download_link_href += use_shortlinks ? '?d=1' : '&d=1'; if (crypt_key.length > 0) { direct_download_link_href += '&k=' + crypt_key; @@ -132,6 +142,7 @@ require(JIRAFEAU_ROOT . 'lib/lang.php'); ?> // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later var web_root = ""; +var use_shortlinks = ; var lang_array = ; var lang_array_fallback = ;