getSecretKey and jsonresult
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
import axios from "axios";
|
||||
import { getStoreKey } from "@/api/lock";
|
||||
import storage from "@/libs/storage";
|
||||
import { md5 } from "@/libs/secret";
|
||||
import { md5, wrap } from "@/libs/secret";
|
||||
import NoteConstant from "@/libs/constants";
|
||||
|
||||
axios.interceptors.response.use(undefined, (err) => {
|
||||
const { config: originalRequest } = err;
|
||||
if (
|
||||
(err?.code === 'ECONNABORTED' ||
|
||||
err?.message === 'Network Error' ||
|
||||
err?.message?.includes?.('timeout')) &&
|
||||
!originalRequest._retry
|
||||
) {
|
||||
originalRequest._retry = true;
|
||||
return axios.request(originalRequest);
|
||||
}
|
||||
});
|
||||
|
||||
export function saveNote(noteForm, secret) {
|
||||
let storeKey = secret.storeKey;
|
||||
@@ -11,6 +23,14 @@ export function saveNote(noteForm, secret) {
|
||||
let storeInfo = storage.local.getText(storeKey);
|
||||
let starray = storeInfo.split("|");
|
||||
|
||||
if (starray[2] == "1") {
|
||||
return new Promise(function (onCompleted) {
|
||||
let res = { data: {} };
|
||||
res.data.code = "100013";
|
||||
onCompleted(res);
|
||||
});
|
||||
}
|
||||
|
||||
let note = {
|
||||
lock: starray[0],
|
||||
cipher: starray[1],
|
||||
@@ -19,6 +39,15 @@ export function saveNote(noteForm, secret) {
|
||||
key: noteForm.key,
|
||||
};
|
||||
|
||||
let viewStoreText = wrap(noteForm.text, secret.secretKey);
|
||||
if (viewStoreText != note.text) {
|
||||
return new Promise(function (onCompleted) {
|
||||
let res = { data: {} };
|
||||
res.data.code = "100014";
|
||||
onCompleted(res);
|
||||
});
|
||||
}
|
||||
|
||||
let bufferArrary = eval("[" + note.text + "]");
|
||||
let array = Uint8Array.from(bufferArrary);
|
||||
let blob = new Blob([array], { type: "application/octet-stream" });
|
||||
@@ -28,7 +57,7 @@ export function saveNote(noteForm, secret) {
|
||||
form.append("lock", note.lock);
|
||||
form.append("key", note.key);
|
||||
form.append("md5", md5(note.text));
|
||||
form.append("initTime",note.initTime)
|
||||
form.append("initTime", note.initTime)
|
||||
|
||||
let config = {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
@@ -91,16 +120,17 @@ export function getKeyMeta() {
|
||||
}
|
||||
|
||||
export function ajaxGet(url) {
|
||||
let data = {};
|
||||
let data = null;
|
||||
let xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.open("GET", url, false);
|
||||
xmlhttp.onreadystatechange = () => {
|
||||
if (xmlhttp.readyState == 4) {
|
||||
if (xmlhttp.status == 200 || xmlhttp.status == 304) {
|
||||
if (xmlhttp.responseText) {
|
||||
data = JSON.parse(xmlhttp.responseText);
|
||||
} else {
|
||||
data = {};
|
||||
let rs = JSON.parse(xmlhttp.responseText);
|
||||
if (rs && rs.code == "000000") {
|
||||
data = rs.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user