diff options
Diffstat (limited to 'util')
-rwxr-xr-x | util/docker-init.sh | 11 | ||||
-rwxr-xr-x | util/elmgen.pl | 204 | ||||
-rw-r--r-- | util/sql/schema.sql | 2 | ||||
-rwxr-xr-x | util/vndb-dev-server.pl | 8 | ||||
-rwxr-xr-x | util/vndb3.pl | 70 |
5 files changed, 289 insertions, 6 deletions
diff --git a/util/docker-init.sh b/util/docker-init.sh index 31c1f415..0ac0aca1 100755 --- a/util/docker-init.sh +++ b/util/docker-init.sh @@ -67,7 +67,7 @@ pg_start() { read -p "Choice: " opt if [[ $opt =~ ^[Yy] ]] then - curl https://s.vndb.org/devdump.tar.gz | tar -xzf- + curl -L https://dl.vndb.org/dump/vndb-dev-latest.tar.gz | tar -xzf- psql -U vndb -f dump.sql rm dump.sql fi @@ -83,7 +83,7 @@ pg_start() { # Should run as devuser devshell() { cd /var/www - util/vndb-dev-server.pl + util/vndb-dev-server.pl $1 bash } @@ -94,10 +94,15 @@ case "$1" in su devuser -c '/var/www/util/docker-init.sh pg_start' exec su devuser -c '/var/www/util/docker-init.sh devshell' ;; + 3) + mkdevuser + su devuser -c '/var/www/util/docker-init.sh pg_start' + exec su devuser -c '/var/www/util/docker-init.sh devshell 3' + ;; pg_start) pg_start ;; devshell) - devshell + devshell $2 ;; esac diff --git a/util/elmgen.pl b/util/elmgen.pl new file mode 100755 index 00000000..d95aba58 --- /dev/null +++ b/util/elmgen.pl @@ -0,0 +1,204 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use Cwd 'abs_path'; +my $ROOT; +BEGIN { ($ROOT = abs_path $0) =~ s{/util/elmgen\.pl$}{}; } +use lib $ROOT.'/lib'; +use TUWF; +use VN3::Validation; +use VN3::Auth; +use VN3::Types; +use VN3::VN::Edit; +use VN3::Release::Edit; +use VN3::Producer::Edit; +use VN3::Char::Edit; +use VN3::Staff::Edit; +use VN3::Docs::Edit; +use VN3::User::Settings; + +my $conf = require $ROOT.'/data/config3.pl'; + + +sub indent($) { $_[0] =~ s/\n/\n /gr } +sub list { indent "[ ".join("\n, ", @_)."\n]" } +sub string($) { '"'.($_[0] =~ s/([\\"])/\\$1/gr).'"' } +sub tuple { '('.join(', ', @_).')' } + +sub to_camel($) { (ucfirst $_[0]) =~ s/_([a-z])/'_'.uc $1/egr; } + +sub nested_type { + my($prefix, $obj) = @_; + my @keys = $obj->{keys} ? grep $obj->{keys}{$_}{keys}||($obj->{keys}{$_}{values}&&$obj->{keys}{$_}{values}{keys}), sort keys %{$obj->{keys}} : (); + + nested_type($prefix . to_camel $_, $obj->{keys}{$_}{values} || $obj->{keys}{$_}) for @keys; + + printf "type alias %s = %s\n\n", $prefix, $obj->elm_type( + keys => +{ map +($_, ($obj->{keys}{$_}{values} ? 'List ' : '') . $prefix . to_camel $_), @keys } + ); +} + +sub encoder { + my($name, $type, $obj) = @_; + printf "%s : %s -> JE.Value\n", $name, $type; + printf "%s = %s\n\n", $name, $obj->elm_encoder(json_encode => 'JE.'); +} + + + +my $perms = VN3::Auth::listPerms(); + +my $vn_lengths = list map tuple($_, string vn_length_display $_), 0..$#VN_LENGTHS; +my $vn_relations = list map tuple(string $_, string vn_relation_display $_), vn_relations; +my $producer_relations=list map tuple(string $_, string producer_relation_display $_), keys %PRODUCER_RELATIONS; +my $staff_roles = list map tuple(string $_, string $STAFF_ROLES{$_}), keys %STAFF_ROLES; +my $user_perms = list map tuple($perms->{$_}, string $_), sort keys %$perms; +my $languages = list map tuple(string $_, string $LANG{$_}), sort { $LANG{$a} cmp $LANG{$b} } keys %LANG; +my $platforms = list map tuple(string $_, string $PLATFORMS{$_}), keys %PLATFORMS; +my $release_types= list map string($_), release_types; +my $producer_types=list map tuple(string $_, string $PRODUCER_TYPES{$_}), keys %PRODUCER_TYPES; +my $minages = list map tuple($_, string minage_display_full $_), @MINAGE; +my $resolutions = list map tuple(string $_, string resolution_display_full $_), keys %RESOLUTIONS; +my $voiced = list map string($_), @VOICED; +my $animated = list map string($_), @ANIMATED; +my $gender = list map tuple(string $_, string gender_display $_), keys %GENDERS; +my $bloodt = list map tuple(string $_, string blood_type_display $_), keys %BLOOD_TYPES; +my $charroles = list map tuple(string $_, string char_role_display $_), keys %CHAR_ROLES; +my $media = list map tuple(string($_), sprintf('{ qty = %s, single = %s, plural = %s }', + $MEDIA{$_}{qty} ? 'True' : 'False', + string($MEDIA{$_}{single}), string($MEDIA{$_}{plural}))), keys %MEDIA; +my $vnlist_status= list map tuple($_, string $VNLIST_STATUS[$_]), 0..$#VNLIST_STATUS; +my $email = string { tuwf->compile({ email => 1 })->analyze->html5_validation() }->{pattern}; +my $weburl = string { tuwf->compile({ weburl => 1 })->analyze->html5_validation() }->{pattern}; +my $vnvote = string { tuwf->compile({ vnvote => 1 })->analyze->html5_validation() }->{pattern}; + + +print <<"EOF"; +-- This file is automatically generated from util/elmgen.pl +-- DO NOT EDIT! +module Lib.Gen exposing (..) + +import Json.Encode as JE + +urlStatic : String +urlStatic = "$conf->{url_static}" + +vnLengths : List (Int, String) +vnLengths = + $vn_lengths + +vnRelations : List (String, String) +vnRelations = + $vn_relations + +producerRelations : List (String, String) +producerRelations = + $producer_relations + +staffRoles : List (String, String) +staffRoles = + $staff_roles + +userPerms : List (Int, String) +userPerms = + $user_perms + +languages : List (String, String) +languages = + $languages + +platforms : List (String, String) +platforms = + $platforms + +releaseTypes : List String +releaseTypes = + $release_types + +producerTypes : List (String, String) +producerTypes = + $producer_types + +minAges : List (Int, String) +minAges = + $minages + +resolutions : List (String, String) +resolutions = + $resolutions + +voiced : List String +voiced = + $voiced + +animated : List String +animated = + $animated + +genders : List (String, String) +genders = + $gender + +bloodTypes : List (String, String) +bloodTypes = + $bloodt + +charRoles : List (String, String) +charRoles = + $charroles + +type alias Medium = + { qty : Bool + , single : String + , plural : String + } + +media : List (String, Medium) +media = + $media + +vnlistStatus : List (Int, String) +vnlistStatus = + $vnlist_status + +emailPattern : String +emailPattern = $email + +weburlPattern : String +weburlPattern = $weburl + +vnvotePattern : String +vnvotePattern = $vnvote + +EOF + + +nested_type VNEdit => $VN3::VN::Edit::FORM_OUT->analyze; +nested_type VNEditSend => $VN3::VN::Edit::FORM_IN->analyze; +encoder vneditSendEncode => VNEditSend => $VN3::VN::Edit::FORM_IN->analyze; + +nested_type RelEdit => $VN3::Release::Edit::FORM_OUT->analyze; +nested_type RelEditSend => $VN3::Release::Edit::FORM_IN->analyze; +encoder releditSendEncode => RelEditSend => $VN3::Release::Edit::FORM_IN->analyze; + +nested_type ProdEdit => $VN3::Producer::Edit::FORM_OUT->analyze; +nested_type ProdEditSend => $VN3::Producer::Edit::FORM_IN->analyze; +encoder prodeditSendEncode => ProdEditSend => $VN3::Producer::Edit::FORM_IN->analyze; + +nested_type CharEdit => $VN3::Char::Edit::FORM_OUT->analyze; +nested_type CharEditSend => $VN3::Char::Edit::FORM_IN->analyze; +encoder chareditSendEncode => CharEditSend => $VN3::Char::Edit::FORM_IN->analyze; + +nested_type StaffEdit => $VN3::Staff::Edit::FORM_OUT->analyze; +nested_type StaffEditSend => $VN3::Staff::Edit::FORM_IN->analyze; +encoder staffeditSendEncode => StaffEditSend => $VN3::Staff::Edit::FORM_IN->analyze; + +nested_type DocEdit => $VN3::Docs::Edit::FORM_OUT->analyze; +nested_type DocEditSend => $VN3::Docs::Edit::FORM_IN->analyze; +encoder doceditSendEncode => DocEditSend => $VN3::Docs::Edit::FORM_IN->analyze; + +nested_type UserEdit => $VN3::User::Settings::FORM_OUT->analyze; +nested_type UserEditSend => $VN3::User::Settings::FORM_IN->analyze; +encoder usereditSendEncode => UserEditSend => $VN3::User::Settings::FORM_IN->analyze; diff --git a/util/sql/schema.sql b/util/sql/schema.sql index b62b33a8..c76fc88a 100644 --- a/util/sql/schema.sql +++ b/util/sql/schema.sql @@ -65,7 +65,7 @@ CREATE TABLE anime ( ann_id integer, -- [pub] nfo_id varchar(200), -- [pub] type anime_type, -- [pub] - title_romaji varchar(250) -- [pub] + title_romaji varchar(250), -- [pub] title_kanji varchar(250), -- [pub] lastfetch timestamptz ); diff --git a/util/vndb-dev-server.pl b/util/vndb-dev-server.pl index 763748b6..bc23997a 100755 --- a/util/vndb-dev-server.pl +++ b/util/vndb-dev-server.pl @@ -15,6 +15,8 @@ use Cwd 'abs_path'; my $listen_port = $ENV{TUWF_HTTP_SERVER_PORT} || 3000; $ENV{TUWF_HTTP_SERVER_PORT} = $listen_port+1; +my $script = $ARGV[0] && $ARGV[0] eq '3' ? 'vndb3.pl' : 'vndb.pl'; + my($pid, $prog, $killed); sub prog_start { @@ -28,7 +30,7 @@ sub prog_start { } print $d; }; - $prog = run_cmd "$ROOT/util/vndb.pl", + $prog = run_cmd "$ROOT/util/$script", '$$' => \$pid, '>' => $output, '2>' => $output; @@ -102,7 +104,9 @@ sub checkmod { chdir $ROOT; $check->($_) for (qw{ util/vndb.pl + util/vndb3.pl data/config.pl + data/config3.pl data/global.pl }); @@ -150,6 +154,6 @@ while(1) { my $prog_conn = AE::cv; tcp_connect '127.0.0.1', $ENV{TUWF_HTTP_SERVER_PORT}, sub { $prog_conn->send(shift); }; - my $prog_fh = $prog_conn->recv || die "Unable to connect to vndb.pl? $!"; + my $prog_fh = $prog_conn->recv || die "Unable to connect to $script? $!"; pipe_fhs($serv_fh, $prog_fh); } 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; |