403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/vue/vuex/src/builder/database/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/js/ui/vue/vuex/src/builder/database/localstorage.js
/**
 * Bitrix Vuex wrapper
 * LocalStorage driver for Vuex Builder
 *
 * @package bitrix
 * @subpackage ui
 * @copyright 2001-2019 Bitrix
 */

import {md5} from "main.md5";

export class VuexBuilderDatabaseLocalStorage
{
	constructor(config = {})
	{
		this.siteId = config.siteId || 'default';
		this.userId = config.userId || 0;
		this.storage = config.storage || 'default';
		this.name = config.name || '';

		this.enabled = false;

		if (typeof window.localStorage !== 'undefined')
		{
			try
			{
				window.localStorage.setItem('__bx_test_ls_feature__', 'ok');
				if (window.localStorage.getItem('__bx_test_ls_feature__') === 'ok')
				{
					window.localStorage.removeItem('__bx_test_ls_feature__');
					this.enabled = true;
				}
			}
			catch(e)
			{
			}
		}

		this.code = 'bx-vuex-'+(window.md5 || md5)(
			this.siteId+'/'+
			this.userId+'/'+
			this.storage+'/'+
			this.name
		);
	}

	get()
	{
		return new Promise((resolve, reject) =>
		{
			if (!this.enabled)
			{
				resolve(null);
				return true;
			}

			let result = window.localStorage.getItem(this.code);
			if (typeof result !== "string")
			{
				resolve(null);
				return true;
			}

			try
			{
				resolve(
					this.prepareValueAfterGet(
						JSON.parse(result)
					)
				);
			}
			catch(error)
			{
				reject(error);
			}
		});
	}

	set(value)
	{
		return new Promise((resolve, reject) =>
		{
			if (this.enabled)
			{
				window.localStorage.setItem(this.code, JSON.stringify(this.prepareValueBeforeSet(value)));
			}
			resolve(true);
		});
	}

	clear()
	{
		return new Promise((resolve, reject) =>
		{
			if (this.enabled)
			{
				window.localStorage.removeItem(this.code);
			}
			resolve(true);
		});
	}

	/**
	 * @private
	 */
	prepareValueAfterGet(value)
	{
		if (value instanceof Array)
		{
			value = value.map(element => this.prepareValueAfterGet(element));
		}
		else if (value instanceof Date)
		{
		}
		else if (value && typeof value === 'object')
		{
			for (let index in value)
			{
				if (value.hasOwnProperty(index))
				{
					value[index] = this.prepareValueAfterGet(value[index]);
				}
			}
		}
		else if (typeof value === 'string')
		{
			if (value.startsWith('#DT#'))
			{
				value = new Date(value.substring(4));
			}
		}

		return value;
	}

	/**
	 * @private
	 */
	prepareValueBeforeSet(value)
	{
		if (value instanceof Array)
		{
			value = value.map(element => this.prepareValueBeforeSet(element));
		}
		else if (value instanceof Date)
		{
			value = '#DT#'+value.toISOString();
		}
		else if (value && typeof value === 'object')
		{
			for (let index in value)
			{
				if (value.hasOwnProperty(index))
				{
					value[index] = this.prepareValueBeforeSet(value[index]);
				}
			}
		}

		return value;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit