diff --git a/apps/envited.ascs.digital/common/ipfs/index.ts b/apps/envited.ascs.digital/common/ipfs/index.ts index 1a53f6a6..0b5ac618 100644 --- a/apps/envited.ascs.digital/common/ipfs/index.ts +++ b/apps/envited.ascs.digital/common/ipfs/index.ts @@ -9,7 +9,6 @@ import { export type UploadJson = ReturnType export type CreateGroup = ReturnType - export const pinata = new PinataSDK({ pinataJwt: `${process.env.PINATA_JWT}`, pinataGateway: `${process.env.PINATA_GATEWAY}`, diff --git a/apps/envited.ascs.digital/listener/index.ts b/apps/envited.ascs.digital/listener/index.ts index 950c350b..599b8384 100644 --- a/apps/envited.ascs.digital/listener/index.ts +++ b/apps/envited.ascs.digital/listener/index.ts @@ -5,10 +5,11 @@ import { drizzle } from 'drizzle-orm/aws-data-api/pg' import { connectDb } from '../common/database' import * as schema from '../common/database/schema' +import { downloadFile } from '../common/ipfs' import { log } from '../common/logger' import { listenToAssetContract } from './listener' import { getTokenByTokenId, insertToken } from './persistence' -import { downloadFile } from '../common/ipfs' +import { PinataSDK } from 'pinata-web3' const Tezos = new TezosToolkit(process.env.NEXT_PUBLIC_WEB3_RPC_URL || 'https://ghostnet.ecadinfra.com') const db = async () => { @@ -39,7 +40,14 @@ const connection = await db() // })() const test = async () => { - const f = await downloadFile("bafkreifskuvufcolrg5czp7jqmd52sysgac6nyhowu6c6bbklk4gtgx2xu") + const pinata = new PinataSDK({ + pinataJwt: `${process.env.PINATA_JWT}`, + pinataGateway: `${process.env.PINATA_GATEWAY}`, + pinataGatewayKey: `${process.env.PINATA_GATEWAY_KEY}`, + }) + + const f = await pinata.gateways.get('bafkreic6ju7honlocx2tztv6bv72owunxiva2y4c7vlreai7iqdx56jgva') + // const f = await downloadFile('bafkreifskuvufcolrg5czp7jqmd52sysgac6nyhowu6c6bbklk4gtgx2xu') console.log(f) } diff --git a/apps/envited.ascs.digital/modules/AddAssets/AddAssets.actions.ts b/apps/envited.ascs.digital/modules/AddAssets/AddAssets.actions.ts index 25c60011..3bc22eb0 100644 --- a/apps/envited.ascs.digital/modules/AddAssets/AddAssets.actions.ts +++ b/apps/envited.ascs.digital/modules/AddAssets/AddAssets.actions.ts @@ -4,11 +4,12 @@ import { revalidatePath } from 'next/cache' import { isNil } from 'ramda' import { getServerSession } from '../../common/auth' -import { getAssetUploadUrl, getUniqueFilename } from '../../common/aws' +import { getAssetUploadUrl } from '../../common/aws' import { ERRORS } from '../../common/constants' import { log } from '../../common/logger' import { insertAsset } from '../../common/serverActions' -import { badRequestError, formatError, internalServerErrorError, slugify, unauthorizedError } from '../../common/utils' +import { badRequestError, formatError, internalServerErrorError, unauthorizedError } from '../../common/utils' +import { createFilename } from '../../common/asset/validateAndCreateMetadata.utils' export async function addAssetsForm(formData: FormData) { const assets = formData.getAll('assets') as File[] @@ -29,19 +30,19 @@ export async function addAssetsForm(formData: FormData) { const result = assets.map(async (asset: File) => { const arrayBuffer = Buffer.from(await asset.arrayBuffer()) - const uniqueFilename = getUniqueFilename(slugify(asset.name), asset.name) - const signedUrl = await getAssetUploadUrl(uniqueFilename) + const cid = await createFilename(arrayBuffer) + const signedUrl = await getAssetUploadUrl(cid) const uploadResult = await fetch(signedUrl, { body: arrayBuffer, method: 'PUT', headers: { 'Content-Type': asset.type, - 'Content-Disposition': `attachment; filename="${uniqueFilename}"`, + 'Content-Disposition': `attachment; filename="${cid}"`, }, }) - await insertAsset(uniqueFilename) + await insertAsset(cid) return uploadResult }) diff --git a/listener.config.js b/listener.config.js index 3e8fdb14..83c28f7c 100644 --- a/listener.config.js +++ b/listener.config.js @@ -14,6 +14,9 @@ module.exports = { RDS_DB_NAME: 'envited', RDS_RESOURCE_ARN: 'arn:aws:rds:eu-central-1:597778497612:cluster:staging-envitedascsdigital-envited-envited46e22b9b-l2rchfuookv5', + PINATA_GATEWAY_KEY: 'yCNvt4_psrxde9cshtn7vPtK5HujxSUYaRyNT5aVIu1l5eH2S7pUxSEl7UVQhF-4', + PINATA_GATEWAY: 'plum-secret-aardwolf-688.mypinata.cloud', + PINATA_JWT: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiI3ODY1NTQyMC1kYzM0LTRjMTQtODczYi05NjE4MmQwNDA2ZDciLCJlbWFpbCI6InBpbmF0YUBlbnZpdGVkLm1hcmtldCIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJwaW5fcG9saWN5Ijp7InJlZ2lvbnMiOlt7ImRlc2lyZWRSZXBsaWNhdGlvbkNvdW50IjoxLCJpZCI6IkZSQTEifSx7ImRlc2lyZWRSZXBsaWNhdGlvbkNvdW50IjoxLCJpZCI6Ik5ZQzEifV0sInZlcnNpb24iOjF9LCJtZmFfZW5hYmxlZCI6ZmFsc2UsInN0YXR1cyI6IkFDVElWRSJ9LCJhdXRoZW50aWNhdGlvblR5cGUiOiJzY29wZWRLZXkiLCJzY29wZWRLZXlLZXkiOiIxNGMxZTAyNzJlNzA3ODE0ZjcwNyIsInNjb3BlZEtleVNlY3JldCI6ImE2MzQ2N2VmMzc0ZmRjNzQ1Mzc2OTBmYjlkNjM3ODk1NjAyMzQ5Y2RmMDJkZGU2MTg2ZmFhOTllNGEwM2VhN2MiLCJleHAiOjE3NjQ2ODM4ODF9.Eu6nr-ZbpCYd4HuejxKCo4xG7qPoioJyBik6x3kJPm4' }, env_development: { ENV: 'development', @@ -24,6 +27,9 @@ module.exports = { POSTGRES_DATABASE_NAME: 'envited', POSTGRES_DATABASE_USER: 'admin', POSTGRES_DATABASE_PASSWORD: '123456', + PINATA_GATEWAY_KEY: 'yCNvt4_psrxde9cshtn7vPtK5HujxSUYaRyNT5aVIu1l5eH2S7pUxSEl7UVQhF-4', + PINATA_GATEWAY: 'plum-secret-aardwolf-688.mypinata.cloud', + PINATA_JWT: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiI3ODY1NTQyMC1kYzM0LTRjMTQtODczYi05NjE4MmQwNDA2ZDciLCJlbWFpbCI6InBpbmF0YUBlbnZpdGVkLm1hcmtldCIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJwaW5fcG9saWN5Ijp7InJlZ2lvbnMiOlt7ImRlc2lyZWRSZXBsaWNhdGlvbkNvdW50IjoxLCJpZCI6IkZSQTEifSx7ImRlc2lyZWRSZXBsaWNhdGlvbkNvdW50IjoxLCJpZCI6Ik5ZQzEifV0sInZlcnNpb24iOjF9LCJtZmFfZW5hYmxlZCI6ZmFsc2UsInN0YXR1cyI6IkFDVElWRSJ9LCJhdXRoZW50aWNhdGlvblR5cGUiOiJzY29wZWRLZXkiLCJzY29wZWRLZXlLZXkiOiIxNGMxZTAyNzJlNzA3ODE0ZjcwNyIsInNjb3BlZEtleVNlY3JldCI6ImE2MzQ2N2VmMzc0ZmRjNzQ1Mzc2OTBmYjlkNjM3ODk1NjAyMzQ5Y2RmMDJkZGU2MTg2ZmFhOTllNGEwM2VhN2MiLCJleHAiOjE3NjQ2ODM4ODF9.Eu6nr-ZbpCYd4HuejxKCo4xG7qPoioJyBik6x3kJPm4' }, }, ],