Batch processor (.trsr charge) now also accessible via web interface

Plus, added `./trsr server` and `./trsr sql` calls. These are essentially execs of
morbo and sqlite3 with appropriate arguments.
This commit is contained in:
Florian "flowdy" Heß
2017-02-17 17:09:59 +01:00
parent a686011cf4
commit f5cde1c585
6 changed files with 160 additions and 145 deletions

View File

@@ -3,6 +3,7 @@ use strict;
package TrsrDB::HTTP::Account;
use Mojo::Base 'Mojolicious::Controller';
use Carp qw(croak);
use FindBin qw($Bin);
sub list {
my $self = shift;
@@ -79,6 +80,25 @@ sub upsert {
return;
}
sub batch_processor {
my $self = shift;
if ( $self->req->method eq 'POST' ) {
my $text = $self->req->headers->content_type =~ m{^text/plain\b}
? $self->req->body
: $self->param("batch")
;
open my $fh, '<', \$text;
require "$Bin/trsr" or die;
$self->app->db->storage->txn_do(sub {
Commands::act_on_other_db($self->app->db);
Commands::charge_account($fh);
});
$self->redirect_to('home');
}
}
sub history {
my $self = shift;
my %query = ( account => $self->stash("account") );