📦 deps(thirdparty): update snapshots
This commit is contained in:
@@ -19,25 +19,45 @@ export class GitHubDownloadError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
export function getGitHubTokenGuidance(): string {
|
||||
return (
|
||||
'To increase your GitHub API rate limit, set the UI_PRO_MAX_GITHUB_TOKEN environment variable\n' +
|
||||
'to a GitHub Personal Access Token (no scopes needed for public repos).\n' +
|
||||
'Create one at: https://github.com/settings/tokens\n' +
|
||||
'Example: UI_PRO_MAX_GITHUB_TOKEN=ghp_xxx uipro init\n' +
|
||||
'Or pass it directly: uipro init --token ghp_xxx'
|
||||
);
|
||||
}
|
||||
|
||||
function checkRateLimit(response: Response): void {
|
||||
const remaining = response.headers.get('x-ratelimit-remaining');
|
||||
if (response.status === 403 && remaining === '0') {
|
||||
const resetTime = response.headers.get('x-ratelimit-reset');
|
||||
const resetDate = resetTime ? new Date(parseInt(resetTime) * 1000).toLocaleTimeString() : 'unknown';
|
||||
throw new GitHubRateLimitError(`GitHub API rate limit exceeded. Resets at ${resetDate}`);
|
||||
throw new GitHubRateLimitError(
|
||||
`GitHub API rate limit exceeded. Resets at ${resetDate}.\n${getGitHubTokenGuidance()}`
|
||||
);
|
||||
}
|
||||
if (response.status === 429) {
|
||||
throw new GitHubRateLimitError('GitHub API rate limit exceeded (429 Too Many Requests)');
|
||||
throw new GitHubRateLimitError(
|
||||
`GitHub API rate limit exceeded (429 Too Many Requests).\n${getGitHubTokenGuidance()}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchReleases(): Promise<Release[]> {
|
||||
function getAuthHeaders(token?: string): Record<string, string> {
|
||||
const resolved = (token || process.env['UI_PRO_MAX_GITHUB_TOKEN'] || process.env['GITHUB_TOKEN'])?.trim();
|
||||
return resolved ? { 'Authorization': `Bearer ${resolved}` } : {};
|
||||
}
|
||||
|
||||
export async function fetchReleases(token?: string): Promise<Release[]> {
|
||||
const url = `${API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/releases`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
'User-Agent': 'uipro-cli',
|
||||
...getAuthHeaders(token),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -50,13 +70,14 @@ export async function fetchReleases(): Promise<Release[]> {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function getLatestRelease(): Promise<Release> {
|
||||
export async function getLatestRelease(token?: string): Promise<Release> {
|
||||
const url = `${API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'Accept': 'application/vnd.github.v3+json',
|
||||
'User-Agent': 'uipro-cli',
|
||||
...getAuthHeaders(token),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -69,11 +90,12 @@ export async function getLatestRelease(): Promise<Release> {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function downloadRelease(url: string, dest: string): Promise<void> {
|
||||
export async function downloadRelease(url: string, dest: string, token?: string): Promise<void> {
|
||||
const response = await fetch(url, {
|
||||
headers: {
|
||||
'User-Agent': 'uipro-cli',
|
||||
'Accept': 'application/octet-stream',
|
||||
...getAuthHeaders(token),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user