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 Apr 9, 2024
2 parents 3dd8d45 + 9cfa8a3 commit 25679d9
Showing 1 changed file with 36 additions and 52 deletions.
88 changes: 36 additions & 52 deletions components/IscnUploadForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -820,28 +820,6 @@ 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()
Expand All @@ -855,38 +833,41 @@ export default class IscnUploadForm extends Vue {
}
async setEbookCoverFromImages() {
if (
this.epubMetadataList[0] &&
this.epubMetadataList[0].thumbnailArweaveId
) {
return
if (this.epubMetadataList?.find(epubMetadata => epubMetadata.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
}
const transactionHash =
// eslint-disable-next-line no-await-in-loop
existingData.transactionHash || (await this.sendArweaveFeeTx(file))
// 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
const uploadPromises = this.fileRecords
.filter(file => IMAGE_MIME_TYPES.includes(file.fileType))
.map(async (file) => {
const existingData = this.sentArweaveTransactionInfo.get(file.ipfsHash) || {};
if (existingData.arweaveId) {
return {
thumbnailIpfsHash: file.ipfsHash,
thumbnailArweaveId: existingData.arweaveId,
};
}
}
let { transactionHash } = existingData;
if (!transactionHash) {
transactionHash = await this.sendArweaveFeeTx(file);
}
const arweaveId = await this.uploadFileAndGetArweaveId(file, transactionHash);
if (arweaveId) {
this.sentArweaveTransactionInfo.set(file.ipfsHash, { transactionHash, arweaveId });
return {
thumbnailIpfsHash: file.ipfsHash,
thumbnailArweaveId: arweaveId,
};
}
return false
});
const results = await Promise.all(uploadPromises);
this.epubMetadataList.push(...results.filter(Boolean));
}
async onSubmit() {
Expand Down Expand Up @@ -914,7 +895,10 @@ export default class IscnUploadForm extends Vue {
try {
this.uploadStatus = 'uploading';
if (this.checkUploadFileTypeIsPDF()) {
if (
this.fileRecords.find((file) => file.fileType === 'application/pdf') &&
!this.fileRecords.find((file) => file.fileType === 'application/epub+zip')
) {
await this.setEbookCoverFromImages()
}
Expand Down

0 comments on commit 25679d9

Please sign in to comment.