Skip to content

Commit e8adcb9

Browse files
committed
feat(#1616): add support for ipfs in metadata validation service
1 parent d113332 commit e8adcb9

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ changes.
1616
- Add support for displaying Motion of No Confidence Governance Action [Issue 1597](https://github.com/IntersectMBO/govtool/issues/1597)
1717
- Add support for displaying Update committee/threshold Governance Action [Issue 1598](https://github.com/IntersectMBO/govtool/issues/1598)
1818
- Add support for displaying New Constitution and/or Guardrails Script Governance Action [Issue 1599](https://github.com/IntersectMBO/govtool/issues/1598)
19+
- Add support for ipfs in metadata validation service [Issue 1616](https://github.com/IntersectMBO/govtool/issues/1616)
1920

2021
### Fixed
2122

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
PORT=3000
1+
PORT=3000
2+
IPFS_GATEWAY=https://ipfs.some.gateway
3+
IPFS_PROJECT_ID=ipfsprojectid

govtool/metadata-validation/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM node:lts-hydrogen
22

3+
ARG IPFS_GATEWAY
4+
ARG IPFS_PROJECT_ID
5+
36
WORKDIR /dist
47

58
COPY package*.json ./

govtool/metadata-validation/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ services:
88
container_name: metadata-validation
99
environment:
1010
- PORT=${PORT}
11+
- IPFS_GATEWAY=${IPFS_GATEWAY}
12+
- IPFS_PROJECT_ID=${IPFS_PROJECT_ID}
1113
ports:
1214
- ${PORT}:${PORT}
1315
volumes:

govtool/metadata-validation/src/app.service.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,30 @@ export class AppService {
2222
let metadata: Record<string, unknown>;
2323
let standard = paramStandard;
2424

25+
const isIPFS = url.startsWith('ipfs://');
26+
if (isIPFS) {
27+
url = `${process.env.IPFS_GATEWAY}/${url.slice(7)}`;
28+
}
29+
2530
try {
2631
const { data: rawData } = await firstValueFrom(
27-
this.httpService.get(url).pipe(
28-
finalize(() => Logger.log(`Fetching ${url} completed`)),
29-
catchError((error) => {
30-
Logger.error(error, JSON.stringify(error));
31-
throw MetadataValidationStatus.URL_NOT_FOUND;
32-
}),
33-
),
32+
this.httpService
33+
.get(url, {
34+
headers: {
35+
'Content-Type': 'application/json',
36+
...(isIPFS &&
37+
process.env.IPFS_PROJECT_ID && {
38+
project_id: process.env.IPFS_PROJECT_ID,
39+
}),
40+
},
41+
})
42+
.pipe(
43+
finalize(() => Logger.log(`Fetching ${url} completed`)),
44+
catchError((error) => {
45+
Logger.error(error, JSON.stringify(error));
46+
throw MetadataValidationStatus.URL_NOT_FOUND;
47+
}),
48+
),
3449
);
3550

3651
let parsedData;

0 commit comments

Comments
 (0)