Merge pull request 'feat(plugin): aquarelle seed media + upload script' (#39) from feat/aquarelle-seed-media into main
This commit is contained in:
commit
ffb39a3bf5
3 changed files with 114 additions and 0 deletions
35
scripts/upload-aquarelles.sh
Executable file
35
scripts/upload-aquarelles.sh
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env bash
|
||||
# Upload des illustrations aquarelles dans MinIO sous karbe-medias/seed/aquarelle/
|
||||
# + applique policy download (public-read) pour qu'elles soient servies via
|
||||
# media.karbe.cosmolan.fr.
|
||||
#
|
||||
# Prerequis :
|
||||
# - Fichiers présents dans /tmp/karbe-aquarelles/
|
||||
# - MinIO container karbe-minio en up + bucket karbe-medias existant
|
||||
# - .env.production accessible pour récupérer MINIO_ROOT_USER/PASSWORD
|
||||
#
|
||||
# Usage : ./scripts/upload-aquarelles.sh
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SRC="${1:-/tmp/karbe-aquarelles}"
|
||||
BUCKET="karbe-medias"
|
||||
PREFIX="seed/aquarelle"
|
||||
|
||||
ENV_FILE="/home/ubuntu/karbe/.env.production"
|
||||
USER=$(sudo grep -oP '^MINIO_ROOT_USER=\K.*' "$ENV_FILE")
|
||||
PASS=$(sudo grep -oP '^MINIO_ROOT_PASSWORD=\K.*' "$ENV_FILE")
|
||||
|
||||
echo " upload depuis $SRC vers minio://$BUCKET/$PREFIX/"
|
||||
docker run --rm \
|
||||
--network karbe-net \
|
||||
-v "$SRC:/data:ro" \
|
||||
--entrypoint sh \
|
||||
minio/mc:latest \
|
||||
-c "
|
||||
mc alias set karbe http://karbe-minio:9000 '$USER' '$PASS' >/dev/null
|
||||
mc cp /data/*.jpg /data/*.png karbe/$BUCKET/$PREFIX/
|
||||
mc anonymous set download karbe/$BUCKET || true
|
||||
echo '---'
|
||||
mc ls karbe/$BUCKET/$PREFIX/ | head -20
|
||||
"
|
||||
|
|
@ -30,6 +30,7 @@ import {
|
|||
seedPirogueProviders,
|
||||
} from "./seeds/pirogue-providers-default";
|
||||
import { seedEnglishContentPages } from "./seeds/content-pages-en";
|
||||
import { detachAquarelleMedia, seedAquarelleMedia } from "./seeds/aquarelle-media";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
// Mutuelle exclusion theme-guyane / theme-aquarelle : activer l'un
|
||||
|
|
@ -119,4 +120,18 @@ export const pluginHooks: Record<string, PluginHookSet | undefined> = {
|
|||
await disableOtherTheme("theme-aquarelle");
|
||||
},
|
||||
},
|
||||
"image-gallery-aquarelle-seed": {
|
||||
onEnable: async () => {
|
||||
const { attached } = await seedAquarelleMedia();
|
||||
console.log(
|
||||
`[plugin image-gallery-aquarelle-seed] ${attached} Media attachés aux carbets démo`,
|
||||
);
|
||||
},
|
||||
onDisable: async () => {
|
||||
const count = await detachAquarelleMedia();
|
||||
console.log(
|
||||
`[plugin image-gallery-aquarelle-seed] ${count} Media seedés détachés`,
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
64
src/lib/plugins/seeds/aquarelle-media.ts
Normal file
64
src/lib/plugins/seeds/aquarelle-media.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* Seed du plugin `image-gallery-aquarelle-seed`.
|
||||
*
|
||||
* Crée des entrées Media qui pointent vers les illustrations aquarelle uploadées
|
||||
* dans MinIO (bucket karbe-medias/seed/aquarelle/...). Une par carbet démo,
|
||||
* + une « hero » et 4 « scènes » accessibles séparément via l'URL theme.
|
||||
*
|
||||
* Les fichiers MinIO doivent être uploadés AVANT activation du plugin
|
||||
* (cf. scripts/upload-aquarelles.sh). Si les fichiers ne sont pas là, le seed
|
||||
* crée quand même les Media (URLs publiques 404, mais le toggle reste réversible).
|
||||
*/
|
||||
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { MediaType } from "@/generated/prisma/enums";
|
||||
import { aquarelleUrl } from "@/lib/theme";
|
||||
|
||||
const CARBET_AQUARELLES: { slug: string; file: string }[] = [
|
||||
{ slug: "demo-karbe-awara-maroni", file: "02-planche-carbet-awara.png" },
|
||||
{ slug: "demo-karbe-wapa-comte", file: "03-planche-carbet-wapa.png" },
|
||||
{ slug: "demo-karbe-maripa-approuague", file: "04-planche-carbet-maripa.png" },
|
||||
{ slug: "demo-karbe-paripou-oyapock", file: "05-planche-carbet-paripou.png" },
|
||||
{ slug: "demo-karbe-mahury-ce-hopital", file: "06-planche-carbet-mahury.png" },
|
||||
{ slug: "demo-karbe-kourou-couleuvre", file: "07-planche-carbet-kourou.png" },
|
||||
];
|
||||
|
||||
const SEED_PREFIX = "seed/aquarelle/";
|
||||
|
||||
export async function seedAquarelleMedia(): Promise<{ attached: number }> {
|
||||
let attached = 0;
|
||||
for (const { slug, file } of CARBET_AQUARELLES) {
|
||||
const carbet = await prisma.carbet.findUnique({ where: { slug } });
|
||||
if (!carbet) continue;
|
||||
|
||||
const s3Key = `${SEED_PREFIX}${file}`;
|
||||
const url = aquarelleUrl(file);
|
||||
|
||||
// Existe déjà ? upsert manuel via s3Key (pas d'unique sur s3Key, on filtre).
|
||||
const existing = await prisma.media.findFirst({
|
||||
where: { carbetId: carbet.id, s3Key },
|
||||
});
|
||||
if (existing) {
|
||||
attached += 1;
|
||||
continue;
|
||||
}
|
||||
await prisma.media.create({
|
||||
data: {
|
||||
carbetId: carbet.id,
|
||||
type: MediaType.PHOTO,
|
||||
s3Key,
|
||||
s3Url: url,
|
||||
sortOrder: 0,
|
||||
},
|
||||
});
|
||||
attached += 1;
|
||||
}
|
||||
return { attached };
|
||||
}
|
||||
|
||||
export async function detachAquarelleMedia(): Promise<number> {
|
||||
const result = await prisma.media.deleteMany({
|
||||
where: { s3Key: { startsWith: SEED_PREFIX } },
|
||||
});
|
||||
return result.count;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue