From ebbd788fbb2c0b45d4473798efc57eec8ba74a25 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期二, 18 六月 2024 14:51:16 +0800
Subject: [PATCH] 版本更新至2.11.5

---
 src/utils/cache/storageCache.ts |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/utils/cache/storageCache.ts b/src/utils/cache/storageCache.ts
index 84ba2aa..3250408 100644
--- a/src/utils/cache/storageCache.ts
+++ b/src/utils/cache/storageCache.ts
@@ -1,7 +1,6 @@
-import { cacheCipher } from '/@/settings/encryptionSetting';
-import type { EncryptionParams } from '/@/utils/cipher';
-import { AesEncryption } from '/@/utils/cipher';
-import { isNullOrUnDef } from '/@/utils/is';
+import { cacheCipher } from '@/settings/encryptionSetting';
+import { isNil } from '@/utils/is';
+import { Encryption, EncryptionFactory, EncryptionParams } from '@/utils/cipher';
 
 export interface CreateStorageParams extends EncryptionParams {
   prefixKey: string;
@@ -9,6 +8,7 @@
   hasEncrypt: boolean;
   timeout?: Nullable<number>;
 }
+// TODO 绉婚櫎姝ゆ枃浠跺す涓嬪叏閮ㄤ唬鐮�
 export const createStorage = ({
   prefixKey = '',
   storage = sessionStorage,
@@ -21,8 +21,10 @@
     throw new Error('When hasEncrypt is true, the key or iv must be 16 bits!');
   }
 
-  const encryption = new AesEncryption({ key, iv });
-
+  const persistEncryption: Encryption = EncryptionFactory.createAesEncryption({
+    key: cacheCipher.key,
+    iv: cacheCipher.iv,
+  });
   /**
    * Cache class
    * Construction parameters can be passed into sessionStorage, localStorage,
@@ -32,7 +34,7 @@
   const WebStorage = class WebStorage {
     private storage: Storage;
     private prefixKey?: string;
-    private encryption: AesEncryption;
+    private encryption: Encryption;
     private hasEncrypt: boolean;
     /**
      *
@@ -41,7 +43,7 @@
     constructor() {
       this.storage = storage;
       this.prefixKey = prefixKey;
-      this.encryption = encryption;
+      this.encryption = persistEncryption;
       this.hasEncrypt = hasEncrypt;
     }
 
@@ -60,11 +62,9 @@
       const stringData = JSON.stringify({
         value,
         time: Date.now(),
-        expire: !isNullOrUnDef(expire) ? new Date().getTime() + expire * 1000 : null,
+        expire: !isNil(expire) ? new Date().getTime() + expire * 1000 : null,
       });
-      const stringifyValue = this.hasEncrypt
-        ? this.encryption.encryptByAES(stringData)
-        : stringData;
+      const stringifyValue = this.hasEncrypt ? this.encryption.encrypt(stringData) : stringData;
       this.storage.setItem(this.getKey(key), stringifyValue);
     }
 
@@ -79,10 +79,10 @@
       if (!val) return def;
 
       try {
-        const decVal = this.hasEncrypt ? this.encryption.decryptByAES(val) : val;
+        const decVal = this.hasEncrypt ? this.encryption.decrypt(val) : val;
         const data = JSON.parse(decVal);
         const { value, expire } = data;
-        if (isNullOrUnDef(expire) || expire >= new Date().getTime()) {
+        if (isNil(expire) || expire >= new Date().getTime()) {
           return value;
         }
         this.remove(key);

--
Gitblit v1.9.3