-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfura.ts
More file actions
56 lines (43 loc) · 1.78 KB
/
infura.ts
File metadata and controls
56 lines (43 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { create as ipfsHttpClient } from "ipfs-http-client";
import type { FilesWithId, ImagesPreview } from '@lib/types/file';
const authorization = "Basic " +
btoa(process.env.NEXT_PUBLIC_INFURA_API_KEY + ":" + process.env.NEXT_PUBLIC_INFURA_API_KEY_SECRET);
export async function uploadImages(
userId: string,
files: FilesWithId
): Promise<ImagesPreview | null> {
if (!files.length) return null;
const ipfs = ipfsHttpClient({
url: "https://ipfs.infura.io:5001/api/v0",
headers: {
authorization,
},
});
const imagesPreview = await Promise.all(
files.map(async (file) => {
let src: string;
const { id, name: alt } = file;
const result = await ipfs.add(file);
src = `https://nostamask.infura-ipfs.io/ipfs/${result.path}`
// const storageRef = ref(storage, `images/${userId}/${alt}`);
// try {
// src = await getDownloadURL(storageRef);
// } catch {
// await uploadBytesResumable(storageRef, file);
// src = await getDownloadURL(storageRef);
// }
// ----------------------------------------------------
// INFURA IPFS API (REQ FS - USE IPFS HTTP CLIENT) ----
// ----------------------------------------------------
// const storeImageFile = await sdk.storeFile(
// "./integration-test/ipfs-test/metamask.jpeg",
// );
// console.log("storeImageUrl ----", storeImageFile);
// ----------------------------------------------------
// https://docs.infura.io/infura-expansion-apis/nft-api/nft-sdk/javascript-api/ipfs-methods
// ----------------------------------------------------
return { id, src, alt };
})
);
return imagesPreview;
}