@bobfrankston/gcards 0.1.32 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gcards.ts +20 -2
- package/glib/gutils.ts +11 -1
- package/package.json +1 -1
package/gcards.ts
CHANGED
|
@@ -179,7 +179,16 @@ interface DeletedIndex {
|
|
|
179
179
|
function loadDeleted(paths: UserPaths): DeletedIndex {
|
|
180
180
|
if (fs.existsSync(paths.deletedFile)) {
|
|
181
181
|
try {
|
|
182
|
-
|
|
182
|
+
const parsed = parseJsonc(fs.readFileSync(paths.deletedFile, 'utf-8'));
|
|
183
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
184
|
+
console.warn(`Warning: ${paths.deletedFile} is not a valid object, returning empty deleted index`);
|
|
185
|
+
return { deleted: {} };
|
|
186
|
+
}
|
|
187
|
+
if (!parsed.deleted || typeof parsed.deleted !== 'object') {
|
|
188
|
+
console.warn(`Warning: ${paths.deletedFile} missing or invalid deleted field, initializing empty`);
|
|
189
|
+
parsed.deleted = {};
|
|
190
|
+
}
|
|
191
|
+
return parsed as DeletedIndex;
|
|
183
192
|
} catch (e: any) {
|
|
184
193
|
throw new Error(`Failed to parse ${paths.deletedFile}: ${e.message}`);
|
|
185
194
|
}
|
|
@@ -228,7 +237,16 @@ interface PhotosIndex {
|
|
|
228
237
|
function loadPhotos(paths: UserPaths): PhotosIndex {
|
|
229
238
|
if (fs.existsSync(paths.photosFile)) {
|
|
230
239
|
try {
|
|
231
|
-
|
|
240
|
+
const parsed = parseJsonc(fs.readFileSync(paths.photosFile, 'utf-8'));
|
|
241
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
242
|
+
console.warn(`Warning: ${paths.photosFile} is not a valid object, returning empty photos index`);
|
|
243
|
+
return { photos: {} };
|
|
244
|
+
}
|
|
245
|
+
if (!parsed.photos || typeof parsed.photos !== 'object') {
|
|
246
|
+
console.warn(`Warning: ${paths.photosFile} missing or invalid photos field, initializing empty`);
|
|
247
|
+
parsed.photos = {};
|
|
248
|
+
}
|
|
249
|
+
return parsed as PhotosIndex;
|
|
232
250
|
} catch (e: any) {
|
|
233
251
|
throw new Error(`Failed to parse ${paths.photosFile}: ${e.message}`);
|
|
234
252
|
}
|
package/glib/gutils.ts
CHANGED
|
@@ -84,7 +84,17 @@ export function ensureUserDir(user: string): void {
|
|
|
84
84
|
export function loadIndex(paths: UserPaths): ContactIndex {
|
|
85
85
|
if (fs.existsSync(paths.indexFile)) {
|
|
86
86
|
try {
|
|
87
|
-
|
|
87
|
+
const parsed = parseJsonc(fs.readFileSync(paths.indexFile, 'utf-8'));
|
|
88
|
+
// Ensure contacts field exists
|
|
89
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
90
|
+
console.warn(`Warning: ${paths.indexFile} is not a valid object, returning empty index`);
|
|
91
|
+
return { contacts: {}, lastSync: '' };
|
|
92
|
+
}
|
|
93
|
+
if (!parsed.contacts || typeof parsed.contacts !== 'object') {
|
|
94
|
+
console.warn(`Warning: ${paths.indexFile} missing or invalid contacts field, initializing empty`);
|
|
95
|
+
parsed.contacts = {};
|
|
96
|
+
}
|
|
97
|
+
return parsed as ContactIndex;
|
|
88
98
|
} catch (e: any) {
|
|
89
99
|
throw new Error(`Failed to parse ${paths.indexFile}: ${e.message}`);
|
|
90
100
|
}
|