Fraser commited on
Commit
5056db8
·
1 Parent(s): 5435413
src/lib/db/trainerScanning.ts CHANGED
@@ -12,9 +12,21 @@ export async function initializeTrainerScanProgress(imagePaths: string[]): Promi
12
  // Extract trainer name and image index from path
13
  // Format: "trainer_images/001_Willow_Snap/image_001.jpg"
14
  const pathParts = imagePath.split('/');
 
 
 
 
 
15
  const trainerName = pathParts[1]; // "001_Willow_Snap"
16
  const imageFile = pathParts[2]; // "image_001.jpg"
17
- const imageIndex = parseInt(imageFile.match(/image_(\d+)\.jpg/)?.[1] || '1');
 
 
 
 
 
 
 
18
 
19
  const remoteUrl = `https://huggingface.co/datasets/Fraser/piclets/resolve/main/${imagePath}`;
20
 
 
12
  // Extract trainer name and image index from path
13
  // Format: "trainer_images/001_Willow_Snap/image_001.jpg"
14
  const pathParts = imagePath.split('/');
15
+ if (pathParts.length < 3) {
16
+ console.warn(`Skipping invalid path format: ${imagePath}`);
17
+ continue;
18
+ }
19
+
20
  const trainerName = pathParts[1]; // "001_Willow_Snap"
21
  const imageFile = pathParts[2]; // "image_001.jpg"
22
+
23
+ if (!trainerName || !imageFile) {
24
+ console.warn(`Skipping path with missing parts: ${imagePath}`);
25
+ continue;
26
+ }
27
+
28
+ const imageMatch = imageFile.match(/image_(\d+)\.jpg/);
29
+ const imageIndex = imageMatch ? parseInt(imageMatch[1]) : 1;
30
 
31
  const remoteUrl = `https://huggingface.co/datasets/Fraser/piclets/resolve/main/${imagePath}`;
32
 
src/lib/services/trainerScanService.ts CHANGED
@@ -77,8 +77,23 @@ export class TrainerScanService {
77
  async initializeFromFile(): Promise<void> {
78
  try {
79
  const response = await fetch('/trainer_image_paths.txt');
 
 
 
 
80
  const content = await response.text();
81
- const imagePaths = content.trim().split('\n').filter(path => path.trim());
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  await initializeTrainerScanProgress(imagePaths);
84
  this.notifyStateChange(await this.getCurrentState());
 
77
  async initializeFromFile(): Promise<void> {
78
  try {
79
  const response = await fetch('/trainer_image_paths.txt');
80
+ if (!response.ok) {
81
+ throw new Error(`Failed to fetch trainer_image_paths.txt: ${response.statusText}`);
82
+ }
83
+
84
  const content = await response.text();
85
+ if (!content) {
86
+ throw new Error('trainer_image_paths.txt is empty');
87
+ }
88
+
89
+ const imagePaths = content.trim().split('\n')
90
+ .map(path => typeof path === 'string' ? path.trim() : '')
91
+ .filter(path => path.length > 0);
92
+ console.log(`Loaded ${imagePaths.length} trainer image paths`);
93
+
94
+ if (imagePaths.length === 0) {
95
+ throw new Error('No valid image paths found in trainer_image_paths.txt');
96
+ }
97
 
98
  await initializeTrainerScanProgress(imagePaths);
99
  this.notifyStateChange(await this.getCurrentState());