initial statistics implementation

This commit is contained in:
Stefan Hardegger
2025-10-20 08:50:12 +02:00
parent 30c0132a92
commit 378265c3a3
6 changed files with 596 additions and 2 deletions

View File

@@ -1053,15 +1053,23 @@ export const clearLibraryCache = (): void => {
currentLibraryId = null;
};
// Library statistics endpoints
export const statisticsApi = {
getOverviewStatistics: async (libraryId: string): Promise<import('../types/api').LibraryOverviewStats> => {
const response = await api.get(`/libraries/${libraryId}/statistics/overview`);
return response.data;
},
};
// Image utility - now library-aware
export const getImageUrl = (path: string): string => {
if (!path) return '';
// For compatibility during transition, handle both patterns
if (path.startsWith('http')) {
return path; // External URL
}
// Use library-aware API endpoint
const libraryId = getCurrentLibraryId();
return `/api/files/images/${libraryId}/${path}`;

View File

@@ -204,4 +204,33 @@ export interface FilterPreset {
description?: string;
filters: Partial<AdvancedFilters>;
category: 'length' | 'date' | 'rating' | 'reading' | 'content' | 'organization';
}
// Library Statistics
export interface LibraryOverviewStats {
// Collection Overview
totalStories: number;
totalAuthors: number;
totalSeries: number;
totalTags: number;
totalCollections: number;
uniqueSourceDomains: number;
// Content Metrics
totalWordCount: number;
averageWordsPerStory: number;
longestStory: StoryWordCount | null;
shortestStory: StoryWordCount | null;
// Reading Time
totalReadingTimeMinutes: number;
averageReadingTimeMinutes: number;
}
export interface StoryWordCount {
id: string;
title: string;
authorName: string;
wordCount: number;
readingTimeMinutes: number;
}