-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release-0.3.17' of https://github.com/spect-ai/circles.v1…
… into develop
- Loading branch information
Showing
7 changed files
with
166 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,53 @@ | ||
import { create } from "ipfs-http-client"; | ||
import ImageKit from "imagekit-javascript"; | ||
// SDK initialization | ||
|
||
var imagekit = new ImageKit({ | ||
publicKey: "public_CqD2Qv50op/DuvGfKx9tDIDqNTc=", | ||
urlEndpoint: "https://ik.imagekit.io/spectcdn", | ||
authenticationEndpoint: "https://circles.spect.network/api/authImageKit", | ||
}); | ||
|
||
// URL generation | ||
|
||
// Upload function internally uses the ImageKit.io javascript SDK | ||
// function upload(data) { | ||
// var file = document.getElementById("file1"); | ||
// imagekit.upload({ | ||
// file : file.files[0], | ||
// fileName : "abc1.jpg", | ||
// tags : ["tag1"] | ||
// }, function(err, result) { | ||
// console.log(arguments); | ||
// console.log(imagekit.url({ | ||
// src: result.url, | ||
// transformation : [{ height: 300, width: 400}] | ||
// })); | ||
// }) | ||
// } | ||
|
||
export async function storeImage(imageFile: File) { | ||
const projectId = "2E6toVcDcGO87J2tX6GHK4aBILR"; | ||
const projectSecret = "9f96144517b0a20eef70c46239ab0ad7"; | ||
const auth = | ||
"Basic " + Buffer.from(projectId + ":" + projectSecret).toString("base64"); | ||
|
||
const client = create({ | ||
host: "ipfs.infura.io", | ||
port: 5001, | ||
protocol: "https", | ||
headers: { | ||
authorization: auth, | ||
}, | ||
}); | ||
// const projectId = "2E6toVcDcGO87J2tX6GHK4aBILR"; | ||
// const projectSecret = "9f96144517b0a20eef70c46239ab0ad7"; | ||
// const auth = | ||
// "Basic " + Buffer.from(projectId + ":" + projectSecret).toString("base64"); | ||
|
||
const res = await client.add(imageFile); | ||
// const client = create({ | ||
// host: "ipfs.infura.io", | ||
// port: 5001, | ||
// protocol: "https", | ||
// headers: { | ||
// authorization: auth, | ||
// }, | ||
// }); | ||
|
||
return { imageGatewayURL: `https://spect.infura-ipfs.io/ipfs/${res.cid}` }; | ||
// const res = await client.add(imageFile); | ||
|
||
// return { imageGatewayURL: `https://spect.infura-ipfs.io/ipfs/${res.cid}` }; | ||
|
||
const res = await imagekit.upload({ | ||
file: imageFile, | ||
fileName: imageFile.name, | ||
}); | ||
console.log({ res }); | ||
return { imageGatewayURL: res.url }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// auth image kit | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
import ImageKit from "imagekit"; | ||
|
||
const imagekit = new ImageKit({ | ||
publicKey: "public_CqD2Qv50op/DuvGfKx9tDIDqNTc=", | ||
urlEndpoint: "https://ik.imagekit.io/spectcdn", | ||
privateKey: process.env.IMAGEKIT_PRIVATE_KEY || "", | ||
}); | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
console.log("auth image kit"); | ||
try { | ||
const signatureObj = imagekit.getAuthenticationParameters( | ||
req.query.token as string, | ||
parseInt(req.query.expire as string) | ||
); | ||
|
||
res.status(200).send(signatureObj); | ||
} catch (err) { | ||
console.error( | ||
"Error while responding to auth request:", | ||
JSON.stringify(err, undefined, 2) | ||
); | ||
res.status(500).send("Internal Server Error"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters