|
105 | 105 | </table>
|
106 | 106 | </div>
|
107 | 107 | </div>
|
| 108 | + <FormField v-if="hasEbookInRecords"> |
| 109 | + <CheckBox v-model="isEncryptEBookData">{{ $t('UploadForm.label.encryptEBookData') }}</CheckBox> |
| 110 | + </FormField> |
108 | 111 | <FormField v-if="showAddISCNPageOption">
|
109 | 112 | <CheckBox v-model="isAddISCNPageToEbook">{{ $t('UploadForm.label.insertISCNPage') }}</CheckBox>
|
110 | 113 | </FormField>
|
@@ -244,6 +247,7 @@ import exifr from 'exifr'
|
244 | 247 | import Hash from 'ipfs-only-hash'
|
245 | 248 | import BigNumber from 'bignumber.js'
|
246 | 249 | import ePub from 'epubjs';
|
| 250 | +import { encryptDataWithAES } from 'arweavekit/dist/lib/encryption'; |
247 | 251 |
|
248 | 252 | import { OfflineSigner } from '@cosmjs/proto-signing'
|
249 | 253 |
|
@@ -310,6 +314,7 @@ export default class IscnUploadForm extends Vue {
|
310 | 314 | isOpenSignDialog = false
|
311 | 315 | isOpenWarningSnackbar = false
|
312 | 316 | isSizeExceeded = false
|
| 317 | + isEncryptEBookData = true |
313 | 318 | isAddISCNPageToEbook = false
|
314 | 319 |
|
315 | 320 | uploadSizeLimit: number = UPLOAD_FILESIZE_MAX
|
@@ -402,14 +407,18 @@ export default class IscnUploadForm extends Vue {
|
402 | 407 | }
|
403 | 408 | }
|
404 | 409 |
|
405 |
| - get showAddISCNPageOption() { |
406 |
| - return this.mode === MODE.EDIT |
407 |
| - && this.fileRecords.some(file => [ |
| 410 | + get hasEbookInRecords() { |
| 411 | + return this.fileRecords.some(file => [ |
408 | 412 | 'application/epub+zip',
|
409 | 413 | 'application/pdf',
|
410 | 414 | ].includes(file.fileType))
|
411 | 415 | }
|
412 | 416 |
|
| 417 | + get showAddISCNPageOption() { |
| 418 | + return this.mode === MODE.EDIT |
| 419 | + && this.hasEbookInRecords |
| 420 | + } |
| 421 | +
|
413 | 422 | get modifiedFileRecords() {
|
414 | 423 | if (!this.isAddISCNPageToEbook || this.mode !== MODE.EDIT) return this.fileRecords
|
415 | 424 | return this.fileRecords.map((record) => {
|
@@ -844,15 +853,29 @@ export default class IscnUploadForm extends Vue {
|
844 | 853 | }
|
845 | 854 | }
|
846 | 855 |
|
| 856 | + let key; |
847 | 857 | try {
|
848 | 858 | const arrayBuffer = await tempRecord.fileBlob.arrayBuffer();
|
849 |
| - const buffer = Buffer.from(arrayBuffer); |
| 859 | + let buffer = Buffer.from(arrayBuffer); |
| 860 | + if ([ |
| 861 | + 'application/epub+zip', |
| 862 | + 'application/pdf', |
| 863 | + ].includes(record.fileType) |
| 864 | + && this.isEncryptEBookData) { |
| 865 | + const { |
| 866 | + rawEncryptedKeyAsBase64, |
| 867 | + combinedArrayBuffer, |
| 868 | + } = await encryptDataWithAES({ data: arrayBuffer }); |
| 869 | + buffer = Buffer.from(combinedArrayBuffer); |
| 870 | + key = rawEncryptedKeyAsBase64 |
| 871 | + } |
850 | 872 | const { arweaveId, arweaveLink } = await uploadSingleFileToBundlr(buffer, {
|
851 | 873 | fileSize: tempRecord.fileBlob?.size || 0,
|
852 | 874 | ipfsHash: tempRecord.ipfsHash,
|
853 | 875 | fileType: tempRecord.fileType as string,
|
854 | 876 | txHash: tempRecord.transactionHash,
|
855 | 877 | token: this.getToken,
|
| 878 | + key, |
856 | 879 | });
|
857 | 880 | if (arweaveId) {
|
858 | 881 | const uploadedData = this.sentArweaveTransactionInfo.get(record.ipfsHash) || {};
|
|
0 commit comments