diff --git a/deploy.sh b/deploy.sh index c917a15..c19cdd6 100755 --- a/deploy.sh +++ b/deploy.sh @@ -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 @@ -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 --- @@ -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" diff --git a/frontend/eslint.config.js b/frontend/eslint.config.js index b308e20..e543ea0 100644 --- a/frontend/eslint.config.js +++ b/frontend/eslint.config.js @@ -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', diff --git a/frontend/src/app/app.spec.ts b/frontend/src/app/app.spec.ts index b0596a0..d23c1f2 100644 --- a/frontend/src/app/app.spec.ts +++ b/frontend/src/app/app.spec.ts @@ -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 diff --git a/frontend/src/app/review/decisions/review-decisions.service.spec.ts b/frontend/src/app/review/decisions/review-decisions.service.spec.ts index 5146d38..c1c9f3f 100644 --- a/frontend/src/app/review/decisions/review-decisions.service.spec.ts +++ b/frontend/src/app/review/decisions/review-decisions.service.spec.ts @@ -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(); @@ -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 }, @@ -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 }, diff --git a/frontend/src/app/review/decisions/review-decisions.service.ts b/frontend/src/app/review/decisions/review-decisions.service.ts index 097f2c6..5b3272f 100644 --- a/frontend/src/app/review/decisions/review-decisions.service.ts +++ b/frontend/src/app/review/decisions/review-decisions.service.ts @@ -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'; @@ -259,8 +260,10 @@ export class ReviewDecisionsService { *
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. * *
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 @@ -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. */ @@ -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)]; @@ -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())); } /** diff --git a/frontend/src/app/review/progress/daily-tally.spec.ts b/frontend/src/app/review/progress/daily-tally.spec.ts new file mode 100644 index 0000000..cbce15d --- /dev/null +++ b/frontend/src/app/review/progress/daily-tally.spec.ts @@ -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); + }); +}); diff --git a/frontend/src/app/review/progress/daily-tally.ts b/frontend/src/app/review/progress/daily-tally.ts new file mode 100644 index 0000000..5bc9eca --- /dev/null +++ b/frontend/src/app/review/progress/daily-tally.ts @@ -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); +} diff --git a/frontend/src/app/review/progress/review-stats.service.ts b/frontend/src/app/review/progress/review-stats.service.ts index a911a48..27dd894 100644 --- a/frontend/src/app/review/progress/review-stats.service.ts +++ b/frontend/src/app/review/progress/review-stats.service.ts @@ -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[] }[] { @@ -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, diff --git a/ops/nginx-route.conf b/ops/nginx-route.conf new file mode 100644 index 0000000..1e4e4d6 --- /dev/null +++ b/ops/nginx-route.conf @@ -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; +}