replaced localstorage cache with ram cache
This commit is contained in:
		
							
								
								
									
										2
									
								
								db.js
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								db.js
									
									
									
									
									
								
							| @ -1,6 +1,6 @@ | |||||||
| const mysql = require('mysql'); | const mysql = require('mysql'); | ||||||
| const vars = require('./vars'); | const vars = require('./vars'); | ||||||
| const db_host = "localhost"; | const db_host = "db"; | ||||||
|  |  | ||||||
| const admin = mysql.createConnection({ | const admin = mysql.createConnection({ | ||||||
|     host: db_host, |     host: db_host, | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ window.dragMoveListener = dragMoveListener; | |||||||
| let root = document.getElementById("drags"); | let root = document.getElementById("drags"); | ||||||
| let objs = { height:"2",width:"4"}; | let objs = { height:"2",width:"4"}; | ||||||
| let objs_store = {}; | let objs_store = {}; | ||||||
|  | let objs_imgs = {}; | ||||||
| let proj_from = "cloud"; | let proj_from = "cloud"; | ||||||
|  |  | ||||||
| function create(clas,x,y,body,id,size){ | function create(clas,x,y,body,id,size){ | ||||||
| @ -32,19 +33,19 @@ function create(clas,x,y,body,id,size){ | |||||||
|         } |         } | ||||||
|         else if (db_data != null){ |         else if (db_data != null){ | ||||||
|             if ($.cookie("cache") == "true"){ |             if ($.cookie("cache") == "true"){ | ||||||
|                 if (localStorage.getItem(`${main_clas}`) == null){ |                 if (objs_imgs[main_clas] == null){ | ||||||
|                     load_obj(main_clas,"`img`",(odata)=>{ |                     load_obj(main_clas,"`img`",(odata)=>{ | ||||||
|                         localStorage.setItem(main_clas,odata["img"]); |                         objs_imgs[main_clas] = odata["img"]; | ||||||
|                         make(odata["img"]); |                         make(odata["img"]); | ||||||
|                     }) |                     }) | ||||||
|                 } |                 } | ||||||
|                 else{ |                 else{ | ||||||
|                     make(localStorage.getItem(main_clas)) |                     make(objs_imgs[main_clas]) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             else{ |             else{ | ||||||
|                 load_obj(main_clas,"`img`",(odata)=>{ |                 load_obj(main_clas,"`img`",(odata)=>{ | ||||||
|                     localStorage.setItem(main_clas,odata["img"]); |                     objs_imgs[main_clas] = odata["img"]; | ||||||
|                     make(odata["img"]); |                     make(odata["img"]); | ||||||
|                 }) |                 }) | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -49,14 +49,14 @@ | |||||||
|                     <label for="obj_height"><%= lang("height") %> </label> |                     <label for="obj_height"><%= lang("height") %> </label> | ||||||
|                     <div id="obj_height_value">100см</div> |                     <div id="obj_height_value">100см</div> | ||||||
|                 </div> |                 </div> | ||||||
|                 <input style="width: 100%;" type="range" step="0.5" min="1" max="100" id="obj_height" value="100" oninput="obj_size_change('height')">  |                 <input style="width: 100%;" type="range" step="1" min="1" max="100" id="obj_height" value="100" oninput="obj_size_change('height')">  | ||||||
|             </div> |             </div> | ||||||
|             <div> |             <div> | ||||||
|                 <div style="display: flex;width: 100%;justify-content: space-between;"> |                 <div style="display: flex;width: 100%;justify-content: space-between;"> | ||||||
|                     <label for="obj_width"><%= lang("width") %></label> |                     <label for="obj_width"><%= lang("width") %></label> | ||||||
|                     <div id="obj_width_value">100см</div> |                     <div id="obj_width_value">100см</div> | ||||||
|                 </div> |                 </div> | ||||||
|                 <input style="width: 100%;" type="range" step="0.5" min="1" max="100" id="obj_width" value="100" oninput="obj_size_change('width')">  |                 <input style="width: 100%;" type="range" step="1" min="1" max="100" id="obj_width" value="100" oninput="obj_size_change('width')">  | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|         <div> |         <div> | ||||||
| @ -162,6 +162,9 @@ | |||||||
|                     setTimeout(()=>{ |                     setTimeout(()=>{ | ||||||
|                         edit_get_objs(); |                         edit_get_objs(); | ||||||
|                     },1000) |                     },1000) | ||||||
|  |                     setTimeout(()=>{ | ||||||
|  |                         document.getElementById("obj_resp").innerHTML = ""; | ||||||
|  |                     },3000) | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -42,27 +42,11 @@ | |||||||
|         document.getElementById("objs_in_group").innerHTML = ""; |         document.getElementById("objs_in_group").innerHTML = ""; | ||||||
|         edit_load_objs((data)=>{ |         edit_load_objs((data)=>{ | ||||||
|             data.forEach(value => { |             data.forEach(value => { | ||||||
|                 console.log(value); |                 // console.log(value); | ||||||
|                 // // console.log($.cookie("cache")); |                 // // console.log($.cookie("cache")); | ||||||
|                 // console.log(localStorage.getItem(`${value["name"]}`)); |  | ||||||
|                 if ($.cookie("cache") == "true"){ |  | ||||||
|                     if (localStorage.getItem(`${value["name"]}`) == null){ |  | ||||||
|                 edit_load_obj(value["name"],"`img`",(odata)=>{ |                 edit_load_obj(value["name"],"`img`",(odata)=>{ | ||||||
|                             localStorage.setItem(value["name"],odata["img"]); |  | ||||||
|                         make(odata["img"]); |                         make(odata["img"]); | ||||||
|                 }) |                 }) | ||||||
|                     } |  | ||||||
|                     else{ |  | ||||||
|                         make(localStorage.getItem(value["name"])) |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|                 else{ |  | ||||||
|                     $.cookie("cache","true",{path:"/;SameSite=Strict"}) |  | ||||||
|                     edit_load_obj(value["name"],"`img`",(odata)=>{ |  | ||||||
|                         localStorage.setItem(value["name"],odata["img"]); |  | ||||||
|                         make(odata["img"]); |  | ||||||
|                     }) |  | ||||||
|                 }  |  | ||||||
|                 function make(img){ |                 function make(img){ | ||||||
|                     let obj_list = document.getElementById("objs_in_group"); |                     let obj_list = document.getElementById("objs_in_group"); | ||||||
|                     let obj =  document.createElement('div'); |                     let obj =  document.createElement('div'); | ||||||
| @ -107,7 +91,6 @@ | |||||||
|             img : document.querySelector('#img_prev').src |             img : document.querySelector('#img_prev').src | ||||||
|         } |         } | ||||||
|         let changes = {} |         let changes = {} | ||||||
|         localStorage.removeItem((cur_atts["name"]+"/g/"+select.options[select.selectedIndex].value).replace(" ","$")); |  | ||||||
|         attributes.forEach(element => { |         attributes.forEach(element => { | ||||||
|             // console.log(cur_atts[element],menu.getAttribute(`obj_${element}`)); |             // console.log(cur_atts[element],menu.getAttribute(`obj_${element}`)); | ||||||
|             if(element != attributes.at(-1)){ |             if(element != attributes.at(-1)){ | ||||||
| @ -145,6 +128,9 @@ | |||||||
|                             document.getElementById("obj_resp").innerHTML = ("name was not changed because its taken"); |                             document.getElementById("obj_resp").innerHTML = ("name was not changed because its taken"); | ||||||
|                         } |                         } | ||||||
|                     },1000) |                     },1000) | ||||||
|  |                     setTimeout(()=>{ | ||||||
|  |                         document.getElementById("obj_resp").innerHTML = ""; | ||||||
|  |                     },3000) | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user