diff --git a/packages/endpoint-posts/lib/middleware/validation.js b/packages/endpoint-posts/lib/middleware/validation.js index 3e319c4a5..660027f4c 100644 --- a/packages/endpoint-posts/lib/middleware/validation.js +++ b/packages/endpoint-posts/lib/middleware/validation.js @@ -2,12 +2,11 @@ import { check } from "express-validator"; import { LAT_LONG_RE } from "../utils.js"; export const validate = [ - check("audio") + check("audio.*") .if((value, { req }) => req.body?.["post-type"] === "audio") - .exists() - .isURL() + .notEmpty() .withMessage((value, { req }) => - req.__(`posts.error.url.empty`, "https://example.org/audio.mp3"), + req.__(`posts.error.media.empty`, "/music/audio.mp3"), ), check("bookmark-of") .if((value, { req }) => req.body?.["post-type"] === "bookmark") @@ -58,28 +57,26 @@ export const validate = [ ) .notEmpty() .withMessage((value, { req, path }) => req.__(`posts.error.${path}.empty`)), - check("photo") + check("photo.*.url") .if((value, { req }) => req.body?.["post-type"] === "photo") - .exists() - .isURL() + .notEmpty() .withMessage((value, { req }) => - req.__(`posts.error.url.empty`, "https://example.org/photo.jpg"), + req.__(`posts.error.media.empty`, "/photos/image.jpg"), ), - check("mp-photo-alt") + check("photo.*.alt") .if((value, { req }) => req.body?.["post-type"] === "photo") .notEmpty() - .withMessage((value, { req, path }) => req.__(`posts.error.${path}.empty`)), + .withMessage((value, { req }) => req.__(`posts.error.mp-photo-alt.empty`)), check("geo") .if((value, { req }) => req.body?.geo) .custom((value) => value.match(LAT_LONG_RE)) .withMessage((value, { req, path }) => req.__(`posts.error.${path}.invalid`), ), - check("video") + check("video.*") .if((value, { req }) => req.body?.["post-type"] === "video") - .exists() - .isURL() + .notEmpty() .withMessage((value, { req }) => - req.__(`posts.error.url.empty`, "https://example.org/video.mp4"), + req.__(`posts.error.media.empty`, "/movies/video.mp4"), ), ]; diff --git a/packages/endpoint-posts/locales/de.json b/packages/endpoint-posts/locales/de.json index 5ea827c47..1ef2d0ecd 100644 --- a/packages/endpoint-posts/locales/de.json +++ b/packages/endpoint-posts/locales/de.json @@ -17,6 +17,9 @@ "geo": { "invalid": "Geben Sie gültige Koordinaten ein" }, + "media": { + "empty": "Geben Sie einen Dateipfad oder eine Webadresse wie %s ein" + }, "mp-photo-alt": { "empty": "Geben Sie eine Beschreibung dieses Fotos ein" }, @@ -31,10 +34,7 @@ "advancedOptions": "Erweiterte Optionen", "audio": { "label": "Audio", - "title": "Audio %s", - "url": { - "label": "URL" - } + "title": "Audio %s" }, "back": "Beitragstyp ändern", "bookmark-of": { @@ -60,6 +60,12 @@ "like-of": { "label": "Wie von" }, + "media": { + "label": "Dateipfad oder URL" + }, + "mp-photo-alt": { + "label": "Barrierefreie Beschreibung" + }, "mp-slug": { "label": "Slug" }, @@ -70,14 +76,8 @@ "label": "Titel" }, "photo": { - "alt": { - "label": "Barrierefreie Beschreibung" - }, "label": "Foto", - "title": "Foto %s", - "url": { - "label": "URL" - } + "title": "Foto %s" }, "publish": "Beitrag veröffentlichen", "publishDraft": "Entwurf speichern", @@ -98,10 +98,7 @@ "updateDraft": "Entwurf aktualisieren", "video": { "label": "Video", - "title": "Video %s", - "url": { - "label": "URL" - } + "title": "Video %s" }, "visibility": { "label": "Sichtbarkeit" diff --git a/packages/endpoint-posts/locales/en.json b/packages/endpoint-posts/locales/en.json index bf4e75b49..b4e35629b 100644 --- a/packages/endpoint-posts/locales/en.json +++ b/packages/endpoint-posts/locales/en.json @@ -15,6 +15,9 @@ }, "url": { "empty": "Enter a web address like %s" + }, + "media": { + "empty": "Enter a file path or web address like %s" } }, "status": { @@ -59,10 +62,7 @@ "cancel": "Cancel", "audio": { "label": "Audio", - "title": "Audio %s", - "url": { - "label": "URL" - } + "title": "Audio %s" }, "bookmark-of": { "label": "Bookmark of" @@ -88,15 +88,11 @@ "name": { "label": "Title" }, - "photo": { - "label": "Photo", - "title": "Photo %s", - "alt": { - "label": "Accessible description" - }, - "url": { - "label": "URL" - } + "media": { + "label": "File path or URL" + }, + "mp-photo-alt": { + "label": "Accessible description" }, "mp-slug": { "label": "URL slug" @@ -104,6 +100,10 @@ "mp-syndicate-to": { "label": "Syndicate to" }, + "photo": { + "label": "Photo", + "title": "Photo %s" + }, "repost-of": { "label": "Repost of" }, @@ -119,10 +119,7 @@ }, "video": { "label": "Video", - "title": "Video %s", - "url": { - "label": "URL" - } + "title": "Video %s" }, "visibility": { "label": "Visibility" diff --git a/packages/endpoint-posts/locales/es.json b/packages/endpoint-posts/locales/es.json index e2cf94d85..a9977c5dc 100644 --- a/packages/endpoint-posts/locales/es.json +++ b/packages/endpoint-posts/locales/es.json @@ -17,6 +17,9 @@ "geo": { "invalid": "Introduce coordenadas válidas" }, + "media": { + "empty": "Introduce una ruta de archivo o una dirección web como %s" + }, "mp-photo-alt": { "empty": "Introduce una descripción de esta foto" }, @@ -31,10 +34,7 @@ "advancedOptions": "Opciones avanzadas", "audio": { "label": "Sonido", - "title": "Sonido %s", - "url": { - "label": "URL" - } + "title": "Sonido %s" }, "back": "Cambiar tipo de publicación", "bookmark-of": { @@ -60,6 +60,12 @@ "like-of": { "label": "Como de" }, + "media": { + "label": "Ruta o URL del archivo" + }, + "mp-photo-alt": { + "label": "Descripción accesible" + }, "mp-slug": { "label": "URL slug" }, @@ -70,14 +76,8 @@ "label": "Título" }, "photo": { - "alt": { - "label": "Descripción accesible" - }, "label": "Foto", - "title": "Foto %s", - "url": { - "label": "URL" - } + "title": "Foto %s" }, "publish": "Publicar publicación", "publishDraft": "Guardar borrador", @@ -98,10 +98,7 @@ "updateDraft": "Actualizar borrador", "video": { "label": "Vídeo", - "title": "Vídeo %s", - "url": { - "label": "URL" - } + "title": "Vídeo %s" }, "visibility": { "label": "Visibilidad" diff --git a/packages/endpoint-posts/locales/fr.json b/packages/endpoint-posts/locales/fr.json index 565b8f020..a84cb8433 100644 --- a/packages/endpoint-posts/locales/fr.json +++ b/packages/endpoint-posts/locales/fr.json @@ -17,6 +17,9 @@ "geo": { "invalid": "Saisir des coordonnées valides" }, + "media": { + "empty": "Entrez un chemin de fichier ou une adresse Web telle que %s" + }, "mp-photo-alt": { "empty": "Entrez une description de cette photo" }, @@ -31,10 +34,7 @@ "advancedOptions": "Options avancées", "audio": { "label": "Audio", - "title": "Audio %s", - "url": { - "label": "URL" - } + "title": "Audio %s" }, "back": "Modifier le type de publication", "bookmark-of": { @@ -60,6 +60,12 @@ "like-of": { "label": "J’aime" }, + "media": { + "label": "Chemin du fichier ou URL" + }, + "mp-photo-alt": { + "label": "Description accessible" + }, "mp-slug": { "label": "Identifiant unique d’URL (slug)" }, @@ -70,14 +76,8 @@ "label": "Titre" }, "photo": { - "alt": { - "label": "Description accessible" - }, "label": "Photo", - "title": "Photo %s", - "url": { - "label": "URL" - } + "title": "Photo %s" }, "publish": "Publier la publication", "publishDraft": "Enregistrer le brouillon", @@ -98,10 +98,7 @@ "updateDraft": "Mettre à jour le brouillon", "video": { "label": "Vidéo", - "title": "Vidéo %s", - "url": { - "label": "URL" - } + "title": "Vidéo %s" }, "visibility": { "label": "Visibilité" diff --git a/packages/endpoint-posts/locales/id.json b/packages/endpoint-posts/locales/id.json index c58cb21b2..ed52f3bad 100644 --- a/packages/endpoint-posts/locales/id.json +++ b/packages/endpoint-posts/locales/id.json @@ -17,6 +17,9 @@ "geo": { "invalid": "Masukkan koordinat yang valid" }, + "media": { + "empty": "Masukkan jalur berkas atau alamat web seperti %s" + }, "mp-photo-alt": { "empty": "Masukkan deskripsi foto ini" }, @@ -31,10 +34,7 @@ "advancedOptions": "Opsi lanjutan", "audio": { "label": "Audio", - "title": "Audio %s", - "url": { - "label": "Tautan (URL)" - } + "title": "Audio %s" }, "back": "Ubah jenis posting", "bookmark-of": { @@ -60,6 +60,12 @@ "like-of": { "label": "Seperti" }, + "media": { + "label": "Jalur file atau URL" + }, + "mp-photo-alt": { + "label": "Deskripsi yang dapat diakses" + }, "mp-slug": { "label": "URL siput" }, @@ -70,14 +76,8 @@ "label": "Judul" }, "photo": { - "alt": { - "label": "Deskripsi yang dapat diakses" - }, "label": "Foto", - "title": "Foto %s", - "url": { - "label": "Tautan (URL)" - } + "title": "Foto %s" }, "publish": "Publikasikan postingan", "publishDraft": "Simpan draf", @@ -98,10 +98,7 @@ "updateDraft": "Perbarui draf", "video": { "label": "Video", - "title": "Video %s", - "url": { - "label": "Tautan (URL)" - } + "title": "Video %s" }, "visibility": { "label": "Visibilitas" diff --git a/packages/endpoint-posts/locales/nl.json b/packages/endpoint-posts/locales/nl.json index 3846bac8b..cb1036fc8 100644 --- a/packages/endpoint-posts/locales/nl.json +++ b/packages/endpoint-posts/locales/nl.json @@ -17,6 +17,9 @@ "geo": { "invalid": "Voer geldige coördinaten in" }, + "media": { + "empty": "Voer een bestandspad of webadres in, zoals %s" + }, "mp-photo-alt": { "empty": "Voer een beschrijving van deze foto in" }, @@ -31,10 +34,7 @@ "advancedOptions": "Geavanceerde opties", "audio": { "label": "Audio", - "title": "Audio %s", - "url": { - "label": "URL" - } + "title": "Audio %s" }, "back": "Berichttype wijzigen", "bookmark-of": { @@ -60,6 +60,12 @@ "like-of": { "label": "Zoals van" }, + "media": { + "label": "Bestandspad of URL" + }, + "mp-photo-alt": { + "label": "Toegankelijke beschrijving" + }, "mp-slug": { "label": "URL-slug" }, @@ -70,14 +76,8 @@ "label": "Titel" }, "photo": { - "alt": { - "label": "Toegankelijke beschrijving" - }, "label": "Foto", - "title": "Foto %s", - "url": { - "label": "URL" - } + "title": "Foto %s" }, "publish": "Post publiceren", "publishDraft": "Concept opslaan", @@ -98,10 +98,7 @@ "updateDraft": "Concept bijwerken", "video": { "label": "Video", - "title": "Video %s", - "url": { - "label": "URL" - } + "title": "Video %s" }, "visibility": { "label": "Zichtbaarheid" diff --git a/packages/endpoint-posts/locales/pl.json b/packages/endpoint-posts/locales/pl.json index af276004a..30d464dab 100644 --- a/packages/endpoint-posts/locales/pl.json +++ b/packages/endpoint-posts/locales/pl.json @@ -17,6 +17,9 @@ "geo": { "invalid": "Wprowadź poprawne współrzędne" }, + "media": { + "empty": "Wprowadź ścieżkę pliku lub adres internetowy, taki jak %s" + }, "mp-photo-alt": { "empty": "Wprowadź opis tego zdjęcia" }, @@ -31,10 +34,7 @@ "advancedOptions": "Zaawansowane opcje", "audio": { "label": "Audio", - "title": "Audio %s", - "url": { - "label": "Adres URL" - } + "title": "Audio %s" }, "back": "Zmień typ posta", "bookmark-of": { @@ -60,6 +60,12 @@ "like-of": { "label": "Jak z" }, + "media": { + "label": "Ścieżka pliku lub adres URL" + }, + "mp-photo-alt": { + "label": "Dostępny opis" + }, "mp-slug": { "label": "Ślimak URL" }, @@ -70,14 +76,8 @@ "label": "Tytuł" }, "photo": { - "alt": { - "label": "Dostępny opis" - }, "label": "Zdjęcie", - "title": "Zdjęcie %s", - "url": { - "label": "Adres URL" - } + "title": "Zdjęcie %s" }, "publish": "Opublikuj post", "publishDraft": "Zapisz szkic", @@ -98,10 +98,7 @@ "updateDraft": "Zaktualizuj wersję roboczą", "video": { "label": "Wideo", - "title": "Wideo %s", - "url": { - "label": "Adres URL" - } + "title": "Wideo %s" }, "visibility": { "label": "Widoczność" diff --git a/packages/endpoint-posts/locales/pt.json b/packages/endpoint-posts/locales/pt.json index f749941ae..2de488e2a 100644 --- a/packages/endpoint-posts/locales/pt.json +++ b/packages/endpoint-posts/locales/pt.json @@ -17,6 +17,9 @@ "geo": { "invalid": "Insira coordenadas válidas" }, + "media": { + "empty": "Insira um caminho de arquivo ou endereço da web como %s" + }, "mp-photo-alt": { "empty": "Insira uma descrição desta foto" }, @@ -31,10 +34,7 @@ "advancedOptions": "Opções avançadas", "audio": { "label": "Áudio", - "title": "Áudio %s", - "url": { - "label": "URL" - } + "title": "Áudio %s" }, "back": "Alterar tipo de postagem", "bookmark-of": { @@ -60,6 +60,12 @@ "like-of": { "label": "Como de" }, + "media": { + "label": "Caminho do arquivo ou URL" + }, + "mp-photo-alt": { + "label": "Descrição acessível" + }, "mp-slug": { "label": "Slug de URL" }, @@ -70,14 +76,8 @@ "label": "Título" }, "photo": { - "alt": { - "label": "Descrição acessível" - }, "label": "Foto", - "title": "Foto %s", - "url": { - "label": "URL" - } + "title": "Foto %s" }, "publish": "Publicar postagem", "publishDraft": "Salvar rascunho", @@ -98,10 +98,7 @@ "updateDraft": "Atualizar rascunho", "video": { "label": "Vídeo", - "title": "Vídeo %s", - "url": { - "label": "URL" - } + "title": "Vídeo %s" }, "visibility": { "label": "Visibilidade" diff --git a/packages/endpoint-posts/locales/sr.json b/packages/endpoint-posts/locales/sr.json index 40d99162e..8fb39524c 100644 --- a/packages/endpoint-posts/locales/sr.json +++ b/packages/endpoint-posts/locales/sr.json @@ -17,6 +17,9 @@ "geo": { "invalid": "Unesite važeće koordinate" }, + "media": { + "empty": "Unesite putanju datoteke ili veb adresu kao što je %s" + }, "mp-photo-alt": { "empty": "Unesite opis ove fotografije" }, @@ -31,10 +34,7 @@ "advancedOptions": "Napredne opcije", "audio": { "label": "Audio", - "title": "Audio %s", - "url": { - "label": "URL" - } + "title": "Audio %s" }, "back": "Promenite tip posta", "bookmark-of": { @@ -60,6 +60,12 @@ "like-of": { "label": "Kao od" }, + "media": { + "label": "Putanja ili URL datoteke" + }, + "mp-photo-alt": { + "label": "Pristupačan opis" + }, "mp-slug": { "label": "URL slag" }, @@ -70,14 +76,8 @@ "label": "Naslov" }, "photo": { - "alt": { - "label": "Pristupačan opis" - }, "label": "Fotografija", - "title": "Fotografija %s", - "url": { - "label": "URL" - } + "title": "Fotografija %s" }, "publish": "Objavi post", "publishDraft": "Sačuvaj nacrt", @@ -98,10 +98,7 @@ "updateDraft": "Ažurirajte nacrt", "video": { "label": "Video", - "title": "Video %s", - "url": { - "label": "URL" - } + "title": "Video %s" }, "visibility": { "label": "Vidljivost" diff --git a/packages/endpoint-posts/locales/zh-Hans-CN.json b/packages/endpoint-posts/locales/zh-Hans-CN.json index 6761d4ea3..cbb2f2e5f 100644 --- a/packages/endpoint-posts/locales/zh-Hans-CN.json +++ b/packages/endpoint-posts/locales/zh-Hans-CN.json @@ -17,6 +17,9 @@ "geo": { "invalid": "输入有效坐标" }, + "media": { + "empty": "输入文件路径或网址,如 %s" + }, "mp-photo-alt": { "empty": "输入这张照片的描述" }, @@ -31,10 +34,7 @@ "advancedOptions": "高级选项", "audio": { "label": "音频", - "title": "音频 %s", - "url": { - "label": "网址" - } + "title": "音频 %s" }, "back": "更改帖子类型", "bookmark-of": { @@ -60,6 +60,12 @@ "like-of": { "label": "像这样" }, + "media": { + "label": "文件路径或 URL" + }, + "mp-photo-alt": { + "label": "无障碍描述" + }, "mp-slug": { "label": "网址 slug" }, @@ -70,14 +76,8 @@ "label": "标题" }, "photo": { - "alt": { - "label": "无障碍描述" - }, "label": "照片", - "title": "照片 %s", - "url": { - "label": "网址" - } + "title": "照片 %s" }, "publish": "发布帖子", "publishDraft": "保存草稿", @@ -98,10 +98,7 @@ "updateDraft": "更新草稿", "video": { "label": "视频", - "title": "视频 %s", - "url": { - "label": "网址" - } + "title": "视频 %s" }, "visibility": { "label": "可见度" diff --git a/packages/endpoint-posts/views/post-form.njk b/packages/endpoint-posts/views/post-form.njk index 108d32ac3..1cdf892b1 100644 --- a/packages/endpoint-posts/views/post-form.njk +++ b/packages/endpoint-posts/views/post-form.njk @@ -23,23 +23,24 @@ {% call fieldset({ classes: "fieldset--group", legend: { - text: __("posts.form.audio.title", index) if audio else __("posts.form.audio.label") + text: __("posts.form.audio.title", index + 1) } }) %} + {% set errorPath = errors["audio[" + index + "]"] %} {{ input({ - id: "audio", - name: "audio", + id: "audio-" + index, + name: "audio[" + index + "]", type: "url", - value: errors.audio.value or audio.url, + value: errorPath.value or audio, label: { - text: __("posts.form.audio.url.label") + text: __("posts.form.media.label") }, attributes: { placeholder: "https://" }, errorMessage: { - text: errors.audio.msg - } if errors.audio + text: errorPath.msg + } if errorPath }) | indent(2) }} {% endcall %} {% endmacro %} @@ -48,36 +49,38 @@ {% call fieldset({ classes: "fieldset--group", legend: { - text: __("posts.form.photo.title", index) if photo else __("posts.form.photo.label") + text: __("posts.form.photo.title", index + 1) } }) %} + {% set errorPath = errors["photo[" + index + "].url"] %} {{ input({ - id: "photo", - name: "photo", + id: "photo-" + index + "-url", + name: "photo[" + index + "][url]", type: "url", - value: errors.photo.value or photo.url, + value: errorPath.value or photo.url, label: { - text: __("posts.form.photo.url.label") + text: __("posts.form.media.label") }, attributes: { placeholder: "https://" }, errorMessage: { - text: errors.photo.msg - } if errors.photo + text: errorPath.msg + } if errorPath }) | indent(2) }} + {% set errorPath = errors["photo[" + index + "].alt"] %} {{ textarea({ - id: "mp-photo-alt", - name: "mp-photo-alt", - value: errors["mp-photo-alt"].value or photo.alt, + id: "photo-" + index + "-alt", + name: "photo[" + index + "][alt]", + value: errorPath.value or photo.alt, label: { - text: __("posts.form.photo.alt.label") + text: __("posts.form.mp-photo-alt.label") }, rows: 1, errorMessage: { - text: errors["mp-photo-alt"].msg - } if errors["mp-photo-alt"] + text: errorPath.msg + } if errorPath }) | indent(2) }} {% endcall %} {% endmacro %} @@ -86,23 +89,24 @@ {% call fieldset({ classes: "fieldset--group", legend: { - text: __("posts.form.video.title", index) if video else __("posts.form.video.label") + text: __("posts.form.video.title", index + 1) } }) %} + {% set errorPath = errors["video[" + index + "]"] %} {{ input({ - id: "video", - name: "video", + id: "video-" + index, + name: "video[" + index + "]", type: "url", - value: errors.video.value or video.url, + value: errorPath.value or video, label: { - text: __("posts.form.video.url.label") + text: __("posts.form.media.label") }, attributes: { placeholder: "https://" }, errorMessage: { - text: errors.video.msg - } if errors.video + text: errorPath.msg + } if errorPath }) | indent(2) }} {% endcall %} {% endmacro %} @@ -248,25 +252,25 @@ {% if postType === "audio" %} {% for audio in post.audio %} - {{ audioFieldset(loop.index, audio) }} + {{ audioFieldset(loop.index0, audio) }} {% else %} - {{ audioFieldset(1, false) }} + {{ audioFieldset(0, false) }} {% endfor %} {% endif %} {% if postType === "photo" %} {% for photo in post.photo %} - {{ photoFieldset(loop.index, photo) }} + {{ photoFieldset(loop.index0, photo) }} {% else %} - {{ photoFieldset(1, false) }} + {{ photoFieldset(0, false) }} {% endfor %} {% endif %} {% if postType === "video" %} {% for video in post.video %} - {{ videoFieldset(loop.index, video) }} + {{ videoFieldset(loop.index0, video) }} {% else %} - {{ videoFieldset(1, false) }} + {{ videoFieldset(0, false) }} {% endfor %} {% endif %}