Skip to content

Commit

Permalink
feat(endpoint-posts): validate media arrays, allow for file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Aug 9, 2023
1 parent daec422 commit 25d14a7
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 199 deletions.
25 changes: 11 additions & 14 deletions packages/endpoint-posts/lib/middleware/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"),
),
];
27 changes: 12 additions & 15 deletions packages/endpoint-posts/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -31,10 +34,7 @@
"advancedOptions": "Erweiterte Optionen",
"audio": {
"label": "Audio",
"title": "Audio %s",
"url": {
"label": "URL"
}
"title": "Audio %s"
},
"back": "Beitragstyp ändern",
"bookmark-of": {
Expand All @@ -60,6 +60,12 @@
"like-of": {
"label": "Wie von"
},
"media": {
"label": "Dateipfad oder URL"
},
"mp-photo-alt": {
"label": "Barrierefreie Beschreibung"
},
"mp-slug": {
"label": "Slug"
},
Expand All @@ -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",
Expand All @@ -98,10 +98,7 @@
"updateDraft": "Entwurf aktualisieren",
"video": {
"label": "Video",
"title": "Video %s",
"url": {
"label": "URL"
}
"title": "Video %s"
},
"visibility": {
"label": "Sichtbarkeit"
Expand Down
31 changes: 14 additions & 17 deletions packages/endpoint-posts/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
},
"url": {
"empty": "Enter a web address like %s"
},
"media": {
"empty": "Enter a file path or web address like %s"
}
},
"status": {
Expand Down Expand Up @@ -59,10 +62,7 @@
"cancel": "Cancel",
"audio": {
"label": "Audio",
"title": "Audio %s",
"url": {
"label": "URL"
}
"title": "Audio %s"
},
"bookmark-of": {
"label": "Bookmark of"
Expand All @@ -88,22 +88,22 @@
"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"
},
"mp-syndicate-to": {
"label": "Syndicate to"
},
"photo": {
"label": "Photo",
"title": "Photo %s"
},
"repost-of": {
"label": "Repost of"
},
Expand All @@ -119,10 +119,7 @@
},
"video": {
"label": "Video",
"title": "Video %s",
"url": {
"label": "URL"
}
"title": "Video %s"
},
"visibility": {
"label": "Visibility"
Expand Down
27 changes: 12 additions & 15 deletions packages/endpoint-posts/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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": {
Expand All @@ -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"
},
Expand All @@ -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",
Expand All @@ -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"
Expand Down
27 changes: 12 additions & 15 deletions packages/endpoint-posts/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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": {
Expand All @@ -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)"
},
Expand All @@ -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",
Expand All @@ -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é"
Expand Down
27 changes: 12 additions & 15 deletions packages/endpoint-posts/locales/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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": {
Expand All @@ -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"
},
Expand All @@ -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",
Expand All @@ -98,10 +98,7 @@
"updateDraft": "Perbarui draf",
"video": {
"label": "Video",
"title": "Video %s",
"url": {
"label": "Tautan (URL)"
}
"title": "Video %s"
},
"visibility": {
"label": "Visibilitas"
Expand Down
Loading

0 comments on commit 25d14a7

Please sign in to comment.