Skip to content

Commit

Permalink
spheron replaced with thirdweb
Browse files Browse the repository at this point in the history
  • Loading branch information
tempe-techie committed May 30, 2024
1 parent cde331e commit 8a3b440
Show file tree
Hide file tree
Showing 13 changed files with 502 additions and 352 deletions.
25 changes: 0 additions & 25 deletions api/imageUploader.js

This file was deleted.

9 changes: 9 additions & 0 deletions components/chat/ChatFeed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
@processFileUrl="insertImage"
title="Upload image"
infoText="Upload an image."
storageType="ipfs"
:componentId="$.uid"
:maxFileSize="$config.fileUploadSizeLimit"
/>
Expand Down Expand Up @@ -385,6 +386,14 @@ export default {
},
async insertImage(imageUrl) {
if (imageUrl.startsWith("ipfs://")) {
imageUrl = imageUrl.replace("ipfs://", this.$config.ipfsGateway);
}
if (imageUrl.endsWith(".JPG") || imageUrl.endsWith(".PNG") || imageUrl.endsWith(".JPEG") || imageUrl.endsWith(".GIF")) {
imageUrl = imageUrl.replace(".JPG", ".jpg").replace(".PNG", ".png").replace(".JPEG", ".jpeg").replace(".GIF", ".gif");
}
// add image url to postText
if (!this.postText) {
this.postText = imageUrl + " ";
Expand Down
3 changes: 2 additions & 1 deletion components/nft/collection/AddImageToCollectionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

<FileUploadInput
btnCls="btn btn-primary"
:maxFileSize="$config.fileUploadSizeLimit"
:maxFileSize="$config.fileUploadSizeLimit"
storageType="ipfs"
@processUploadedFileUrl="insertImageLink"
/>

Expand Down
15 changes: 14 additions & 1 deletion components/nft/collection/ChangeCollectionPreviewModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<FileUploadInput
btnCls="btn btn-primary"
storageType="ipfs"
:maxFileSize="$config.fileUploadSizeLimit"
@processUploadedFileUrl="insertImageLink"
/>
Expand All @@ -29,7 +30,7 @@
<input v-model="imageUrl" type="text" class="form-control">

<div v-if="imageUrl" class="mt-3">
<img :src="imageUrl" class="img-thumbnail img-fluid" style="max-width: 100px;" />
<img :src="parseImageLink" class="img-thumbnail img-fluid" style="max-width: 100px;" />
<br />
<small>If image didn't appear above, then something is wrong with the link you added.</small>
</div>
Expand Down Expand Up @@ -74,6 +75,18 @@ export default {
this.componentId = this.$.uid;
},
computed: {
parseImageLink() {
let parsedImage = this.imageUrl;
if (parsedImage && parsedImage.includes("ipfs://")) {
parsedImage = parsedImage.replace("ipfs://", this.$config.ipfsGateway);
}
return parsedImage;
}
},
methods: {
async updateImage() {
this.waiting = true;
Expand Down
1 change: 1 addition & 0 deletions components/profile/PunkProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
@processFileUrl="insertImage"
title="Change profile image"
infoText="Upload a new profile picture."
storageType="ipfs"
:componentId="$.uid"
:maxFileSize="$config.fileUploadSizeLimit"
/>
Expand Down
69 changes: 13 additions & 56 deletions components/storage/FileUploadInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
</template>

<script>
import { upload } from "@spheron/browser-upload";
import ImageKit from "imagekit-javascript";
import { uploadFileToThirdWeb } from "~/utils/ipfsUtils";
export default {
name: "FileUploadInput",
props: ["btnCls", "maxFileSize"],
props: ["btnCls", "maxFileSize", "storageType"],
emits: ["processUploadedFileUrl"],
data() {
Expand Down Expand Up @@ -91,43 +91,6 @@ export default {
this.waitingUpload = false;
},
async fetchUploadToken() {
const thisAppUrl = window.location.origin;
let fetcherService;
if (this.$config.fileUploadTokenService === "netlify") {
fetcherService = thisAppUrl + "/.netlify/functions/imageUploader";
} else if (this.$config.fileUploadTokenService === "vercel") {
fetcherService = thisAppUrl + "/api/imageUploader";
}
if (fetcherService) {
try {
const resp = await $fetch(fetcherService).catch((error) => error.data);
let response = resp;
if (typeof(resp) === "string") {
response = JSON.parse(resp);
}
if (response?.error) {
console.log("Error fetching upload token: ", response["error"]);
throw response["error"];
}
if (response?.data) {
this.uploadToken = response["data"];
}
} catch (e) {
console.log("Error fetching a file upload token: ", e);
throw e;
}
}
},
handleFileInput(event) {
const uploadedFile = event.target.files[0];
this.uploadedFileSize = uploadedFile.size;
Expand Down Expand Up @@ -191,28 +154,22 @@ export default {
async uploadFile() {
this.waitingUpload = true;
try {
// get session token
await this.fetchUploadToken();
if (this.uploadToken) {
const token = this.uploadToken;
if (this.storageType === "ipfs") {
// upload to IPFS
const fileUri = await uploadFileToThirdWeb(this.file);
const { protocolLink, cid } = await upload([this.file], { token });
const cid = fileUri.replace("ipfs://", "").split("/")[0];
//const fullFileUrl = protocolLink + "/" + this.newFileName;
const fullFileUrl = this.$config.ipfsGateway + cid + "/" + this.newFileName;
if (cid) {
await this.pinCid(cid);
}
if (cid) {
await this.pinCid(cid);
}
// emit file url
this.$emit("processUploadedFileUrl", fileUri);
// emit file url
this.$emit("processUploadedFileUrl", fullFileUrl);
}
} catch (e) {
console.log("Error uploading file. Switching to fallback upload method.");
} else {
// upload to a centralized storage service (imagekit)
await this.fallbackUpload();
}
Expand Down
3 changes: 2 additions & 1 deletion components/storage/FileUploadModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<FileUploadInput
btnCls="btn btn-primary"
:maxFileSize="maxFileSize"
:storageType="storageType"
@processUploadedFileUrl="processUploadedFileUrl"
/>
</div>
Expand Down Expand Up @@ -73,7 +74,7 @@ import FileUploadInput from '~/components/storage/FileUploadInput.vue';
export default {
name: "FileUploadModal",
props: ["title", "componentId", "infoText", "maxFileSize"],
props: ["title", "componentId", "infoText", "maxFileSize", "storageType"],
emits: ["processFileUrl"],
components: { FileUploadInput },
Expand Down
25 changes: 0 additions & 25 deletions netlify/functions/imageUploader.js

This file was deleted.

3 changes: 2 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default defineNuxtConfig({
expiryCollections: 1000 * 60 * 60 * 24 * 7, // must be in milliseconds (0 means no expiration)
expiryUsernames: 1000 * 60 * 60 * 24 * 7, // must be in milliseconds (0 means no expiration)
favicon: "/img/favicon.svg",
fileUploadEnabled: true, // enable/disable file uploads (enable only if external file storage is used, e.g. IPFS via Spheron)
fileUploadEnabled: true, // enable/disable file uploads (enable only if external file storage is used, e.g. IPFS via Thirdweb)
fileUploadSizeLimit: 1 * 1024 * 1024, // max file upload size in bytes (1 * 1024 * 1024 = 1 MB)
fileUploadTokenService: process.env.FILE_UPLOAD_SERVICE || "netlify", // "netlify" or "vercel" (or leave empty for no file uploads)
getPostsLimit: 30, // number of posts to fetch from Orbis in the getPosts() function
Expand Down Expand Up @@ -138,6 +138,7 @@ export default defineNuxtConfig({
swapPriceImpactMaxBps: 1000, // max price impact in bips (1 bps = 0.01%, 1000bps = 10%) for the swap function
swapRouterAddress: "0x0b7F9c544FAF10DFc6137Bd2ba9fF423cC62FBD7", // iggy swap router contract address
tenorApiKey: process.env.TENOR_KEY || "",
thirdwebClientId: process.env.THIRDWEB_CLIENT_ID || "",
tldName: ".degen",
tokenAddress: null, // leave null if it's a native token of the chain
tokenDecimals: 18,
Expand Down
Loading

0 comments on commit 8a3b440

Please sign in to comment.