new flashcards
All checks were successful
Mindforge API Build and Deploy / Build Mindforge API Image (push) Successful in 4m4s
Mindforge Web Build and Deploy (internal) / Build Mindforge Web Image (push) Successful in 5m29s
Mindforge Web Build and Deploy (internal) / Deploy Mindforge Web (internal) (push) Successful in 9s
Mindforge API Build and Deploy / Deploy Mindforge API (internal) (push) Successful in 8s

This commit is contained in:
2026-05-30 11:59:19 -03:00
parent b9736293d3
commit b80d28f671
27 changed files with 1735 additions and 290 deletions

View File

@@ -26,17 +26,66 @@ export interface CheckFileResponse {
result: string;
}
export type FlashcardDifficulty = 'Easy' | 'Hard';
export interface GenerateFlashcardsRequest {
fileContent: string;
fileName: string;
filePaths: string[];
amount: number;
mode: FlashcardMode;
difficulty: FlashcardDifficulty;
}
export type FlashcardMode = 'Basic' | 'Simple' | 'Detailed' | 'Hyper';
export interface FlashcardCard {
id: number;
libraryId: number;
front: string;
back: string;
position: number;
createdAt: string;
}
export interface FlashcardLibrarySummary {
id: number;
filePath: string;
fileName: string;
subject: string;
difficulty: string;
cardCount: number;
createdAt: string;
updatedAt: string;
}
export interface FlashcardLibraryDetails extends FlashcardLibrarySummary {
cards: FlashcardCard[];
}
export interface GenerateFlashcardsResponse {
result: string;
libraries: FlashcardLibraryDetails[];
}
export interface FlashcardReviewSessionRequest {
libraryIds: number[];
}
export interface FlashcardReviewSessionResponse {
cards: FlashcardCard[];
}
async function throwIfNotOk(response: Response, fallback: string) {
if (response.ok) {
return;
}
let apiMessage = '';
try {
const body = await response.json();
if (typeof body?.error === 'string' && body.error.length > 0) {
apiMessage = body.error;
}
} catch {
// Ignore parse failures and throw fallback below.
}
throw new Error(apiMessage || fallback);
}
export const MindforgeApiService = {
@@ -49,9 +98,7 @@ export const MindforgeApiService = {
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Error checking file: ${response.statusText}`);
}
await throwIfNotOk(response, `Erro ao validar arquivo: ${response.statusText}`);
return response.json();
},
@@ -64,27 +111,50 @@ export const MindforgeApiService = {
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`Error generating flashcards: ${response.statusText}`);
}
await throwIfNotOk(response, `Erro ao gerar flashcards: ${response.statusText}`);
return response.json();
},
async getFlashcardLibraries(): Promise<FlashcardLibrarySummary[]> {
const response = await fetch(`${BASE_URL}/api/v1/flashcard/libraries`);
await throwIfNotOk(response, `Erro ao buscar bibliotecas de flashcards: ${response.statusText}`);
return response.json();
},
async getFlashcardLibrary(id: number): Promise<FlashcardLibraryDetails> {
const response = await fetch(`${BASE_URL}/api/v1/flashcard/libraries/${id}`);
await throwIfNotOk(response, `Erro ao buscar biblioteca ${id}: ${response.statusText}`);
return response.json();
},
async createFlashcardReviewSession(data: FlashcardReviewSessionRequest): Promise<FlashcardReviewSessionResponse> {
const response = await fetch(`${BASE_URL}/api/v1/flashcard/review-session`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
await throwIfNotOk(response, `Erro ao iniciar revisao: ${response.statusText}`);
return response.json();
},
async getRepositoryInfo(): Promise<RepositoryInfo> {
const response = await fetch(`${BASE_URL}/api/v1/repository/info`);
if (!response.ok) throw new Error(`Error fetching repository info: ${response.statusText}`);
await throwIfNotOk(response, `Erro ao buscar info do repositorio: ${response.statusText}`);
return response.json();
},
async getRepositoryTree(): Promise<FileTreeNode[]> {
const response = await fetch(`${BASE_URL}/api/v1/repository/tree`);
if (!response.ok) throw new Error(`Error fetching repository tree: ${response.statusText}`);
await throwIfNotOk(response, `Erro ao buscar arvore do repositorio: ${response.statusText}`);
return response.json();
},
async getFileContent(path: string): Promise<FileContentResponse> {
const response = await fetch(`${BASE_URL}/api/v1/repository/file?path=${encodeURIComponent(path)}`);
if (!response.ok) throw new Error(`Error fetching file ${path}: ${response.statusText}`);
await throwIfNotOk(response, `Erro ao buscar arquivo ${path}: ${response.statusText}`);
return response.json();
},
};