Skip to content

Commit

Permalink
feat(helia): ✨ Add version string.
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Arora <[email protected]>
  • Loading branch information
whizzzkid committed Oct 4, 2023
1 parent 09c0d18 commit 8ce2220
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
30 changes: 29 additions & 1 deletion src/heliaServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { type Request, type Response } from 'express'
import { DEFAULT_MIME_TYPE, parseContentType } from './contentType.js'
import { HeliaFetch } from './heliaFetch.js'

const HELIA_RELEASE_INFO_API = (version: string): string => `https://api.github.com/repos/ipfs/helia/git/ref/tags/helia-v${version}`

export interface IRouteEntry {
path: string
type: 'get' | 'post'
Expand Down Expand Up @@ -42,8 +44,12 @@ class HeliaServer {
type: 'get',
handler: async (request, response): Promise<void> => this.fetchIpns({ request, response })
}, {
path: '/api/v0/repo/gc',
path: '/api/v0/version',
type: 'get',
handler: async (request, response): Promise<void> => this.heliaVersion({ request, response })
}, {
path: '/api/v0/repo/gc',
type: 'post',
handler: async (request, response): Promise<void> => this.gc({ request, response })
}, {
path: '/*',
Expand Down Expand Up @@ -132,6 +138,28 @@ class HeliaServer {
}
}

/**
* Get the helia version
*/
async heliaVersion ({ response }: IRouteHandler): Promise<void> {
await this.isReady

try {
const { default: packageJson } = await import('../../node_modules/helia/package.json', {
assert: { type: 'json' }
})
const { version: heliaVersionString } = packageJson

const ghResp = await (await fetch(HELIA_RELEASE_INFO_API(heliaVersionString))).json()
response.json({
Version: heliaVersionString,
Commit: ghResp.object.sha.slice(0, 7)
})
} catch (error) {
response.status(500).end()
}
}

/**
* GC the node
*/
Expand Down
4 changes: 4 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*/package.json' {
export const name: string
export const version: string
}
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist"
"outDir": "dist",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "NodeNext",
"module": "NodeNext"
},
"include": [
"src",
Expand Down

0 comments on commit 8ce2220

Please sign in to comment.