Skip to content

Commit

Permalink
refactor(envited.ascs.digital): update file name
Browse files Browse the repository at this point in the history
Signed-off-by: Roy Scheeren <[email protected]>
  • Loading branch information
royscheeren committed Dec 18, 2024
1 parent e4903dd commit 3c4e47c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
1 change: 0 additions & 1 deletion apps/envited.ascs.digital/common/ipfs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {

export type UploadJson = ReturnType<typeof _uploadJson>
export type CreateGroup = ReturnType<typeof _createGroup>

export const pinata = new PinataSDK({
pinataJwt: `${process.env.PINATA_JWT}`,
pinataGateway: `${process.env.PINATA_GATEWAY}`,
Expand Down
12 changes: 10 additions & 2 deletions apps/envited.ascs.digital/listener/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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)
}

Expand Down
13 changes: 7 additions & 6 deletions apps/envited.ascs.digital/modules/AddAssets/AddAssets.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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
})
Expand Down
6 changes: 6 additions & 0 deletions listener.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'
},
},
],
Expand Down

0 comments on commit 3c4e47c

Please sign in to comment.