diff --git a/src/app/api/certificat/[idAdresse]/components/certificat.tsx b/src/app/api/certificat/[idAdresse]/components/certificat.tsx index 601ed1fa5..7c7b8fe1a 100644 --- a/src/app/api/certificat/[idAdresse]/components/certificat.tsx +++ b/src/app/api/certificat/[idAdresse]/components/certificat.tsx @@ -30,9 +30,10 @@ interface CertificatNumerotationProps { telephone?: string email?: string } + logoUrl: string } -const CertificatNumerotation: React.FC = ({ data, qrCodeDataURL, mairie }) => { +const CertificatNumerotation: React.FC = ({ data, qrCodeDataURL, mairie, logoUrl }) => { const nomCommune = data.full_address.districtDefaultLabel const libelleVoie = data.full_address.commonToponymDefaultLabel const numero = data.full_address.number @@ -40,7 +41,7 @@ const CertificatNumerotation: React.FC = ({ data, q const { cog } = data.full_address const parcelles = data.cadastre_ids.map(id => id.replace(/(\d+)([A-Z])/, '$1 $2')) - const logoUrl = `public/logos/certificat/${cog}.png` + // const logoUrl = `public/logos/certificat/${cog}.png` const logoAdresse = `public/logos/certificat/adresse-logo.png` const dateObj = new Date(data.createdAt) @@ -67,6 +68,7 @@ const CertificatNumerotation: React.FC = ({ data, q + {'\n'} {/* Conteneur pour le logo de la mairie et les informations */} diff --git a/src/app/api/certificat/[idAdresse]/route.tsx b/src/app/api/certificat/[idAdresse]/route.tsx index cb5cb1c14..e6944f5a0 100644 --- a/src/app/api/certificat/[idAdresse]/route.tsx +++ b/src/app/api/certificat/[idAdresse]/route.tsx @@ -13,10 +13,8 @@ const isDistrictCertifiable = async (banIdDistrict: string | null): Promise ) diff --git a/src/lib/api-wikidata.ts b/src/lib/api-wikidata.ts index ebb9d7384..9087149e5 100644 --- a/src/lib/api-wikidata.ts +++ b/src/lib/api-wikidata.ts @@ -43,3 +43,32 @@ export const getCommuneFlag = async (codeCommune: string): Promise ` + SELECT ?city + ?inseeCode + ?cityLabel + ?logo + WHERE + { + ?city wdt:P374 "${codeCommune}". + ?city wdt:P374 ?inseeCode. + OPTIONAL { ?city wdt:P154 ?logo. } # Récupère le logo de la ville si disponible + SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } + } + ORDER BY ?inseeCode +` + +export const getCommuneLogo = async (codeCommune: string): Promise => { + const url = `${BASE_URL}/sparql?query=${encodeURIComponent(communeLogoQuery(codeCommune))}` + // Wikidata blocks requests without a user agent specific enough + const response = await fetch(url, { + headers: { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36', + }, + }) + const responseBody = await response.text() + const flagUrl = responseBody.match(/http.*\.png/)?.[0] + + return flagUrl +}