Commit 0ef44310 authored by Benjamin Bouvier's avatar Benjamin Bouvier Committed by Luc Didry

Allow to delete old links; fixes #11.

parent 064cf000
......@@ -182,8 +182,10 @@ sub startup {
$custom_url = undef if (defined($custom_url) && $custom_url eq '');
my ($msg, $short);
if (defined($custom_url) && ($custom_url =~ m/^a(pi)?$|^stats$/ || $custom_url =~ m/\.json$/ || $custom_url !~ m/^[-a-zA-Z0-9_]+$/)) {
$msg = $c->l('The shortened text can contain only numbers, letters and the - and _ character, can\'t be "a", "api" or "stats" or end with ".json". Your URL to shorten: %1', $url);
if (defined($custom_url) && ($custom_url =~ m/^a(pi)?$|^stats$/ || $custom_url =~ m/^d$/ ||
$custom_url =~ m/\.json$/ || $custom_url !~ m/^[-a-zA-Z0-9_]+$/))
{
$msg = $c->l('The shortened text can contain only numbers, letters and the - and _ character, can\'t be "a", "api", "d" or "stats" or end with ".json". Your URL to shorten: %1', $url);
} elsif (defined($custom_url) && LstuModel::Lstu->count('WHERE short = ?', $custom_url) > 0) {
$msg = $c->l('The shortened text (%1) is already used. Please choose another one.', $custom_url);
} elsif (is_http_uri($url->to_string) || is_https_uri($url->to_string)) {
......@@ -347,6 +349,39 @@ sub startup {
}
});
$r->get('/d/:short' => sub {
my $c = shift;
my $short = $c->param('short');
if (defined($c->session('token')) && SessionModel::Sessions->count('WHERE token = ?', $c->session('token'))) {
my @urls = LstuModel::Lstu->select('WHERE short = ?', $short);
if (scalar(@urls)) {
my $deleted = LstuModel::Lstu->delete_where('short = ?', $short);
$c->respond_to(
json => { json => { success => Mojo::JSON->true, deleted => $deleted } },
any => sub {
my $c = shift;
$c->res->code(301);
$c->redirect_to('stats');
}
);
} else {
my $msg = $c->l('The shortened URL %1 doesn\'t exist.', $c->url_for('/')->to_abs.$short);
$c->respond_to(
json => { json => { success => Mojo::JSON->false, msg => $msg } },
any => sub {
my $c = shift;
$c->flash('msg' => $msg);
$c->redirect_to('stats');
}
);
}
} else {
$c->flash('msg' => $c->l('Bad password'));
$c->redirect_to('stats');
}
})->name('delete');
$r->get('/:short' => sub {
my $c = shift;
my $short = $c->param('short');
......
# Lstu
# Copyright (C) 2013 - 2015 Luc Didry
# This file is distributed under the same license as the Lstu package.
#
#
# Translators:
# Luc Didry <luc@didry.org>, 2015
msgid ""
......@@ -55,5 +55,6 @@ msgstr ""
#. ($url)
#: lib/Lstu.pm:184
msgid "The shortened text can contain only numbers, letters and the - and _ character, can't be \"a\", \"api\" or \"stats\" or end with \".json\". Your URL to shorten: %1"
msgid "The shortened text can contain only numbers, letters and the - and _
character, can't be \"a\", \"api\", \"d\" or \"stats\" or end with \".json\". Your URL to shorten: %1"
msgstr ""
# Lstu
# Copyright (C) 2013 - 2015 Luc Didry
# This file is distributed under the same license as the Lstu package.
#
#
# Translators:
# Translators:
# Luc Didry <luc@didry.org>, 2015
......@@ -143,9 +143,9 @@ msgid "The shortened text (%1) is already used. Please choose another one."
msgstr "Le texte du raccourci (%1) est déjà utilisé. Veuillez en choisir un autre"
#. ($url)
#: lib/Lstu.pm:184
msgid "The shortened text can contain only numbers, letters and the - and _ character, can't be \"a\", \"api\" or \"stats\" or end with \".json\". Your URL to shorten: %1"
msgstr "Le texte du raccourci ne doit contenir que des chiffres, des lettres et les caractères - et _, ne peut être \"a\", \"api\" ou \"stats\" ou se terminer par \".json\". Rappel de l’URL à raccourcir : %1"
#: lib/Lstu.pm:188
msgid "The shortened text can contain only numbers, letters and the - and _ character, can't be \"a\", \"api\", \"d\" or \"stats\" or end with \".json\". Your URL to shorten: %1"
msgstr "Le texte du raccourci ne doit contenir que des chiffres, des lettres et les caractères - et _, ne peut être \"a\", \"api\", \"d\" ou \"stats\" ou se terminer par \".json\". Rappel de l’URL à raccourcir : %1"
#:
msgid "URL"
......
......@@ -28,6 +28,11 @@
<th><%= l('Shortened URL') %></th>
<th><%= l('Counter') %></th>
<th><%= l('Created') %></th>
% if (defined(config('adminpwd'))) {
% if (defined(stash('admin'))) {
<th><%= l('Delete') %></th>
% }
% }
</tr>
% my $i = 1;
% if (defined(stash('page')) && stash('page') >= 0) {
......@@ -41,6 +46,11 @@
<td><%= link_to $prefix.$url->{short} => $prefix.$url->{short} %></td>
<td><%= $url->{counter} %></td>
<td><%= Mojo::Date->new($url->{timestamp})->to_string %></td>
% if (defined(config('adminpwd'))) {
% if (defined(stash('admin'))) {
<td><%= link_to x => url_for('delete', {short => $url->{short}}) %></td>
% }
% }
</tr>
% }
</table>
......
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