Skip to content

Commit 05ed010

Browse files
committed
Add URL_STRIP_EXTENSION constant (#2)
This small update allows users to remove the file extension from the resulting URL, as requested. This is useful for instances using a rewrite rule in order to automatically find the corresponding file. Be careful, as the filename generator only checks against existing files of the same extension. It is therefore possible to have two files with the exact same name, as long as they have a different extension. Version bumped to 2.3.0
1 parent 150596d commit 05ed010

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

sharexen.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
// Example: ['Mario', 'Toad'] (sorry Luigi)
6565
define('ADMINS', []);
6666

67+
// Strip file extensions from generated URLs
68+
// This is only useful if you have a rewrite rule
69+
define('URL_STRIP_EXTENSION', false);
70+
6771
// Log requests to Discord using a webhook
6872
// If you do not know what this is about, please ignore
6973
// It is not recommended to set this if your API is heavily used
@@ -180,6 +184,16 @@ function check_constants()
180184
'Invalid ADMINS constant, must be an array.');
181185
}
182186

187+
if (!defined('URL_STRIP_EXTENSION'))
188+
{
189+
define('URL_STRIP_EXTENSION', false);
190+
}
191+
if (gettype(URL_STRIP_EXTENSION) !== 'boolean')
192+
{
193+
error_die($data, 500, 'invalid_server_configuration',
194+
'Invalid URL_STRIP_EXTENSION constant, must be a boolean.');
195+
}
196+
183197
if (!defined('DISCORD_WEBHOOK_URL'))
184198
{
185199
define('DISCORD_WEBHOOK_URL', '');
@@ -466,6 +480,11 @@ function generate_all_urls(&$data, $deletion = true)
466480

467481
$data['url'] = "$protocol$domain$sub$name";
468482

483+
if (URL_STRIP_EXTENSION)
484+
{
485+
$data['url'] = preg_replace('/\.[^.]+$/', '', $data['url']);
486+
}
487+
469488
if (!$deletion)
470489
{
471490
return;
@@ -741,7 +760,7 @@ function info_endpoint(&$data)
741760
}
742761
}
743762

744-
define('VERSION', '2.2.1');
763+
define('VERSION', '2.3.0');
745764
define('SOURCE', 'https://github.com/Xenthys/ShareXen');
746765

747766
$data = [

0 commit comments

Comments
 (0)