mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
31859651d7
Every help screen checked against the v5 redesign. Tours is documented for the first time, as a screen of its own with twelve screens under it, and notifications get help of their own. All pictures are taken again on a realistic demo trip, with short loops where a still cannot show the motion. The English is plain and every language is written naturally rather than word for word. The switcher shows two levels at most, a screen's overview lists its sub-screens as cards above its guides, each wiki page is linked once, and the help sidebar is wider. Fixes found along the way: Save to Collection keeps a tour's route, a track dropped on the places column opens the Tours import, tour Share on desktop, the unsaved tour draft lives on the account, a route click no longer adds an end point, Trip places leaves the trip's tours out, Escape closes a stage's day menu, confirms before destructive deletes, DWD warnings sharing one id kept apart, a booking's date moves with it, and smaller fixes across notifications, bookings, the day plan, stays, Atlas, Collections, Vacay and the admin screens.
77 lines
4.0 KiB
TypeScript
77 lines
4.0 KiB
TypeScript
import type { APIRequestContext } from '@playwright/test';
|
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
/**
|
|
* Cover photos for the demo trips.
|
|
*
|
|
* A drawn cover reads as a placeholder at the size the dashboard shows it, and
|
|
* the help pictures are meant to look like a real traveller's TREK. So the
|
|
* covers are landscape photographs from Wikimedia Commons under free licences,
|
|
* downloaded at run time into `e2e/.tmp/photos/` and never committed: the
|
|
* repository carries no photographs. No person is recognisable in any of them.
|
|
*
|
|
* When Commons cannot be reached the trip simply keeps no cover, which the
|
|
* dashboard handles; the run does not fail over a decoration.
|
|
*/
|
|
export const COVER_PHOTOS = {
|
|
// Kiyomizu-dera, Kyoto, November 2016 -02.jpg, CC BY-SA 4.0
|
|
japan:
|
|
'https://thumb.wikimedia.org/wikipedia/commons/thumb/a/ae/Kiyomizu-dera%2C_Kyoto%2C_November_2016_-02.jpg/1920px-Kiyomizu-dera%2C_Kyoto%2C_November_2016_-02.jpg',
|
|
// Croda dei Toni and Tre Cime di Lavaredo from Monte Specie, 2025 October.jpg, CC BY-SA 4.0
|
|
dolomites:
|
|
'https://thumb.wikimedia.org/wikipedia/commons/thumb/7/77/Croda_dei_Toni_and_Tre_Cime_di_Lavaredo_from_Monte_Specie%2C_Val_Pusteria%2C_Trentino-Alto_Adige%2C_Italy%2C_2025_October.jpg/1920px-Croda_dei_Toni_and_Tre_Cime_di_Lavaredo_from_Monte_Specie%2C_Val_Pusteria%2C_Trentino-Alto_Adige%2C_Italy%2C_2025_October.jpg',
|
|
// Sella Ronda Overview.jpg, CC0
|
|
ski: 'https://thumb.wikimedia.org/wikipedia/commons/thumb/6/60/Sella_Ronda_Overview.jpg/1920px-Sella_Ronda_Overview.jpg',
|
|
// Geirangerfjord from Ørnesvingen, 2013 June.jpg, CC BY-SA 3.0
|
|
norway:
|
|
'https://thumb.wikimedia.org/wikipedia/commons/thumb/2/2b/Geirangerfjord_from_%C3%98rnesvingen%2C_2013_June.jpg/1920px-Geirangerfjord_from_%C3%98rnesvingen%2C_2013_June.jpg',
|
|
// RhB ABe 4-4 III mit Bernina-Express am Lago Bianco.jpg, CC BY-SA 3.0
|
|
alps: 'https://thumb.wikimedia.org/wikipedia/commons/thumb/7/7c/RhB_ABe_4-4_III_mit_Bernina-Express_am_Lago_Bianco.jpg/1920px-RhB_ABe_4-4_III_mit_Bernina-Express_am_Lago_Bianco.jpg',
|
|
// Le tram 28.jpg, CC BY-SA 4.0
|
|
lisbon: 'https://thumb.wikimedia.org/wikipedia/commons/thumb/b/b5/Le_tram_28.jpg/1920px-Le_tram_28.jpg',
|
|
} as const;
|
|
|
|
export type CoverPhoto = keyof typeof COVER_PHOTOS;
|
|
|
|
const PHOTO_DIR = path.join(process.cwd(), 'e2e', '.tmp', 'photos');
|
|
// Commons asks every client to name itself; anonymous bursts get a 429.
|
|
const USER_AGENT = 'TREK-help-media/1.0 (documentation screenshots; https://github.com/liketrek/TREK)';
|
|
|
|
/** The photo on disk, downloaded once; null when Commons cannot be reached. */
|
|
export async function coverPhoto(key: CoverPhoto): Promise<string | null> {
|
|
const file = path.join(PHOTO_DIR, `${key}.jpg`);
|
|
if (existsSync(file)) return file;
|
|
mkdirSync(PHOTO_DIR, { recursive: true });
|
|
for (let attempt = 1; attempt <= 4; attempt++) {
|
|
try {
|
|
const res = await fetch(COVER_PHOTOS[key], {
|
|
headers: { 'User-Agent': USER_AGENT },
|
|
signal: AbortSignal.timeout(30_000),
|
|
});
|
|
if (res.status === 429) {
|
|
await new Promise((resolve) => setTimeout(resolve, attempt * 5_000));
|
|
continue;
|
|
}
|
|
if (!res.ok) break;
|
|
writeFileSync(file, Buffer.from(await res.arrayBuffer()));
|
|
return file;
|
|
} catch {
|
|
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
|
}
|
|
}
|
|
console.warn(`cover photo "${key}" could not be downloaded; the trip keeps no cover`);
|
|
return null;
|
|
}
|
|
|
|
/** Upload the photo as the trip's cover, the way the trip form does. */
|
|
export async function setTripCover(api: APIRequestContext, tripId: number, key: CoverPhoto): Promise<void> {
|
|
const file = await coverPhoto(key);
|
|
if (!file) return;
|
|
const { readFileSync } = await import('node:fs');
|
|
const res = await api.post(`/api/trips/${tripId}/cover`, {
|
|
multipart: { cover: { name: `${key}.jpg`, mimeType: 'image/jpeg', buffer: readFileSync(file) } },
|
|
});
|
|
if (!res.ok()) console.warn(`cover for trip ${tripId} was refused: ${res.status()} ${await res.text()}`);
|
|
}
|