From 3b4aa4587e051b401a8304c223870ed3986f994c Mon Sep 17 00:00:00 2001 From: William Chong Date: Thu, 22 Jun 2023 02:29:05 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Support=20minting=20via=20ipfs=20or?= =?UTF-8?q?=20ar=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/en.json | 4 ++-- pages/new/index.vue | 21 +++++++++++++++++++-- pages/nft/url/index.vue | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/locales/en.json b/locales/en.json index f9d23cb6..fae17206 100644 --- a/locales/en.json +++ b/locales/en.json @@ -314,7 +314,7 @@ "NFTPortal.loadingMessage.waitingImgFee": "Waiting for image upload transaction...", "NFTPortal.mint.error":"Oops, something went wrong when {error}, please try again.", "NFTPortal.placeholder.message":"Say Something ...", - "NFTPortal.placeholder.register":"https://like.co or iscn://likecoin-chain/dLbKMa8EVO9RF4UmoWKk2ocUq7IsxMcnQL1_Ps5Vg80/1", + "NFTPortal.placeholder.register":"https://... or iscn://... or ipfs://... or ar://...", "NFTPortal.textfield.guide.add": "Add message to your collectors", "NFTPortal.textfield.guide.edit": "Edit", "NFTPortal.textfield.label.message": "Message", @@ -331,7 +331,7 @@ "UploadForm.attention": "Do not connect to Ledger hardware wallets for signing.\n Ledger service temporarily unavailable.", "UploadForm.button.back": "Back", "UploadForm.button.confirm": "Confirm", - "UploadForm.button.mintUrl": "Has a URL? Mint NFT here", + "UploadForm.button.mintUrl": "Has a URL, Arweave or IPFS hash? Mint NFT here", "UploadForm.button.selectFile": "Select a file", "UploadForm.button.skip": "Skip Upload", "UploadForm.button": "Start Upload", diff --git a/pages/new/index.vue b/pages/new/index.vue index 9819347e..ea623599 100644 --- a/pages/new/index.vue +++ b/pages/new/index.vue @@ -111,8 +111,8 @@ export default class NewIndexPage extends Vue { ) => ISCNRecordWithID[] | PromiseLike state = 'init' - ipfsHash = '' - arweaveId = '' + ipfsHash = this.$route.query.ipfs_hash || '' + arweaveId = this.$route.query.arweave_id || '' fileSHA256 = '' fileData = '' fileType = '' @@ -146,6 +146,23 @@ export default class NewIndexPage extends Vue { } } + async mounted() { + if ((this.ipfsHash || this.arweaveId) && this.shouldSkipToMintNFT) { + this.state = 'iscn'; + let url; + if (this.arweaveId) url = `https://arweave.net/${this.arweaveId}`; + else if (this.ipfsHash) url = `https://ipfs.io/ipfs/${this.ipfsHash}`; + if (url) { + const { data, headers } = await this.$axios.get(url, { responseType: 'blob' }) + this.fileBlob = data as Blob + this.isImage = headers['content-type'].startsWith('image') + this.fileType = headers['content-type'] + this.fileSize = headers['content-length'] + this.fileData = `data:${this.fileType};base64,${Buffer.from(await data.arrayBuffer(), 'binary').toString('base64')}` + } + } + } + onSubmitUpload({ ipfsHash, arweaveId, diff --git a/pages/nft/url/index.vue b/pages/nft/url/index.vue index 047eb057..033150b0 100644 --- a/pages/nft/url/index.vue +++ b/pages/nft/url/index.vue @@ -576,6 +576,22 @@ export default class FetchIndex extends Vue { break } + if (this.url.startsWith('ipfs://') || this.url.startsWith('ar://') ) { + const ipfsHash = this.url.startsWith('ipfs://') ? this.url.replace('ipfs://', '') : undefined; + const arweaveId = this.url.startsWith('ar://') ? this.url.replace('ar://', '') : undefined; + this.$router.push( + this.localeLocation({ + name: 'new', + query: { + ipfs_hash: ipfsHash, + arweave_id: arweaveId, + mint: '1', + }, + })!, + ) + break + } + if (this.$route.query.url !== this.url) { this.$router.replace({ query: { @@ -816,6 +832,10 @@ export default class FetchIndex extends Vue { this.isInputValueValid = true return } + if (this.url.startsWith('ipfs://') || this.url.startsWith('ar://')) { + this.isInputValueValid = true + return + } if (this.crawlURLRegex.test(url)) { if (url.includes(LIKER_LAND_URL)) { this.errorMessage = this.$t(