getSecretKey and jsonresult
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
import { aesEncrypt, md5 } from "@/libs/secret";
|
import { md5 } from "@/libs/secret";
|
||||||
|
|
||||||
export function getStoreKey(key) {
|
export function getStoreKey(key) {
|
||||||
return md5(key + key);
|
return md5(key + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSecretKey(key, password) {
|
// export function getSecretKey(key, password) {
|
||||||
if (!password) {
|
// if (!password) {
|
||||||
password = key;
|
// password = key;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return md5(aesEncrypt(key, password));
|
// return md5(aesEncrypt(key, password));
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { getStoreKey } from "@/api/lock";
|
import { getStoreKey } from "@/api/lock";
|
||||||
import storage from "@/libs/storage";
|
import storage from "@/libs/storage";
|
||||||
import { md5 } from "@/libs/secret";
|
import { md5, wrap } from "@/libs/secret";
|
||||||
import NoteConstant from "@/libs/constants";
|
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) {
|
export function saveNote(noteForm, secret) {
|
||||||
let storeKey = secret.storeKey;
|
let storeKey = secret.storeKey;
|
||||||
@@ -11,6 +23,14 @@ export function saveNote(noteForm, secret) {
|
|||||||
let storeInfo = storage.local.getText(storeKey);
|
let storeInfo = storage.local.getText(storeKey);
|
||||||
let starray = storeInfo.split("|");
|
let starray = storeInfo.split("|");
|
||||||
|
|
||||||
|
if (starray[2] == "1") {
|
||||||
|
return new Promise(function (onCompleted) {
|
||||||
|
let res = { data: {} };
|
||||||
|
res.data.code = "100013";
|
||||||
|
onCompleted(res);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let note = {
|
let note = {
|
||||||
lock: starray[0],
|
lock: starray[0],
|
||||||
cipher: starray[1],
|
cipher: starray[1],
|
||||||
@@ -19,6 +39,15 @@ export function saveNote(noteForm, secret) {
|
|||||||
key: noteForm.key,
|
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 bufferArrary = eval("[" + note.text + "]");
|
||||||
let array = Uint8Array.from(bufferArrary);
|
let array = Uint8Array.from(bufferArrary);
|
||||||
let blob = new Blob([array], { type: "application/octet-stream" });
|
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("lock", note.lock);
|
||||||
form.append("key", note.key);
|
form.append("key", note.key);
|
||||||
form.append("md5", md5(note.text));
|
form.append("md5", md5(note.text));
|
||||||
form.append("initTime",note.initTime)
|
form.append("initTime", note.initTime)
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
headers: { "Content-Type": "multipart/form-data" },
|
headers: { "Content-Type": "multipart/form-data" },
|
||||||
@@ -91,16 +120,17 @@ export function getKeyMeta() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ajaxGet(url) {
|
export function ajaxGet(url) {
|
||||||
let data = {};
|
let data = null;
|
||||||
let xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
xmlhttp.open("GET", url, false);
|
xmlhttp.open("GET", url, false);
|
||||||
xmlhttp.onreadystatechange = () => {
|
xmlhttp.onreadystatechange = () => {
|
||||||
if (xmlhttp.readyState == 4) {
|
if (xmlhttp.readyState == 4) {
|
||||||
if (xmlhttp.status == 200 || xmlhttp.status == 304) {
|
if (xmlhttp.status == 200 || xmlhttp.status == 304) {
|
||||||
if (xmlhttp.responseText) {
|
if (xmlhttp.responseText) {
|
||||||
data = JSON.parse(xmlhttp.responseText);
|
let rs = JSON.parse(xmlhttp.responseText);
|
||||||
} else {
|
if (rs && rs.code == "000000") {
|
||||||
data = {};
|
data = rs.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ const en = {
|
|||||||
"100006": "Server Unavailable!",
|
"100006": "Server Unavailable!",
|
||||||
"100011": "Empty Note!",
|
"100011": "Empty Note!",
|
||||||
"100012": "Too Large, Beyond {0}!",
|
"100012": "Too Large, Beyond {0}!",
|
||||||
|
"100013": "Repetitive submit!",
|
||||||
|
"100014": "Modified Text!",
|
||||||
|
"800001": "Repetitive Submit!",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
export default en;
|
export default en;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { getKeyMeta } from "@/api/note";
|
||||||
|
import { getStoreKey } from "@/api/lock";
|
||||||
import { wrap } from "@/libs/secret";
|
import { wrap } from "@/libs/secret";
|
||||||
import storage from "@/libs/storage";
|
import storage from "@/libs/storage";
|
||||||
import escapeHtml from "escape-html";
|
import escapeHtml from "escape-html";
|
||||||
@@ -24,6 +26,31 @@ export function setStoreText(noteForm, state, secret) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setNewStoreText(noteForm) {
|
||||||
|
let keyMeta =getKeyMeta();
|
||||||
|
let storeKey = getStoreKey(keyMeta.key);
|
||||||
|
|
||||||
|
let text = noteForm.text;
|
||||||
|
|
||||||
|
let storeText = "";
|
||||||
|
|
||||||
|
if (text) {
|
||||||
|
storeText = wrap(text, keyMeta.secretKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
storage.local.setText(
|
||||||
|
storeKey,
|
||||||
|
"0|" +
|
||||||
|
keyMeta.cipher +
|
||||||
|
"|0|" +
|
||||||
|
keyMeta.serverTime +
|
||||||
|
"|" +
|
||||||
|
storeText
|
||||||
|
);
|
||||||
|
|
||||||
|
return keyMeta.key;
|
||||||
|
}
|
||||||
|
|
||||||
export function clearStoreText(key) {
|
export function clearStoreText(key) {
|
||||||
if (!key) {
|
if (!key) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -151,8 +151,8 @@
|
|||||||
<Form :model="noteForm" :label-width="80">
|
<Form :model="noteForm" :label-width="80">
|
||||||
<div id="wrapper" style="border-left: 2px solid #ed4014;">
|
<div id="wrapper" style="border-left: 2px solid #ed4014;">
|
||||||
<Input element-id="noteText" type="textarea" :border="false" v-model="noteForm.text" autofocus
|
<Input element-id="noteText" type="textarea" :border="false" v-model="noteForm.text" autofocus
|
||||||
:autosize="{ minRows: 30, maxRows: 409600 }" :placeholder="$t('content.noteTip')"
|
:autosize="{ minRows: 30, maxRows: 409600 }" :placeholder="$t('content.noteTip')" @input="recordText"
|
||||||
@input="recordText" @on-keydown="recordEventKdown" />
|
@on-keydown="recordEventKdown" />
|
||||||
</div>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -171,8 +171,7 @@
|
|||||||
{{ $t("message.askTodelete") }}
|
{{ $t("message.askTodelete") }}
|
||||||
</p>
|
</p>
|
||||||
<p style="text-align: center;">
|
<p style="text-align: center;">
|
||||||
<Button type="error" :loading="model.deleting" style="border-radius: 0px;font-size: 19px;"
|
<Button type="error" :loading="model.deleting" style="border-radius: 0px;font-size: 19px;" @click="dropNote()">{{
|
||||||
@click="dropNote()">{{
|
|
||||||
$t("button.yes")
|
$t("button.yes")
|
||||||
}}</Button>
|
}}</Button>
|
||||||
</p>
|
</p>
|
||||||
@@ -191,15 +190,14 @@
|
|||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { unwrap } from '../libs/secret'
|
import { unwrap } from '../libs/secret'
|
||||||
import { saveNote } from "@/api/note";
|
import { saveNote } from "@/api/note";
|
||||||
import { getSecretKey, getStoreKey } from "@/api/lock";
|
import { getStoreKey } from "@/api/lock";
|
||||||
import storage from "@/libs/storage";
|
import storage from "@/libs/storage";
|
||||||
import { setStoreText } from "@/libs/noteStorage";
|
import { setStoreText,setNewStoreText } from "@/libs/noteStorage";
|
||||||
import { saveAs } from 'file-saver';
|
import { saveAs } from 'file-saver';
|
||||||
import { isWeixin } from "@/libs/utils";
|
import { isWeixin } from "@/libs/utils";
|
||||||
import NoteConstant from "@/libs/constants";
|
import NoteConstant from "@/libs/constants";
|
||||||
@@ -237,10 +235,13 @@ export default {
|
|||||||
toTopState: false,
|
toTopState: false,
|
||||||
showMenuState: false,
|
showMenuState: false,
|
||||||
showHeaderShade: false,
|
showHeaderShade: false,
|
||||||
|
pageSession: '',
|
||||||
errorInfo: '',
|
errorInfo: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
this.pageSession = new Date().getTime();
|
||||||
|
|
||||||
// read $route
|
// read $route
|
||||||
this.noteForm.key = this.$route.params.name;
|
this.noteForm.key = this.$route.params.name;
|
||||||
let keyMeta = this.$route.meta.keyMeta;
|
let keyMeta = this.$route.meta.keyMeta;
|
||||||
@@ -257,13 +258,12 @@ export default {
|
|||||||
// let noteMeta = this.$route.meta.noteMeta;
|
// let noteMeta = this.$route.meta.noteMeta;
|
||||||
let storeKey = getStoreKey(this.noteForm.key);
|
let storeKey = getStoreKey(this.noteForm.key);
|
||||||
this.secret.storeKey = storeKey;
|
this.secret.storeKey = storeKey;
|
||||||
let secretKey = getSecretKey(this.noteForm.key, this.secret.password);
|
|
||||||
this.secret.secretKey = secretKey;
|
|
||||||
|
|
||||||
// first edit
|
// first edit
|
||||||
if (keyMeta) {
|
if (keyMeta) {
|
||||||
this.state.lock = 0;
|
this.state.lock = 0;
|
||||||
this.secret.cipher = keyMeta.cipher;
|
this.secret.cipher = keyMeta.cipher;
|
||||||
|
this.secret.secretKey = keyMeta.secretKey;
|
||||||
this.state.serverTime = keyMeta.serverTime;
|
this.state.serverTime = keyMeta.serverTime;
|
||||||
// key init Time
|
// key init Time
|
||||||
this.state.initTime = keyMeta.serverTime;
|
this.state.initTime = keyMeta.serverTime;
|
||||||
@@ -278,6 +278,9 @@ export default {
|
|||||||
storage.local.setText(storeKey, "0|" + this.secret.cipher + "|0|" + this.state.initTime + "|");
|
storage.local.setText(storeKey, "0|" + this.secret.cipher + "|0|" + this.state.initTime + "|");
|
||||||
} else {
|
} else {
|
||||||
// second edit
|
// second edit
|
||||||
|
let noteMeta = this.$route.meta.noteMeta;
|
||||||
|
this.secret.secretKey = noteMeta.secretKey;
|
||||||
|
|
||||||
let storeInfo = storage.local.getText(storeKey);
|
let storeInfo = storage.local.getText(storeKey);
|
||||||
let starray = storeInfo.split('|');
|
let starray = storeInfo.split('|');
|
||||||
this.state.lock = parseInt(starray[0]);
|
this.state.lock = parseInt(starray[0]);
|
||||||
@@ -286,7 +289,7 @@ export default {
|
|||||||
|
|
||||||
//draw text;
|
//draw text;
|
||||||
if (starray[4]) {
|
if (starray[4]) {
|
||||||
this.noteForm.text = unwrap(starray[4], secretKey);
|
this.noteForm.text = unwrap(starray[4], this.secret.secretKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +348,7 @@ export default {
|
|||||||
recordText() {
|
recordText() {
|
||||||
let text = this.noteForm.text;
|
let text = this.noteForm.text;
|
||||||
if (text.length > NoteConstant.noteMaxCount) {
|
if (text.length > NoteConstant.noteMaxCount) {
|
||||||
this.errorInfo = this.$t('error.100012',[NoteConstant.noteMaxDesc]);
|
this.errorInfo = this.$t('error.100012', [NoteConstant.noteMaxDesc]);
|
||||||
this.model.showError = true;
|
this.model.showError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -374,7 +377,7 @@ export default {
|
|||||||
let text = event.currentTarget.value;
|
let text = event.currentTarget.value;
|
||||||
|
|
||||||
if (text.length > NoteConstant.noteMaxCount) {
|
if (text.length > NoteConstant.noteMaxCount) {
|
||||||
this.errorInfo = this.$t('error.100012',[NoteConstant.noteMaxDesc]);
|
this.errorInfo = this.$t('error.100012', [NoteConstant.noteMaxDesc]);
|
||||||
this.model.showError = true;
|
this.model.showError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -393,25 +396,8 @@ export default {
|
|||||||
setStoreText(this.noteForm, this.state, this.secret);
|
setStoreText(this.noteForm, this.state, this.secret);
|
||||||
|
|
||||||
} else if (event.ctrlKey && (event.which == 13)) {
|
} else if (event.ctrlKey && (event.which == 13)) {
|
||||||
|
|
||||||
if (this.state.locking == 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.validateForm()) {
|
|
||||||
this.state.locking = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//save
|
//save
|
||||||
let that = this;
|
this.submitNote();
|
||||||
this.save().then(res => {
|
|
||||||
if (res) {
|
|
||||||
that.state.commited = 1;
|
|
||||||
setStoreText(this.noteForm, this.state, this.secret);
|
|
||||||
location.reload();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
save() {
|
save() {
|
||||||
@@ -420,7 +406,7 @@ export default {
|
|||||||
validateForm() {
|
validateForm() {
|
||||||
let text = this.noteForm.text;
|
let text = this.noteForm.text;
|
||||||
if (text.length > NoteConstant.noteMaxCount) {
|
if (text.length > NoteConstant.noteMaxCount) {
|
||||||
this.errorInfo = this.$t('error.100012',[NoteConstant.noteMaxDesc]);
|
this.errorInfo = this.$t('error.100012', [NoteConstant.noteMaxDesc]);
|
||||||
this.model.showError = true;
|
this.model.showError = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -449,14 +435,26 @@ export default {
|
|||||||
|
|
||||||
let that = this;
|
let that = this;
|
||||||
this.save().then(res => {
|
this.save().then(res => {
|
||||||
if (res) {
|
if (res.data && res.data.code == "000000") {
|
||||||
let storeInfo = storage.local.getText(that.secret.storeKey);
|
|
||||||
let starray = storeInfo.split("|");
|
|
||||||
storage.local.setText(that.secret.storeKey, starray[0] + '|' + starray[1] + '|1|' + starray[3] + '|' + starray[4]);
|
|
||||||
storage.session.setText(that.secret.storeKey + "_share", '1');
|
storage.session.setText(that.secret.storeKey + "_share", '1');
|
||||||
|
|
||||||
|
that.state.commited = 1;
|
||||||
|
setStoreText(this.noteForm, this.state, this.secret);
|
||||||
|
|
||||||
location.reload();
|
location.reload();
|
||||||
this.state.locking = 0;
|
this.state.locking = 0;
|
||||||
|
} else {
|
||||||
|
alert(res.data.code);
|
||||||
|
this.model.submitting = false;
|
||||||
|
this.state.locking = 0;
|
||||||
|
if(res.data.code=="100013"||res.data.code=="800001"){
|
||||||
|
let key = setNewStoreText(this.noteForm);
|
||||||
|
location.href="/"+key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
alert(error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
refresh() {
|
refresh() {
|
||||||
|
|||||||
@@ -339,7 +339,7 @@
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
import { md5, unwrap } from "@/libs/secret";
|
import { md5, unwrap } from "@/libs/secret";
|
||||||
import { getStoreKey, getSecretKey } from "@/api/lock";
|
import { getStoreKey } from "@/api/lock";
|
||||||
import { deleteNote, getNoteBlob } from "@/api/note";
|
import { deleteNote, getNoteBlob } from "@/api/note";
|
||||||
import storage from "@/libs/storage";
|
import storage from "@/libs/storage";
|
||||||
//import { getEscapeText } from "@/libs/noteStorage";
|
//import { getEscapeText } from "@/libs/noteStorage";
|
||||||
@@ -394,6 +394,7 @@ export default {
|
|||||||
// read $route
|
// read $route
|
||||||
this.noteForm.key = this.$route.params.name;
|
this.noteForm.key = this.$route.params.name;
|
||||||
let noteMeta = this.$route.meta.noteMeta;
|
let noteMeta = this.$route.meta.noteMeta;
|
||||||
|
this.secret.secretKey = noteMeta.secretKey;
|
||||||
|
|
||||||
//ipad chrome url not redirect
|
//ipad chrome url not redirect
|
||||||
let path = location.pathname;
|
let path = location.pathname;
|
||||||
@@ -406,7 +407,6 @@ export default {
|
|||||||
|
|
||||||
this.noteForm.noteUrl = getNoteUrl(this.noteForm.key);
|
this.noteForm.noteUrl = getNoteUrl(this.noteForm.key);
|
||||||
this.secret.storeKey = getStoreKey(this.noteForm.key);
|
this.secret.storeKey = getStoreKey(this.noteForm.key);
|
||||||
this.secret.secretKey = getSecretKey(this.noteForm.key, this.secret.password);
|
|
||||||
|
|
||||||
if (noteMeta) {
|
if (noteMeta) {
|
||||||
this.state.lock = noteMeta.lock;
|
this.state.lock = noteMeta.lock;
|
||||||
@@ -553,12 +553,14 @@ export default {
|
|||||||
this.model.deleting = true;
|
this.model.deleting = true;
|
||||||
let that = this;
|
let that = this;
|
||||||
deleteNote(this.noteForm.key).then(res => {
|
deleteNote(this.noteForm.key).then(res => {
|
||||||
if (res) {
|
if (res.data&&res.data.code=="000000") {
|
||||||
storage.local.delete(that.secret.storeKey);
|
storage.local.delete(that.secret.storeKey);
|
||||||
location.reload();
|
location.reload();
|
||||||
} else {
|
} else {
|
||||||
that.model.deleting = false;
|
that.model.deleting = false;
|
||||||
}
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
alert(error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
loadText() {
|
loadText() {
|
||||||
|
|||||||
Reference in New Issue
Block a user