From 7ea918753364b0fd8c2b943d1a5115c5f7431ecc Mon Sep 17 00:00:00 2001 From: Ali Zemani Date: Mon, 2 Sep 2024 15:47:39 +0330 Subject: [PATCH] clean Home --- src/front/home.ts | 83 +++++++++++++++++++++++++++++++++-------------- src/index.ts | 24 -------------- 2 files changed, 58 insertions(+), 49 deletions(-) diff --git a/src/front/home.ts b/src/front/home.ts index faac8df..596e466 100644 --- a/src/front/home.ts +++ b/src/front/home.ts @@ -1,6 +1,50 @@ import { Environment } from "../types"; +import { KVModel } from "../utils/kv-storage"; +import { convertToPersianNumbers } from "../utils/tools"; export const HomePageContent = async (env: Environment) => { + const statsModel = new KVModel("stats", env.NekonymousKV); + + // GitHub repository information + const githubOwner = "mehotkhan"; + const githubRepo = "Nekonymous"; + const githubUrl = `https://github.com/${githubOwner}/${githubRepo}`; + + let commitHash = "N/A"; + let commitDate = "N/A"; + let commitMessage = "N/A"; + let commitUrl = githubUrl; + let conversationsCount = ""; + let usersCount = ""; + + const today = new Date().toISOString().split("T")[0]; + + conversationsCount = convertToPersianNumbers( + (await statsModel.get(`newConversation:${today}`)) || 0 + ); + usersCount = convertToPersianNumbers( + (await statsModel.get(`newUser:${today}`)) || 0 + ); + + // Fetch the latest commit from GitHub + const commitInfo = await fetch( + `https://api.github.com/repos/${githubOwner}/${githubRepo}/commits/master`, + { + headers: { + "User-Agent": "Cloudflare Worker", + Accept: "application/vnd.github.v3+json", + }, + } + ); + + if (commitInfo.ok) { + const commitData = await commitInfo.json(); + commitHash = commitData.sha.substring(0, 7); // Shortened commit hash + commitDate = new Date(commitData.commit.author.date).toLocaleDateString(); + commitMessage = commitData.commit.message.split("\n")[0]; // Extract first line of commit message + commitUrl = commitData.html_url; // URL to the specific commit on GitHub + } + return `

@@ -10,19 +54,18 @@ export const HomePageContent = async (env: Environment) => {

کاربران

-

- در حال بارگذاری... +

+ ${usersCount}

تعداد مکالمات

-

- در حال بارگذاری... +

+ ${conversationsCount}

-

نِکونیموس به شما این امکان را می‌دهد که به صورت ناشناس و امن با دیگر کاربران چت کنید. این ربات با استفاده از تکنولوژی‌های پیشرفته و رمزنگاری @@ -41,27 +84,17 @@ export const HomePageContent = async (env: Environment) => { شروع به استفاده از ربات

- + + + + `; }; diff --git a/src/index.ts b/src/index.ts index fa81e0a..5e06d0d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,9 +5,7 @@ import { AboutPageContent } from "./front/about"; import { HomePageContent } from "./front/home"; import pageLayout from "./front/layout"; import { Environment } from "./types"; -import { KVModel } from "./utils/kv-storage"; import { Router } from "./utils/router"; -import { convertToPersianNumbers } from "./utils/tools"; // INBOX DURABLE OBJECTS export { InboxDurableObject }; @@ -53,28 +51,6 @@ router.get( } ); -/** - * API endpoint to get chart data in JSON format. - * This will be used to update the chart data on the home page every 5 seconds. - */ -router.get( - "/api/stats", - async (request: Request, env: Environment, ctx: ExecutionContext) => { - const statsModel = new KVModel("stats", env.NekonymousKV); - - const today = new Date().toISOString().split("T")[0]; - - const conversationsCount = - (await statsModel.get(`newConversation:${today}`)) || 0; - const usersCount = (await statsModel.get(`newUser:${today}`)) || 0; - - return Response.json({ - conversationsCount: convertToPersianNumbers(conversationsCount), - usersCount: convertToPersianNumbers(usersCount), - }); - } -); - /** * Define the bot webhook route. * This handles incoming webhook requests from Telegram to the bot.