Skip to content

Commit

Permalink
feat(#1616): add support for ipfs in metadata validation service
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Nov 15, 2024
1 parent d113332 commit e8adcb9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion govtool/metadata-validation/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
PORT=3000
PORT=3000
IPFS_GATEWAY=https://ipfs.some.gateway
IPFS_PROJECT_ID=ipfsprojectid
3 changes: 3 additions & 0 deletions govtool/metadata-validation/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM node:lts-hydrogen

ARG IPFS_GATEWAY
ARG IPFS_PROJECT_ID

WORKDIR /dist

COPY package*.json ./
Expand Down
2 changes: 2 additions & 0 deletions govtool/metadata-validation/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 22 additions & 7 deletions govtool/metadata-validation/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,30 @@ export class AppService {
let metadata: Record<string, unknown>;
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;
Expand Down

0 comments on commit e8adcb9

Please sign in to comment.