summaryrefslogtreecommitdiff
path: root/util/vndb3.pl
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-07-25 14:30:04 +0200
committerYorhel <git@yorhel.nl>2019-07-25 14:36:21 +0200
commitf296495a912ce759df11c43e78b4552788bdbff2 (patch)
tree0c10802de65fb7c8475722e12234bff5eb980628 /util/vndb3.pl
parent0f3cfeb85caec6424bcbea47142eefbf8011636b (diff)
Merge the v3 branch into separate namespace + fix Docker stuff (again)
I was getting tired of having to keep two branches up-to-date with the latest developments, so decided to throw v3 into the same branch - just different files (...which will get mostly rewritten again soon). The two versions aren't very different in terms of dependencies, build system and support code, so they can now properly share files. Added a section to the README to avoid confusion. This merge also makes it easier to quickly switch between the different versions, which is handy for development. It's even possible to run both at the same time, but my scripts use the same port so that needs a workaround. And it's amazing how often I break the Docker scripts.
Diffstat (limited to 'util/vndb3.pl')
-rwxr-xr-xutil/vndb3.pl70
1 files changed, 70 insertions, 0 deletions
diff --git a/util/vndb3.pl b/util/vndb3.pl
new file mode 100755
index 00000000..d2f18833
--- /dev/null
+++ b/util/vndb3.pl
@@ -0,0 +1,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;