mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
new session service
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { AES, SHA1, enc } from "crypto-js";
|
||||
import { environment } from 'src/environments/environment'
|
||||
|
||||
|
||||
function prefix() {
|
||||
return environment.version.lastCommitNumber + environment.id+"-";
|
||||
}
|
||||
|
||||
export function GET({key, localStorage, instance}) {
|
||||
if(environment.storageProduction) {
|
||||
|
||||
try {
|
||||
const newKey = prefix() + SHA1(key).toString()
|
||||
const cipherText = localStorage.getItem(newKey)
|
||||
const bytes = AES.decrypt(cipherText, newKey)
|
||||
var decryptedData = bytes.toString(enc.Utf8);
|
||||
const restoredData = JSON.parse(decryptedData)
|
||||
|
||||
Object.assign(instance, restoredData);
|
||||
|
||||
return restoredData
|
||||
|
||||
} catch(error) {
|
||||
console.log(error)
|
||||
return {}
|
||||
}
|
||||
|
||||
} else {
|
||||
return JSON.parse(localStorage.getItem(prefix() + key))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export function SAVE({key, localStorage, instance, dataToSave}) {
|
||||
if(environment.storageProduction) {
|
||||
const newKey = prefix() + SHA1(key).toString()
|
||||
const stringifyData = JSON.stringify(dataToSave)
|
||||
|
||||
const cipherText = AES.encrypt(stringifyData, newKey).toString();
|
||||
|
||||
localStorage.setItem(newKey, cipherText)
|
||||
|
||||
} else {
|
||||
localStorage.setItem(prefix() + key, dataToSave)
|
||||
}
|
||||
}
|
||||
|
||||
export function DELETE({key, localStorage, instance}) {
|
||||
if(environment.storageProduction) {
|
||||
const newKey = prefix() + SHA1(key).toString()
|
||||
localStorage.removeItem(newKey)
|
||||
|
||||
} else {
|
||||
localStorage.removeItem(prefix() + key)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { models } from 'beast-orm'
|
||||
//import { models } from 'beast-orm'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { models } from 'src/plugin/src'
|
||||
const { ArrayField, JsonField} = models.indexedDB.fields
|
||||
|
||||
export class MessageModel extends models.Model {
|
||||
@@ -80,9 +81,6 @@ models.register({
|
||||
models: [PublicationModel, ActionModel]
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
export class WebtrixUserModel extends models.Model {
|
||||
FullName = models.CharField()
|
||||
Role = models.CharField()
|
||||
@@ -102,4 +100,3 @@ models.register({
|
||||
version: 14,
|
||||
models: [PublicationModel, ActionModel]
|
||||
})
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface Environment {
|
||||
PR: string
|
||||
VP: string
|
||||
dispatchPR: string
|
||||
storageProduction: boolean
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user