Skip to content

Commit

Permalink
Add headers to ipfs
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Aug 16, 2023
1 parent 2253c7d commit 0d4c5ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/subsocial-query/subsocial/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface SubsocialConnectionConfig {
substrateUrl: string
ipfsNodeUrl: string
ipfsAdminNodeUrl?: string
headers?: Record<string, any>
postConnectConfig?: (api: SubsocialApi) => void
}

Expand All @@ -15,14 +16,16 @@ const clientConfig: SubsocialConnectionConfig = {
ipfsNodeUrl: 'https://ipfs.subsocial.network',
ipfsAdminNodeUrl: 'https://gw.crustfiles.app',
}

const serverIpfsHeader = { authorization: `Bearer ${getCrustIpfsAuth()}` }
const serverConfig: SubsocialConnectionConfig = {
substrateUrl: SUBSTRATE_URL,
ipfsNodeUrl: 'https://gw.crustfiles.app',
ipfsAdminNodeUrl: 'https://gw.crustfiles.app',
headers: serverIpfsHeader,
postConnectConfig: (api) => {
const headers = { authorization: `Bearer ${getCrustIpfsAuth()}` }
api.ipfs.setWriteHeaders(headers)
api.ipfs.setPinHeaders(headers)
api.ipfs.setWriteHeaders(serverIpfsHeader)
api.ipfs.setPinHeaders(serverIpfsHeader)
},
}
export function getConnectionConfig() {
Expand Down
10 changes: 8 additions & 2 deletions src/subsocial-query/subsocial/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ async function connectToSubsocialApi(config: SubsocialConnectionConfig) {
const { SubsocialApi } = await import('@subsocial/api')
const { WsProvider, ApiPromise } = await import('@polkadot/api')

const { ipfsNodeUrl, substrateUrl, postConnectConfig, ipfsAdminNodeUrl } =
config
const {
ipfsNodeUrl,
substrateUrl,
postConnectConfig,
ipfsAdminNodeUrl,
headers,
} = config

const provider = new WsProvider(substrateUrl, 15_000, {})
const substrateApi = await ApiPromise.create({ provider })
const api = new SubsocialApi({
substrateApi,
ipfsNodeUrl,
ipfsAdminNodeUrl,
headers,
})

postConnectConfig?.(api)
Expand Down

0 comments on commit 0d4c5ad

Please sign in to comment.