diff --git a/src/subsocial-query/subsocial/config.ts b/src/subsocial-query/subsocial/config.ts index bfbd207a4..344b0a442 100644 --- a/src/subsocial-query/subsocial/config.ts +++ b/src/subsocial-query/subsocial/config.ts @@ -6,6 +6,7 @@ export interface SubsocialConnectionConfig { substrateUrl: string ipfsNodeUrl: string ipfsAdminNodeUrl?: string + headers?: Record postConnectConfig?: (api: SubsocialApi) => void } @@ -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() { diff --git a/src/subsocial-query/subsocial/connection.ts b/src/subsocial-query/subsocial/connection.ts index c07afd1e6..0cd9bf658 100644 --- a/src/subsocial-query/subsocial/connection.ts +++ b/src/subsocial-query/subsocial/connection.ts @@ -13,8 +13,13 @@ 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 }) @@ -22,6 +27,7 @@ async function connectToSubsocialApi(config: SubsocialConnectionConfig) { substrateApi, ipfsNodeUrl, ipfsAdminNodeUrl, + headers, }) postConnectConfig?.(api)