|
50 | 50 |
|
51 | 51 | <script>
|
52 | 52 | import fs from 'fs'
|
| 53 | +import path from 'path' |
53 | 54 | import Papa from 'papaparse'
|
54 | 55 | import { remote, ipcRenderer } from 'electron'
|
55 | 56 | import { mapActions, mapMutations, mapState } from 'vuex'
|
56 | 57 | import CryptoUtils from '@/utils/crypto'
|
| 58 | +import SystemService from '@/api/services/System' |
57 | 59 |
|
58 | 60 | export default {
|
59 | 61 | data() {
|
@@ -96,20 +98,89 @@ export default {
|
96 | 98 | },
|
97 | 99 |
|
98 | 100 | async onExport() {
|
99 |
| - const filePath = remote.dialog.showSaveDialogSync(null) |
| 101 | + const dir = remote.dialog.showOpenDialogSync({ |
| 102 | + title: 'Select Export Directory', |
| 103 | + properties: ['openDirectory', 'createDirectory'] |
| 104 | + }) |
100 | 105 |
|
101 |
| - if (!filePath) { |
| 106 | + if (dir.length === 0) { |
102 | 107 | return
|
103 | 108 | }
|
104 |
| -
|
| 109 | + |
105 | 110 | try {
|
106 |
| - const data = await this.Export() |
107 |
| -
|
108 |
| - const itemList = JSON.parse(CryptoUtils.aesDecrypt(data)) |
109 |
| - itemList.forEach(item => CryptoUtils.decryptFields(item)) |
110 |
| -
|
111 |
| - const csvContent = Papa.unparse(itemList) |
112 |
| - fs.writeFileSync(filePath, csvContent) |
| 111 | + const { data } = await SystemService.Export() |
| 112 | + |
| 113 | + const itemList = JSON.parse(CryptoUtils.aesDecrypt(data.data)) |
| 114 | + |
| 115 | + // console.log(itemList.Logins) |
| 116 | + const LoginEncryptedFields = ['username', 'password', 'extra'] |
| 117 | + itemList.Logins.forEach(item => CryptoUtils.decryptFields(item, LoginEncryptedFields)) |
| 118 | + |
| 119 | + const ServerEncryptedFields = ['ip','username','password','hosting_username','hosting_password','admin_username','admin_password','extra'] |
| 120 | + itemList.Servers.forEach(item => CryptoUtils.decryptFields(item, ServerEncryptedFields)) |
| 121 | + |
| 122 | + const NoteEncryptedFields = ['note'] |
| 123 | + itemList.Notes.forEach(item => CryptoUtils.decryptFields(item, NoteEncryptedFields)) |
| 124 | + |
| 125 | + const EmailEncryptedFields = ['email', 'password'] |
| 126 | + itemList.Emails.forEach(item => CryptoUtils.decryptFields(item, EmailEncryptedFields)) |
| 127 | + |
| 128 | + const CreditCardEncryptedFields = ['type', 'number', 'expiry_date', 'cardholder_name', 'verification_number'] |
| 129 | + itemList.CreditCards.forEach(item => CryptoUtils.decryptFields(item, CreditCardEncryptedFields)) |
| 130 | + |
| 131 | + const BankAccountEncryptedFields = ['account_name', 'account_number', 'iban', 'currency', 'password'] |
| 132 | + itemList.BankAccounts.forEach(item => CryptoUtils.decryptFields(item, BankAccountEncryptedFields)) |
| 133 | + |
| 134 | + const contentLogins = Papa.unparse(itemList.Logins) |
| 135 | + fs.writeFile(path.join(dir[0],"logins.csv"), contentLogins, function (err) { |
| 136 | + if (err) { |
| 137 | + this.$notifyError(this.$t('Something went wrong.')) |
| 138 | + console.log(err) |
| 139 | + } |
| 140 | + }); |
| 141 | + |
| 142 | + const contentServer = Papa.unparse(itemList.Servers) |
| 143 | + fs.writeFile(path.join(dir[0],"servers.csv"), contentServer, function (err) { |
| 144 | + if (err) { |
| 145 | + this.$notifyError(this.$t('Something went wrong.')) |
| 146 | + console.log(err) |
| 147 | + } |
| 148 | + }); |
| 149 | + |
| 150 | + const contentNote = Papa.unparse(itemList.Notes) |
| 151 | + fs.writeFile(path.join(dir[0],"notes.csv"), contentNote, function (err) { |
| 152 | + if (err) { |
| 153 | + this.$notifyError(this.$t('Something went wrong.')) |
| 154 | + console.log(err) |
| 155 | + } |
| 156 | + }); |
| 157 | + |
| 158 | + const contentEmail = Papa.unparse(itemList.Emails) |
| 159 | + fs.writeFile(path.join(dir[0],"emails.csv"), contentEmail, function (err) { |
| 160 | + if (err) { |
| 161 | + this.$notifyError(this.$t('Something went wrong.')) |
| 162 | + console.log(err) |
| 163 | + } |
| 164 | + }); |
| 165 | + |
| 166 | + const contentCreditCard = Papa.unparse(itemList.CreditCards) |
| 167 | + fs.writeFile(path.join(dir[0],"credit_cards.csv"), contentCreditCard, function (err) { |
| 168 | + if (err) { |
| 169 | + this.$notifyError(this.$t('Something went wrong.')) |
| 170 | + console.log(err) |
| 171 | + } |
| 172 | + }); |
| 173 | + |
| 174 | + const contentBankAccount = Papa.unparse(itemList.BankAccounts) |
| 175 | + fs.writeFile(path.join(dir[0],"credit_cards.csv"), contentBankAccount, function (err) { |
| 176 | + if (err) { |
| 177 | + this.$notifyError(this.$t('Something went wrong.')) |
| 178 | + console.log(err) |
| 179 | + } |
| 180 | + }); |
| 181 | + |
| 182 | + this.$notifySuccess(this.$t(`All records exported successfully.`)) |
| 183 | + |
113 | 184 | } catch (error) {
|
114 | 185 | this.$notifyError(this.$t('Something went wrong.'))
|
115 | 186 | console.log(error)
|
|
0 commit comments