AOSSIE-Org / AOSSIE-Org/PictoPy

Feat: Real-Time Image Library Synchronization after new image add in Local

Đang mở
#1,006 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
283
Fork
679
Merge trung bình
7 ngày 2 giờ
Pull request đã merge (30 ngày)
3

Mô tả

### Describe the feature

# Real-Time Image Library Synchronization

## Problem

Currently, PictoPy does not update the gallery in real time when images are added via the OS file system (Explorer/Finder).

- The `sync-microservice` exists but only logs file events
- Newly added images appear only after restarting the application
- This makes the application feel static and unreliable

---

## Goal

Enable real-time library synchronization so that when a new image is added to the library folder:

- The image is detected immediately
- The image is inserted into the database instantly
- The frontend shows a toast notification
- The gallery updates without requiring an application restart

**Example notification:**

New photo detected: IMG_1234.jpg

---

## Proposed Workflow (High-Level)

```

OS File System

sync-microservice (File Watcher)

Backend API (db_insert_image)

Tauri Event

Frontend Toast Notification

Gallery Auto-Refresh

```

---

## Implementation Plan

### 1. Watch Library Folder (sync-microservice)

- Use a cross-platform file watcher (e.g. `chokidar`)
- Watch the user-configured library path (no hardcoded paths)
- Detect only supported image formats (`.jpg`, `.jpeg`, `.png`, `.webp`)

**Files to change:**
- `sync-microservice/index.ts` (update)
- `sync-microservice/fileWatcher.ts` (new)

---

### 2. Backend API – Insert Image Immediately

- Add a new endpoint:
```
POST /sync/new-image

```
- Reuse existing `db_insert_image` logic
- Prevent duplicate entries using a unique path or hash

**Files to change:**
- `backend/routes/sync.routes.ts` (new)
- `backend/controllers/sync.controller.ts` (new)

---

### 3. Emit Real-Time Event to Frontend

- After inserting the image into the database, emit a Tauri event
- Event name: `image-added`
- Payload structure:
```json
{
"id": "image_id",
"name": "IMG_1234.jpg",
"path": "/absolute/path/to/image"
}

```

## 4. Files to change:

src-tauri/src/main.rs (update – event emission only)

### 5. Frontend – Toast Notification and Auto Refresh
Listen for the image-added event

Display a toast notification

Refresh gallery data automatically without user interaction

## Files to change:
```
frontend/src/App.tsx or frontend/src/Home.tsx (update)

frontend/src/hooks/useImageEvents.ts (new)
```

### Add ScreenShots

## demo screenshot

Image

hello @rahulharpal1603 sir
Please assign this issue to me

### Record

- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.