Browse Source

Refactor is_browser view switching

master
Lucas 1 year ago
parent
commit
44366faaf2
  1. 25
      lib/Pastry.pm
  2. 0
      views/browser/400.tt
  3. 0
      views/browser/upload_success.tt
  4. 1
      views/cli/400.tt
  5. 1
      views/cli/upload_success.tt

25
lib/Pastry.pm

@ -35,25 +35,22 @@ get "/" => sub {
post "/" => sub {
my @uploads = upload("upload");
my $is_browser = (body_parameters->get("is_browser") // 0) == 1;
my $view_dir = $is_browser ? "browser" : "cli";
my $layout = $is_browser ? setting("layout") : undef;
content_type("text/plain") unless $is_browser;
if (!@uploads) {
status 400;
if ($is_browser) {
return template "400" => {};
} else {
content_type("text/plain");
return "Missing upload parameter\n";
}
return template "$view_dir/400",
{},
{layout => $layout};
}
my $upload_uri = uri_for("u/");
if ($is_browser) {
return template "upload_success" =>
{upload_uri => $upload_uri};
} else {
content_type("text/plain");
return "$upload_uri\n";
}
my $upload_uri = uri_for("u");
return template "$view_dir/upload_success",
{upload_uri => $upload_uri},
{layout => $layout};
};
1;

0
views/400.tt → views/browser/400.tt

0
views/upload_success.tt → views/browser/upload_success.tt

1
views/cli/400.tt

@ -0,0 +1 @@
missing upload parameter

1
views/cli/upload_success.tt

@ -0,0 +1 @@
<% upload_uri %>