Files
novafarma/docs/BACKEND_SETUP.md
David Kotnik 6aa5aaf5bb assets: Deleted 3 images via Visual Asset Manager
DELETED FILES (via backend API):
- interior_kitchen_fridge_1767523986761.png
- interior_secret_passage_1767524112663.png
- uploaded_image_1767490252657.png

UPDATED:
- tools/asset_manifest.json: Regenerated (1,166 → 1,163 assets)

ADDED DOCUMENTATION:
- docs/BACKEND_SETUP.md: Backend API setup guide
- tools/requirements.txt: Flask dependencies

TOTAL ASSETS: 1,166 → 1,163 (-3)

METHOD: Visual Asset Manager backend API
BACKEND STATUS:  Working perfectly on port 5001
DELETE FEATURE:  Fully functional

First successful delete via UI! 🎉
2026-01-04 20:33:26 +01:00

219 lines
4.0 KiB
Markdown

# 🚀 Visual Asset Manager - Backend Setup
**Status**: ✅ FULLY FUNCTIONAL
**Delete**: Now actually deletes files from disk
**Re-roll**: API ready (image generation TBD)
---
## 🎯 QUICK START
### 1. Install Dependencies
```bash
pip3 install Flask flask-cors
```
### 2. Start Backend Server
```bash
cd /Users/davidkotnik/repos/novafarma
python3 tools/asset_backend.py
```
Server starts on: **http://localhost:5000**
### 3. Start Frontend Server
```bash
# In another terminal:
cd /Users/davidkotnik/repos/novafarma
python3 -m http.server 8080
```
Frontend URL: **http://localhost:8080/tools/visual_asset_manager.html**
---
## ✅ WHAT NOW WORKS:
### 🗑️ DELETE (Fully Functional!)
1. Klikni "Delete" na asset cardu
2. Confirm dialog
3. **Backend dejansko izbriše datoteko iz diska**
4. Auto-regenerira manifest
5. Galerija se osvež i
**Flow:**
```
Frontend → DELETE /api/asset/{id}
Backend finds file
os.remove() - file deleted
Regenerate manifest
Return success → Frontend reloads
```
### 🔄 RE-ROLL (API Ready)
1. Klikni "Re-roll"
2. Backend API endpoint ready
3. **TODO**: Image generation not yet implemented
4. For now: Shows placeholder message
---
## 🔌 API ENDPOINTS:
### Health Check
```bash
GET http://localhost:5000/api/health
```
### Get All Assets
```bash
GET http://localhost:5000/api/assets
```
### Delete Asset
```bash
DELETE http://localhost:5000/api/asset/{asset_id}
Response:
{
"success": true,
"message": "Asset deleted successfully",
"deleted_file": "assets/path/to/file.png"
}
```
### Re-roll Asset
```bash
POST http://localhost:5000/api/asset/{asset_id}/reroll
Response:
{
"success": true,
"message": "Re-roll requested",
"note": "Image generation not yet implemented"
}
```
### Regenerate Manifest
```bash
POST http://localhost:5000/api/manifest/regenerate
Response:
{
"success": true,
"message": "Manifest regenerated",
"total_assets": 1166
}
```
---
## 🎬 WORKFLOW EXAMPLE:
### Delete Unwanted Asset:
1. **Odpri galerijo**: http://localhost:8080/tools/visual_asset_manager.html
2. **Find asset**: Use search or filter
3. **Click Delete**: Red button
4. **Confirm**: Dialog asks for confirmation
5. **Wait**: Backend deletes file (2s)
6. **Auto-refresh**: Gallery shows updated list
**Result**: File physically deleted from disk!
---
## 🛠️ DEVELOPMENT:
### Backend Code
`tools/asset_backend.py` - Flask API server
### Frontend Code
`tools/visual_asset_manager.html` - Updated with API calls
### Dependencies
`to ols/requirements.txt`:
- Flask==3.0.0
- flask-cors==4.0.0
---
## 🔒 SECURITY NOTES:
⚠️ **Development Only**
- CORS is open (allows all origins)
- No authentication
- Debug mode enabled
- NOT for production use
**For production**, add:
- Authentication
- CORS restrictions
- Rate limiting
- Input validation
- HTTPS
---
## 🐛 TROUBLESHOOTING:
### Backend not starting?
```bash
# Check if Flask installed:
pip3 show Flask
# Check port 5000 available:
lsof -ti:5000
# View backend logs:
tail -f /tmp/backend.log
```
### Delete not working?
```bash
# Check backend is running:
curl http://localhost:5000/api/health
# Should return:
# {"status": "ok", "message": "Asset Backend API is running"}
```
### CORS errors?
```bash
# Make sure both servers running:
# Backend: localhost:5000
# Frontend: localhost:8080
```
---
## 📊 STATUS:
| Feature | Status | Notes |
|---------|--------|-------|
| Backend API | ✅ Running | Flask on port 5000 |
| Delete Endpoint | ✅ Working | Deletes files from disk |
| Re-roll Endpoint | ⚠️ API Only | Image gen not implemented |
| Manifest Regen | ✅ Working | Auto-updates after delete |
| Frontend Integration | ✅ Working | API calls functional |
---
## 🚀 NEXT STEPS:
1. **Image Generation**: Integrate Gemini API for re-roll
2. **Batch Delete**: Select multiple assets
3. **Undo**: Trash bin before permanent delete
4. **Preview Changes**: Show what will be deleted
5. **Authentication**: Add user login
---
**Setup Time**: ~15 min
**Dependencies**: Flask, flask-cors
**Ready**: YES ✅