#! /usr/bin/perl
###
### URL shortening userv interface for Odin
###
### (c) 2015 Mark Wooding
###
###----- Licensing notice ---------------------------------------------------
###
### This file is part of the `odin.gg' service, `odin-cgi'.
###
### `odin-cgi' is free software; you can redistribute it and/or modify
### it under the terms of the GNU Affero General Public License as
### published by the Free Software Foundation; either version 3 of the
### License, or (at your option) any later version.
###
### `odin-cgi' is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU Affero General Public License for more details.
###
### You should have received a copy of the GNU Affero General Public
### License along with `odin-cgi'; if not, see
### .
use lib "lib";
use Odin;
use DBI;
Odin::cmdline_who;
my $op = shift(@ARGV) // "help";
if ($op eq "help") {
print <selectall_arrayref
("SELECT tag, stamp, url
FROM odin_shorturl WHERE owner = ?
ORDER BY stamp", undef, $Odin::WHO)}) {
my ($tag, $stamp, $url) = @$r;
Odin::print_columns Odin::fmt_time $stamp => 25, $tag => 12, $url =>0;
}
} elsif ($op eq "new") {
@ARGV == 1 or Odin::fail "usage: new URL";
my ($url) = @ARGV;
my $tag = Odin::new_shorturl $url;
print "$Odin::SHORTURL/$tag\n";
} elsif ($op eq "get") {
@ARGV >= 0 or Odin::fail "usage: get TAG ...";
if (@ARGV == 1) { print Odin::get_shorturl $ARGV[0], "\n"; }
else {
for my $tag (@ARGV)
{ printf "%-12s %s\n", $tag, Odin::get_shorturl $tag; }
}
} elsif ($op eq "del") {
@ARGV >= 0 or Odin::fail "usage: del TAG ...";
Odin::delete_shorturl @ARGV;
} else {
Odin::fail "unknown operation `$op'";
}