Skip to content

Commit

Permalink
🔀 Merge #457 into deploy/rinkeby
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraHuang22 committed Mar 19, 2024
2 parents 4e48ddd + d8660fc commit 2faade5
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 7 deletions.
8 changes: 4 additions & 4 deletions components/IscnRegisterForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1067,12 +1067,12 @@ export default class IscnRegisterForm extends Vue {
this.uploadStatus = 'loading'
if (this.epubMetadata) {
this.name = this.epubMetadata.title
this.name = this.epubMetadata.title || ''
this.description = this.extractText(this.epubMetadata.description)
this.author.name = this.epubMetadata.author
this.author.name = this.epubMetadata.author || ''
this.author.authorDescription = 'Author'
this.language = this.epubMetadata.language
this.tags = this.epubMetadata.tags
this.language = this.epubMetadata.language || ''
this.tags = this.epubMetadata.tags || []
this.thumbnailUrl = this.formatArweave(
this.epubMetadata.thumbnailArweaveId,
) as string
Expand Down
89 changes: 86 additions & 3 deletions components/IscnUploadForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ const MODE = {
EDIT: 'edit',
}
const IMAGE_MIME_TYPES = [
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
]
@Component
export default class IscnUploadForm extends Vue {
@Prop(Number) readonly step: number | undefined
Expand Down Expand Up @@ -743,7 +750,6 @@ export default class IscnUploadForm extends Vue {
if (!this.signer) throw new Error('SIGNER_NOT_INITED');
if (!this.arweaveFeeTargetAddress) throw new Error('TARGET_ADDRESS_NOT_SET');
if (!this.arweaveFeeMap[record.ipfsHash]) throw new Error('ARWEAVE_FEE_NOT_SET');
this.uploadStatus = 'signing';
const memo = JSON.stringify({ ipfs: record.ipfsHash, fileSize: record.fileBlob?.size || 0 });
try {
const { transactionHash } = await sendLIKE(this.address, this.arweaveFeeTargetAddress, this.arweaveFeeMap[record.ipfsHash], this.signer, memo);
Expand All @@ -758,8 +764,6 @@ export default class IscnUploadForm extends Vue {
// TODO: Handle error
// eslint-disable-next-line no-console
console.error(err);
} finally {
this.uploadStatus = '';
}
return '';
}
Expand All @@ -775,10 +779,13 @@ export default class IscnUploadForm extends Vue {
tempRecord.transactionHash = transactionHash
if (!tempRecord.transactionHash) {
this.uploadStatus = 'signing';
tempRecord.transactionHash = await this.sendArweaveFeeTx(tempRecord);
if (!tempRecord.transactionHash) {
this.uploadStatus = '';
throw new Error('TRANSACTION_NOT_SENT')
}
this.uploadStatus = 'uploading';
}
try {
Expand Down Expand Up @@ -813,6 +820,77 @@ export default class IscnUploadForm extends Vue {
}
}
checkUploadFileTypeIsPDF() {
let hasPDF = false;
// eslint-disable-next-line no-restricted-syntax
for (const file of this.fileRecords) {
if (file.fileType === 'application/epub+zip') {
return false;
}
if (file.fileType === 'application/pdf') {
hasPDF = true;
}
}
return hasPDF;
}
addToEpubMetadataList(ipfsHash: string, arweaveId: string) {
this.epubMetadataList.push({
thumbnailIpfsHash: ipfsHash,
thumbnailArweaveId: arweaveId,
})
}
// eslint-disable-next-line class-methods-use-this
async uploadFileAndGetArweaveId(file: any, txHash: string) {
const arrayBuffer = await file.fileBlob.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
return uploadSingleFileToBundlr(buffer, {
fileSize: file.fileBlob?.size || 0,
ipfsHash: file.ipfsHash,
fileType: file.fileType,
txHash,
})
}
async setEbookCoverFromImages() {
if (
this.epubMetadataList[0] &&
this.epubMetadataList[0].thumbnailArweaveId
) {
return
}
// eslint-disable-next-line no-restricted-syntax
for (const file of this.fileRecords) {
if (IMAGE_MIME_TYPES.includes(file.fileType)) {
const existingData =
this.sentArweaveTransactionInfo.get(file.ipfsHash) || {}
if (existingData.arweaveId) {
this.addToEpubMetadataList(file.ipfsHash, existingData.arweaveId)
return
}
this.uploadStatus = 'signing';
const transactionHash =
// eslint-disable-next-line no-await-in-loop
existingData.transactionHash || (await this.sendArweaveFeeTx(file))
this.uploadStatus = 'uploading';
// eslint-disable-next-line no-await-in-loop
const arweaveId = await this.uploadFileAndGetArweaveId(
file,
transactionHash,
)
if (arweaveId) {
this.addToEpubMetadataList(file.ipfsHash, arweaveId)
this.sentArweaveTransactionInfo.set(file.ipfsHash, { transactionHash, arweaveId });
return
}
return
}
}
}
async onSubmit() {
if (IS_CHAIN_UPGRADING) return
logTrackerEvent(this, 'ISCNCreate', 'ClickUpload', '', 1);
Expand All @@ -837,6 +915,11 @@ export default class IscnUploadForm extends Vue {
try {
this.uploadStatus = 'uploading';
if (this.checkUploadFileTypeIsPDF()) {
await this.setEbookCoverFromImages()
}
// eslint-disable-next-line no-restricted-syntax
this.numberOfSignNeeded = this.modifiedFileRecords.length;
this.signProgress = 0;
Expand Down

0 comments on commit 2faade5

Please sign in to comment.