Files
wehub-resource-sync 719032b19f
Update Schema / Update configuration json schema (push) Has been cancelled
Memory Benchmark / Memory Test (Full Analysis) (push) Has been cancelled
CI Quality / Lint GitHub Actions (actionlint) (push) Has been cancelled
CI Quality / Lint GitHub Actions (zizmor) (push) Has been cancelled
CI Quality / Check typos (push) Has been cancelled
CI / Test coverage (push) Has been cancelled
CI / Test (22.x, windows-latest) (push) Has been cancelled
CI / Test (24.x, macos-latest) (push) Has been cancelled
CI / Test (24.x, ubuntu-latest) (push) Has been cancelled
CI / Test (24.x, windows-latest) (push) Has been cancelled
CI / Test (26.x, macos-latest) (push) Has been cancelled
CI / Test (26.x, ubuntu-latest) (push) Has been cancelled
CI / Test (26.x, windows-latest) (push) Has been cancelled
CI / Test with Bun (latest, macos-latest) (push) Has been cancelled
CI / Test with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Test with Bun (latest, windows-latest) (push) Has been cancelled
CI / Build and run (22.x, macos-latest) (push) Has been cancelled
CI / Build and run (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (22.x, windows-latest) (push) Has been cancelled
autofix.ci / autofix (push) Has been cancelled
CI Browser Extension / Lint Browser Extension (push) Has been cancelled
CI Browser Extension / Test Browser Extension (push) Has been cancelled
Memory Benchmark / Memory Test (push) Has been cancelled
CI Website / Lint Website Client (push) Has been cancelled
CI Website / Lint Website Server (push) Has been cancelled
CI Website / Test Website Server (push) Has been cancelled
CI Website / Bundle Website Server (push) Has been cancelled
CI / Lint Biome (push) Has been cancelled
CI / Lint oxlint (push) Has been cancelled
CI / Lint TypeScript (push) Has been cancelled
CI / Lint Secretlint (push) Has been cancelled
CI / Test (22.x, macos-latest) (push) Has been cancelled
CI / Test (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, macos-latest) (push) Has been cancelled
CI / Build and run (24.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, windows-latest) (push) Has been cancelled
CI / Build and run (26.x, macos-latest) (push) Has been cancelled
CI / Build and run (26.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (26.x, windows-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, macos-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Docker / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Docker / build (linux/arm/v7, ubuntu-24.04-arm) (push) Has been cancelled
Docker / build (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Docker / merge (push) Has been cancelled
Pack repository with Repomix / pack-repo (push) Has been cancelled
Performance Benchmark History / Benchmark (macos-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (ubuntu-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (windows-latest) (push) Has been cancelled
Performance Benchmark History / Store Results (push) Has been cancelled
Test Repomix Action / Test Node.js 22 (push) Has been cancelled
Test Repomix Action / Test Node.js 24 (push) Has been cancelled
Test Repomix Action / Test Node.js 26 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:37 +08:00

101 lines
2.7 KiB
TypeScript

import type { PackOptions, PackProgressStage, PackRequest, PackResult } from '../api/client';
import { packRepository } from '../api/client';
import { type AnalyticsActionType, analyticsUtils } from './analytics';
interface RequestHandlerOptions {
onSuccess?: (result: PackResult) => void;
onError?: (error: string) => void;
onAbort?: (message: string) => void;
onProgress?: (stage: PackProgressStage, message?: string) => void;
signal?: AbortSignal;
file?: File;
turnstileToken?: string;
}
/**
* Handle repository packing request
*/
export async function handlePackRequest(
url: string,
format: 'xml' | 'markdown' | 'plain',
options: PackOptions,
handlerOptions: RequestHandlerOptions = {},
): Promise<void> {
const { onSuccess, onError, onAbort, onProgress, signal, file, turnstileToken } = handlerOptions;
const processedUrl = url.trim();
// Track pack start
analyticsUtils.trackPackStart(processedUrl);
try {
const request: PackRequest = {
url: processedUrl,
format,
options,
file,
};
const response = await packRepository(
request,
{
onProgress,
signal,
},
turnstileToken,
);
// Track successful pack
if (response.metadata.summary) {
analyticsUtils.trackPackSuccess(
processedUrl,
response.metadata.summary.totalFiles,
response.metadata.summary.totalCharacters,
);
}
onSuccess?.(response);
} catch (err) {
// Check for abort/timeout first, regardless of error type
if (signal?.aborted) {
const isTimeout = signal?.reason === 'timeout';
if (isTimeout) {
onAbort?.('Request timed out.\nPlease consider using Include Patterns or Ignore Patterns to reduce the scope.');
return;
}
const isCancelled = signal?.reason === 'cancel';
if (isCancelled) {
onAbort?.('Request was cancelled.');
return;
}
onAbort?.('Request was cancelled with an unknown reason.');
return;
}
let errorMessage: string;
if (err instanceof Error) {
errorMessage = err.message;
} else {
errorMessage = 'An unexpected error occurred';
}
analyticsUtils.trackPackError(processedUrl, errorMessage);
console.error('Error processing repository:', err);
onError?.(errorMessage);
}
}
/**
* Handle form input changes with analytics tracking
*/
export function handleOptionChange(value: boolean | string, analyticsAction: AnalyticsActionType): void {
if (typeof value === 'boolean') {
analyticsUtils.trackOptionToggle(analyticsAction, value);
} else {
analyticsUtils.trackOptionToggle(analyticsAction, Boolean(value));
}
}