37f9d56d49
* Accept audio & video files for upload * Rename image related variables * Implement getAssetType util * Preview & upload support for video files * Preview & upload support for audio files * Preview update for audio files * New look for audio previews on asset list * Remove extra refs Co-authored-by: findolor <anakisci@gmail.com>
30 lines
864 B
TypeScript
30 lines
864 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'
|
|
|
|
export const uploadToPinata = async (
|
|
fileArray: File[],
|
|
pinataApiKey: string,
|
|
pinataSecretKey: string,
|
|
fileType: UploadFileType,
|
|
): Promise<string> => {
|
|
console.log('Uploading to Pinata...')
|
|
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
|
|
}
|