hex plus plus

This commit is contained in:
Jesse-Ma
2023-03-31 10:21:44 +08:00
parent f369e59f6f
commit 8e6ce23b98
7 changed files with 97 additions and 56 deletions

View File

@@ -1,8 +1,9 @@
import axios from "axios";
import { getStoreKey } from "@/api/lock";
import storage from "@/libs/storage";
import { md5, wrap,convertBase64ToHexString,convertHexStringToUint8Array} from "@/libs/secret";
import { md5, wrap} from "@/libs/secret";
import NoteConstant from "@/libs/constants";
import { Buffer } from 'buffer';
axios.interceptors.response.use(undefined, (err) => {
const { config: originalRequest } = err;
@@ -48,14 +49,7 @@ export function saveNote(noteForm, secret) {
});
}
// let bufferArrary = eval("[" + note.text + "]");
// let array = Uint8Array.from(bufferArrary);
// let encoder = new TextEncoder()
// let array = encoder.encode(note.text)
let hexString = convertBase64ToHexString(note.text)
let array = convertHexStringToUint8Array(hexString)
let array = Buffer.from(note.text, 'base64')
let blob = new Blob([array], { type: "application/octet-stream" });
let form = new FormData();

View File

@@ -88,15 +88,15 @@ export function aesDecrypt(word, keyWord) {
return decrypt;
}
//base64 encode
// export function encode(text) {
// return Buffer.from(text, 'utf-8').toString('base64');
// }
//base64 encode btoa
export function base64Encode(text) {
return Buffer.from(text, 'utf-8').toString('base64');
}
//base64 decode
// export function decode(text) {
// return Buffer.from(text,'base64').toString('utf-8');
// }
//base64 decode atob
export function base64Decode(text) {
return Buffer.from(text,'base64').toString('utf-8');
}
export function noteUnzip(wdary) {
let data = unzip(wdary);

View File

@@ -549,7 +549,7 @@ export default {
dataURLToBlob(dataurl) {
let arr = dataurl.split(',');
let mime = arr[0].match(/:(.*?);/)[1];
let bstr = atob(arr[1]);
let bstr = window.atob(arr[1]);
let n = bstr.length;
let u8arr = new Uint8Array(n);
while (n--) {

View File

@@ -172,17 +172,17 @@
<img style="height:40px;float:left;cursor: pointer;" alt="refresh flagnote" src="/static/logo.png"
v-on:click="refreshPage()">
<!--
<div style="float:left;width:auto;vertical-align: center;">
<div style="font-size: 18px;
color: red;
line-height: 40px;
display: inline-block;
font-weight: bold;
height: 40px;">{{
state.ttlDesc
}}</div>
</div>
-->
<div style="float:left;width:auto;vertical-align: center;">
<div style="font-size: 18px;
color: red;
line-height: 40px;
display: inline-block;
font-weight: bold;
height: 40px;">{{
state.ttlDesc
}}</div>
</div>
-->
<div style="float:left;width:auto;">
@@ -225,9 +225,9 @@
<!--
<Button type="error" icon="md-refresh" style="border-radius: 0px;font-size: 24px;"
@click="refreshPage()"></Button>
-->
<Button type="error" icon="md-refresh" style="border-radius: 0px;font-size: 24px;"
@click="refreshPage()"></Button>
-->
<Button aria-label="crop" v-show="model.showDownloadText" type="error" icon="md-crop"
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 }"
@on-cancel="closeShareModel">
<p style="text-align: center;
z-index: 1000;
position: absolute;
top: -2px;
left: 0px;
width: 100%;">
z-index: 1000;
position: absolute;
top: -2px;
left: 0px;
width: 100%;">
<Tag style="border-radius: 0px;" v-show="model.copyTip" color="#ed4014" text="">Url Copied.</Tag>
</p>
<p style="text-align: center;margin-top:20px;line-height:100%">
@@ -336,7 +336,7 @@
<script>
import { md5, unwrap,convertUint8ArrayToHexString,convertHexStringToBase64 } from "@/libs/secret";
import { md5, unwrap } from "@/libs/secret";
import { getStoreKey } from "@/api/lock";
import { deleteNote, getNoteBlob } from "@/api/note";
import storage from "@/libs/storage";
@@ -346,6 +346,7 @@ import Clipboard from "clipboard";
import { saveAs } from 'file-saver';
import { isWeixin, getNoteUrl } from "@/libs/utils";
import html2canvas from "html2canvas";
import { Buffer } from 'buffer';
export default {
name: 'ViewNote',
@@ -589,12 +590,7 @@ export default {
return;
}
// let decoder = new TextDecoder();
// let bytesString = decoder.decode(e.target.result);
let hexString = convertUint8ArrayToHexString(new Uint8Array(e.target.result));
let base64String = convertHexStringToBase64(hexString);
let base64String = Buffer.from(e.target.result).toString('base64')
that.noteForm.text = unwrap(base64String, that.secret.secretKey);
//that.noteForm.escapeText = getEscapeText(that.noteForm.text);
@@ -669,7 +665,7 @@ export default {
dataURLToBlob(dataurl) {
let arr = dataurl.split(',');
let mime = arr[0].match(/:(.*?);/)[1];
let bstr = atob(arr[1]);
let bstr = window.atob(arr[1]);
let n = bstr.length;
let u8arr = new Uint8Array(n);
while (n--) {
@@ -681,24 +677,24 @@ export default {
let canvasID = this.$refs["html2canvas"];
let that = this;
let a = document.createElement('a');
html2canvas(canvasID,{
scale: 1,
html2canvas(canvasID, {
scale: 1,
windowWidth: document.getElementById("noteText").offsetWidth,
onclone: (clonedDocument) => {
let nt = clonedDocument.getElementById("noteText");
const div = clonedDocument.createElement('div')
div.innerText = nt.value
div.style.color="black";
div.style.color = "black";
div.style.padding = "0px";
div.style.textAlign = "left";
div.style.wordBreak = "break-word";
div.style.whiteSpace = "pre-wrap";
div.style.verticalAlign = "top";
div.style.fontSize ="15px";
div.style.width= "100%";
div.style.border="0px";
div.style.fontFamily="'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif";
div.style.fontSize = "15px";
div.style.width = "100%";
div.style.border = "0px";
div.style.fontFamily = "'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', '微软雅黑', Arial, sans-serif";
nt.style.display = 'none'