Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/fix ipfs uploading error #39

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions apps/web/pages/api/v0/course/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ const handlePostRequest = async (

const credentialImageBuffer = fs.readFileSync(filepath)

const ipfsCredentialImageData = await IpfsConnector.upload(
credentialImageBuffer,
mimetype ?? '',
originalFilename ?? '',
)
const ipfsCredentialImageData = await IpfsConnector.upload({
fileContent: credentialImageBuffer,
fileName: originalFilename ?? '',
mimeType: mimetype ?? '',
})

const ipfsCredentialMetadata = await IpfsConnector.upload(
{
const ipfsCredentialMetadata = await IpfsConnector.upload({
fileContent: {
name: name,
description: description,
image: ipfsCredentialImageData.url,
},
'',
'data/json',
)
fileName: '',
mimeType: 'data/json',
})

const credential = await prisma.credential.create({
data: {
Expand Down
21 changes: 11 additions & 10 deletions apps/web/pages/api/v0/course/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,27 @@ const handlePostRequest = async (
}

const { mimetype, filepath, originalFilename } = imageFile
console.log(originalFilename)
const courseImageBuffer = fs.readFileSync(filepath)

const ipfsCourseImageData = await IpfsConnector.upload(
courseImageBuffer,
mimetype ?? '',
originalFilename ?? '',
)
const ipfsCourseImageData = await IpfsConnector.upload({
fileContent: courseImageBuffer,
fileName: originalFilename ?? '',
mimeType: mimetype ?? '',
})

const ipfsCourseMetadata = await IpfsConnector.upload(
{
const ipfsCourseMetadata = await IpfsConnector.upload({
fileContent: {
image: ipfsCourseImageData.url,
name: name,
description: description,
website: website,
'snapshot-ens': snapshotEns,
'media-channel': mediaChannel,
},
'',
'data/json',
)
fileName: '',
mimeType: 'data/json',
})

res.status(200).json({
status: ApiResponseStatus.success,
Expand Down
14 changes: 9 additions & 5 deletions packages/ipfs/src/connectors/infura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ export class InfuraIpfsConnector implements IpfsConnector {
this.ipfsGateway = ipfsGateway
}

public async upload(
fileContent: Buffer | Record<string, any>,
fileName: string,
mimeType: string,
): Promise<IpfsUploadResult> {
public async upload({
fileContent,
fileName,
mimeType,
}: {
fileContent: Buffer | Record<string, any>
fileName: string
mimeType: string
}): Promise<IpfsUploadResult> {
const formData = new FormData()

if (fileContent instanceof Buffer) {
Expand Down
14 changes: 9 additions & 5 deletions packages/ipfs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ export type IpfsUploadResult = {
}

export interface IpfsConnector {
upload(
fileContent: Buffer | Record<string, any>,
mimeType?: string,
fileName?: string,
): Promise<IpfsUploadResult>
upload({
fileContent,
mimeType,
fileName,
}: {
fileContent: Buffer | Record<string, any>
mimeType?: string
fileName?: string
}): Promise<IpfsUploadResult>
}
Loading