Docs in English (part 1), seeding guide, Coolify deployment
- Translate to English every doc the code branches did not touch: AGENT.md, developer guide, vibe, CHANGELOG, docs index, module pages, all skills except ipal-seo-check (14 pages follow after the security/SEO merge). Placeholder marker is now [TO FILL: …]; skill resources renamed to section-code.md / nav-code.md. AGENT.md and the ipal-skills pointer block say the docs are in English. - docs/seeding.md: create-only, natural keys, never delete, no users or secrets, empty-field globals, fallbackLocale: false, dry run, backup and restore, production update guard, seeds vs migrations, Coolify Terminal. Seed templates gain --dry-run, the SEED_UPDATE production guard (IPAL_SEED_ALLOW_PROD_UPDATE), skip of edited records and a summary. "Seeding on production" rule block in AGENT.md. - Coolify is the single deployment path (deployment, env, developer guide, ipal-setup): build vs runtime env, migrations on container start (prodMigrations), health check and rolling updates, rollback, backups and restore, DNS/Let's Encrypt/CAA. R2: custom domain needs a Cloudflare zone; default is media served by the app (R2_PUBLIC_URL empty). - docsConsistency: no Polish prose outside code/quoted data (pending pages listed); IPAL_* names may also be read by shipped skill templates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6e3979bae6
commit
2d9f3e15d4
+78
-77
@@ -1,27 +1,27 @@
|
||||
# media — kolekcja Media: nazwy plików, za duże uploady, placeholdery, propsy `<Media>`
|
||||
# media — the Media collection: file names, oversized uploads, placeholders, `<Media>` props
|
||||
|
||||
Klocki do kolekcji upload projektu (zwykle `media`) i do własnego komponentu `<Media>`.
|
||||
Plugin **nie dodaje** kolekcji Media ani komponentu — projekt składa je z tych części. Wszystko
|
||||
z głównego entry `@intecion/ipal-kit`.
|
||||
Building blocks for the project's upload collection (usually `media`) and for your own `<Media>` component.
|
||||
The plugin **does not add** a Media collection or a component — the project assembles them from these parts. Everything
|
||||
comes from the main entry `@intecion/ipal-kit`.
|
||||
|
||||
Powiązane: [storage.md](./storage.md) (R2, `buildImagesConfig`, `MediaPreconnect`, `YouTubeEmbed`),
|
||||
Related: [storage.md](./storage.md) (R2, `buildImagesConfig`, `MediaPreconnect`, `YouTubeEmbed`),
|
||||
[security.md](./security.md) (`buildUploadSecurityHeaders`).
|
||||
|
||||
| Eksport | Co to | Gdzie |
|
||||
| Export | What it is | Where |
|
||||
|---|---|---|
|
||||
| `normalizeFilenameHook` | `beforeOperation` — czyści nazwę pliku | `hooks.beforeOperation` |
|
||||
| `normalizeFilename(name)` | ta sama funkcja, bez hooka | dowolnie |
|
||||
| `buildOptimizeUploadHook(options?)` | `beforeOperation` — siatka na za duże pliki | `hooks.beforeOperation` |
|
||||
| `buildOptimizeUploadField(name?)` | checkbox zgody „Optimize this upload” | `fields` |
|
||||
| `buildMediaPlaceholderHook({ field?, size? })` | `beforeOperation` — blur + kolor dominujący | `hooks.beforeOperation` |
|
||||
| `buildMediaPlaceholderField(name?)` | ukryta grupa `placeholder` | `fields` |
|
||||
| `mediaImageProps(resource, options?)` | propsy `next/image` | komponent `<Media>` |
|
||||
| `videoProps(resource, options?)` | atrybuty `<video>` | komponent `<Media>` |
|
||||
| `MEDIA_SIZES` | gotowe wartości `sizes` | komponent `<Media>` |
|
||||
| `normalizeFilenameHook` | `beforeOperation` — cleans the file name | `hooks.beforeOperation` |
|
||||
| `normalizeFilename(name)` | the same function, without the hook | anywhere |
|
||||
| `buildOptimizeUploadHook(options?)` | `beforeOperation` — safety net for oversized files | `hooks.beforeOperation` |
|
||||
| `buildOptimizeUploadField(name?)` | consent checkbox "Optimize this upload" | `fields` |
|
||||
| `buildMediaPlaceholderHook({ field?, size? })` | `beforeOperation` — blur + dominant color | `hooks.beforeOperation` |
|
||||
| `buildMediaPlaceholderField(name?)` | hidden `placeholder` group | `fields` |
|
||||
| `mediaImageProps(resource, options?)` | `next/image` props | `<Media>` component |
|
||||
| `videoProps(resource, options?)` | `<video>` attributes | `<Media>` component |
|
||||
| `MEDIA_SIZES` | ready `sizes` values | `<Media>` component |
|
||||
|
||||
Typy: `OptimizeUploadOptions`, `MediaImageOptions`, `MediaImageProps`, `VideoMode`, `VideoProps`.
|
||||
Types: `OptimizeUploadOptions`, `MediaImageOptions`, `MediaImageProps`, `VideoMode`, `VideoProps`.
|
||||
|
||||
## Pełna kolekcja
|
||||
## Full collection
|
||||
|
||||
```ts
|
||||
// collections/Media.ts
|
||||
@@ -36,86 +36,87 @@ import {
|
||||
|
||||
export const Media: CollectionConfig = {
|
||||
slug: 'media',
|
||||
access: { read: () => true }, // public files; required when media are served by the app (/api/media/file/…)
|
||||
upload: { focalPoint: true, mimeTypes: ['image/*', 'application/pdf', 'video/mp4', 'video/webm'] },
|
||||
hooks: {
|
||||
// kolejność: najpierw nazwa, potem ewentualna konwersja, na końcu placeholder z gotowego pliku
|
||||
// order: name first, then any conversion, the placeholder last from the final file
|
||||
beforeOperation: [normalizeFilenameHook, buildOptimizeUploadHook(), buildMediaPlaceholderHook()],
|
||||
},
|
||||
fields: [
|
||||
{ name: 'alt', type: 'text', required: true, localized: true },
|
||||
buildOptimizeUploadField(), // checkbox w sidebarze
|
||||
buildMediaPlaceholderField(), // ukryte: placeholder.blurDataURL, placeholder.color
|
||||
buildOptimizeUploadField(), // checkbox in the sidebar
|
||||
buildMediaPlaceholderField(), // hidden: placeholder.blurDataURL, placeholder.color
|
||||
],
|
||||
}
|
||||
```
|
||||
|
||||
`buildOptimizeUploadHook` i `buildMediaPlaceholderHook` używają `sharp` przekazanego do
|
||||
`buildConfig({ sharp })` — plugin go nie importuje. Postgres z migracjami: nowe pola →
|
||||
`buildOptimizeUploadHook` and `buildMediaPlaceholderHook` use the `sharp` passed to
|
||||
`buildConfig({ sharp })` — the plugin does not import it. Postgres with migrations: new fields →
|
||||
`pnpm payload migrate:create`.
|
||||
|
||||
**Wyłącz / nadpisz:** każda część jest opt-in i niezależna — nie wpinasz hooka, nic się nie dzieje.
|
||||
Nazwy pól zmienisz parametrem (`consentField`, `field`, `name`), progi opcjami; zamiast hooka możesz
|
||||
użyć samej funkcji (`normalizeFilename`) we własnym hooku.
|
||||
**Turn off / override:** every part is opt-in and independent — if you don't wire a hook, nothing happens.
|
||||
Change field names with a parameter (`consentField`, `field`, `name`), thresholds with options; instead of the hook you can
|
||||
use the bare function (`normalizeFilename`) in your own hook.
|
||||
|
||||
## Nazwy plików — `normalizeFilenameHook`
|
||||
## File names — `normalizeFilenameHook`
|
||||
|
||||
Slugifikuje nazwę (diakrytyki, spacje, wielkość liter), zachowuje rozszerzenie (małymi literami):
|
||||
Slugifies the name (diacritics, spaces, letter case), keeps the extension (lowercase):
|
||||
|
||||
```
|
||||
"Zdjęcie jeden nad morzem.jpg" → "zdjecie-jeden-nad-morzem.jpg"
|
||||
"Faktura #12 (2024).PDF" → "faktura-12-2024.pdf"
|
||||
"###.png" → "plik.png" (pusta nazwa → „plik”)
|
||||
"###.png" → "plik.png" (empty name → "plik")
|
||||
```
|
||||
|
||||
Działa przy `create` i `update` z plikiem. Biegnie PRZED warstwą storage, więc czysta nazwa trafia
|
||||
i do bazy, i na dysk / do R2. Efekt: czyste, przenośne URL-e bez `%20` i znaków, które psują cache.
|
||||
Runs on `create` and on `update` with a file. It runs BEFORE the storage layer, so the clean name goes
|
||||
both to the database and to disk / R2. Result: clean, portable URLs without `%20` and characters that break caching.
|
||||
|
||||
## Za duże pliki — `buildOptimizeUploadHook` (za zgodą)
|
||||
## Oversized files — `buildOptimizeUploadHook` (with consent)
|
||||
|
||||
**Pliki przygotowuje programista / redaktor.** Hook tylko łapie wpadki (telefonowe zdjęcie 8 MB,
|
||||
surowe wideo 300 MB) i **niczego nie zmienia bez zgody**:
|
||||
**The developer / editor prepares the files.** The hook only catches mistakes (an 8 MB phone photo,
|
||||
a 300 MB raw video) and **changes nothing without consent**:
|
||||
|
||||
1. JPG/PNG ponad limit → zapis zatrzymany (400), komunikat np. „Image is 9.3 MB (limit 1.5 MB),
|
||||
4000 px wide (limit 2560 px). Tick *Optimize this upload*…”.
|
||||
2. Redaktor zaznacza checkbox i zapisuje ponownie → **WebP**, szerokość ≤ `maxImageWidth`, obrót wg
|
||||
EXIF, **metadane (EXIF/GPS) usunięte**; rozszerzenie → `.webp`. Checkbox wraca na „odznaczony”.
|
||||
Gdy konwersja nie zmniejszyła pliku, a szerokość była OK — zostaje oryginał.
|
||||
3. Wideo ponad limit → zatrzymane z instrukcją eksportu (MP4 H.264, 720p–1080p, 2–4 Mbit/s, fast
|
||||
start). **Wideo nigdy nie jest konwertowane.**
|
||||
1. JPG/PNG over the limit → save stopped (400), message e.g. "Image is 9.3 MB (limit 1.5 MB),
|
||||
4000 px wide (limit 2560 px). Tick *Optimize this upload*…".
|
||||
2. The editor ticks the checkbox and saves again → **WebP**, width ≤ `maxImageWidth`, rotated by
|
||||
EXIF, **metadata (EXIF/GPS) removed**; extension → `.webp`. The checkbox goes back to "unticked".
|
||||
When conversion did not make the file smaller and the width was fine — the original stays.
|
||||
3. Video over the limit → stopped with export instructions (MP4 H.264, 720p–1080p, 2–4 Mbit/s, fast
|
||||
start). **Video is never converted.**
|
||||
|
||||
| Typ | Zachowanie |
|
||||
| Type | Behavior |
|
||||
|---|---|
|
||||
| JPG, PNG w limicie | bez zmian |
|
||||
| JPG, PNG ponad limit | stop → za zgodą WebP + resize + bez metadanych |
|
||||
| GIF, SVG, WebP, AVIF, PDF, animowany PNG | zawsze bez zmian |
|
||||
| wideo ponad limit | stop z instrukcją (bez konwersji) |
|
||||
| JPG, PNG within the limit | unchanged |
|
||||
| JPG, PNG over the limit | stop → with consent WebP + resize + no metadata |
|
||||
| GIF, SVG, WebP, AVIF, PDF, animated PNG | always unchanged |
|
||||
| video over the limit | stop with instructions (no conversion) |
|
||||
|
||||
| Opcja | Domyślnie |
|
||||
| Option | Default |
|
||||
|---|---|
|
||||
| `maxImageBytes` | 1.5 MB |
|
||||
| `maxImageWidth` | 2560 px (też docelowa szerokość) |
|
||||
| `quality` | 82 (WebP stratny: JPG, PNG przy `png: 'lossy'`) |
|
||||
| `png` | `'lossless'` (zrzuty, logotypy); `'lossy'` = mniejsze, ryzyko rozmycia tekstu |
|
||||
| `maxVideoBytes` | 20 MB; `false` = bez limitu |
|
||||
| `consentField` | `'optimizeOnUpload'` — musi zgadzać się z `buildOptimizeUploadField(name)` |
|
||||
| `maxImageWidth` | 2560 px (also the target width) |
|
||||
| `quality` | 82 (lossy WebP: JPG, PNG with `png: 'lossy'`) |
|
||||
| `png` | `'lossless'` (screenshots, logos); `'lossy'` = smaller, risk of blurry text |
|
||||
| `maxVideoBytes` | 20 MB; `false` = no limit |
|
||||
| `consentField` | `'optimizeOnUpload'` — must match `buildOptimizeUploadField(name)` |
|
||||
|
||||
Bez `sharp` w configu: szerokość nie jest sprawdzana (tylko rozmiar), a zgoda na konwersję kończy
|
||||
się błędem 500 „Image optimization needs sharp”. Kolekcja musi dopuszczać `image/webp`
|
||||
(`image/*` dopuszcza).
|
||||
Without `sharp` in the config: the width is not checked (only the size), and consenting to conversion ends
|
||||
with a 500 error "Image optimization needs sharp". The collection must allow `image/webp`
|
||||
(`image/*` allows it).
|
||||
|
||||
## Placeholdery — `buildMediaPlaceholderHook` + `buildMediaPlaceholderField`
|
||||
## Placeholders — `buildMediaPlaceholderHook` + `buildMediaPlaceholderField`
|
||||
|
||||
Przy uploadzie obrazu rastrowego (AVIF, GIF, JPEG, PNG, WebP) liczy ~16 px podgląd (base64 WebP,
|
||||
kilkaset bajtów) i kolor dominujący. Zapisuje w ukrytej grupie `placeholder`
|
||||
(`blurDataURL`, `color`); obrazy z przezroczystością dostają `color: null`. Błąd nigdy nie blokuje
|
||||
uploadu (ostrzeżenie w logu). Bez `sharp` — nic. Istniejące obrazy dostają placeholder dopiero po
|
||||
ponownym zapisie z nowym plikiem.
|
||||
On upload of a raster image (AVIF, GIF, JPEG, PNG, WebP) it computes a ~16 px preview (base64 WebP,
|
||||
a few hundred bytes) and the dominant color. It saves them in the hidden `placeholder` group
|
||||
(`blurDataURL`, `color`); images with transparency get `color: null`. An error never blocks the
|
||||
upload (warning in the log). Without `sharp` — nothing. Existing images get a placeholder only after
|
||||
being saved again with a new file.
|
||||
|
||||
Opcje hooka: `field` (domyślnie `'placeholder'`), `size` (domyślnie 16 px).
|
||||
Hook options: `field` (default `'placeholder'`), `size` (default 16 px).
|
||||
|
||||
## `<Media>` w projekcie — `mediaImageProps`, `videoProps`, `MEDIA_SIZES`
|
||||
## `<Media>` in the project — `mediaImageProps`, `videoProps`, `MEDIA_SIZES`
|
||||
|
||||
Plugin liczy szczegóły wydajności, projekt zostawia sobie markup i wygląd:
|
||||
The plugin computes the performance details; the project keeps the markup and the look:
|
||||
|
||||
```tsx
|
||||
// src/components/ui/Media.tsx
|
||||
@@ -131,21 +132,21 @@ export function Media({ resource, priority, className }: Props) {
|
||||
}
|
||||
```
|
||||
|
||||
**`mediaImageProps(resource, { alt?, sizes?, priority?, placeholderColor? })`** → propsy
|
||||
`next/image` albo `null` (wideo, PDF, sam id, brak `width`/`height`):
|
||||
- `width`/`height` z dokumentu (bez przesunięć layoutu), `alt` z dokumentu (nadpisanie: `alt`, `''` dla dekoracji);
|
||||
- `sizes` domyślnie `'100vw'` — podaj realną szerokość (`MEDIA_SIZES`);
|
||||
- `priority: true` (jeden obraz LCP na stronę) → `loading="eager"`, `fetchPriority="high"`, `preload`
|
||||
(Next 16); inaczej `loading="lazy"`;
|
||||
**`mediaImageProps(resource, { alt?, sizes?, priority?, placeholderColor? })`** → `next/image`
|
||||
props or `null` (video, PDF, a bare id, no `width`/`height`):
|
||||
- `width`/`height` from the document (no layout shift), `alt` from the document (override: `alt`, `''` for decoration);
|
||||
- `sizes` defaults to `'100vw'` — give the real width (`MEDIA_SIZES`);
|
||||
- `priority: true` (one LCP image per page) → `loading="eager"`, `fetchPriority="high"`, `preload`
|
||||
(Next 16); otherwise `loading="lazy"`;
|
||||
- focal point (≠ 50/50) → `style.objectPosition`;
|
||||
- `placeholder.blurDataURL` → `placeholder="blur"`;
|
||||
- `placeholder.color` → `style.backgroundColor` wg `placeholderColor`: `'auto'` (domyślnie — tylko JPEG,
|
||||
bo kolor zostaje pod przezroczystymi pikselami), `true` (zawsze), `false` (nigdy).
|
||||
- `placeholder.color` → `style.backgroundColor` per `placeholderColor`: `'auto'` (default — JPEG only,
|
||||
because the color stays under transparent pixels), `true` (always), `false` (never).
|
||||
|
||||
**`videoProps(resource, { mode?, poster?, reducedMotion? })`** → atrybuty `<video>` albo `null`:
|
||||
- `'player'` (domyślnie): `controls`, `preload="none"`, `poster`;
|
||||
- `'background'`: `autoPlay` (wyłączone przy `reducedMotion: true`), `muted`, `loop`, `preload="metadata"`;
|
||||
- zawsze `playsInline`; `poster` — URL albo dokument Media.
|
||||
**`videoProps(resource, { mode?, poster?, reducedMotion? })`** → `<video>` attributes or `null`:
|
||||
- `'player'` (default): `controls`, `preload="none"`, `poster`;
|
||||
- `'background'`: `autoPlay` (off with `reducedMotion: true`), `muted`, `loop`, `preload="metadata"`;
|
||||
- always `playsInline`; `poster` — a URL or a Media document.
|
||||
|
||||
**`MEDIA_SIZES`** — punkty wyjścia dla `sizes`: `full` (`100vw`), `half`, `third`, `quarter`,
|
||||
`thumb` (`160px`). Każdą wartość możesz zastąpić własnym stringiem.
|
||||
**`MEDIA_SIZES`** — starting points for `sizes`: `full` (`100vw`), `half`, `third`, `quarter`,
|
||||
`thumb` (`160px`). You can replace any value with your own string.
|
||||
|
||||
Reference in New Issue
Block a user