2022-09-23 16:45:55 -06:00
|
|
|
use Mojolicious::Lite -signatures;
|
|
|
|
use Mojo::SQLite;
|
|
|
|
|
|
|
|
#helper unstable => sub { state $sql = Mojo::SQLite->new('sqlite:unstable.db') };
|
|
|
|
helper stable => sub { state $sql = Mojo::SQLite->new('sqlite:stable.db') };
|
|
|
|
|
|
|
|
my $query = q{
|
|
|
|
SELECT
|
|
|
|
FULLPKGNAME,
|
|
|
|
FULLPKGPATH,
|
|
|
|
COMMENT,
|
|
|
|
DESCRIPTION,
|
|
|
|
highlight(ports_fts, 2, '<b>', '</b>') AS COMMENT_MATCH,
|
|
|
|
highlight(ports_fts, 3, '<b>', '</b>') AS DESCR_MATCH
|
|
|
|
FROM ports_fts
|
|
|
|
WHERE ports_fts MATCH ? ORDER BY rank;
|
|
|
|
};
|
|
|
|
|
|
|
|
get '/' => sub ($c) {
|
2022-09-23 20:25:02 -06:00
|
|
|
my $v = $c->validation;
|
2022-09-23 16:45:55 -06:00
|
|
|
my $search = $c->param('search');
|
2022-09-23 20:25:02 -06:00
|
|
|
|
2022-09-23 16:45:55 -06:00
|
|
|
#my $unstable = $c->param('unstable');
|
|
|
|
|
|
|
|
if ( defined $search && $search ne "" ) {
|
2022-09-23 20:25:02 -06:00
|
|
|
return $c->render( text => 'Bad CSRF token!', status => 403 )
|
|
|
|
if $v->csrf_protect->has_error('csrf_token');
|
|
|
|
|
|
|
|
my $db = $c->stable->db;
|
2022-09-23 16:45:55 -06:00
|
|
|
|
2022-09-23 20:25:02 -06:00
|
|
|
#$db = $c->unstable->db if defined $unstable;
|
2022-09-23 16:45:55 -06:00
|
|
|
|
2022-09-23 20:25:02 -06:00
|
|
|
my $results = $db->query( $query, $search )->hashes;
|
|
|
|
|
|
|
|
$c->render(
|
|
|
|
template => 'results',
|
|
|
|
search => $search,
|
|
|
|
results => $results
|
|
|
|
);
|
2022-09-23 16:45:55 -06:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$c->render( template => 'index' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
app->start;
|
|
|
|
__DATA__
|
|
|
|
@@ layouts/default.html.ep
|
|
|
|
<!doctype html>
|
|
|
|
<html class="no-js" lang="">
|
|
|
|
<head>
|
|
|
|
<title>OpenBSD.app</title>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
|
|
<meta name="description" content="OpenBSD package search">
|
|
|
|
<style>
|
|
|
|
body {
|
|
|
|
font-family: Avenir, 'Open Sans', sans-serif;
|
|
|
|
}
|
|
|
|
|
2022-09-23 20:25:02 -06:00
|
|
|
table {
|
|
|
|
border-collapse:separate;
|
|
|
|
border:solid black 1px;
|
|
|
|
border-radius:6px;
|
2022-09-23 16:45:55 -06:00
|
|
|
}
|
|
|
|
|
2022-09-23 20:25:02 -06:00
|
|
|
td, th {
|
|
|
|
border-left:solid black 1px;
|
|
|
|
border-top:solid black 1px;
|
|
|
|
}
|
|
|
|
|
|
|
|
th {
|
|
|
|
border-top: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
td:first-child, th:first-child {
|
|
|
|
border-left: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
td {
|
|
|
|
padding: 10px;
|
2022-09-23 16:45:55 -06:00
|
|
|
}
|
|
|
|
|
2022-09-23 20:25:02 -06:00
|
|
|
.nowrap {
|
|
|
|
white-space: nowrap;
|
2022-09-23 16:45:55 -06:00
|
|
|
}
|
|
|
|
|
2022-09-23 20:25:02 -06:00
|
|
|
code {
|
|
|
|
background: #ccc;
|
|
|
|
padding: 3px;
|
|
|
|
border-radius:6px;
|
2022-09-23 16:45:55 -06:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="wrap">
|
|
|
|
<div class="search">
|
|
|
|
%= form_for '/' => begin
|
|
|
|
%= text_field search => ""
|
|
|
|
%= csrf_field
|
|
|
|
%= submit_button 'Search...'
|
|
|
|
% end
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr />
|
|
|
|
<%== content %>
|
|
|
|
<hr />
|
|
|
|
<footer>
|
2022-09-23 18:19:40 -06:00
|
|
|
<a href="https://github.com/qbit/openbsd.app">OpenBSD.app</a> © 2022
|
2022-09-23 16:45:55 -06:00
|
|
|
</footer>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|
|
|
|
@@ results.html.ep
|
|
|
|
% layout 'default';
|
2022-09-23 20:25:02 -06:00
|
|
|
Found <%= @$results %> results for '<%= $search %>':
|
2022-09-23 16:45:55 -06:00
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Path</th>
|
|
|
|
<th>Comment</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
% foreach my $result (@$results) {
|
|
|
|
<tr>
|
2022-09-23 20:25:02 -06:00
|
|
|
<td class="nowrap">
|
|
|
|
<div>
|
|
|
|
<%= $result->{FULLPKGPATH} %><br />
|
|
|
|
<code>pkg_add <%= $result->{FULLPKGNAME} %></code>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td class="nowrap"><%== $result->{COMMENT_MATCH} %></td>
|
2022-09-23 16:45:55 -06:00
|
|
|
<td><%== $result->{DESCR_MATCH} %></td>
|
|
|
|
</tr>
|
|
|
|
% }
|
|
|
|
</table>
|
|
|
|
|
|
|
|
@@ index.html.ep
|
|
|
|
% layout 'default';
|
|
|
|
Welcome!
|