3 %# URL shortener webservice for Odin
5 %# (c) 2015 Mark Wooding
7 %#----- Licensing notice ----------------------------------------------------
9 %# This file is part of the `odin.gg' service, `odin-cgi'.
11 %# `odin-cgi' is free software; you can redistribute it and/or modify
12 %# it under the terms of the GNU Affero General Public License as
13 %# published by the Free Software Foundation; either version 3 of the
14 %# License, or (at your option) any later version.
16 %# `odin-cgi' is distributed in the hope that it will be useful,
17 %# but WITHOUT ANY WARRANTY; without even the implied warranty of
18 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 %# GNU Affero General Public License for more details.
21 %# You should have received a copy of the GNU Affero General Public
22 %# License along with `odin-cgi'; if not, see
23 %# <http://www.gnu.org/licenses/>.
25 <&| SELF:wrapper, title => "odin.gg URL Shortener" &>
26 <h1><tt>odin.gg</tt> URL Shortener</h1>
27 <form method="POST" accept-charset="UTF-8" enctype="multipart/form-data">
28 <label for="url" accesskey="u"><u>U</u>RL to shorten:</label>
29 <input id="url" name="u" value="<% $u // "" |h %>">
30 <button type="submit">Go</button>
33 <p>Shortened to: <a href="<% "$Odin::SHORTURL/$tag" %>"><%
34 "$Odin::SHORTURL/$tag" %></a>
39 my $tag = $m->dhandler_arg;
41 my $url = Odin::get_shorturl $tag;
42 if ($q) { $m->comp(".query", url => $url); }
43 else { $m->redirect($url, 301); }
45 } elsif (defined $u) {
46 $tag = Odin::new_shorturl $u;
48 Odin::path_info($r) =~ m:/$:
49 or $m->redirect("$Odin::SHORTURL/", 301);
60 % $r->content_type("text/plain; charset=utf8");
68 <&| SELF:error, title => "not found", status => 404 &>\
69 tag ‘<% $tag |h %>’ not found
77 <&| SELF:error, title => "invalid url", status => 404 &>\
78 ‘<tt><% $u |h %></tt>’ is not a valid URL