File Upload
Overview
The File Upload feature in the macseem/wikismith repository enables users to upload files to wikis and repositories seamlessly. This functionality is essential for enhancing collaboration and content management within the platform. It allows users to generate wikis based on the uploaded files, facilitating better documentation and knowledge sharing.
User-facing behavior
- Users can upload files directly through the web interface.
- The system processes the uploaded files to generate wiki content automatically.
- Feedback on the upload progress is provided to the user, enhancing the user experience.
- If the upload is successful, users receive a confirmation and can navigate to the newly created wiki pages.
Architecture and data flow
- The File Upload feature interacts with various components of the application:
- Frontend: Handles user interactions and file selections.
- API Layer: Receives file uploads and initiates processing.
- Backend Services: Analyze the files, generate wiki content, and store it in the database.
- The flow begins with the user uploading a file, which is sent to the API. The API processes the file, analyzes its content, and generates corresponding wiki pages based on predefined templates.
Key implementation details
- The API for handling file uploads is implemented in
apps/web/src/app/api/generate/route.ts. It includes functions for parsing GitHub URLs, ingesting file content, and generating wikis.
import { NextResponse } from 'next/server';
import { parseGitHubUrl, ingest, analyze, classify } from '@wikismith/analyzer';
// Other imports...
- The
buildDeterministicWikiPagesfunction is responsible for creating wiki pages based on the analyzed features from the uploaded files. It tracks progress and generates an overview page along with individual feature pages.
const buildDeterministicWikiPages = async (
featureTree: IClassifiedFeatureTree,
repoFullName: string,
commitSha: string,
onProgress?: (completed: number, total: number) => void,
): Promise<IWikiPage[]> => {
// Function implementation...
};
- The
slugifyfunction ensures that page slugs are generated in a URL-friendly format, which is crucial for maintaining clean and accessible links.
const slugify = (value: string): string => {
const normalized = value
.trim()
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '');
return normalized || 'feature';
};
- The maximum body size for uploads is set to 1024 bytes, ensuring that the system can handle file sizes efficiently without overwhelming the server.
const MAX_BODY_SIZE = 1024;
Key files
apps/web/src/app/api/generate/route.ts- Central file for handling file upload requests and generating wikis. It contains key functions for processing uploads and generating content based on file analysis. source@wikismith/analyzer- Library used for analyzing and classifying uploaded files, crucial for determining the content of generated wikis. source@wikismith/generator- Responsible for generating wiki content based on the analyzed data from uploaded files. This module plays a vital role in transforming raw file data into structured wiki pages. source@wikismith/shared- Contains shared types and error handling mechanisms used across the application, ensuring consistency and reliability in handling file uploads and wiki generation. source