import { getKeyMeta } from "@/api/note";
import { getStoreKey } from "@/api/lock";
import { wrap } from "@/libs/secret";
import storage from "@/libs/storage";
import escapeHtml from "escape-html";
export function setStoreText(noteForm, state, secret) {
let text = noteForm.text;
let storeText = "";
if (text) {
storeText = wrap(text, secret.secretKey);
}
storage.local.setText(
secret.storeKey,
state.lock +
"|" +
secret.cipher +
"|" +
state.commited +
"|" +
state.initTime +
"|" +
storeText
);
}
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) {
if (!key) {
return;
}
storage.local.delete(key);
}
export function getEscapeText(text) {
let textEscape = escapeHtml(text);
textEscape = textEscape.replace(new RegExp(" ", "gm"), " ");
textEscape = textEscape.replace(new RegExp("\\r\\n", "gm"), "
");
textEscape = textEscape.replace(new RegExp("\\r", "gm"), "
");
textEscape = textEscape.replace(new RegExp("\\n", "gm"), "
");
textEscape = textEscape.replace(
new RegExp("\\t", "gm"),
'
' ); return textEscape; }