INSERT INTO `cp_filejs` (`id`,`app`,`path`,`modul`,`file_name`,`content`) VALUES ('230','4','u8/manager','auth','js/utils.js--','export function formatPostDate(date) {\r\n const postDate = new Date(date)\r\n // show date as Just now, 1 minute ago, 1 hour ago, 1 day ago, 1 week ago, 1 month ago, 1 year ago\r\n const currentDate = new Date()\r\n const diff = currentDate - postDate\r\n const seconds = Math.floor(diff / 1000)\r\n const minutes = Math.floor(seconds / 60)\r\n const hours = Math.floor(minutes / 60)\r\n const days = Math.floor(hours / 24)\r\n const weeks = Math.floor(days / 7)\r\n const months = Math.floor(days / 30)\r\n if (months > 0) {\r\n return months === 1 ? \\\\\\\\\\\\\\\'1 month ago\\\\\\\\\\\\\\\' : `${months} months ago`\r\n }\r\n if (weeks > 0) {\r\n return weeks === 1 ? \\\\\\\\\\\\\\\'1 week ago\\\\\\\\\\\\\\\' : `${weeks} weeks ago`\r\n }\r\n if (days > 0) {\r\n return days === 1 ? \\\\\\\\\\\\\\\'1 day ago\\\\\\\\\\\\\\\' : `${days} days ago`\r\n }\r\n if (hours > 0) {\r\n return hours === 1 ? \\\\\\\\\\\\\\\'1 hour ago\\\\\\\\\\\\\\\' : `${hours} hours ago`\r\n }\r\n if (minutes > 0) {\r\n return minutes === 1 ? \\\\\\\\\\\\\\\'1 minute ago\\\\\\\\\\\\\\\' : `${minutes} minutes ago`\r\n }\r\n return \\\\\\\\\\\\\\\'Just now\\\\\\\\\\\\\\\'\r\n}\r\nexport const timedFetch = async (url, fetchObj, error = \\\\\\\\\\\\\\\'Your connection seems unstable.\\\\\\\\\\\\\\\', timeout = TIMEOUT_MS_LOW) => {\r\n const controller = new AbortController()\r\n const signal = controller.signal\r\n try {\r\n const user = await getSessionUser()\r\n if (!user) return\r\n setTimeout(() => {\r\n controller.abort()\r\n }, TIMEOUT_MS_LOW)\r\n const response = await fetch(url,\r\n fetchObj,\r\n signal\r\n )\r\n const data = await response.json()\r\n return data\r\n } catch (error) {\r\n if (error.name === \\\\\\\\\\\\\\\'AbortError\\\\\\\\\\\\\\\') {\r\n throw {\r\n message: error,\r\n name: \\\\\\\"TimeOutError\\\\\\\"\r\n };\r\n } else {\r\n throw error; // Rethrow any other errors\r\n }\r\n }\r\n}');