mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-02-06 03:30:25 -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';
|
||||
|
||||
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> {
|
||||
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}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user