Skip to content

Commit

Permalink
use blob url to replace data url (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sneezry authored Jan 2, 2022
1 parent c57d05f commit 05dbda0
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/components/Popup/BackupPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
</template>
<script lang="ts">
import Vue from "vue";
import { mapState } from "vuex";
import { Encryption } from "../../models/encryption";
import { EntryStorage } from "../../models/storage";
import * as CryptoJS from "crypto-js";
export default Vue.extend({
data: function () {
Expand Down Expand Up @@ -152,10 +148,7 @@ function getBackupFile(
let json = JSON.stringify(entryData, null, 2);
// for windows notepad
json = json.replace(/\n/g, "\r\n");
const base64Data = CryptoJS.enc.Base64.stringify(
CryptoJS.enc.Utf8.parse(json)
);
return `data:application/octet-stream;base64,${base64Data}`;
return downloadFileUrlBuilder(json);
}
function getOneLineOtpBackupFile(entryData: { [hash: string]: OTPStorage }) {
Expand Down Expand Up @@ -198,10 +191,12 @@ function getOneLineOtpBackupFile(entryData: { [hash: string]: OTPStorage }) {
otpAuthLines.push(otpAuthLine);
}
const base64Data = CryptoJS.enc.Base64.stringify(
CryptoJS.enc.Utf8.parse(otpAuthLines.join("\r\n"))
);
return `data:application/octet-stream;base64,${base64Data}`;
return downloadFileUrlBuilder(otpAuthLines.join("\r\n"));
}
function downloadFileUrlBuilder(content: string) {
const blob = new Blob([content], { type: "application/octet-stream" });
return URL.createObjectURL(blob);
}
function removeUnsafeData(data: string) {
Expand Down

0 comments on commit 05dbda0

Please sign in to comment.