mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-02-17 05:41:10 -05:00
✨ feat(tutorial): Fetch the latest tutorial version from GitHub API for dynamic URL generation
This commit is contained in:
parent
9140b8ad1e
commit
28f8c78963
@ -1,9 +1,17 @@
|
|||||||
const BASE_URL = 'https://cdn.jsdelivr.net/gh/perfect-panel/ppanel-tutorial';
|
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<string> {
|
export async function getTutorial(path: string): Promise<string> {
|
||||||
|
const version = await getVersion();
|
||||||
try {
|
try {
|
||||||
const url = `${BASE_URL}/${path}`;
|
const url = `${BASE_URL}@${version}/${path}`;
|
||||||
await fetch(url.replace('cdn', 'purge'));
|
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user