1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
use askama::Template;
#[derive(Debug, Clone)]
pub struct Page {
pub title: String,
pub flash: String,
pub has_flash: bool,
pub flash_err: bool,
pub csrf: String,
pub pending: i64,
pub running: i64,
pub attention: i64,
pub nav_reviews: &'static str,
pub nav_builds: &'static str,
pub nav_attention: &'static str,
pub nav_packages: &'static str,
pub nav_subscriptions: &'static str,
pub nav_audit: &'static str,
pub nav_settings: &'static str,
pub gated: bool,
}
impl Page {
pub fn new(title: &str, csrf: String) -> Self {
Self {
title: title.into(),
flash: String::new(),
has_flash: false,
flash_err: false,
csrf,
pending: 0,
running: 0,
attention: 0,
nav_reviews: "",
nav_builds: "",
nav_attention: "",
nav_packages: "",
nav_subscriptions: "",
nav_audit: "",
nav_settings: "",
gated: false,
}
}
pub fn flash(mut self, msg: String, err: bool) -> Self {
self.flash = msg;
self.has_flash = true;
self.flash_err = err;
self
}
}
#[derive(Template)]
#[template(path = "login.html")]
pub(crate) struct Login {
pub page: Page,
pub error: String,
}
#[derive(Template)]
#[template(path = "error.html")]
pub(crate) struct ErrorPage {
pub page: Page,
pub status: String,
pub message: String,
pub detail: String,
}
#[derive(Template)]
#[template(path = "dashboard.html")]
pub(crate) struct Dashboard {
pub page: Page,
pub subscriptions: i64,
pub index_count: i64,
pub pending_reviews: i64,
pub running_builds: i64,
pub attention: i64,
pub publishes: Vec<PublishRow>,
}
#[derive(Debug, Clone)]
pub(crate) struct PublishRow {
pub name: String,
pub version: String,
pub published_at: String,
pub aur_commit: String,
pub aur_commit_short: String,
}
#[derive(Template)]
#[template(path = "reviews.html")]
pub(crate) struct ReviewsPage {
pub page: Page,
pub rows: Vec<ReviewRow>,
}
#[derive(Debug, Clone)]
pub(crate) struct ReviewRow {
pub id: i64,
pub pkgbase: String,
pub version: String,
pub kind: String,
pub risk: String,
pub signals: Vec<String>,
pub age: String,
pub revision: i64,
}
#[derive(Template)]
#[template(path = "review.html")]
pub(crate) struct ReviewDetail {
pub page: Page,
pub c: ReviewHead,
pub base_version: String,
pub has_base: bool,
pub panels: Vec<Panel>,
pub recipe: String,
pub srcinfo: String,
pub has_srcinfo: bool,
pub sources_resolved: String,
pub deps_resolved: String,
}
#[derive(Debug, Clone)]
pub(crate) struct ReviewHead {
pub id: i64,
pub pkgbase: String,
pub version: String,
pub kind: String,
pub is_first: bool,
pub risk: String,
pub signals: Vec<String>,
pub missing_deps: Vec<String>,
pub dependents: Vec<String>,
pub revision: i64,
pub aur_commit: String,
pub aur_commit_short: String,
pub identity_hash: String,
pub diff_digest: String,
}
#[derive(Debug, Clone)]
pub struct Panel {
pub title: String,
pub body: String,
pub empty: bool,
pub empty_note: String,
}
impl Panel {
pub fn new(title: &str, body: String) -> Self {
Self {
title: title.into(),
empty: body.trim().is_empty(),
empty_note: "no change".into(),
body,
}
}
}
#[derive(Template)]
#[template(path = "subscriptions.html")]
pub struct Subscriptions {
pub page: Page,
pub rows: Vec<SubRow>,
}
#[derive(Debug, Clone)]
pub(crate) struct SubRow {
pub name: String,
pub state: String,
pub maintainer: String,
pub last_checked: String,
pub next_check: String,
pub last_error: String,
pub has_error: bool,
pub pending: i64,
pub pause_label: &'static str,
}
#[derive(Template)]
#[template(path = "attention.html")]
/// `pub(crate)`, not `pub`: the census counted it as test-only because the word appears in `tests/http.rs`, but only inside a string — a route path, a content type, the word "redirect" in an assertion message. Nothing in the test tier calls it.
pub(crate) struct Attention {
pub page: Page,
pub empty: bool,
pub notices: Vec<NoticeRow>,
pub unbuilt: Vec<UnbuiltRow>,
pub outdated: Vec<StaleRow>,
pub missing: Vec<StaleRow>,
pub downgrades: Vec<StaleRow>,
pub blocked: Vec<BlockedRow>,
}
#[derive(Debug, Clone)]
pub(crate) struct UnbuiltRow {
pub pkgbase: String,
pub approved: String,
pub serving: String,
pub error: String,
pub build_id: String,
}
#[derive(Debug, Clone)]
pub(crate) struct NoticeRow {
pub id: i64,
pub pkgbase: String,
pub kind: String,
pub severity: String,
pub detail: String,
pub created_at: String,
}
#[derive(Debug, Clone)]
pub(crate) struct StaleRow {
pub pkgbase: String,
pub dependency: String,
pub built_with: String,
pub now: String,
}
#[derive(Debug, Clone)]
pub(crate) struct BlockedRow {
pub id: String,
pub id_short: String,
pub pkgbase: String,
pub blocked_on: Vec<String>,
}
#[derive(Template)]
#[template(path = "packages.html")]
pub struct Packages {
pub page: Page,
pub repo: String,
pub rows: Vec<IndexRow>,
pub snippet: String,
}
#[derive(Debug, Clone)]
pub(crate) struct IndexRow {
pub name: String,
pub version: String,
pub arch: String,
pub size: String,
pub published_at: String,
}
#[derive(Template)]
#[template(path = "package.html")]
pub(crate) struct PackageDetail {
pub page: Page,
pub name: String,
pub summary: String,
pub can_withdraw: bool,
pub stale: Vec<String>,
pub unbuilt: Vec<UnbuiltRow>,
pub deps_in: Vec<String>,
pub deps_out: Vec<String>,
pub timeline: Vec<TimelineRow>,
pub builds: Vec<BuildLite>,
}
#[derive(Debug, Clone)]
pub(crate) struct TimelineRow {
pub version: String,
pub state: String,
pub aur_commit: String,
pub aur_commit_short: String,
pub published_at: String,
pub approver: String,
}
#[derive(Template)]
#[template(path = "builds.html")]
pub struct Builds {
pub page: Page,
pub rows: Vec<BuildRow>,
pub recent: Vec<BuildRow>,
}
#[derive(Template)]
#[template(path = "builds_table.html")]
pub(crate) struct BuildsTable {
pub page: Page,
pub rows: Vec<BuildRow>,
pub recent: Vec<BuildRow>,
}
#[derive(Debug, Clone)]
pub(crate) struct BuildLite {
pub id: String,
pub id_short: String,
pub kind: String,
pub state: String,
pub step: String,
}
#[derive(Debug, Clone)]
pub struct BuildRow {
pub id: String,
pub id_short: String,
pub pkgbase: String,
pub version: String,
pub kind: String,
pub state: String,
pub step: String,
pub lease: String,
pub cancel: bool,
pub error: String,
}
#[derive(Template)]
#[template(path = "build.html")]
pub(crate) struct BuildDetail {
pub page: Page,
pub id: String,
pub id_short: String,
pub pkgbase: String,
pub version: String,
pub kind: String,
pub state: String,
pub error: String,
pub blocked_on: Vec<String>,
pub steps: Vec<StepRow>,
pub log: String,
pub log_lines: usize,
pub log_truncated: bool,
}
#[derive(Debug, Clone)]
pub(crate) struct StepRow {
pub step: String,
pub status: String,
pub attempt: i64,
pub digest: String,
pub cls: String,
pub error: String,
}
#[derive(Template)]
#[template(path = "audit.html")]
pub struct Audit {
pub page: Page,
pub rows: Vec<AuditRow>,
}
#[derive(Debug, Clone)]
pub(crate) struct AuditRow {
pub at: String,
pub actor_kind: String,
pub actor: String,
pub action: String,
pub entity: String,
pub entity_id: String,
pub detail: String,
}
#[derive(Template)]
#[template(path = "settings.html")]
pub(crate) struct Settings {
pub page: Page,
pub rows: Vec<SettingRow>,
pub repo: String,
}
#[derive(Debug, Clone)]
pub(crate) struct SettingRow {
pub key: String,
pub value: String,
}
pub(crate) fn static_asset(name: &str, accept_gzip: bool) -> crate::http::Res {
use crate::http::Res;
match name {
"app.css" => {
let mut r = Res::text(200, std::include_str!("../../static/app.css").to_string());
r.content_type = "text/css".into();
r
}
"htmx.min.js" => {
if accept_gzip {
let gz: &[u8] = std::include_bytes!("../../static/htmx.min.js.gz");
let mut r = Res::stream(
"text/javascript",
std::io::Cursor::new(gz.to_vec()),
Some(gz.len()),
);
r.header("Content-Encoding", "gzip");
r.header("Cache-Control", "public, max-age=86400");
return r;
}
let raw: &[u8] = std::include_bytes!("../../static/htmx.min.js");
let mut r = Res::stream(
"text/javascript",
std::io::Cursor::new(raw.to_vec()),
Some(raw.len()),
);
r.header("Cache-Control", "public, max-age=86400");
r
}
_ => Res::text(404, "not found\n".into()),
}
}
|