Security: - Token revocation. User gains a TokenVersion counter embedded in both tokens as a "tv" claim; AuthenticateToken rejects a token whose version no longer matches the row. Logout bumps it, so logging out now kills outstanding tokens rather than only clearing cookies. Costs one primary-key SELECT per authenticated request, which is the price of having revocation at all. - Spotify OAuth CSRF. The fixed SPOTIFY_AUTH_STATE constant is replaced by a per-request one-shot nonce, verified and consumed on callback. - Private chat attachments. Attachments on private messages are written to /backend/uploads/private/ and served at /uploads/private/, gated by the same nginx auth_request admin check used for /hasura/ and /notes/. Private uploads are rejected from non-admin callers. - The icecast admin UI (/radio/admin/) is behind the admin gate; listener traffic is untouched. - Store caches are mutex-guarded, so -race is clean. Bugs: - The email pipeline no longer drops emails permanently on transient failure. Failures record an attempt counter and are retried up to 3 times; the fetch window rewinds to the oldest retryable email's ReceivedAt, without which a retry could never re-fetch it. - Rowing duplicate detection distinguishes ErrRecordNotFound from a real DB error, so a transient failure no longer causes a duplicate insert plus a paid Claude call. - DeletePost propagates its delete error instead of reporting success. - RecentlyPlayed populates the cache it reads. - main.go exits non-zero if r.Run fails, so a port conflict is visible. - Python: the scan truncation flag is set on every deadline path; timed_out is reported by the worker rather than inferred from the clock; date validation uses Europe/London rather than server-local time. - Vue: Time.vue and Radio.vue intervals are cleared on unmount; Feed.vue guards a missing author; Timer.vue gets an explicit state machine and compares total elapsed seconds; Elle.vue's comma-operator call and per-frame console.log are fixed. Simplification: - One TTLCache replaces three near-identical cache implementations, with the differing eviction rules as explicit parameters. - run_scan's transport index no longer uses one object as both ordering record and live output; its three phases are separate functions. - _price_hotels submits all work to a single pool, so the nested-executor deadlock hazard is gone by construction. - The NDJSON event generators share one implementation. - IMAP FETCH responses pair each line with its literal in the type, so callers no longer hand-skip alternate entries. - Shared helpers for slice-of-pointers, markdown fences and auth cookies. - Vue: useHotelSearch, createMirrorStore, useRotation, useCreateForm, useLinkAttrs, ListWidget and LinkTableItems replace duplicated blocks. - nginx dev config's duplicated :80/:443 bodies share one partial. Infra: certbot passes --deploy-hook touching a sentinel that nginx's watcher reloads on, so renewed certs are served without a restart, and the watcher also removes the manual restart after first issuance. db is gated on service_healthy, autoheal is pinned, and the unused envsubst entries are dropped. Verified: go build/vet, npx vite build, py_compile, docker compose config for both overlays, bash -n on all scripts, and an envsubst render of every nginx template (no leftover placeholders, runtime vars preserved, braces balanced). Co-Authored-By: Claude Opus 5 <[email protected]>
373 lines
13 KiB
Vue
373 lines
13 KiB
Vue
<script setup>
|
||
/**
|
||
* "Single stay" tab of /hotels: cheapest hotels for one specific check-in date.
|
||
*
|
||
* Results stream in: the backend sends a `hotels` event with room prices first,
|
||
* then a `transport` event per hotel as each route is priced, then `done`. Rows
|
||
* are patched in place by hotel `code` so the table fills in rather than
|
||
* reloading, and PENDING_ROUTE marks the not-yet-priced ones.
|
||
*
|
||
* The abort/ticker/stream lifecycle lives in useHotelSearch(); this panel only
|
||
* supplies the request body and how to apply each streamed event.
|
||
*/
|
||
import { ref, computed, onMounted } from "vue";
|
||
import SharedFields from "./SharedFields.vue";
|
||
import HotelRows from "./HotelRows.vue";
|
||
import { useHotelSearch } from "./useHotelSearch.js";
|
||
import { nextFriday, todayIso } from "./useHotelForm.js";
|
||
import {
|
||
gbp,
|
||
fmtDate,
|
||
fmtTime,
|
||
cycleText,
|
||
byRoom,
|
||
byTotal,
|
||
byCycle,
|
||
byMinutes,
|
||
PENDING_ROUTE,
|
||
} from "./hotelsFormat.js";
|
||
|
||
const props = defineProps({
|
||
form: { type: Object, required: true },
|
||
});
|
||
|
||
const RANKINGS = [
|
||
{ key: "total", label: "Stay + transport" },
|
||
{ key: "room", label: "Stay only" },
|
||
{ key: "cycle", label: "Cycle time" },
|
||
{ key: "minutes", label: "Travel time" },
|
||
];
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Form state (this panel's own fields; shared ones live in props.form)
|
||
// ---------------------------------------------------------------------------
|
||
const checkin = ref(nextFriday());
|
||
const nights = ref(1);
|
||
const top = ref(20);
|
||
const rankBy = ref("total");
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Search state (searching/errorMsg/summary/done/elapsed come from the
|
||
// composable; rows and `cached` are this panel's own)
|
||
// ---------------------------------------------------------------------------
|
||
const rows = ref([]);
|
||
const cached = ref(false);
|
||
|
||
const {
|
||
searching,
|
||
errorMsg,
|
||
summary,
|
||
done,
|
||
elapsed,
|
||
statusText,
|
||
hasResults,
|
||
run: onSearch,
|
||
} = useHotelSearch({
|
||
url: "/py/hotels/search/stream",
|
||
buildRequest,
|
||
applyEvent,
|
||
onStart,
|
||
busyLabel: "Searching",
|
||
failMessage: "Search failed.",
|
||
earlyMessage: "The search ended early; showing what came back.",
|
||
});
|
||
|
||
const pricedCount = computed(
|
||
() => rows.value.filter((r) => r.total != null || r.route !== PENDING_ROUTE).length,
|
||
);
|
||
|
||
const sortedRows = computed(() => {
|
||
const cmp = { total: byTotal, room: byRoom, cycle: byCycle, minutes: byMinutes }[
|
||
rankBy.value
|
||
];
|
||
return [...rows.value].sort(cmp);
|
||
});
|
||
|
||
function firstBy(cmp, ok) {
|
||
const list = rows.value.filter(ok);
|
||
if (!list.length) return null;
|
||
return list.reduce((best, r) => (cmp(r, best) < 0 ? r : best));
|
||
}
|
||
|
||
const picks = computed(() => {
|
||
const p = [];
|
||
const best = firstBy(byTotal, (r) => r.total != null);
|
||
if (best)
|
||
p.push({
|
||
label: "Best value",
|
||
row: best,
|
||
maths: `${gbp(best.room_price)} stay + ${gbp(best.transport_total)} travel = ${gbp(best.total)}`,
|
||
sub: `${best.travel_minutes} min by ${best.route}`,
|
||
});
|
||
const room = firstBy(byRoom, (r) => r.room_price != null);
|
||
if (room)
|
||
p.push({
|
||
label: "Cheapest room",
|
||
row: room,
|
||
maths: `${gbp(room.room_price)} for the stay`,
|
||
sub:
|
||
room.total != null
|
||
? `${gbp(room.total)} with transport (${room.travel_minutes} min)`
|
||
: "transport not priced yet",
|
||
});
|
||
const cycle = firstBy(byCycle, (r) => r.cycle_minutes != null);
|
||
if (cycle)
|
||
p.push({
|
||
label: "Quickest cycle",
|
||
row: cycle,
|
||
maths: `${cycleText(cycle)} ride, ${gbp(cycle.room_price)} stay`,
|
||
sub: `${cycle.cycle_km} km from ${summary.value?.origin_name ?? "origin"}`,
|
||
});
|
||
return p;
|
||
});
|
||
|
||
const summaryText = computed(() => {
|
||
const s = summary.value;
|
||
if (!s) return "";
|
||
const party =
|
||
`${s.adults} adult${s.adults === 1 ? "" : "s"}` +
|
||
(s.children ? ` + ${s.children} child${s.children === 1 ? "" : "ren"}` : "") +
|
||
` in ${s.rooms} room${s.rooms === 1 ? "" : "s"}`;
|
||
const railcard = s.railcard_holders
|
||
? ` (${s.railcard_holders} with railcard)`
|
||
: "";
|
||
return (
|
||
`Cheapest ${rows.value.length} of ${s.hotels_available} available Travelodges near ` +
|
||
`'${s.location}', ${fmtDate(s.checkin)} → ${fmtDate(s.checkout)} ` +
|
||
`(${s.nights} night${s.nights === 1 ? "" : "s"}, ${party}), ` +
|
||
`with round-trip transport from ${s.origin_name} departing ${fmtTime(s.depart)}${railcard}.`
|
||
);
|
||
});
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Persistence
|
||
// ---------------------------------------------------------------------------
|
||
function saveConfig() {
|
||
props.form.save({
|
||
checkin: checkin.value,
|
||
nights: nights.value,
|
||
top: top.value,
|
||
rankBy: rankBy.value,
|
||
});
|
||
}
|
||
|
||
function loadConfig() {
|
||
const c = props.form.stored();
|
||
nights.value = c.nights ?? nights.value;
|
||
top.value = Math.min(40, c.top ?? top.value);
|
||
if (RANKINGS.some((r) => r.key === c.rankBy)) rankBy.value = c.rankBy;
|
||
// Only restore the date if it is still in the future.
|
||
if (c.checkin && c.checkin >= todayIso()) checkin.value = c.checkin;
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Search
|
||
// ---------------------------------------------------------------------------
|
||
function buildRequest() {
|
||
return {
|
||
...props.form.sharedBody(),
|
||
checkin: checkin.value,
|
||
nights: Number(nights.value),
|
||
top: Number(top.value),
|
||
};
|
||
}
|
||
|
||
/**
|
||
* Apply one NDJSON event from the search stream.
|
||
*
|
||
* Order is `hotels` (room prices for all candidates) -> many `transport`
|
||
* (one per hotel as its route is priced) -> `done`. Transport events patch the
|
||
* existing row in place, matched on hotel `code`, so the table fills in
|
||
* column-by-column instead of being rebuilt — that is what keeps scroll
|
||
* position and sort order stable while results arrive.
|
||
*/
|
||
function applyEvent(ev) {
|
||
switch (ev.event) {
|
||
case "hotels":
|
||
summary.value = ev.summary;
|
||
rows.value = ev.rows;
|
||
cached.value = !!ev.cached;
|
||
break;
|
||
case "transport": {
|
||
const existing = rows.value.find((r) => r.code === ev.row.code);
|
||
if (existing) Object.assign(existing, ev.row);
|
||
else rows.value.push(ev.row);
|
||
break;
|
||
}
|
||
case "done":
|
||
summary.value = ev.summary;
|
||
rows.value = ev.rows;
|
||
cached.value = !!ev.cached;
|
||
done.value = true;
|
||
break;
|
||
case "error":
|
||
errorMsg.value = ev.detail || "Search failed.";
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
/** Reset this panel's own result state before a run. */
|
||
function onStart() {
|
||
rows.value = [];
|
||
cached.value = false;
|
||
saveConfig();
|
||
}
|
||
|
||
onMounted(loadConfig);
|
||
</script>
|
||
|
||
<template>
|
||
<section class="panel">
|
||
<h2 class="panelTitle">Search</h2>
|
||
<form class="configGrid" @submit.prevent="onSearch">
|
||
<SharedFields :form="form" />
|
||
<label>
|
||
Check-in
|
||
<input type="date" v-model="checkin" required />
|
||
</label>
|
||
<label>
|
||
Nights
|
||
<input type="number" v-model.number="nights" min="1" max="14" />
|
||
</label>
|
||
<label>
|
||
Hotels to price
|
||
<input type="number" v-model.number="top" min="1" max="40" />
|
||
<span class="hint"
|
||
>N cheapest by room rate; TfL allows about 24 hotels a
|
||
minute</span
|
||
>
|
||
</label>
|
||
|
||
<div class="controls">
|
||
<button class="btn" type="submit" :disabled="searching">
|
||
{{ searching ? "Searching…" : "Search" }}
|
||
</button>
|
||
<span class="statusChip" :class="statusText.toLowerCase()">
|
||
{{ statusText }}
|
||
</span>
|
||
<span v-if="searching" class="stepCounter">{{ elapsed }}s</span>
|
||
<span class="note">
|
||
Hotels appear within a couple of seconds; transport prices
|
||
fill in as TfL answers.
|
||
</span>
|
||
</div>
|
||
</form>
|
||
|
||
<p v-if="errorMsg" class="errorBox">{{ errorMsg }}</p>
|
||
</section>
|
||
|
||
<section v-if="hasResults" class="panel">
|
||
<h2 class="panelTitle">
|
||
Results
|
||
<span v-if="cached" class="cachedTag">cached</span>
|
||
<span v-if="summary.truncated" class="cachedTag warn">time limit hit</span>
|
||
</h2>
|
||
<p class="summary">{{ summaryText }}</p>
|
||
|
||
<div class="progress" v-if="rows.length">
|
||
<div class="progressBar">
|
||
<div
|
||
class="progressFill"
|
||
:style="{ width: `${(100 * pricedCount) / rows.length}%` }"
|
||
></div>
|
||
</div>
|
||
<span class="progressText">
|
||
{{ pricedCount }} / {{ rows.length }} priced on TfL
|
||
</span>
|
||
</div>
|
||
|
||
<div v-if="picks.length" class="picks">
|
||
<div v-for="p in picks" :key="p.label" class="pick">
|
||
<span class="pickLabel">{{ p.label }}</span>
|
||
<a
|
||
class="pickName"
|
||
:href="p.row.url"
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
>{{ p.row.name }}</a
|
||
>
|
||
<span class="pickMaths">{{ p.maths }}</span>
|
||
<span class="pickSub">{{ p.sub }}</span>
|
||
</div>
|
||
</div>
|
||
|
||
<p v-if="!rows.length" class="note">
|
||
No hotels with availability matched that search.
|
||
</p>
|
||
|
||
<template v-else>
|
||
<div class="rankBar">
|
||
<span class="rankLabel">Rank by</span>
|
||
<button
|
||
v-for="r in RANKINGS"
|
||
:key="r.key"
|
||
type="button"
|
||
class="rankBtn"
|
||
:class="{ active: rankBy === r.key }"
|
||
@click="rankBy = r.key; saveConfig()"
|
||
>
|
||
{{ r.label }}
|
||
</button>
|
||
</div>
|
||
|
||
<div class="tableWrap">
|
||
<table class="results">
|
||
<thead>
|
||
<tr>
|
||
<th class="num">#</th>
|
||
<th class="num" :class="{ sorted: rankBy === 'total' }">Total</th>
|
||
<th class="num" :class="{ sorted: rankBy === 'room' }">Stay</th>
|
||
<th class="num">Travel</th>
|
||
<th class="num" :class="{ sorted: rankBy === 'minutes' }">Mins</th>
|
||
<th class="num" :class="{ sorted: rankBy === 'cycle' }">Cycle</th>
|
||
<th>Hotel</th>
|
||
<th>Route (cheapest acceptable)</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<HotelRows :rows="sortedRows" />
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</template>
|
||
|
||
<details class="help">
|
||
<summary>Notes</summary>
|
||
<ul>
|
||
<li>
|
||
Stay price is Travelodge's cheapest room(s) for the whole
|
||
stay and all rooms. Rank by "Stay only" to ignore transport
|
||
entirely.
|
||
</li>
|
||
<li>
|
||
Transport is the TfL adult pay-as-you-go single each way,
|
||
multiplied by adults. The return is assumed off-peak (next
|
||
day).
|
||
</li>
|
||
<li>
|
||
Cycle time is from the origin station on your own bike. A
|
||
"~" means it is estimated from the distance at about 14
|
||
km/h; without a tilde it is TfL's cycle route.
|
||
</li>
|
||
<li>
|
||
Children 10 and under travel free on TfL; 11–15s pay child
|
||
fares with a Zip card (not included).
|
||
</li>
|
||
<li>
|
||
The Railcard's 1/3 off applies to off-peak Tube and rail
|
||
fares only, and only when the Railcard is linked to an
|
||
Oyster card (not contactless).
|
||
</li>
|
||
<li>
|
||
Bus fares are flat and never discounted. Prices are rounded
|
||
to 5p. Room prices may be up to 30 minutes old. Everything
|
||
is an estimate: check the booking page and TfL before
|
||
paying.
|
||
</li>
|
||
</ul>
|
||
</details>
|
||
</section>
|
||
</template>
|