Verified Commit f73fc7c8 authored by Luc Didry's avatar Luc Didry
Browse files

💄 — Make a distinction between inexistant and disabled URLs

parent 7d2dbfc2
Pipeline #410048 passed with stages
in 7 minutes and 1 second
......@@ -4,6 +4,7 @@ Revision history for Perl application Lstu
0.23-1 2021-04-??
- Fix disabled URLs still showing in admin interface (#79)
- Make a distinction between inexistant and disabled URLs
0.23-0 2021-04-26
- Update translations
......
......@@ -185,15 +185,24 @@ sub get {
}
my $url;
my $disabled_url = 0;
if (scalar(@{$c->config('memcached_servers')})) {
$url = $c->chi('lstu_urls_cache')->compute($short, undef, sub {
my $db_url = Lstu::DB::URL->new(app => $c, short => $short);
return $db_url->url unless $db_url->disabled;
return undef;
if ($db_url->disabled) {
$disabled_url++;
return undef
} else {
return $db_url->url;
}
});
} else {
my $db_url = Lstu::DB::URL->new(app => $c, short => $short);
$url = $db_url->url unless $db_url->disabled;
if ($db_url->disabled) {
$disabled_url++;
} else {
$url = $db_url->url;
}
}
if ($url) {
......@@ -226,7 +235,12 @@ sub get {
}
});
} else {
my $msg = $c->l('The shortened URL %1 doesn\'t exist.', $c->url_for('/')->to_abs.$short);
my $msg;
if ($disabled_url) {
$msg = $c->l('The shortened URL %1 no longer exists.', $c->url_for('/')->to_abs.$short);
} else {
$msg = $c->l('The shortened URL %1 doesn\'t exist.', $c->url_for('/')->to_abs.$short);
}
$c->res->code(404);
$c->respond_to(
json => { json => { success => Mojo::JSON->false, msg => $msg } },
......
......@@ -174,7 +174,7 @@ $t->get_ok('/d'.$b)
# Verify that short URL does not exists anymore
$t->get_ok($a.'.json')
->status_is(404)
->json_is({success => false, msg => 'The shortened URL '.$a.' doesn\'t exist.'});
->json_is({success => false, msg => 'The shortened URL '.$a.' no longer exists.'});
# Create short URL
$a = $t->ua->post('/a' => form => { lsturl => 'https://lstu.fr', format => 'json' })->res->json('/short');
......
......@@ -261,6 +261,11 @@ msgstr ""
msgid "The shortened URL %1 doesn't exist."
msgstr "The shortened URL %1 doesn't exist."
#. ($c->url_for('/')
#: lib/Lstu/Controller/URL.pm:240
msgid "The shortened URL %1 no longer exists."
msgstr "The shortened URL %1 no longer exists."
#. ($url)
#: lib/Lstu/Controller/URL.pm:59
msgid ""
......
......@@ -277,6 +277,11 @@ msgstr ""
msgid "The shortened URL %1 doesn't exist."
msgstr "L’URL raccourcie %1 n’existe pas."
#. ($c->url_for('/')
#: lib/Lstu/Controller/URL.pm:240
msgid "The shortened URL %1 no longer exists."
msgstr "L’URL raccourcie %1 n’existe plus."
#. ($url)
#: lib/Lstu/Controller/URL.pm:59
msgid ""
......
......@@ -223,10 +223,15 @@ msgid "The URL you want to shorten comes from a domain (%1) that is blacklisted
msgstr ""
#. ($c->url_for('/')
#: lib/Lstu/Controller/Admin.pm:131 lib/Lstu/Controller/Stats.pm:184 lib/Lstu/Controller/URL.pm:229
#: lib/Lstu/Controller/Admin.pm:131 lib/Lstu/Controller/Stats.pm:184 lib/Lstu/Controller/URL.pm:242
msgid "The shortened URL %1 doesn't exist."
msgstr ""
#. ($c->url_for('/')
#: lib/Lstu/Controller/URL.pm:240
msgid "The shortened URL %1 no longer exists."
msgstr ""
#. ($url)
#: lib/Lstu/Controller/URL.pm:59
msgid "The shortened text can't be \"a\", \"api\", \"d\", \"cookie\", \"stats\", \"fullstats\", \"login\" or \"logout\" or end with \".json\". Your URL to shorten: %1"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment