summaryrefslogtreecommitdiff
path: root/util/vndb3.pl
blob: d2f18833ec467d31d3b8188350122ea00a1e16ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl

use strict;
use warnings;
use TUWF;

use Cwd 'abs_path';
my $ROOT;
BEGIN { ($ROOT = abs_path $0) =~ s{/util/vndb3\.pl$}{}; }
use lib $ROOT.'/lib';

use PWLookup;

$|=1; # Disable buffering on STDOUT, otherwise vndb-dev-server.pl won't pick up our readyness notification.

my $conf = require $ROOT.'/data/config3.pl';

# Make the configuration available as tuwf->conf
sub TUWF::Object::conf { $conf }


# Make our root path available as tuwf->root
# Optionally accepts other path components to assemble a file path:
#   tuwf->root('static/sf/01/1.jpg')
sub TUWF::Object::root { shift; join '/', $ROOT, @_ }


# tuwf->imgpath(cg => $image_id)
sub TUWF::Object::imgpath {
    tuwf->root(static => $_[1] => sprintf '%02d/%d.jpg', $_[2]%100, $_[2]);
}


# tuwf->imgurl(cv => $image_id)
sub TUWF::Object::imgurl {
    sprintf '%s/%s/%02d/%d.jpg', $_[0]->conf->{url_static}, $_[1], $_[2]%100, $_[2];
}


# tuwf->resDenied
sub TUWF::Object::resDenied {
    TUWF::_very_simple_page(403, '403 - Permission Denied', 'You do not have the permission to access this page.');
}

# tuwf->isUnsafePass($pass)
sub TUWF::Object::isUnsafePass {
    $_[0]->conf->{password_db} && PWLookup::lookup($_[0]->conf->{password_db}, $_[1])
}


TUWF::set %{ $conf->{tuwf} || {} };

TUWF::set import_modules => 0;

# If we're running standalone, serve www/ and static/ too.
TUWF::hook before => sub {
    my $static = tuwf->{_TUWF}{http} &&
        (  tuwf->resFile(tuwf->root('www'),    tuwf->reqPath)
        || tuwf->resFile(tuwf->root('static'), tuwf->reqPath)
        );
    if($static) {
        tuwf->resHeader('Cache-Control' => 'max-age=31536000');
        tuwf->done;
    }
};


require VN3::Validation; # Load this early, to ensure the custom_validations are available
TUWF::load_recursive 'VN3';
TUWF::run;