mirror of
https://github.com/mudabbir-ahmad/Media-Aggregation-and-Sorting-System.git
synced 2026-10-07 19:40:20 +00:00
feat: implement Google Photos import functionality and save media items to the database
This commit is contained in:
1 parent
5c096fbab4
commit
04046702d3
2 files changed
+151
-70
No files matched your search
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user