feat: implement Google Photos import functionality and save media items to the database

This commit is contained in:
bobbert committed 2026-02-24 23:59:18 +00:00
1 parent 5c096fbab4
commit 04046702d3
2 files changed
+151 -70

No files matched your search

+31
View File
@@ -239,6 +239,37 @@ const DatabaseService = {
}
},
/**
* Save a normalised media item object to the DB.
* Skips duplicates (same user_id + source_id).
*/
saveMediaItem: async (userId, item) => {
try {
await DatabaseService.ensureDb();
if (!userId || !item.source_service) return;
// Check for existing entry to avoid duplicates
if (item.source_id) {
const existing = await db.getFirstAsync(
'SELECT id FROM media WHERE user_id = ? AND source_id = ?',
[userId, item.source_id]
);
if (existing) return existing.id;
}
const result = await db.runAsync(
`INSERT INTO media (user_id, source_service, source_id, title, description, local_path, remote_path, media_type, created_date)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[userId, item.source_service, item.source_id || null, item.title || null,
item.description || null, item.local_path || null, item.remote_path || null,
item.media_type || null, item.created_date || null]
);
return result.lastInsertRowId;
} catch (error) {
console.error('Error saving media item:', error);
}
},
getMediaByUser: async (userId) => {
try {
await DatabaseService.ensureDb();