Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TAS-1968] ✨ Add Arweave link DRM option #495

Merged
merged 7 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion components/ContentFingerprintLink.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<Link v-if="href" :href="href" :nofollow="true">
<Link v-if="href" :href="href" :nofollow="true" @click.native="onClick">
{{ item }}
</Link>
<div v-else>
Expand All @@ -9,7 +9,11 @@

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
import { namespace } from 'vuex-class'
import { ARWEAVE_ENDPOINT, IPFS_VIEW_GATEWAY_URL } from '~/constant';
import { LIKE_CO_API_ROOT } from '~/constant/api';

const bookApiModule = namespace('book-api')

export enum ContentFirgerprints {
arweave = 'ar',
Expand All @@ -22,10 +26,16 @@
export default class ContentFingerprintLink extends Vue {
@Prop(String) readonly item: string | undefined

@bookApiModule.Getter('getToken') getToken!: string

get prefix() {
return this.item && this.item.substr(0, this.item.indexOf(':'))
}

get isArweaveApiLink() {
return this.item?.startsWith(LIKE_CO_API_ROOT)
}

get href() {
if (!this.item) return null
switch (this.prefix) {
Expand All @@ -45,5 +55,24 @@
return this.item
}
}

async onClick(e: Event) {
if (this.item && this.isArweaveApiLink) {
e.stopPropagation()
e.preventDefault()
let link = this.item
try {
const { data } = await this.$axios.get(this.item, {
headers: {
Authorization: `Bearer ${this.getToken}`,
},
})
link = data.link
} catch (error) {
console.error(error)

Check warning on line 72 in components/ContentFingerprintLink.vue

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 18)

Unexpected console statement
}
window.open(link, '_blank')
}
}
}
</script>
72 changes: 48 additions & 24 deletions components/IscnRegisterForm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :class="['flex', 'flex-col']">
<div :class="['flex', 'flex-col', 'w-full']">
<Card class="p-[32px]" :has-padding="false">
<!-- header -->
<IscnFormHeader :step="step" :total-step="4" />
Expand Down Expand Up @@ -237,6 +237,15 @@
/>
</FormField>
<Divider class="my-[12px]" />
<FormField
v-if="shouldShowDRMOption"
:label="$t('IscnRegisterForm.label.drm')"
class="mb-[12px]"
>
<CheckBox v-model="isUseArweaveLink">
{{ $t('IscnRegisterForm.label.drm.details') }}
</CheckBox>
</FormField>
<FormField
v-if="type === 'Book'"
:label="$t('IscnRegisterForm.label.sameAs')"
Expand Down Expand Up @@ -270,17 +279,17 @@
<!-- fingerPrint -->
<FormField
:label="$t('IscnRegisterForm.label.fingerprints')"
class="mb-[12px]"
class="mb-[12px] max-w-full"
>
<ContentFingerprintLink
v-for="ipfs of ipfsHashList"
:key="ipfs"
:item="formatIpfs(ipfs)"
/>
<ContentFingerprintLink
v-for="ar of uploadArweaveIdList"
:key="ar"
:item="formatArweave(ar)"
v-for="link of combinedArweaveLinks"
:key="link"
:item="link"
/>
<ContentFingerprintLink
v-for="(f, i) in customContentFingerprints"
Expand Down Expand Up @@ -708,7 +717,8 @@ export enum AuthorDialogType {
@Component
export default class IscnRegisterForm extends Vue {
@Prop({ default: [] }) readonly fileRecords!: any[]
@Prop({ default: [] }) readonly uploadArweaveList!: string[]
@Prop({ default: [] }) readonly uploadArweaveIdList!: string[]
@Prop({ default: [] }) readonly uploadArweaveLinkList!: string[]
@Prop() readonly epubMetadata!: any | null

@Prop(String) readonly ipfsHash!: string
Expand Down Expand Up @@ -801,6 +811,7 @@ export default class IscnRegisterForm extends Vue {
isRegisterNumbersProtocolAsset = false
numbersProtocolAssetIds = new Map<string, string>()

isUseArweaveLink= false
isOpenFileInfoDialog = false
isOpenAuthorDialog = false
isOpenWarningSnackbar = false
Expand Down Expand Up @@ -836,6 +847,10 @@ export default class IscnRegisterForm extends Vue {
return !this.fileRecords.some((file) => file.fileData)
}

get shouldShowDRMOption() {
return this.uploadArweaveLinkList.filter(Boolean).length
}

get tagsString(): string {
return this.tags.join(',')
}
Expand Down Expand Up @@ -906,14 +921,23 @@ export default class IscnRegisterForm extends Vue {
: this.$t('IscnRegisterForm.title.editStakeholder')
}

get combinedArweaveLinks() {
if (this.isUseArweaveLink) {
const list = [...this.uploadArweaveLinkList]
if (this.arweaveId) {
list.push(this.formatArweave(this.arweaveId) as string)
}
return list;
}
return this.combinedArweaveIdList.map((link) => this.formatArweave(link))
}

get contentFingerprintLinks() {
const array = []
if (this.uploadArweaveIdList) {
array.push(
...this.uploadArweaveIdList.map((id: string) => this.formatArweave(id)),
)
const array: string[] = []
if (this.combinedArweaveLinks.length) {
array.push(...this.combinedArweaveLinks)
}
if (this.ipfsHashList.length) {
if (!this.isUseArweaveLink && this.ipfsHashList.length) {
array.push(...this.ipfsHashList.map((ipfs) => this.formatIpfs(ipfs)))
}
if (this.customContentFingerprints.length) {
Expand Down Expand Up @@ -1013,8 +1037,8 @@ export default class IscnRegisterForm extends Vue {
isbn: this.isbn,
exifInfo: this.exif.filter((file) => file),
license: this.formattedLicense,
ipfsHash: this.ipfsHashList,
arweaveId: this.uploadArweaveIdList,
ipfsHash: '',
arweaveId: '',
numbersProtocolAssetId: [...this.numbersProtocolAssetIds.values()],
fileSHA256: this.fileRecords.map((file) => file.fileSHA256),
author: this.author.name,
Expand All @@ -1024,7 +1048,7 @@ export default class IscnRegisterForm extends Vue {
likerIds: this.likerIds,
likerIdsAddresses: this.likerIdsAddresses,
authorDescriptions: this.authorDescriptions,
contentFingerprints: this.customContentFingerprints,
contentFingerprints: this.contentFingerprintLinks,
inLanguage: this.language,
thumbnailUrl: this.thumbnailUrl,
publisher: this.publisher,
Expand All @@ -1040,11 +1064,11 @@ export default class IscnRegisterForm extends Vue {
if (this.arweaveFee.lte(0)) {
return 1
}
return this.uploadArweaveIdList.length ? 2 : 1
return this.combinedArweaveIdList.length ? 2 : 1
}

get totalSignStep() {
if (this.uploadArweaveIdList.length && this.arweaveFee.lte(0)) return 1
if (this.combinedArweaveIdList.length && this.arweaveFee.lte(0)) return 1
return 2
}

Expand All @@ -1058,7 +1082,7 @@ export default class IscnRegisterForm extends Vue {
if (this.isUploadingArweave) {
return this.$t('IscnRegisterForm.signDialog.closeWarning')
}
if (this.uploadArweaveIdList.length) {
if (this.combinedArweaveIdList.length) {
return this.$t('IscnRegisterForm.signDialog.sign.iscn.register')
}
return this.$t('IscnRegisterForm.signDialog.sign.arweave.upload')
Expand Down Expand Up @@ -1094,10 +1118,10 @@ export default class IscnRegisterForm extends Vue {
)
}

get uploadArweaveIdList() {
get combinedArweaveIdList() {
let arweaveIdList: string[] = []
if (this.uploadArweaveList && this.uploadArweaveList.length) {
arweaveIdList = [...this.uploadArweaveList]
if (this.uploadArweaveIdList && this.uploadArweaveIdList.length) {
arweaveIdList = [...this.uploadArweaveIdList]
}
if (this.arweaveId) {
arweaveIdList.push(this.arweaveId)
Expand Down Expand Up @@ -1315,11 +1339,11 @@ export default class IscnRegisterForm extends Vue {
}

formatIpfs(ipfsHash: string) {
return this.$t('IscnRegisterForm.ipfs.link', { hash: ipfsHash })
return this.$t('IscnRegisterForm.ipfs.link', { hash: ipfsHash }) as string
}

formatArweave(arweaveId: string) {
return this.$t('IscnRegisterForm.arweave.link', { arweaveId })
return this.$t('IscnRegisterForm.arweave.link', { arweaveId }) as string
}

async getLikerIdsAddresses() {
Expand Down Expand Up @@ -1456,7 +1480,7 @@ estimation,
}
if (
!this.fileRecords.some((file) => file.fileBlob) ||
this.uploadArweaveIdList.length
this.combinedArweaveIdList.length
)
await this.submitToISCN()
}
Expand Down
37 changes: 25 additions & 12 deletions components/IscnUploadForm.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div class="w-full">
<Card class="p-[32px]" :has-padding="false">
<!-- header -->
<IscnFormHeader v-if="mode === 'register'" :step="step" :total-step="4" />
Expand Down Expand Up @@ -317,7 +317,7 @@
arweaveFee = new BigNumber(0)
arweaveFeeMap: Record<string, string> = {}
sentArweaveTransactionInfo = new Map<
string, { transactionHash?: string, arweaveId?: string }
string, { transactionHash?: string, arweaveId?: string, arweaveLink?: string }
>()

likerId: string = ''
Expand Down Expand Up @@ -657,7 +657,7 @@
}
this.epubMetadataList.push(epubMetadata)
} catch (err) {
console.error(err)

Check warning on line 660 in components/IscnUploadForm.vue

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest, 18)

Unexpected console statement
}
}

Expand Down Expand Up @@ -845,7 +845,7 @@
try {
const arrayBuffer = await tempRecord.fileBlob.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const arweaveId = await uploadSingleFileToBundlr(buffer, {
const { arweaveId, arweaveLink } = await uploadSingleFileToBundlr(buffer, {
fileSize: tempRecord.fileBlob?.size || 0,
ipfsHash: tempRecord.ipfsHash,
fileType: tempRecord.fileType as string,
Expand All @@ -854,14 +854,14 @@
});
if (arweaveId) {
const uploadedData = this.sentArweaveTransactionInfo.get(record.ipfsHash) || {};
this.sentArweaveTransactionInfo.set(record.ipfsHash, { ...uploadedData, arweaveId });
this.sentArweaveTransactionInfo.set(record.ipfsHash, { ...uploadedData, arweaveId, arweaveLink });
if (tempRecord.fileName.includes('cover.jpeg')) {
const metadata = this.epubMetadataList.find((file: any) => file.thumbnailIpfsHash === record.ipfsHash)
if (metadata) {
metadata.thumbnailArweaveId = arweaveId
}
}
this.$emit('arweaveUploaded', { arweaveId })
this.$emit('arweaveUploaded', { arweaveId, arweaveLink })
this.isOpenSignDialog = false
} else {
this.isOpenWarningSnackbar = true
Expand All @@ -879,13 +879,14 @@
async uploadFileAndGetArweaveId(file: any, txHash: string) {
const arrayBuffer = await file.fileBlob.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
return uploadSingleFileToBundlr(buffer, {
const { arweaveId, arweaveLink } = await uploadSingleFileToBundlr(buffer, {
fileSize: file.fileBlob?.size || 0,
ipfsHash: file.ipfsHash,
fileType: file.fileType,
txHash,
token: this.getToken,
})
return { arweaveId, arweaveLink };
}

async setEbookCoverFromImages() {
Expand All @@ -911,7 +912,7 @@
transactionHash = await this.sendArweaveFeeTx(file)
}
// eslint-disable-next-line no-await-in-loop
const arweaveId = await this.uploadFileAndGetArweaveId(
const { arweaveId, arweaveLink } = await this.uploadFileAndGetArweaveId(
file,
transactionHash,
)
Expand All @@ -924,6 +925,7 @@
this.sentArweaveTransactionInfo.set(file.ipfsHash, {
transactionHash,
arweaveId,
arweaveLink,
})
break
}
Expand Down Expand Up @@ -984,17 +986,28 @@
}

const uploadArweaveIdList = Array.from(this.sentArweaveTransactionInfo.values()).map(entry => entry.arweaveId);
const uploadArweaveLinkList = Array.from(this.sentArweaveTransactionInfo.values()).map(entry => entry.arweaveLink);
this.modifiedFileRecords.forEach((record: any, index:number) => {
if (this.sentArweaveTransactionInfo.has(record.ipfsHash)) {
const arweaveId = this.sentArweaveTransactionInfo.get(
const info = this.sentArweaveTransactionInfo.get(
record.ipfsHash,
)?.arweaveId
if (arweaveId) {
this.modifiedFileRecords[index].arweaveId = arweaveId
)
if (info) {
const {
arweaveId,
arweaveLink,
} = info;
if (arweaveId) this.modifiedFileRecords[index].arweaveId = arweaveId
if (arweaveLink) this.modifiedFileRecords[index].arweaveLink = arweaveLink
}
}
})
this.$emit('submit', { fileRecords: this.modifiedFileRecords, arweaveIds: uploadArweaveIdList, epubMetadata: this.epubMetadataList[0] })
this.$emit('submit', {
fileRecords: this.modifiedFileRecords,
arweaveIds: uploadArweaveIdList,
epubMetadata: this.epubMetadataList[0],
arweaveLinks: uploadArweaveLinkList,
})
}

handleSignDialogClose() {
Expand Down
Loading
Loading