Archive: System v4 - Estado al 2024-12-24
This commit is contained in:
222
v4-archive/locker/R2_SYNC_CLIENT.md
Normal file
222
v4-archive/locker/R2_SYNC_CLIENT.md
Normal file
@@ -0,0 +1,222 @@
|
||||
# Sincronización R2 con rclone
|
||||
|
||||
Configuración de sincronización bidireccional entre carpeta local y Cloudflare R2.
|
||||
|
||||
## Requisitos
|
||||
|
||||
- rclone instalado
|
||||
- Credenciales R2 (Access Key + Secret)
|
||||
- macOS con launchd o Linux con systemd
|
||||
|
||||
## Instalación rclone
|
||||
|
||||
### macOS
|
||||
```bash
|
||||
brew install rclone
|
||||
```
|
||||
|
||||
### Linux
|
||||
```bash
|
||||
curl https://rclone.org/install.sh | sudo bash
|
||||
```
|
||||
|
||||
## Configuración
|
||||
|
||||
### 1. Crear archivo de configuración
|
||||
|
||||
```bash
|
||||
mkdir -p ~/.config/rclone
|
||||
```
|
||||
|
||||
### 2. Configurar remote R2
|
||||
|
||||
**~/.config/rclone/rclone.conf:**
|
||||
```ini
|
||||
[r2-architect]
|
||||
type = s3
|
||||
provider = Cloudflare
|
||||
access_key_id = {ACCESS_KEY}
|
||||
secret_access_key = {SECRET_KEY}
|
||||
endpoint = https://7dedae6030f5554d99d37e98a5232996.r2.cloudflarestorage.com
|
||||
acl = private
|
||||
```
|
||||
|
||||
### 3. Verificar conexión
|
||||
|
||||
```bash
|
||||
# Listar contenido del bucket
|
||||
rclone lsf r2-architect:architect/
|
||||
|
||||
# Con verbose para debug
|
||||
rclone ls r2-architect:architect/ -vv
|
||||
```
|
||||
|
||||
## Sincronización
|
||||
|
||||
### Sync unidireccional (R2 → Local)
|
||||
|
||||
```bash
|
||||
rclone sync r2-architect:architect/ "/path/to/local/folder/" --progress
|
||||
```
|
||||
|
||||
### Sync unidireccional (Local → R2)
|
||||
|
||||
```bash
|
||||
rclone sync "/path/to/local/folder/" r2-architect:architect/ --progress
|
||||
```
|
||||
|
||||
### Bisync bidireccional
|
||||
|
||||
```bash
|
||||
# Primera vez: inicializar con --resync
|
||||
rclone bisync "/path/to/local/folder/" r2-architect:architect/ --resync --verbose
|
||||
|
||||
# Ejecuciones posteriores
|
||||
rclone bisync "/path/to/local/folder/" r2-architect:architect/ --verbose
|
||||
```
|
||||
|
||||
## Automatización
|
||||
|
||||
### macOS (launchd)
|
||||
|
||||
**~/Library/LaunchAgents/com.rclone.r2-sync.plist:**
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>com.rclone.r2-sync</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/opt/homebrew/bin/rclone</string>
|
||||
<string>bisync</string>
|
||||
<string>/Users/{user}/R2 Folder/</string>
|
||||
<string>r2-architect:architect/</string>
|
||||
<string>--verbose</string>
|
||||
</array>
|
||||
<key>StartInterval</key>
|
||||
<integer>300</integer>
|
||||
<key>StandardOutPath</key>
|
||||
<string>/Users/{user}/Library/Logs/rclone-r2-sync.log</string>
|
||||
<key>StandardErrorPath</key>
|
||||
<string>/Users/{user}/Library/Logs/rclone-r2-sync.log</string>
|
||||
<key>RunAtLoad</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
```
|
||||
|
||||
**Comandos launchd:**
|
||||
```bash
|
||||
# Cargar servicio
|
||||
launchctl load ~/Library/LaunchAgents/com.rclone.r2-sync.plist
|
||||
|
||||
# Ver estado
|
||||
launchctl list | grep r2-sync
|
||||
|
||||
# Detener
|
||||
launchctl unload ~/Library/LaunchAgents/com.rclone.r2-sync.plist
|
||||
```
|
||||
|
||||
### Linux (systemd)
|
||||
|
||||
**~/.config/systemd/user/rclone-r2-sync.service:**
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Rclone R2 Bisync
|
||||
After=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/rclone bisync /home/{user}/R2/ r2-architect:architect/ --verbose
|
||||
```
|
||||
|
||||
**~/.config/systemd/user/rclone-r2-sync.timer:**
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Run rclone R2 sync every 5 minutes
|
||||
|
||||
[Timer]
|
||||
OnBootSec=1min
|
||||
OnUnitActiveSec=5min
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
```
|
||||
|
||||
**Comandos systemd:**
|
||||
```bash
|
||||
# Habilitar
|
||||
systemctl --user enable rclone-r2-sync.timer
|
||||
systemctl --user start rclone-r2-sync.timer
|
||||
|
||||
# Ver estado
|
||||
systemctl --user status rclone-r2-sync.timer
|
||||
|
||||
# Ejecutar manualmente
|
||||
systemctl --user start rclone-r2-sync.service
|
||||
```
|
||||
|
||||
## Buckets R2 Disponibles
|
||||
|
||||
| Bucket | Uso | Credenciales |
|
||||
|--------|-----|--------------|
|
||||
| architect | Backups, configs, APKs | Token: architect-sync |
|
||||
| hst | Imágenes HST | Token: locker-full-access |
|
||||
| deck | Archivos personales | Token: locker-full-access |
|
||||
| corp | Documentos empresariales | Token: locker-full-access |
|
||||
| locker | General/temporal | Token: locker-full-access |
|
||||
|
||||
## Tokens R2
|
||||
|
||||
### locker-full-access (todos los buckets)
|
||||
```
|
||||
Endpoint: https://7dedae6030f5554d99d37e98a5232996.r2.cloudflarestorage.com
|
||||
Access Key: ecddc771824c3cb3417d9451780db3d2
|
||||
Secret Key: [ver creds_locker en PostgreSQL]
|
||||
```
|
||||
|
||||
### architect-sync (solo bucket architect)
|
||||
```
|
||||
Access Key: 55125dca442b0f3517d194a5bc0502b8
|
||||
Secret Key: [ver creds_locker.r2_architect_token en PostgreSQL]
|
||||
```
|
||||
|
||||
## Comandos útiles
|
||||
|
||||
```bash
|
||||
# Ver logs en tiempo real
|
||||
tail -f ~/Library/Logs/rclone-r2-sync.log
|
||||
|
||||
# Sync manual inmediato
|
||||
rclone bisync "/path/to/folder/" r2-architect:architect/ --verbose
|
||||
|
||||
# Ver diferencias sin sincronizar
|
||||
rclone check "/path/to/folder/" r2-architect:architect/
|
||||
|
||||
# Listar con tamaños
|
||||
rclone ls r2-architect:architect/
|
||||
|
||||
# Subir archivo específico
|
||||
rclone copy archivo.txt r2-architect:architect/path/
|
||||
|
||||
# Descargar archivo
|
||||
rclone copy r2-architect:architect/path/archivo.txt ./
|
||||
```
|
||||
|
||||
## Configuración cliente local
|
||||
|
||||
Ejemplo configurado en Mac (pablotzr):
|
||||
|
||||
| Componente | Valor |
|
||||
|------------|-------|
|
||||
| Carpeta local | /Users/pablotzr/Architect R2/ |
|
||||
| Bucket R2 | architect |
|
||||
| Sync | Bidireccional (bisync) |
|
||||
| Frecuencia | Cada 5 minutos |
|
||||
| Servicio | com.rclone.r2-architect-sync |
|
||||
| Logs | ~/Library/Logs/rclone-r2-sync.log |
|
||||
|
||||
---
|
||||
Creado: 2024-12-24
|
||||
264
v4-archive/locker/README.md
Normal file
264
v4-archive/locker/README.md
Normal file
@@ -0,0 +1,264 @@
|
||||
# LOCKER
|
||||
|
||||

|
||||
|
||||
|
||||
**Gateway de Almacenamiento - Ecosistema TZZR**
|
||||
|
||||
## Cloudflare R2 (Actualizado 2025-12-22)
|
||||
|
||||
### Estado de Buckets
|
||||
|
||||
| Bucket | Estado | Objetos | Contenido |
|
||||
|--------|--------|---------|-----------|
|
||||
| architect | OK | 0 | vacío |
|
||||
| hst | OK | 0 | vacío |
|
||||
| deck | OK | 1 | test.txt (5 bytes) |
|
||||
| corp | OK | 0 | vacío |
|
||||
| locker | OK | 0 | vacío |
|
||||
|
||||
**Resultado:** 5/5 buckets accesibles
|
||||
|
||||
### Credenciales R2
|
||||
|
||||
```
|
||||
Endpoint: https://7dedae6030f5554d99d37e98a5232996.r2.cloudflarestorage.com
|
||||
Access Key: ecddc771824c3cb3417d9451780db3d2
|
||||
Secret Key: c8138e2597100ffb7dd1477ad722c0214f86097cd968752aea3cfcea5d54dbac
|
||||
```
|
||||
|
||||
Token: `locker-full-access` (Object Read & Write, todos los buckets)
|
||||
|
||||
## Descripción
|
||||
|
||||
LOCKER es el **gateway de almacenamiento** del ecosistema. Abstrae el almacenamiento físico permitiendo guardar y recuperar archivos usando referencias `locker://`. Actualmente usa almacenamiento local/Nextcloud, con plan de migrar a solución descentralizada.
|
||||
|
||||
## Arquitectura
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ LOCKER │
|
||||
│ (Gateway de Almacenamiento) │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌───────────────────────────────────────────────────────┐ │
|
||||
│ │ API GATEWAY │ │
|
||||
│ │ locker://corp/facturas/001.pdf → /files/corp/... │ │
|
||||
│ └─────────────────────────────────────────────────────────┘ │
|
||||
│ │ │
|
||||
│ ▼ │
|
||||
│ ┌───────────────────────────────────────────────────────┐ │
|
||||
│ │ STORAGE ROUTER │ │
|
||||
│ └─────────────────────────────────────────────────────────┘ │
|
||||
│ │ │
|
||||
│ ┌─────────────────┼─────────────────┐ │
|
||||
│ ▼ ▼ ▼ │
|
||||
│ ┌───────────┐ ┌───────────┐ ┌───────────┐ │
|
||||
│ │ Local │ │ Nextcloud │ │ IPFS │ │
|
||||
│ │ (actual) │ │ (sync) │ │ (futuro) │ │
|
||||
│ └───────────┘ └───────────┘ └───────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
## Referencias LOCKER
|
||||
|
||||
Formato: `locker://{namespace}/{path}`
|
||||
|
||||
| Namespace | Descripción | Ejemplo |
|
||||
|-----------|-------------|---------|
|
||||
| corp | Documentos empresariales | `locker://corp/facturas/FAC-2025-001.pdf` |
|
||||
| deck | Archivos personales | `locker://deck/fitness/progress/week1.jpg` |
|
||||
| hst | Imágenes de tags | `locker://hst/icons/fit.png` |
|
||||
| factory | Artefactos generados | `locker://factory/artifacts/abc123.md` |
|
||||
| emails | Adjuntos de correo | `locker://emails/adjuntos/2025/01/doc.pdf` |
|
||||
|
||||
## API
|
||||
|
||||
### PUT /api/files/{path}
|
||||
|
||||
Subir archivo.
|
||||
|
||||
```bash
|
||||
curl -X PUT https://locker.tzzr.me/api/files/corp/facturas/001.pdf \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-H "Content-Type: application/pdf" \
|
||||
--data-binary @factura.pdf
|
||||
```
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"ref": "locker://corp/facturas/001.pdf",
|
||||
"url": "https://locker.tzzr.me/corp/facturas/001.pdf",
|
||||
"sha256": "abc123...",
|
||||
"size_bytes": 125000
|
||||
}
|
||||
```
|
||||
|
||||
### GET /api/files/{path}
|
||||
|
||||
Descargar archivo.
|
||||
|
||||
```bash
|
||||
curl https://locker.tzzr.me/api/files/corp/facturas/001.pdf \
|
||||
-H "Authorization: Bearer $API_KEY" \
|
||||
-o factura.pdf
|
||||
```
|
||||
|
||||
### POST /api/signed-url
|
||||
|
||||
Generar URL firmada (acceso temporal).
|
||||
|
||||
```json
|
||||
{
|
||||
"path": "corp/facturas/001.pdf",
|
||||
"expires_in": 3600
|
||||
}
|
||||
```
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"signed_url": "https://locker.tzzr.me/corp/facturas/001.pdf?token=xyz&expires=..."
|
||||
}
|
||||
```
|
||||
|
||||
### DELETE /api/files/{path}
|
||||
|
||||
Eliminar archivo.
|
||||
|
||||
## Integración
|
||||
|
||||
### Con THE FACTORY
|
||||
|
||||
```javascript
|
||||
// FACTORY sube artefactos generados a LOCKER
|
||||
const factory = new FactoryClient();
|
||||
const result = await factory.getJobResultToLocker(jobId, 'corp/facturas/001.pdf');
|
||||
// Returns: { locker_ref: "locker://corp/facturas/001.pdf" }
|
||||
```
|
||||
|
||||
### Con CLARA (CORP)
|
||||
|
||||
```javascript
|
||||
// CLARA guarda facturas certificadas
|
||||
const clara = new Clara();
|
||||
const stored = await clara.storeInLocker(invoiceContent, 'factura', {
|
||||
numero: 'FAC-2025-001'
|
||||
});
|
||||
// locker://corp/facturas/FAC-2025-001.pdf
|
||||
```
|
||||
|
||||
### Con DECK
|
||||
|
||||
```javascript
|
||||
// DECK guarda fotos de progreso
|
||||
const response = await fetch('https://locker.tzzr.me/api/files/deck/fitness/progress/week1.jpg', {
|
||||
method: 'PUT',
|
||||
body: imageBlob
|
||||
});
|
||||
```
|
||||
|
||||
### Con Emails
|
||||
|
||||
```javascript
|
||||
// Adjuntos de email van a LOCKER
|
||||
const attachment = await locker.upload(
|
||||
`emails/adjuntos/2025/01/${emailId}_${filename}`,
|
||||
content
|
||||
);
|
||||
// locker://emails/adjuntos/2025/01/msg001_documento.pdf
|
||||
```
|
||||
|
||||
## Deduplicación
|
||||
|
||||
LOCKER usa SHA-256 para deduplicar:
|
||||
|
||||
```javascript
|
||||
// Si el hash ya existe, retorna referencia existente
|
||||
const result = await locker.upload(path, content);
|
||||
if (result.deduplicated) {
|
||||
console.log('Archivo ya existía:', result.existing_ref);
|
||||
}
|
||||
```
|
||||
|
||||
## Sync con Nextcloud
|
||||
|
||||
LOCKER sincroniza con Nextcloud para acceso desde múltiples dispositivos:
|
||||
|
||||
```
|
||||
LOCKER (API) ←→ Local Storage ←→ Nextcloud Sync
|
||||
│
|
||||
▼
|
||||
Desktop/Mobile Apps
|
||||
```
|
||||
|
||||
## Estructura de Almacenamiento
|
||||
|
||||
```
|
||||
/data/locker/
|
||||
├── corp/
|
||||
│ ├── facturas/
|
||||
│ │ └── FAC-2025-0001.pdf
|
||||
│ ├── pedidos/
|
||||
│ └── productos/
|
||||
├── deck/
|
||||
│ ├── fitness/
|
||||
│ │ ├── progress/
|
||||
│ │ └── plans/
|
||||
│ └── documents/
|
||||
├── hst/
|
||||
│ └── icons/
|
||||
├── factory/
|
||||
│ └── artifacts/
|
||||
└── emails/
|
||||
└── adjuntos/
|
||||
```
|
||||
|
||||
## Roadmap: Descentralización
|
||||
|
||||
Plan de migración a almacenamiento descentralizado:
|
||||
|
||||
```
|
||||
Fase 1 (actual): Local + Nextcloud
|
||||
Fase 2: IPFS para archivos públicos (HST icons)
|
||||
Fase 3: Arweave para documentos certificados
|
||||
Fase 4: Filecoin para backup completo
|
||||
```
|
||||
|
||||
## Estructura del Proyecto
|
||||
|
||||
```
|
||||
locker/
|
||||
├── src/
|
||||
│ ├── api.py # API Gateway
|
||||
│ ├── storage/
|
||||
│ │ ├── local.py
|
||||
│ │ ├── nextcloud.py
|
||||
│ │ └── ipfs.py (futuro)
|
||||
│ └── dedup.py # Deduplicación
|
||||
├── docker/
|
||||
│ └── docker-compose.yml
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## Repositorios Relacionados
|
||||
|
||||
| Repo | Rol |
|
||||
|------|-----|
|
||||
| [the-factory](https://github.com/tzzrgit/the-factory) | Guarda artefactos |
|
||||
| [corp](https://github.com/tzzrgit/corp) | Guarda facturas |
|
||||
| [deck](https://github.com/tzzrgit/deck) | Guarda archivos personales |
|
||||
| [hst-image-server](https://github.com/tzzrgit/hst-image-server) | Imágenes HST |
|
||||
|
||||
## Roadmap
|
||||
|
||||
- [x] API básica (PUT/GET/DELETE)
|
||||
- [x] URLs firmadas
|
||||
- [x] Deduplicación SHA-256
|
||||
- [x] Sync Nextcloud
|
||||
- [ ] IPFS para HST
|
||||
- [ ] Arweave para certificados
|
||||
- [ ] Compresión automática
|
||||
- [ ] CDN para assets públicos
|
||||
Reference in New Issue
Block a user