Skip to content

Commit

Permalink
Merge branch 'deploy/ipfs' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
olehmell committed Aug 23, 2023
2 parents 3302acc + ff044de commit 7436713
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ SERVER_MNEMONIC=<your mnemonic here to send energy to users>
SERVER_DISCUSSION_CREATOR_MNEMONIC=<discussions creator user mnemonic>

CRUST_IPFS_AUTH=<IPFS auth for using crust bucket>
IPFS_WRITE_URL=<IPFS write url>
IPFS_PIN_URL=<IPFS pinning service url>
# ipfs test values
# CRUST_IPFS_AUTH=eyJkYXRhIjp7ImRvbWFpbiI6eyJjaGFpbklkIjoiNSIsIm5hbWUiOiJDbG91ZDMuY2MiLCJ2ZXJpZnlpbmdDb250cmFjdCI6IjB4Q2NDQ2NjY2NDQ0NDY0NDQ0NDQ2NDY0NjY0NjQ0NDY0NjY2NjY2NjQyIsInZlcnNpb24iOiIxIn0sIm1lc3NhZ2UiOnsiZGVzY3JpcHRpb24iOiJTaWduIGZvciBXMyBCdWNrZXQgQWNjZXNzIEF1dGhlbnRpY2F0aW9uIiwic2lnbmluZ0FkZHJlc3MiOiIweDAwNDFjNzA1ZTEwNmVlOWRFMjI3Q2ExMzlBZDRBOTlEQjY0NENCM2EiLCJ0b2tlbkFkZHJlc3MiOiIweDM5ODY2Mzg0MjY4MDMzMkExQWJBM0IwM2JkNmRCNDdhRTk4NDk5NEMiLCJ0b2tlbklkIjoiMzAwMDAzNyIsImVmZmVjdGl2ZVRpbWVzdGFtcCI6MTY3ODUzNzYxNywiZXhwaXJhdGlvblRpbWVzdGFtcCI6MH0sInByaW1hcnlUeXBlIjoiVzNCdWNrZXQiLCJ0eXBlcyI6eyJXM0J1Y2tldCI6W3sibmFtZSI6ImRlc2NyaXB0aW9uIiwidHlwZSI6InN0cmluZyJ9LHsibmFtZSI6InNpZ25pbmdBZGRyZXNzIiwidHlwZSI6ImFkZHJlc3MifSx7Im5hbWUiOiJ0b2tlbkFkZHJlc3MiLCJ0eXBlIjoiYWRkcmVzcyJ9LHsibmFtZSI6InRva2VuSWQiLCJ0eXBlIjoic3RyaW5nIn0seyJuYW1lIjoiZWZmZWN0aXZlVGltZXN0YW1wIiwidHlwZSI6InVpbnQyNTYifSx7Im5hbWUiOiJleHBpcmF0aW9uVGltZXN0YW1wIiwidHlwZSI6InVpbnQyNTYifV19fSwic2lnbmF0dXJlIjoiMHhhMTUxODkyZGNhMTZlMTJkZmViYTFjY2FkMjNmZjM5MGVmODQ1MzdhMGI2MWI4YWQ1NDY1ZGI1ZjI1NjZkMWJmMjc3MGE1OTQyMzFmNzFmYzA5YWVlZGJhNzJkZjM5Y2Y4NDIxMTQ3YzJkNWQyNTFkNDZjNGQyMDFlOGM1MmUzZTFjIn0=
# IPFS_WRITE_URL=https://gw-seattle.crustcloud.io
# IPFS_PIN_URL=https://test-pin.crustcloud.io/psa

NEXT_PUBLIC_SPACE_IDS=<your space(s) where all the posts here will be listed as topics, you can support multiple space ids, separated by comma>
Expand Down
1 change: 1 addition & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SERVER_MNEMONIC="bounce clutch hotel number lab imitate grass loop jewel cousin

# ipfs test values
CRUST_IPFS_AUTH="eyJkYXRhIjp7ImRvbWFpbiI6eyJjaGFpbklkIjoiNSIsIm5hbWUiOiJDbG91ZDMuY2MiLCJ2ZXJpZnlpbmdDb250cmFjdCI6IjB4Q2NDQ2NjY2NDQ0NDY0NDQ0NDQ2NDY0NjY0NjQ0NDY0NjY2NjY2NjQyIsInZlcnNpb24iOiIxIn0sIm1lc3NhZ2UiOnsiZGVzY3JpcHRpb24iOiJTaWduIGZvciBXMyBCdWNrZXQgQWNjZXNzIEF1dGhlbnRpY2F0aW9uIiwic2lnbmluZ0FkZHJlc3MiOiIweDAwNDFjNzA1ZTEwNmVlOWRFMjI3Q2ExMzlBZDRBOTlEQjY0NENCM2EiLCJ0b2tlbkFkZHJlc3MiOiIweDM5ODY2Mzg0MjY4MDMzMkExQWJBM0IwM2JkNmRCNDdhRTk4NDk5NEMiLCJ0b2tlbklkIjoiMzAwMDAzNyIsImVmZmVjdGl2ZVRpbWVzdGFtcCI6MTY3ODUzNzYxNywiZXhwaXJhdGlvblRpbWVzdGFtcCI6MH0sInByaW1hcnlUeXBlIjoiVzNCdWNrZXQiLCJ0eXBlcyI6eyJXM0J1Y2tldCI6W3sibmFtZSI6ImRlc2NyaXB0aW9uIiwidHlwZSI6InN0cmluZyJ9LHsibmFtZSI6InNpZ25pbmdBZGRyZXNzIiwidHlwZSI6ImFkZHJlc3MifSx7Im5hbWUiOiJ0b2tlbkFkZHJlc3MiLCJ0eXBlIjoiYWRkcmVzcyJ9LHsibmFtZSI6InRva2VuSWQiLCJ0eXBlIjoic3RyaW5nIn0seyJuYW1lIjoiZWZmZWN0aXZlVGltZXN0YW1wIiwidHlwZSI6InVpbnQyNTYifSx7Im5hbWUiOiJleHBpcmF0aW9uVGltZXN0YW1wIiwidHlwZSI6InVpbnQyNTYifV19fSwic2lnbmF0dXJlIjoiMHhhMTUxODkyZGNhMTZlMTJkZmViYTFjY2FkMjNmZjM5MGVmODQ1MzdhMGI2MWI4YWQ1NDY1ZGI1ZjI1NjZkMWJmMjc3MGE1OTQyMzFmNzFmYzA5YWVlZGJhNzJkZjM5Y2Y4NDIxMTQ3YzJkNWQyNTFkNDZjNGQyMDFlOGM1MmUzZTFjIn0="
IPFS_WRITE_URL=https://gw-seattle.crustcloud.io
IPFS_PIN_URL="https://test-pin.crustcloud.io/psa"

NEXT_PUBLIC_SPACE_IDS="1001"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
GH_NEXT_PUBLIC_SQUID_URL=https://squid.subsquid.io/xsocial/graphql
GH_NEXT_PUBLIC_COMMUNITY_HUB_ID=1030
GH_NEXT_PUBLIC_GA_ID=G-FT28TL1W3M
GH_IPFS_WRITE_URL=http://new-ipfs-cluster:5001
GH_IPFS_PIN_URL=http://new-ipfs-cluster:9094
GH_CRUST_IPFS_AUTH=${{ secrets.CRUST_IPFS_AUTH }}
GH_SUBSOCIAL_PROMO_SECRET_HEX=${{ secrets.SUBSOCIAL_PROMO_SECRET_HEX }}
Expand Down Expand Up @@ -100,6 +101,7 @@ jobs:
GH_NEXT_PUBLIC_AMP_ID=81d0fc2014ce14eed5a475efe9a44035
GH_NEXT_PUBLIC_SQUID_URL=https://squid.subsquid.io/xsocial/graphql
GH_NEXT_PUBLIC_GA_ID=G-FT28TL1W3M
GH_IPFS_WRITE_URL=https://gw-seattle.crustcloud.io
GH_IPFS_PIN_URL=https://pin.crustcloud.io/psa
GH_CRUST_IPFS_AUTH=${{ secrets.CRUST_IPFS_AUTH }}
GH_SUBSOCIAL_PROMO_SECRET_HEX=${{ secrets.SUBSOCIAL_PROMO_SECRET_HEX }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/feature-based.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
GH_NEXT_PUBLIC_SQUID_URL=https://squid.subsquid.io/xsocial/graphql
GH_NEXT_PUBLIC_COMMUNITY_HUB_ID=1025
GH_NEXT_PUBLIC_GA_ID=G-FT28TL1W3M
GH_IPFS_WRITE_URL=https://gw-seattle.crustcloud.io
GH_IPFS_PIN_URL=https://test-pin.crustcloud.io/psa
GH_COVALENT_API_KEY=cqt_rQtDdp9G9DFvqcGjVPDD4FFCyhFQ
GH_NEXT_PUBLIC_NOTIFICATION_APP_ID=BJaKjx7xtiIXtSUT8tR6VDG0WwhFwdqOqp8L5kc6alGBUtndnlV_DUJ6sze_z70VEBOKk4AT_wZTJqE9dC7sbEQ
Expand Down
1 change: 1 addition & 0 deletions ci.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NEXT_PUBLIC_AMP_ID='$GH_NEXT_PUBLIC_AMP_ID'
NEXT_PUBLIC_SQUID_URL='$GH_NEXT_PUBLIC_SQUID_URL'
NEXT_PUBLIC_COMMUNITY_HUB_ID='$GH_NEXT_PUBLIC_COMMUNITY_HUB_ID'
NEXT_PUBLIC_GA_ID='$GH_NEXT_PUBLIC_GA_ID'
IPFS_WRITE_URL='$GH_IPFS_WRITE_URL'
IPFS_PIN_URL='$GH_IPFS_PIN_URL'
CRUST_IPFS_AUTH='GH_CRUST_IPFS_AUTH'
USER_ID_SALT='$GH_USER_ID_SALT'
Expand Down
4 changes: 4 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ARG GH_NEXT_PUBLIC_AMP_ID
ARG GH_NEXT_PUBLIC_SQUID_URL
ARG GH_NEXT_PUBLIC_COMMUNITY_HUB_ID
ARG GH_NEXT_PUBLIC_GA_ID
ARG GH_IPFS_WRITE_URL
ARG GH_IPFS_PIN_URL
ARG GH_COVALENT_API_KEY
ARG GH_SUBSOCIAL_PROMO_SECRET_HEX
Expand All @@ -45,6 +46,7 @@ ENV NEXT_PUBLIC_CAPTCHA_SITE_KEY=${GH_NEXT_PUBLIC_CAPTCHA_SITE_KEY} \
NEXT_PUBLIC_SQUID_URL=${GH_NEXT_PUBLIC_SQUID_URL} \
NEXT_PUBLIC_COMMUNITY_HUB_ID=${GH_NEXT_PUBLIC_COMMUNITY_HUB_ID} \
NEXT_PUBLIC_GA_ID=${GH_NEXT_PUBLIC_GA_ID} \
IPFS_WRITE_URL=${GH_IPFS_WRITE_URL} \
IPFS_PIN_URL=${GH_IPFS_PIN_URL} \
CAPTCHA_SECRET=${GH_CAPTCHA_SECRET} \
USER_ID_SALT=${GH_USER_ID_SALT} \
Expand Down Expand Up @@ -90,6 +92,7 @@ ARG GH_NEXT_PUBLIC_AMP_ID
ARG GH_NEXT_PUBLIC_SQUID_URL
ARG GH_NEXT_PUBLIC_COMMUNITY_HUB_ID
ARG GH_NEXT_PUBLIC_GA_ID
ARG GH_IPFS_WRITE_URL
ARG GH_IPFS_PIN_URL
ARG GH_COVALENT_API_KEY
ARG GH_SUBSOCIAL_PROMO_SECRET_HEX
Expand All @@ -112,6 +115,7 @@ ENV NEXT_PUBLIC_CAPTCHA_SITE_KEY=${GH_NEXT_PUBLIC_CAPTCHA_SITE_KEY} \
NEXT_PUBLIC_SQUID_URL=${GH_NEXT_PUBLIC_SQUID_URL} \
NEXT_PUBLIC_COMMUNITY_HUB_ID=${GH_NEXT_PUBLIC_COMMUNITY_HUB_ID} \
NEXT_PUBLIC_GA_ID=${GH_NEXT_PUBLIC_GA_ID} \
IPFS_WRITE_URL=${GH_IPFS_WRITE_URL} \
IPFS_PIN_URL=${GH_IPFS_PIN_URL} \
CAPTCHA_SECRET=${GH_CAPTCHA_SECRET} \
USER_ID_SALT=${GH_USER_ID_SALT} \
Expand Down
1 change: 0 additions & 1 deletion src/components/AddressAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const AddressAvatar = forwardRef<HTMLDivElement, AddressAvatarProps>(
? getIpfsContentUrl(profile?.profileSpace?.image)
: undefined

console.log(usedAvatar, profile)
if (ensName) {
usedAvatar = resolveEnsAvatarSrc(ensName)
}
Expand Down
31 changes: 21 additions & 10 deletions src/server/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { getCrustIpfsAuth, getIpfsPinUrl } from '@/utils/env/server'
import {
getCrustIpfsAuth,
getIpfsPinUrl,
getIpfsWriteUrl,
} from '@/utils/env/server'
import { SubsocialIpfsApi } from '@subsocial/api'

export function getIpfsApi() {
const CRUST_IPFS_CONFIG = {
ipfsNodeUrl: 'http://new-ipfs-cluster:5001',
ipfsClusterUrl: getIpfsPinUrl(),
}
const pinUrl = getIpfsPinUrl()
const writeUrl = getIpfsWriteUrl()

console.log('pinUrl', pinUrl)
console.log('writeUrl', writeUrl)

const props = pinUrl.includes('crust')
? { asLink: false, 'meta.gatewayId': 1 }
: { asLink: true }

const headers = { authorization: `Bearer ${getCrustIpfsAuth()}` }

const ipfs = new SubsocialIpfsApi({
...CRUST_IPFS_CONFIG,
ipfsNodeUrl: writeUrl,
ipfsClusterUrl: pinUrl,
headers,
offchainUrl: 'https://api.subsocial.network',
})
Expand All @@ -19,14 +30,14 @@ export function getIpfsApi() {
return {
ipfs,
saveAndPinJson: async (content: Record<any, any>) => {
const cid = await ipfs.saveContentToOffchain(content as any)
// const cid = await ipfs.saveJson(content)
// await ipfs.pinContent(cid, { 'meta.gatewayId': 1 })
// const cid = await ipfs.saveContentToOffchain(content as any)
const cid = await ipfs.saveJson(content)
await ipfs.pinContent(cid, props)
return cid?.toString() ?? ''
},
saveAndPinImage: async (file: any) => {
const cid = await ipfs.saveFile(file)
await ipfs.pinContent(cid, { asLink: true, 'meta.gatewayId': 1 })
await ipfs.pinContent(cid, props)
return cid?.toString() ?? ''
},
}
Expand Down
7 changes: 7 additions & 0 deletions src/utils/env/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ export function getIpfsPinUrl() {
)
}

export function getIpfsWriteUrl() {
return (
checkEnv(process.env.IPFS_WRITE_URL, 'IPFS_WRITE_URL') ||
'https://gw-seattle.crustcloud.io'
)
}

export function getCovalentApiKey() {
return checkEnv(process.env.COVALENT_API_KEY, 'COVALENT_API_KEY')
}
Expand Down

0 comments on commit 7436713

Please sign in to comment.