DURXZGLUO3U3KYCOMEXM4DGCP3HWDCKFIEO5FED42K6BNKRZGE5AC
LWYLPSOW6RBDUREVYKQPW2CB52VSFLTJL7D2AY2SLZVPENAXI5VQC
FTPUZNIRP77PX7MKLMUWJJT7IT4DBFFY5Z3AIG4C25SPFL5ROKAAC
3PJ77S7QASECNZ7PC3FEZXEAOXKVTNORPKPULFF2YTGKDSXLMD5QC
2AMKLNZI7UVD7X5EMX7EGMZ6D7QVG5AF7Q7HVSSADOFHVFS4LPTQC
HSVVEKTY2U5XJ4ZDHF43YEQXRPRWNZLZDDD4W7JFJ55UWD7CEFBQC
LBNVQXUBEZ45SOTGVXK5UEZXIAIZTJLWZNUYFI4JZ6J65N3KPDVQC
XJFHFZCA2VXGYSRDJDLAZZX3MLRH2KDT242DHWRU5XQRJ6XIHZUQC
V2YFPM72UMEDEZVWBQT42KSVDALD5PPJXTBZALKH26SR5PKGC42AC
5NO7NCKTMM5ZW7JYOETUFOSWK2ACTXWDZGJAFXZN6L3OF6BFTNOQC
2V4M2M2RZ5R6I55UIFKRMONPEGBA5FQ7ZB6HM6LHF255AX4JCXXAC
GJFYEU3SVP7TDSYXVZEYGKN4NVWSZX4754PPPTOYPRHUO5RMDWPQC
NUIKDEHLDR4ANFZFRCWBAWZGFVMHCZ7PSMPPFVQJ3AAAAWAQQD4AC
SF2W2W4HFDO7JXYGOTOEUC2PBCTHZTQCU7T6SPPLJWH5BCCCJDRAC
57XH5AZ3MFS3UQZTXBPHJSWVKPPHEX6HIYUDJIDDATIZDPRAE7HQC
QE253KG464JLXJHTILULXUIK527FGXT42IHHDE3BR6ASIYC44MWAC
CKTDT6XXCOLJY4NSPBLFD677LXKC6UB2FTYGSQ72RGMVFQ4OMBUAC
}
sub serveFile {
my ($c, $path) = @_;
my $res = run(cmd => ["nix", "ls-store", "--store", getStoreUri(), "--json", "$path"]);
if ($res->{status}) {
notFound($c, "File '$path' does not exist.") if $res->{stderr} =~ /does not exist/;
die "$res->{stderr}\n";
}
my $ls = decode_json($res->{stdout});
if ($ls->{type} eq "directory" && substr($c->request->uri, -1) ne "/") {
return $c->res->redirect($c->request->uri . "/");
}
elsif ($ls->{type} eq "directory" && defined $ls->{entries}->{"index.html"}) {
return serveFile($c, "$path/index.html");
}
elsif ($ls->{type} eq "symlink") {
my $target = $ls->{target};
return serveFile($c, substr($target, 0, 1) eq "/" ? $target : dirname($path) . "/" . $target);
}
elsif ($ls->{type} eq "regular") {
$c->stash->{'plain'} = { data => grab(cmd => ["nix", "cat-store", "--store", getStoreUri(), "$path"]) };
# Detect MIME type. Borrowed from Catalyst::Plugin::Static::Simple.
my $type = "text/plain";
if ($path =~ /.*\.(\S{1,})$/xms) {
my $ext = $1;
my $mimeTypes = MIME::Types->new(only_complete => 1);
my $t = $mimeTypes->mimeTypeOf($ext);
$type = ref $t ? $t->type : $t if $t;
}
$c->response->content_type($type);
$c->forward('Hydra::View::Plain');
}
else {
error($c, "Do not know how to serve path '$path'.");
}
$c->stash->{'plain'} = { data => readNixFile($path) };
# Detect MIME type. Borrowed from Catalyst::Plugin::Static::Simple.
my $type = "text/plain";
if ($path =~ /.*\.(\S{1,})$/xms) {
my $ext = $1;
my $mimeTypes = MIME::Types->new(only_complete => 1);
my $t = $mimeTypes->mimeTypeOf($ext);
$type = ref $t ? $t->type : $t if $t;
}
$c->response->content_type($type);
$c->forward('Hydra::View::Plain');
serveFile($c, $path);