DocHub
REST endpoints for photo CRUD, send-to-chat, and dual-approach conversation purge

API Endpoints

All endpoints are mounted at /api/library.

CRUD Endpoints

Method Route Description
GET /api/library List all photos
POST /api/library/upload Upload photo (multipart, field: photo)
POST /api/library/save-from-message Save from conversation { chatId, messageId }
GET /api/library/:id/file Serve full-size photo
GET /api/library/:id/thumb Serve thumbnail
PATCH /api/library/:id Update caption { caption }
DELETE /api/library/:id Delete photo, thumbnail, and DB record

Send Endpoint

Method Route Description
POST /api/library/:id/send Send photo to chat { chatId, caption? }

Purge System

The purge removes a photo from every conversation it was sent to, using “delete for me” (recipients keep their copy).

Dual-Approach Algorithm

  1. Tracked sends – query photo_library_sends for all messages sent from this library photo
  2. Hash scan fallback – query media_files table for matching md5_hash to catch photos saved before the library existed or sent manually

For each found message:

  1. Load the WhatsApp message via client.getMessageById(msg_wa_id)
  2. Call msg.delete(false) – “delete for me”
  3. Delete from messages table in DB
  4. Delete from media_files table if present
  5. Clean up photo_library_sends records

Status

Complete and deployed.