Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ $SCP backend/target/photokeeper-backend-0.1.0-SNAPSHOT.jar \
BLUE_PORT=8080
GREEN_PORT=8081
UPSTREAM_CONF=/etc/nginx/conf.d/photokeeper-upstream.conf
ROUTES_DIR=/etc/nginx/app-routes
ROUTE_CONF=$ROUTES_DIR/photokeeper.conf
NGINX_SITE=/etc/nginx/sites-available/gameroom
READY_TIMEOUT=120 # seconds to wait for the new instance to serve a page
DRAIN_SECONDS=10 # let in-flight requests finish before stopping the old one
Expand Down Expand Up @@ -157,28 +159,37 @@ server.servlet.context-path=/photokeeper
server.ssl.enabled=false
EOF"

# --- Point nginx at an upstream it can be re-aimed at ---
# One-time migration off the hardcoded localhost:8080. The site file is shared
# with GameRoom, Keezen and Qwixx, so it is backed up and the result is tested
# before anything is reloaded — a syntax error here would take all of them down.
echo "🔀 Ensuring nginx upstream..."
# --- Point nginx at PhotoKeeper: an upstream it can re-aim, and a route of its own ---
# The route is a file of PhotoKeeper's own in /etc/nginx/app-routes/, included from GameRoom's
# site (GWT_GameRoom/nginx.conf). It used to be a block inside GameRoom's file, and GameRoom's
# setup-pi.sh copies that file over the Pi's — which wiped the block and took PhotoKeeper offline.
# Installed on every release, so the route can never stay lost.
#
# Same nginx serves GameRoom, Keezen, Qwixx and the portfolio, so nothing is reloaded untested: a
# rejected config puts the previous route back and stops the release.
echo "🔀 Ensuring nginx upstream and route..."
$SCP ops/nginx-route.conf "$TARGET:/home/ubuntu/photokeeper-route.conf"
$SSH "
set -e
if [ ! -f $UPSTREAM_CONF ]; then
printf 'upstream photokeeper_backend { server 127.0.0.1:%s; }\n' '$SEED_PORT' | \
sudo tee $UPSTREAM_CONF > /dev/null
fi
if grep -q 'proxy_pass http://localhost:8080/photokeeper/;' $NGINX_SITE; then
sudo cp $NGINX_SITE $NGINX_SITE.pre-bluegreen
sudo sed -i 's|proxy_pass http://localhost:8080/photokeeper/;|proxy_pass http://photokeeper_backend/photokeeper/;|' $NGINX_SITE
if ! sudo nginx -t; then
echo '❌ nginx rejected the upstream change — restoring'
sudo mv $NGINX_SITE.pre-bluegreen $NGINX_SITE
sudo rm -f $UPSTREAM_CONF
exit 1
fi
sudo systemctl reload nginx
fi"
if ! grep -q 'include $ROUTES_DIR/\*.conf;' $NGINX_SITE; then
echo '❌ $NGINX_SITE does not include $ROUTES_DIR/*.conf, so PhotoKeeper would not be reachable.'
echo ' Run GWT_GameRoom/setup-pi.sh (its nginx.conf has the include) and deploy again.'
exit 1
fi
sudo mkdir -p $ROUTES_DIR
[ -f $ROUTE_CONF ] && sudo cp $ROUTE_CONF $ROUTE_CONF.prev
sudo mv /home/ubuntu/photokeeper-route.conf $ROUTE_CONF
if ! sudo nginx -t; then
echo '❌ nginx rejected the PhotoKeeper route — restoring the previous one'
if [ -f $ROUTE_CONF.prev ]; then sudo mv $ROUTE_CONF.prev $ROUTE_CONF; else sudo rm -f $ROUTE_CONF; fi
exit 1
fi
sudo rm -f $ROUTE_CONF.prev
sudo systemctl reload nginx"

# --- Start the idle colour and wait for it to actually answer ---
# --- Insist the port is ours before trusting anything answering on it ---
Expand Down Expand Up @@ -245,5 +256,14 @@ fi
# release after that would find the port taken and refuse to go.
$SSH "sudo systemctl is-active --quiet photokeeper.service && sudo systemctl disable --now photokeeper.service" || true

# --- Confirm it is reachable the way a phone reaches it: through nginx, by hostname ---
# The probes above talk to the instance's port directly, so they pass even when nginx has no
# route to it — which is exactly how PhotoKeeper once went offline with every check green.
if ! $SSH "curl -sf -o /dev/null -H 'Host: antondegroot.uk' http://127.0.0.1/photokeeper/"; then
echo "❌ $COLOUR is running, but nginx does not route /photokeeper/ to it."
echo " Check $ROUTE_CONF and that $NGINX_SITE includes $ROUTES_DIR/*.conf."
exit 1
fi

echo "✅ Done — $COLOUR live on port $PORT. https://antondegroot.uk/photokeeper"
echo " Install page: https://antondegroot.uk/photokeeper/download"
1 change: 1 addition & 0 deletions frontend/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default tseslint.config(
'src/app/review/deck/selection/group-corrections.ts',
'src/app/review/deck/review-buffer-target.ts',
'src/app/review/progress/day.ts',
'src/app/review/progress/daily-tally.ts',
'src/app/review/pano/pano-frames.ts',
'src/app/review/edits/edit-detection.ts',
'src/app/review/edits/merged-photo.ts',
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/app/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,11 @@ describe('App', () => {

app.resolveBurst(['f1']);

// The survivor takes the burst's place, undecided: winning a duel is not a verdict.
expect(app.reviewPhotos().map((p) => p.id)).toEqual(['f1']);
expect(app.reviewPhotos()[0].status).toBe('backlog');
// The survivor takes the burst's place, undecided: winning a duel is not a verdict. The loser
// stays ahead of it as a rejected burst, so the day counts it.
expect(app.reviewPhotos().map((p) => p.id)).toEqual(['burst:alb-1:f1', 'f1']);
expect(app.reviewPhotos()[0].status).toBe('rejected');
expect(app.reviewPhotos()[1].status).toBe('backlog');
await tick();
expect(saved.get('f2')?.status).toBe('rejected'); // loser
expect(saved.has('f1')).toBe(false); // survivor: nothing decided about it yet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ describe('ReviewDecisionsService', () => {
index.set(0);
service.resolveBurst(['f1', 'f2']);
await Promise.resolve();
expect(photos().map((p) => p.id)).toEqual(['f1', 'f2']);
expect(photos().map((p) => p.id)).toEqual(['b1', 'f1', 'f2']);

await undoLatest();

Expand Down Expand Up @@ -616,9 +616,11 @@ describe('ReviewDecisionsService', () => {
service.resolveBurst(['f2']);
await Promise.resolve();

expect(photos().map((p) => p.id)).toEqual(['f2', 'later']);
expect(photos()[0]).toMatchObject({ kind: 'photo', status: 'backlog' });
expect(index()).toBe(0); // the cursor stays on it — it is the next card
// The losers stay on the deck as a decided burst, ahead of the survivor, so the day counts them.
expect(photos().map((p) => p.id)).toEqual(['grp', 'f2', 'later']);
expect(photos()[0]).toMatchObject({ kind: 'burst', status: 'rejected' });
expect(photos()[1]).toMatchObject({ kind: 'photo', status: 'backlog' });
expect(index()).toBe(1); // the cursor is on the survivor — it is the next card
expect(verdicts).toContainEqual({
id: 'f1',
verdict: { status: 'rejected', starred: false, saveOnly: false },
Expand All @@ -639,7 +641,7 @@ describe('ReviewDecisionsService', () => {
service.resolveBurst(['f1', 'f3']);
await Promise.resolve();

expect(photos().map((p) => p.id)).toEqual(['f1', 'f3']);
expect(photos().map((p) => p.id)).toEqual(['grp', 'f1', 'f3']);
expect(verdicts).toContainEqual({
id: 'f2',
verdict: { status: 'rejected', starred: false, saveOnly: false },
Expand Down
28 changes: 20 additions & 8 deletions frontend/src/app/review/decisions/review-decisions.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { decidedPhotographs } from '../progress/daily-tally';
import { Injectable, effect, inject, signal, untracked } from '@angular/core';
import { ReviewStore } from '../../storage/review/review-store';
import { StoredVerdict } from '../../storage/photokeeper-db';
Expand Down Expand Up @@ -259,8 +260,10 @@ export class ReviewDecisionsService {
* <p>Surviving is not a verdict. The duel asks which frames of a near-identical run are worth
* looking at, which is a different question from whether a photograph is a keeper, one to edit, or
* one to set aside — so the survivors go back on the deck as ordinary single photos, right where
* the burst stood, and are judged one at a time. Only those judgements count toward the day, or the
* same photographs would be counted twice.
* the burst stood, and are judged one at a time. The frames that did not survive stay on the deck
* as a rejected burst of their own, just ahead of the survivors: rejecting a frame of a burst is the
* same work as rejecting a single photo, so the day's tally counts each one. The survivors count
* when they are judged, so no photograph is counted twice.
*
* <p>The group is dissolved on the way out. It is spent either way — its frames have been looked
* at — and without that record the next selection hydrates it from detection all over again: the
Expand Down Expand Up @@ -294,10 +297,19 @@ export class ReviewDecisionsService {
this.feed.advance();
return;
}
this.replaceWithFrames(
current,
survivors.map((frame) => burstFrameToPhoto(frame, current)),
);
const culled = current.photos.filter((frame) => !kept.has(frame.id));
const frames = survivors.map((frame) => burstFrameToPhoto(frame, current));
if (culled.length === 0) {
this.replaceWithFrames(current, frames);
return;
}
// Decided, so it goes behind the cursor like any decided unit: the next card is a survivor.
this.replaceWithFrames(current, [
{ ...current, status: 'rejected', photos: culled },
...frames,
]);
this.feed.advance();
this.recordReviewProgress();
}

/** "Reject the whole burst" — the same settlement with nothing kept. */
Expand All @@ -313,7 +325,7 @@ export class ReviewDecisionsService {
* looked at, and judging them while they are still in mind is the point of sending them back
* rather than leaving them to a later day's draw.
*/
private replaceWithFrames(unit: ReviewItem, frames: Photo[]): void {
private replaceWithFrames(unit: ReviewItem, frames: ReviewItem[]): void {
this.feed.photos.update((list) => {
const at = list.findIndex((item) => item.id === unit.id);
return at === -1 ? list : [...list.slice(0, at), ...frames, ...list.slice(at + 1)];
Expand Down Expand Up @@ -627,7 +639,7 @@ export class ReviewDecisionsService {
*/
private recordReviewProgress(): void {
if (!this.feed.loaded()) return;
this.progress.recordReviews(this.feed.photos().filter((p) => p.status !== 'backlog').length);
this.progress.recordReviews(decidedPhotographs(this.feed.photos()));
}

/**
Expand Down
39 changes: 39 additions & 0 deletions frontend/src/app/review/progress/daily-tally.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Burst, Photo } from '../../photo';
import { decidedPhotographs } from './daily-tally';

const frames = (count: number) =>
Array.from({ length: count }, (_, i) => ({ id: `f${i}`, name: `IMG_${i}` }));

function photo(id: string, status: Photo['status']): Photo {
return {
id,
name: id,
album: null,
taken: '2026-11-14',
status,
kind: 'photo',
starred: false,
saveOnly: false,
};
}

describe('decidedPhotographs', () => {
it('counts every frame of a burst: 3 kept out of 10 is 10 photographs judged', () => {
// What a settled burst leaves on the deck: its 7 rejected frames as one decided burst, and the
// 3 survivors as photos judged one at a time. Rejecting a frame of a burst is the same work as
// rejecting a single photo, so the day counts all ten — not 3, and not 4.
const culled: Burst = {
id: 'burst:alb:f0',
name: 'Burst · 7 frames',
album: null,
taken: '2026-11-14',
status: 'rejected',
kind: 'burst',
photos: frames(7),
};

const deck = [culled, photo('k1', 'kept'), photo('k2', 'kept'), photo('k3', 'toEdit')];

expect(decidedPhotographs(deck)).toBe(10);
});
});
22 changes: 22 additions & 0 deletions frontend/src/app/review/progress/daily-tally.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// What counts toward the day's sorting goal. Pure over the deck.

import { ReviewItem } from '../../photo';

/**
* How many photographs deciding this unit judged, for the day's tally.
*
* A burst counts every frame in it: rejecting a frame of a burst is the same work as rejecting a
* single photo, and a ten-frame burst settled in one go is ten photographs looked at. Every other
* unit is one picture — a panorama or a stereo pair is judged as the single image it makes, and an
* edit with its original is one shot.
*/
export function photographsJudged(item: ReviewItem): number {
return item.kind === 'burst' ? item.photos.length : 1;
}

/** The day's tally: photographs judged across every decided unit of the deck. */
export function decidedPhotographs(deck: readonly ReviewItem[]): number {
return deck
.filter((item) => item.status !== 'backlog')
.reduce((sum, item) => sum + photographsJudged(item), 0);
}
20 changes: 13 additions & 7 deletions frontend/src/app/review/progress/review-stats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ReviewFeedService } from '../deck/review-feed.service';
import { ReviewDecisionsService } from '../decisions/review-decisions.service';
import { PreferencesService } from '../../preferences.service';
import { Photo } from '../../photo';
import { decidedPhotographs, photographsJudged } from './daily-tally';

/** Buckets photos by album for the Edit/Print "by album" sections (null album → "No album"). */
function groupByAlbum(photos: Photo[]): { album: string; photos: Photo[] }[] {
Expand All @@ -27,16 +28,21 @@ export class ReviewStatsService {
private readonly decisions = inject(ReviewDecisionsService);
private readonly prefs = inject(PreferencesService);

/** How many units have a verdict today (anything out of backlog), and whether the run is complete. */
readonly doneToday = computed(
() => this.feed.photos().filter((p) => p.status !== 'backlog').length,
);
readonly sessionDone = computed(() => this.doneToday() === this.feed.photos().length);
/**
* How many photographs have been judged today — a burst counts each of its frames (see
* {@link photographsJudged}) — and whether the deck has nothing left undecided.
*/
readonly doneToday = computed(() => decidedPhotographs(this.feed.photos()));
readonly sessionDone = computed(() => this.feed.photos().every((p) => p.status !== 'backlog'));

// Per-verdict tallies for the session summary.
readonly keptCount = computed(() => this.feed.photos().filter((p) => p.status === 'kept').length);
readonly rejectedCount = computed(
() => this.feed.photos().filter((p) => p.status === 'rejected').length,
// Weighted like the day's tally, so a burst's rejected frames show up here as photographs too.
readonly rejectedCount = computed(() =>
this.feed
.photos()
.filter((p) => p.status === 'rejected')
.reduce((sum, p) => sum + photographsJudged(p), 0),
);
readonly toEditCount = computed(
() => this.feed.photos().filter((p) => p.status === 'toEdit').length,
Expand Down
17 changes: 17 additions & 0 deletions ops/nginx-route.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# PhotoKeeper's route on the Pi, installed by deploy.sh as /etc/nginx/app-routes/photokeeper.conf.
#
# Included inside GameRoom's server block (GWT_GameRoom/nginx.conf), which serves antondegroot.uk.
# It is a file of its own rather than a block in GameRoom's file because GameRoom's setup-pi.sh
# copies that file over the Pi's — which once wiped this route and took PhotoKeeper offline.
#
# photokeeper_backend is the blue/green upstream deploy.sh re-aims on each release
# (/etc/nginx/conf.d/photokeeper-upstream.conf). The prefix is kept, not stripped: the app runs
# with context path /photokeeper.
location /photokeeper/ {
proxy_pass http://photokeeper_backend/photokeeper/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Cloudflare Tunnel reaches nginx over plain HTTP; pass on the scheme Cloudflare saw.
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
}
Loading