stargaze-studio/services/upload/pinata.ts
Arda Nakışçı 4ba58eca6d
Refactoring collection creation logic (#20)
* Split collection info component

* Fix texts

* Refactor components

* Create upload details component

* Add on change method to collection details

* Add on change method to minting details

* Add on change method to whitelist details

* Add on change method to royalty details

* Update create page name

* Refactor code for collection creation logic
2022-08-04 12:16:42 +03:00

29 lines
834 B
TypeScript

/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-return */
import axios from 'axios'
import { PINATA_ENDPOINT_URL } from 'utils/constants'
export type UploadFileType = 'assets' | 'metadata' | 'cover'
export const uploadToPinata = async (
fileArray: File[],
pinataApiKey: string,
pinataSecretKey: string,
fileType: UploadFileType,
): Promise<string> => {
const data = new FormData()
fileArray.forEach((file) => {
data.append('file', file, `${fileType}/${file.name}`)
})
const res = await axios.post(PINATA_ENDPOINT_URL, data, {
withCredentials: true,
headers: {
pinata_api_key: pinataApiKey,
pinata_secret_api_key: pinataSecretKey,
},
})
return res.data.IpfsHash
}