From e8adcb9b1e1da66d248f252a16fcca42e58f93c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Fri, 15 Nov 2024 16:44:47 +0100 Subject: [PATCH] feat(#1616): add support for ipfs in metadata validation service --- CHANGELOG.md | 1 + govtool/metadata-validation/.env.example | 4 ++- govtool/metadata-validation/Dockerfile | 3 ++ .../metadata-validation/docker-compose.yml | 2 ++ .../metadata-validation/src/app.service.ts | 29 ++++++++++++++----- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fee842e2c..278f99d91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ changes. - Add support for displaying Motion of No Confidence Governance Action [Issue 1597](https://github.com/IntersectMBO/govtool/issues/1597) - Add support for displaying Update committee/threshold Governance Action [Issue 1598](https://github.com/IntersectMBO/govtool/issues/1598) - Add support for displaying New Constitution and/or Guardrails Script Governance Action [Issue 1599](https://github.com/IntersectMBO/govtool/issues/1598) +- Add support for ipfs in metadata validation service [Issue 1616](https://github.com/IntersectMBO/govtool/issues/1616) ### Fixed diff --git a/govtool/metadata-validation/.env.example b/govtool/metadata-validation/.env.example index c0c68b1ca..3cf07604c 100644 --- a/govtool/metadata-validation/.env.example +++ b/govtool/metadata-validation/.env.example @@ -1 +1,3 @@ -PORT=3000 \ No newline at end of file +PORT=3000 +IPFS_GATEWAY=https://ipfs.some.gateway +IPFS_PROJECT_ID=ipfsprojectid diff --git a/govtool/metadata-validation/Dockerfile b/govtool/metadata-validation/Dockerfile index 5835d6e8e..a245abc71 100644 --- a/govtool/metadata-validation/Dockerfile +++ b/govtool/metadata-validation/Dockerfile @@ -1,5 +1,8 @@ FROM node:lts-hydrogen +ARG IPFS_GATEWAY +ARG IPFS_PROJECT_ID + WORKDIR /dist COPY package*.json ./ diff --git a/govtool/metadata-validation/docker-compose.yml b/govtool/metadata-validation/docker-compose.yml index bdf965762..e27b9b1e6 100644 --- a/govtool/metadata-validation/docker-compose.yml +++ b/govtool/metadata-validation/docker-compose.yml @@ -8,6 +8,8 @@ services: container_name: metadata-validation environment: - PORT=${PORT} + - IPFS_GATEWAY=${IPFS_GATEWAY} + - IPFS_PROJECT_ID=${IPFS_PROJECT_ID} ports: - ${PORT}:${PORT} volumes: diff --git a/govtool/metadata-validation/src/app.service.ts b/govtool/metadata-validation/src/app.service.ts index a948ef173..8955db611 100644 --- a/govtool/metadata-validation/src/app.service.ts +++ b/govtool/metadata-validation/src/app.service.ts @@ -22,15 +22,30 @@ export class AppService { let metadata: Record; let standard = paramStandard; + const isIPFS = url.startsWith('ipfs://'); + if (isIPFS) { + url = `${process.env.IPFS_GATEWAY}/${url.slice(7)}`; + } + try { const { data: rawData } = await firstValueFrom( - this.httpService.get(url).pipe( - finalize(() => Logger.log(`Fetching ${url} completed`)), - catchError((error) => { - Logger.error(error, JSON.stringify(error)); - throw MetadataValidationStatus.URL_NOT_FOUND; - }), - ), + this.httpService + .get(url, { + headers: { + 'Content-Type': 'application/json', + ...(isIPFS && + process.env.IPFS_PROJECT_ID && { + project_id: process.env.IPFS_PROJECT_ID, + }), + }, + }) + .pipe( + finalize(() => Logger.log(`Fetching ${url} completed`)), + catchError((error) => { + Logger.error(error, JSON.stringify(error)); + throw MetadataValidationStatus.URL_NOT_FOUND; + }), + ), ); let parsedData;