fix url
Browse files
src/lib/db/trainerScanning.ts
CHANGED
@@ -36,7 +36,11 @@ export async function initializeTrainerScanProgress(imagePaths: string[]): Promi
|
|
36 |
|
37 |
const imageMatch = imageFile.match(/image_(\d+)\.jpg/);
|
38 |
const imageIndex = imageMatch ? parseInt(imageMatch[1]) : 1;
|
39 |
-
|
|
|
|
|
|
|
|
|
40 |
|
41 |
// Check if this path already exists to avoid duplicates
|
42 |
const existing = await db.trainerScanProgress.get(imagePath);
|
|
|
36 |
|
37 |
const imageMatch = imageFile.match(/image_(\d+)\.jpg/);
|
38 |
const imageIndex = imageMatch ? parseInt(imageMatch[1]) : 1;
|
39 |
+
|
40 |
+
// Build remote URL without trainer_images folder
|
41 |
+
// From: trainer_images/001_Willow_Snap/image_001.jpg
|
42 |
+
// To: https://huggingface.co/datasets/Fraser/piclets/resolve/main/001_Willow_Snap/image_001.jpg
|
43 |
+
const remoteUrl = `https://huggingface.co/datasets/Fraser/piclets/resolve/main/${trainerName}/${imageFile}`;
|
44 |
|
45 |
// Check if this path already exists to avoid duplicates
|
46 |
const existing = await db.trainerScanProgress.get(imagePath);
|
src/lib/services/trainerScanService.ts
CHANGED
@@ -51,26 +51,43 @@ export class TrainerScanService {
|
|
51 |
}
|
52 |
|
53 |
// Notify all subscribers of state changes
|
54 |
-
private notifyStateChange(state: Partial<TrainerScanState>) {
|
55 |
-
const
|
|
|
56 |
this.stateCallbacks.forEach(callback => callback(fullState));
|
57 |
}
|
58 |
|
59 |
// Get current scanning state
|
60 |
private async getCurrentState(): Promise<TrainerScanState> {
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
|
76 |
// Initialize scanning database with image paths from file
|
@@ -97,7 +114,7 @@ export class TrainerScanService {
|
|
97 |
}
|
98 |
|
99 |
await initializeTrainerScanProgress(imagePaths);
|
100 |
-
|
101 |
} catch (error) {
|
102 |
console.error('Failed to initialize trainer scan progress:', error);
|
103 |
throw new Error('Failed to load trainer image paths');
|
@@ -125,16 +142,16 @@ export class TrainerScanService {
|
|
125 |
|
126 |
this.isScanning = true;
|
127 |
this.shouldStop = false;
|
128 |
-
this.notifyStateChange({ isScanning: true, error: null });
|
129 |
|
130 |
try {
|
131 |
await this.processingLoop();
|
132 |
} catch (error) {
|
133 |
console.error('Scanning error:', error);
|
134 |
-
this.notifyStateChange({ error: error instanceof Error ? error.message : 'Unknown error' });
|
135 |
} finally {
|
136 |
this.isScanning = false;
|
137 |
-
this.notifyStateChange({ isScanning: false, currentImage: null, currentTrainer: null });
|
138 |
|
139 |
// Log final summary
|
140 |
const finalStats = await getScanningStats();
|
@@ -163,7 +180,7 @@ export class TrainerScanService {
|
|
163 |
break;
|
164 |
}
|
165 |
|
166 |
-
this.notifyStateChange({
|
167 |
currentImage: nextImage.imagePath,
|
168 |
currentTrainer: typeof nextImage.trainerName === 'string' ? nextImage.trainerName : null
|
169 |
});
|
@@ -190,7 +207,7 @@ export class TrainerScanService {
|
|
190 |
}
|
191 |
|
192 |
// Update progress
|
193 |
-
|
194 |
}
|
195 |
}
|
196 |
|
|
|
51 |
}
|
52 |
|
53 |
// Notify all subscribers of state changes
|
54 |
+
private async notifyStateChange(state: Partial<TrainerScanState>) {
|
55 |
+
const currentState = await this.getCurrentState();
|
56 |
+
const fullState = { ...currentState, ...state };
|
57 |
this.stateCallbacks.forEach(callback => callback(fullState));
|
58 |
}
|
59 |
|
60 |
// Get current scanning state
|
61 |
private async getCurrentState(): Promise<TrainerScanState> {
|
62 |
+
try {
|
63 |
+
const stats = await getScanningStats();
|
64 |
+
return {
|
65 |
+
isScanning: this.isScanning,
|
66 |
+
currentImage: null,
|
67 |
+
currentTrainer: null,
|
68 |
+
progress: {
|
69 |
+
total: stats?.total || 0,
|
70 |
+
completed: stats?.completed || 0,
|
71 |
+
failed: stats?.failed || 0,
|
72 |
+
pending: stats?.pending || 0
|
73 |
+
},
|
74 |
+
error: null
|
75 |
+
};
|
76 |
+
} catch (error) {
|
77 |
+
console.error('Failed to get current state:', error);
|
78 |
+
return {
|
79 |
+
isScanning: this.isScanning,
|
80 |
+
currentImage: null,
|
81 |
+
currentTrainer: null,
|
82 |
+
progress: {
|
83 |
+
total: 0,
|
84 |
+
completed: 0,
|
85 |
+
failed: 0,
|
86 |
+
pending: 0
|
87 |
+
},
|
88 |
+
error: 'Failed to load progress stats'
|
89 |
+
};
|
90 |
+
}
|
91 |
}
|
92 |
|
93 |
// Initialize scanning database with image paths from file
|
|
|
114 |
}
|
115 |
|
116 |
await initializeTrainerScanProgress(imagePaths);
|
117 |
+
await this.notifyStateChange({});
|
118 |
} catch (error) {
|
119 |
console.error('Failed to initialize trainer scan progress:', error);
|
120 |
throw new Error('Failed to load trainer image paths');
|
|
|
142 |
|
143 |
this.isScanning = true;
|
144 |
this.shouldStop = false;
|
145 |
+
await this.notifyStateChange({ isScanning: true, error: null });
|
146 |
|
147 |
try {
|
148 |
await this.processingLoop();
|
149 |
} catch (error) {
|
150 |
console.error('Scanning error:', error);
|
151 |
+
await this.notifyStateChange({ error: error instanceof Error ? error.message : 'Unknown error' });
|
152 |
} finally {
|
153 |
this.isScanning = false;
|
154 |
+
await this.notifyStateChange({ isScanning: false, currentImage: null, currentTrainer: null });
|
155 |
|
156 |
// Log final summary
|
157 |
const finalStats = await getScanningStats();
|
|
|
180 |
break;
|
181 |
}
|
182 |
|
183 |
+
await this.notifyStateChange({
|
184 |
currentImage: nextImage.imagePath,
|
185 |
currentTrainer: typeof nextImage.trainerName === 'string' ? nextImage.trainerName : null
|
186 |
});
|
|
|
207 |
}
|
208 |
|
209 |
// Update progress
|
210 |
+
await this.notifyStateChange({});
|
211 |
}
|
212 |
}
|
213 |
|