2022-09-24 07:36:44 -06:00
|
|
|
use feature 'switch';
|
2022-09-23 16:45:55 -06:00
|
|
|
use Mojolicious::Lite -signatures;
|
|
|
|
use Mojo::SQLite;
|
|
|
|
|
2022-09-24 07:55:35 -06:00
|
|
|
helper unstable => sub { state $sql = Mojo::SQLite->new('sqlite:unstable.db') };
|
2022-09-23 16:45:55 -06:00
|
|
|
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-24 07:36:44 -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-24 07:55:35 -06:00
|
|
|
my $unstable = $c->param('unstable');
|
2022-09-24 07:36:44 -06:00
|
|
|
my $format = $c->param('format');
|
2022-09-23 16:45:55 -06:00
|
|
|
|
|
|
|
if ( defined $search && $search ne "" ) {
|
2022-09-24 07:36:44 -06:00
|
|
|
|
|
|
|
#return $c->render( text => 'Bad CSRF token!', status => 403 )
|
2022-09-23 22:00:35 -06:00
|
|
|
# if $v->csrf_protect->has_error('csrf_token');
|
2022-09-23 20:25:02 -06:00
|
|
|
|
|
|
|
my $db = $c->stable->db;
|
2022-09-23 16:45:55 -06:00
|
|
|
|
2022-09-24 07:55:35 -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;
|
|
|
|
|
2022-09-24 07:36:44 -06:00
|
|
|
given ($format) {
|
|
|
|
when ("json") {
|
|
|
|
$c->render( json => $results );
|
|
|
|
}
|
|
|
|
default {
|
|
|
|
$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 21:45:29 -06:00
|
|
|
background-color: #ffffea;
|
2022-09-23 16:45:55 -06:00
|
|
|
}
|
|
|
|
|
2022-09-23 20:25:02 -06:00
|
|
|
table {
|
|
|
|
border-collapse:separate;
|
|
|
|
border:solid black 1px;
|
|
|
|
border-radius:6px;
|
2022-09-23 21:45:29 -06:00
|
|
|
background-color: #fff;
|
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;
|
|
|
|
}
|
2022-09-23 21:45:29 -06:00
|
|
|
|
2022-09-24 06:51:01 -06:00
|
|
|
th {
|
|
|
|
white-space: nowrap;
|
2022-09-24 06:51:55 -06:00
|
|
|
padding: 6px;
|
2022-09-24 06:51:01 -06:00
|
|
|
}
|
|
|
|
|
2022-09-23 21:45:29 -06:00
|
|
|
.search {
|
|
|
|
padding: 10px;
|
|
|
|
margin: 10px;
|
|
|
|
border-radius:6px;
|
|
|
|
box-shadow: 2px 2px 2px black;
|
|
|
|
}
|
2022-09-23 20:25:02 -06:00
|
|
|
|
2022-09-23 21:45:29 -06:00
|
|
|
th, .search {
|
2022-09-23 20:25:02 -06:00
|
|
|
border-top: none;
|
2022-09-23 21:45:29 -06:00
|
|
|
background-color: #eaeaff;
|
2022-09-23 20:25:02 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
td:first-child, th:first-child {
|
|
|
|
border-left: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
td {
|
|
|
|
padding: 10px;
|
2022-09-23 21:45:29 -06:00
|
|
|
text-align: left;
|
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 21:45:29 -06:00
|
|
|
footer, .wrap, .results {
|
|
|
|
text-align: center;
|
2022-09-23 16:45:55 -06:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="wrap">
|
2022-09-24 07:36:44 -06:00
|
|
|
<h3><a href="/">OpenBSD.app - search packages</a></h3>
|
2022-09-23 16:45:55 -06:00
|
|
|
<div class="search">
|
|
|
|
%= form_for '/' => begin
|
|
|
|
%= text_field search => ""
|
2022-09-24 08:24:38 -06:00
|
|
|
-current
|
2022-09-24 07:55:35 -06:00
|
|
|
%= check_box 'unstable'
|
2022-09-23 16:45:55 -06:00
|
|
|
%= submit_button 'Search...'
|
|
|
|
% end
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-23 21:45:29 -06:00
|
|
|
<div class="results">
|
|
|
|
<%== content %>
|
|
|
|
</div>
|
2022-09-23 16:45:55 -06:00
|
|
|
<hr />
|
|
|
|
<footer>
|
2022-09-24 07:36:44 -06:00
|
|
|
<p><a href="https://github.com/qbit/openbsd.app">OpenBSD.app</a> © 2022</p>
|
|
|
|
<p><a href="https://github.com/qbit/pkg">Prefer CLI?</a></p>
|
2022-09-23 16:45:55 -06:00
|
|
|
</footer>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|
|
|
|
@@ results.html.ep
|
|
|
|
% layout 'default';
|
2022-09-24 07:36:44 -06:00
|
|
|
<p>
|
|
|
|
Found <b><%= @$results %></b> results for '<b><%= $search %></b>'<br />
|
|
|
|
<a href="/?search=<%= $search %>&format=json">View as JSON</a>
|
|
|
|
</p>
|
2022-09-23 21:45:29 -06:00
|
|
|
<table class="results">
|
2022-09-23 16:45:55 -06:00
|
|
|
<thead>
|
|
|
|
<tr>
|
2022-09-23 21:07:13 -06:00
|
|
|
<th>Package Name</th>
|
2022-09-23 21:45:29 -06:00
|
|
|
<th>Path</th>
|
2022-09-23 16:45:55 -06:00
|
|
|
<th>Comment</th>
|
|
|
|
<th>Description</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
% foreach my $result (@$results) {
|
|
|
|
<tr>
|
2022-09-23 21:07:13 -06:00
|
|
|
<td class="nowrap"><%= $result->{FULLPKGNAME} %></td>
|
2022-09-23 21:45:29 -06:00
|
|
|
<td class="nowrap"><%= $result->{FULLPKGPATH} %></td>
|
2022-09-23 20:25:02 -06:00
|
|
|
<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';
|
2022-09-24 10:06:22 -06:00
|
|
|
Welcome! Default search queries OpenBSD 7.2 package sets. You can search -current (packages from 2022-09-23) by toggling the '-current' checkbox.
|