use more Buffer

This commit is contained in:
Jesse-Ma
2023-03-31 15:59:13 +08:00
parent 64db2300b3
commit 83c3901b86
2 changed files with 26 additions and 38 deletions

View File

@@ -1,5 +1,6 @@
import CryptoJS from "crypto-js"; import CryptoJS from "crypto-js";
import pako from "pako"; import pako from "pako";
import {Buffer} from "buffer";
//import {gzip_encode_raw,gzip_decode_raw} from 'wasm-flate'; //import {gzip_encode_raw,gzip_decode_raw} from 'wasm-flate';
const wasmFlate = window.wasm_bindgen; const wasmFlate = window.wasm_bindgen;
@@ -137,16 +138,10 @@ export function convertHexStringToBase64(hexString) {
} }
export function convertHexStringToUint8Array(hexString) { export function convertHexStringToUint8Array(hexString) {
var result = []; return Uint8Array.from(Buffer.from(hexString, 'hex'));
for (var i = 0; i < hexString.length; i += 2) {
result.push(parseInt(hexString.substr(i, 2), 16));
}
return Uint8Array.from(result);
} }
export function convertUint8ArrayToHexString(byteArray) { export function convertUint8ArrayToHexString(byteArray) {
return Array.prototype.map.call(byteArray, function(byte) { return Buffer.from(byteArray).toString('hex');
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('');
} }
function convertWordArrayToUint8Array(wordArray) { function convertWordArrayToUint8Array(wordArray) {

View File

@@ -172,17 +172,17 @@
<img style="height:40px;float:left;cursor: pointer;" alt="refresh flagnote" src="/static/logo.png" <img style="height:40px;float:left;cursor: pointer;" alt="refresh flagnote" src="/static/logo.png"
v-on:click="refreshPage()"> v-on:click="refreshPage()">
<!-- <!--
<div style="float:left;width:auto;vertical-align: center;"> <div style="float:left;width:auto;vertical-align: center;">
<div style="font-size: 18px; <div style="font-size: 18px;
color: red; color: red;
line-height: 40px; line-height: 40px;
display: inline-block; display: inline-block;
font-weight: bold; font-weight: bold;
height: 40px;">{{ height: 40px;">{{
state.ttlDesc state.ttlDesc
}}</div> }}</div>
</div> </div>
--> -->
<div style="float:left;width:auto;"> <div style="float:left;width:auto;">
@@ -225,9 +225,9 @@
<!-- <!--
<Button type="error" icon="md-refresh" style="border-radius: 0px;font-size: 24px;" <Button type="error" icon="md-refresh" style="border-radius: 0px;font-size: 24px;"
@click="refreshPage()"></Button> @click="refreshPage()"></Button>
--> -->
<Button aria-label="crop" v-show="model.showDownloadText" type="error" icon="md-crop" <Button aria-label="crop" v-show="model.showDownloadText" type="error" icon="md-crop"
style="border-radius: 0px;font-size: 24px;" @click="saveImage(); switchMenu();"></Button> style="border-radius: 0px;font-size: 24px;" @click="saveImage(); switchMenu();"></Button>
@@ -275,11 +275,11 @@
<Modal v-model="model.showShare" width="360" footer-hide class-name="qrmodal" :styles="{ borderRadius: 0 }" <Modal v-model="model.showShare" width="360" footer-hide class-name="qrmodal" :styles="{ borderRadius: 0 }"
@on-cancel="closeShareModel"> @on-cancel="closeShareModel">
<p style="text-align: center; <p style="text-align: center;
z-index: 1000; z-index: 1000;
position: absolute; position: absolute;
top: -2px; top: -2px;
left: 0px; left: 0px;
width: 100%;"> width: 100%;">
<Tag style="border-radius: 0px;" v-show="model.copyTip" color="#ed4014" text="">Url Copied.</Tag> <Tag style="border-radius: 0px;" v-show="model.copyTip" color="#ed4014" text="">Url Copied.</Tag>
</p> </p>
<p style="text-align: center;margin-top:20px;line-height:100%"> <p style="text-align: center;margin-top:20px;line-height:100%">
@@ -580,26 +580,19 @@ export default {
return; return;
} }
let blob = new Blob([res.data], { res.data.arrayBuffer().then(function (ab) {
type: res.data.type if (!ab || ab.byteLength == 0) {
});
let reader = new FileReader();
reader.onload = function (e) {
if (!e.target.result || e.target.result.byteLength == 0) {
return; return;
} }
let base64String = Buffer.from(e.target.result).toString('base64') let base64String = Buffer.from(ab).toString('base64')
that.noteForm.text = unwrap(base64String, that.secret.secretKey); that.noteForm.text = unwrap(base64String, that.secret.secretKey);
//that.noteForm.escapeText = getEscapeText(that.noteForm.text);
// if local is enough, set local // if local is enough, set local
if (storage.local.getAvailableSize() > 1 * 1024 * 1024) { if (storage.local.getAvailableSize() > 1 * 1024 * 1024) {
storage.local.setText(that.secret.storeKey, that.state.lock + '|' + that.secret.cipher + '|1|' + that.state.serverTime + '|' + base64String); storage.local.setText(that.secret.storeKey, that.state.lock + '|' + that.secret.cipher + '|1|' + that.state.serverTime + '|' + base64String);
} }
}; });
reader.readAsArrayBuffer(blob);
}); });
} else { } else {