From 28f8c78963898c6e06e9fe5040d77cc9c91ff324 Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Mon, 20 Jan 2025 16:02:53 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(tutorial):=20Fetch=20the=20lat?= =?UTF-8?q?est=20tutorial=20version=20from=20GitHub=20API=20for=20dynamic?= =?UTF-8?q?=20URL=20generation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/user/utils/tutorial.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/user/utils/tutorial.ts b/apps/user/utils/tutorial.ts index 88d7d78..ad3f582 100644 --- a/apps/user/utils/tutorial.ts +++ b/apps/user/utils/tutorial.ts @@ -1,9 +1,17 @@ const BASE_URL = 'https://cdn.jsdelivr.net/gh/perfect-panel/ppanel-tutorial'; +async function getVersion() { + const response = await fetch( + 'https://api.github.com/repos/perfect-panel/ppanel-tutorial/commits', + ); + const json = await response.json(); + return json[0].sha; +} + export async function getTutorial(path: string): Promise { + const version = await getVersion(); try { - const url = `${BASE_URL}/${path}`; - await fetch(url.replace('cdn', 'purge')); + const url = `${BASE_URL}@${version}/${path}`; const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`);