tag i18n
This commit is contained in:
@@ -3,7 +3,9 @@ import storage from "@/libs/storage";
|
||||
import {getSecretKey} from "@/api/lock";
|
||||
import escapeHtml from "escape-html";
|
||||
|
||||
export function setStoreText(text, secret, password) {
|
||||
export function setStoreText(noteForm, secret, password) {
|
||||
let text = noteForm.text;
|
||||
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
@@ -14,7 +16,7 @@ export function setStoreText(text, secret, password) {
|
||||
|
||||
text = "FLAGNOTE#" + text;
|
||||
|
||||
let secretKey = getSecretKey(secret.cipher, password);
|
||||
let secretKey = getSecretKey(noteForm.key, password);
|
||||
let storeText = aesEncrypt(text, secretKey);
|
||||
storeText = zip(storeText);
|
||||
|
||||
@@ -23,7 +25,8 @@ export function setStoreText(text, secret, password) {
|
||||
lock = 1;
|
||||
}
|
||||
|
||||
storage.local.setText(secret.storeKey + '.text', lock + '|' + secret.cipher + '|' + storeText);
|
||||
|
||||
storage.local.setText(secret.storeKey + '.text', lock + '|' + secret.cipher + '|0|'+ noteForm.initTime+'|' + storeText);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,11 +40,10 @@ export function clearStoreText(key) {
|
||||
|
||||
export function getEscapeText(text) {
|
||||
let textEscape = escapeHtml(text);
|
||||
textEscape = textEscape.replaceAll(" ", " ");
|
||||
textEscape = textEscape.replaceAll("\r\n", "<br/>");
|
||||
textEscape = textEscape.replaceAll("\r", "<br/>");
|
||||
textEscape = textEscape.replaceAll("\n", "<br/>");
|
||||
textEscape = textEscape.replaceAll("\t", " ");
|
||||
|
||||
textEscape = textEscape.replace(new RegExp(' ','gm'), " ");
|
||||
textEscape = textEscape.replace(new RegExp('\\r\\n','gm'), "<br/>");
|
||||
textEscape = textEscape.replace(new RegExp('\\r','gm'), "<br/>");
|
||||
textEscape = textEscape.replace(new RegExp('\\n','gm'), "<br/>");
|
||||
textEscape = textEscape.replace(new RegExp('\\t','gm'), " ");
|
||||
return textEscape;
|
||||
}
|
||||
|
||||
@@ -1,53 +1,116 @@
|
||||
class Storage {
|
||||
constructor() {
|
||||
this.session = new Session();
|
||||
this.local = new Local();
|
||||
}
|
||||
constructor() {
|
||||
this.session = new Session();
|
||||
this.local = new Local();
|
||||
}
|
||||
}
|
||||
|
||||
class Session {
|
||||
setObject(key, value) {
|
||||
sessionStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
setObject(key, value) {
|
||||
sessionStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
getObject(key) {
|
||||
return JSON.parse(sessionStorage.getItem(key));
|
||||
}
|
||||
|
||||
getObject(key) {
|
||||
return JSON.parse(sessionStorage.getItem(key));
|
||||
}
|
||||
delete(key) {
|
||||
sessionStorage.removeItem(key);
|
||||
}
|
||||
|
||||
delete(key){
|
||||
sessionStorage.removeItem(key);
|
||||
}
|
||||
setText(key, value) {
|
||||
sessionStorage.setItem(key, value);
|
||||
}
|
||||
|
||||
setText(key, value) {
|
||||
sessionStorage.setItem(key, value);
|
||||
}
|
||||
|
||||
getText(key) {
|
||||
return sessionStorage.getItem(key);
|
||||
}
|
||||
getText(key) {
|
||||
return sessionStorage.getItem(key);
|
||||
}
|
||||
}
|
||||
|
||||
class Local {
|
||||
setObject(key, value) {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
setObject(key, value) {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
}
|
||||
|
||||
getObject(key) {
|
||||
return JSON.parse(localStorage.getItem(key));
|
||||
}
|
||||
getObject(key) {
|
||||
return JSON.parse(localStorage.getItem(key));
|
||||
}
|
||||
|
||||
delete(key){
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
delete(key) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
setText(key, value) {
|
||||
localStorage.setItem(key, value);
|
||||
}
|
||||
setText(key, value) {
|
||||
localStorage.setItem(key, value);
|
||||
}
|
||||
|
||||
getText(key) {
|
||||
return localStorage.getItem(key);
|
||||
getText(key) {
|
||||
return localStorage.getItem(key);
|
||||
}
|
||||
|
||||
getUseSize() {
|
||||
var size = 0;
|
||||
for (let i = 0, len = localStorage.length; i < len; i++) {
|
||||
let key = localStorage.key(i);
|
||||
if (null == key) {
|
||||
continue;
|
||||
}
|
||||
let value = localStorage.getItem(key);
|
||||
if (null != value) {
|
||||
size += value.length;
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
getAvailableSize() {
|
||||
return 5 * 1024 * 1024 - storage.local.getUseSize();
|
||||
}
|
||||
|
||||
dynamicClear(ctt) {
|
||||
if (storage.local.getAvailableSize() < 1 * 1024 * 1024) {
|
||||
|
||||
//remove commited
|
||||
for (let i = 0, len = localStorage.length; i < len; i++) {
|
||||
let key = localStorage.key(i);
|
||||
|
||||
if (null == key) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let value = localStorage.getItem(key);
|
||||
if (key.length == 37 && key.endsWith(".text") && value.length > 50) {
|
||||
let fl = value.substring(35, 36);
|
||||
if (fl == "1") {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//remove expired
|
||||
if (storage.local.getAvailableSize() < 1 * 1024 * 1024) {
|
||||
for (let i = 0, len = localStorage.length; i < len; i++) {
|
||||
let key = localStorage.key(i);
|
||||
if (null == key) {
|
||||
continue;
|
||||
}
|
||||
let value = localStorage.getItem(key);
|
||||
|
||||
if (key.length == 37 && key.endsWith(".text") && value.length > 50) {
|
||||
let starray = value.split("|");
|
||||
let fl = starray[2];
|
||||
let ts = starray[3];
|
||||
|
||||
if (fl == "0") {
|
||||
if (ctt - ts > 3 * 24 * 3600 * 1000) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const storage = new Storage();
|
||||
|
||||
14
src/libs/utils.js
Normal file
14
src/libs/utils.js
Normal file
@@ -0,0 +1,14 @@
|
||||
export function isWeixin(){
|
||||
var useragent = navigator.userAgent;
|
||||
if (useragent.match(/MicroMessenger/i) == 'MicroMessenger') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isIE() {
|
||||
if (navigator.userAgent.match(/msie/) != null || navigator.userAgent.match(/trident/) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user