base_ui/services/log.service.js

205 lines
5.2 KiB
JavaScript
Raw Normal View History

2025-02-01 09:34:55 +00:00
// // import axios from "axios";
// //import os from "os";
// import { v4 as uuidv4 } from 'uuid';
// // import 'sweetalert2/dist/sweetalert2.min.css';
// // import 'assets/common/css/sweetalert2.min.css';
// var httpService = new HttpService(import.meta.env.VITE_REPO_BASE_URL);
// //var local_ip = "";
// var local_city = "";
// var local_country = "";
// var local_gps = "";
// var os_name = "";
// var browser = "";
// var time_new_search = null;
// var id_current_search = "";
// var id_session_search = "";
// var last_query_string = "";
// // const axiosLog = axios.create({
// // baseURL: import.meta.env.VITE_API_SEARCH,
// // })
// // function getNetworkIp() {
// // const url = 'https://api.ipify.org/?format=json';
// // var results= [];
// // axios.get(url).then(response => {
// // results = response.data
// // local_ip = results.ip;
// // // axios.get('http://freegeoip.net/json/'+local_ip).then(response=>{
// // // var res = response.data
// // // local_city = res.city;
// // // local_country = res.country;
// // // local_gps = res.loc;
// // // });
// // })
// // }
// function fnBrowserDetect(){
// let userAgent = navigator.userAgent;
// let browserName;
// if(userAgent.match(/chrome|chromium|crios/i)){
// browserName = "chrome";
// }else if(userAgent.match(/firefox|fxios/i)){
// browserName = "firefox";
// } else if(userAgent.match(/safari/i)){
// browserName = "safari";
// }else if(userAgent.match(/opr\//i)){
// browserName = "opera";
// } else if(userAgent.match(/edg/i)){
// browserName = "edge";
// }else{
// browserName="none";
// }
// return browserName;
// }
// function getOs(){
// var detectedOS = "none";
// if (window.navigator.appVersion.indexOf("Mac") != -1)
// detectedOS = "MacOS";
// if (window.navigator.appVersion.indexOf("Win") != -1)
// detectedOS = "Windows";
// if (window.navigator.appVersion.indexOf("Linux") != -1)
// detectedOS = "Linux";
// return detectedOS;
// }
// function myEncodeQuery(text) {
// // console.log(text)
// if (!text || text == "") return "";
// //text = JSON.stringify(text);
// let ch1 = encodeURIComponent("#");
// let ch3 = encodeURIComponent("\\");
// let ch4 = encodeURIComponent("&");
// text = text.replaceAll("#", ch1);
// text = text.replaceAll("&", ch4);
// text = text.replaceAll("/", "\\");
// text = text.replaceAll("\\", ch3);
// // text = text.replaceAll(".", '%2E');
// return text;
// }
// const LogService = {
// reset(){
// var resetall = true;
// if(time_new_search != null)
// {
// var dt = new Date();
// var diffMs = (time_new_search - dt); // milliseconds
// var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000);
// if(diffMins < 60){
// resetall = false;
// }
// }
// if(resetall){
// //getNetworkIp();
// os_name = getOs();
// id_session_search = uuidv4();
// }
// browser = fnBrowserDetect();
// time_new_search = new Date();
// id_current_search = uuidv4();
// },
// index(
// user,
// query,
// _page,
// _facet,
// _took,
// _owner="",
// _type="",
// _branch="",
// _id_click= "",
// _index_click= -1
// )
// {
// if(query=='')
// return;
// query = myEncodeQuery(query);
// _facet = myEncodeQuery(_facet);
// if(last_query_string != query){
// id_current_search = uuidv4();
// last_query_string = query;
// }
// var dt = new Date();
// //var _minutes = dt.getMinutes();
// var _hour = dt.getHours();
// var _time = dt.getTime();
// var dtfa = dt.toLocaleDateString("fa-IR");
// //var host = window.location.protocol + "//" + window.location.host;
// const obj = {
// id_session:id_session_search,
// id:id_current_search,
// browser: browser,
// os_version: os_name,
// //ip: local_ip,
// gps : local_gps,
// city : local_city,
// country : local_country,
// date: dt.toLocaleDateString(),
// hour: _hour,
// date_fa: dtfa,
// time: _time,
// took:_took,
// query_String : query,
// page: _page,
// owner:_owner,
// type:_type,
// branch:_branch,
// facet: _facet,
// username: user?.user_data?.username,
// userid : user?.user_id,
// id_click:_id_click,
// index_click:_index_click
// };
// const json = JSON.stringify(obj);
// //const blob = new Blob([json], {
// // type: 'application/json'
// //});
// //const data = new FormData();
// //data.append("document", blob);
// // return ApiService
// // .postRequest("/indexlog", json )
// // .then()
// // .catch();
// httpService
// .postRequest("/indexlog", json)
// .then((response) => {
// })
// .catch((error) => {
// });
// }
// };
// //const json = JSON.stringify({ answer: 42 });
// //const res = await axios.post('https://httpbin.org/post', json);
// export default LogService;