Spaces:
Sleeping
Sleeping
Upload 81 files
Browse files- .dockerignore +6 -6
- App.tsx +106 -14
- Dockerfile +33 -33
- bot_telegram/.env +5 -5
- bot_telegram/README.md +26 -26
- bot_telegram/bot.py +118 -118
- bot_telegram/go.mod +8 -8
- bot_telegram/go.sum +4 -4
- bot_telegram/main.go +123 -123
- bot_telegram/sessions/bot_session.session +0 -0
- components/AdminLoginModal.tsx +158 -158
- components/BulkCategoryModal.tsx +95 -95
- components/ConfirmModal.tsx +75 -75
- components/DetailView.tsx +67 -37
- components/FishAudioPlayer.tsx +101 -101
- components/MarkdownRenderer.tsx +16 -3
- components/MoveToFolderModal.tsx +205 -205
- components/extensions/CustomFileExtension.tsx +72 -72
- components/extensions/WordBehaviorExtension.ts +74 -74
- dist/assets/index-B8NpKCEH.js +0 -0
- dist/assets/index-CC3SLb6N.js +0 -0
- dist/assets/index-CdT4gFR-.js +0 -0
- dist/assets/index-DBb-BcX0.js +0 -0
- dist/assets/index-DLwUYtS5.css +1 -1
- dist/assets/index-N97Ka77T.js +0 -0
- dist/favicon.svg +5 -5
- firestore.json +13 -13
- install.bat +7 -7
- public/favicon.svg +5 -5
- requirements.txt +6 -6
- run.bat +23 -23
- types.ts +1 -1
.dockerignore
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
node_modules
|
| 2 |
-
dist
|
| 3 |
-
.env
|
| 4 |
-
.git
|
| 5 |
-
.gitignore
|
| 6 |
-
firestore.json
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
dist
|
| 3 |
+
.env
|
| 4 |
+
.git
|
| 5 |
+
.gitignore
|
| 6 |
+
firestore.json
|
App.tsx
CHANGED
|
@@ -30,6 +30,8 @@ const App: React.FC = () => {
|
|
| 30 |
return 'normal';
|
| 31 |
});
|
| 32 |
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
|
|
|
|
|
|
| 33 |
const [isCategoriesPlusEnabled, setIsCategoriesPlusEnabled] = useState(() => {
|
| 34 |
if (typeof window !== 'undefined') {
|
| 35 |
return localStorage.getItem('categoriesPlusEnabled') === 'true';
|
|
@@ -574,25 +576,115 @@ const App: React.FC = () => {
|
|
| 574 |
return (
|
| 575 |
<div className="min-h-screen bg-background font-sans text-gray-200 selection:bg-primary selection:text-background pb-20">
|
| 576 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
{/* Navbar */}
|
| 578 |
<nav className="sticky top-0 z-50 bg-background/80 backdrop-blur-md border-b border-white/5">
|
| 579 |
<div className="w-full max-w-[95%] 2xl:max-w-[1800px] mx-auto px-4 sm:px-6 lg:px-8">
|
| 580 |
<div className="flex items-center justify-between h-20">
|
| 581 |
-
<div
|
| 582 |
-
className="
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
</div>
|
| 593 |
-
<span className="text-lg sm:text-xl font-bold tracking-tight text-white">
|
| 594 |
-
CodeBy<span className="text-primary">Dante</span>
|
| 595 |
-
</span>
|
| 596 |
</div>
|
| 597 |
|
| 598 |
{view === 'LIST' && (
|
|
|
|
| 30 |
return 'normal';
|
| 31 |
});
|
| 32 |
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
| 33 |
+
const [isFolderMenuOpen, setIsFolderMenuOpen] = useState(false);
|
| 34 |
+
const [folderSearchQuery, setFolderSearchQuery] = useState('');
|
| 35 |
const [isCategoriesPlusEnabled, setIsCategoriesPlusEnabled] = useState(() => {
|
| 36 |
if (typeof window !== 'undefined') {
|
| 37 |
return localStorage.getItem('categoriesPlusEnabled') === 'true';
|
|
|
|
| 576 |
return (
|
| 577 |
<div className="min-h-screen bg-background font-sans text-gray-200 selection:bg-primary selection:text-background pb-20">
|
| 578 |
|
| 579 |
+
{/* Sliding Drawer Sidebar */}
|
| 580 |
+
{isFolderMenuOpen && (
|
| 581 |
+
<>
|
| 582 |
+
{/* Backdrop */}
|
| 583 |
+
<div
|
| 584 |
+
className="fixed inset-0 z-[60] bg-black/60 backdrop-blur-sm animate-in fade-in duration-300"
|
| 585 |
+
onClick={() => setIsFolderMenuOpen(false)}
|
| 586 |
+
/>
|
| 587 |
+
|
| 588 |
+
{/* Sliding Drawer */}
|
| 589 |
+
<div className="fixed top-0 left-0 h-full w-72 bg-[#121212] border-r border-white/10 shadow-2xl z-[70] flex flex-col animate-in slide-in-from-left duration-300">
|
| 590 |
+
<div className="h-20 px-6 border-b border-white/10 flex items-center justify-between shrink-0">
|
| 591 |
+
<span className="font-bold text-lg text-white flex items-center gap-2">
|
| 592 |
+
<Folder size={20} className="text-primary" /> Carpetas
|
| 593 |
+
</span>
|
| 594 |
+
<button onClick={() => setIsFolderMenuOpen(false)} className="text-gray-400 hover:text-white p-2 rounded-lg hover:bg-white/10 transition-colors">
|
| 595 |
+
<ChevronLeft size={20} />
|
| 596 |
+
</button>
|
| 597 |
+
</div>
|
| 598 |
+
|
| 599 |
+
<div className="p-4 border-b border-white/5">
|
| 600 |
+
<div className="relative">
|
| 601 |
+
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500" size={16} />
|
| 602 |
+
<input
|
| 603 |
+
type="text"
|
| 604 |
+
placeholder="Buscar carpeta..."
|
| 605 |
+
className="w-full bg-surface/80 border border-white/5 focus:border-primary/50 rounded-lg py-2 pl-9 pr-3 outline-none text-sm transition-all shadow-inner placeholder:text-gray-600"
|
| 606 |
+
value={folderSearchQuery}
|
| 607 |
+
onChange={(e) => setFolderSearchQuery(e.target.value)}
|
| 608 |
+
/>
|
| 609 |
+
</div>
|
| 610 |
+
</div>
|
| 611 |
+
|
| 612 |
+
<div className="flex-1 overflow-y-auto p-4 custom-scrollbar">
|
| 613 |
+
<div className="flex flex-col gap-1">
|
| 614 |
+
<button
|
| 615 |
+
onClick={() => {
|
| 616 |
+
setCurrentFolderId(null);
|
| 617 |
+
setCurrentPage(1);
|
| 618 |
+
setView('LIST');
|
| 619 |
+
setIsFolderMenuOpen(false);
|
| 620 |
+
}}
|
| 621 |
+
className={`w-full flex items-center gap-3 px-3 py-3 rounded-xl text-sm transition-all ${currentFolderId === null ? 'bg-primary/20 text-primary font-medium' : 'text-gray-400 hover:bg-white/5 hover:text-white'}`}
|
| 622 |
+
>
|
| 623 |
+
<Layers size={18} />
|
| 624 |
+
Raíz
|
| 625 |
+
</button>
|
| 626 |
+
|
| 627 |
+
<div className="my-2 border-t border-white/5"></div>
|
| 628 |
+
|
| 629 |
+
{items.filter(i => i.isFolder && (!folderSearchQuery || (i.title && i.title.toLowerCase().includes(folderSearchQuery.toLowerCase())))).length === 0 && folderSearchQuery && (
|
| 630 |
+
<div className="text-center py-4 text-xs text-gray-500">
|
| 631 |
+
No se encontraron carpetas
|
| 632 |
+
</div>
|
| 633 |
+
)}
|
| 634 |
+
|
| 635 |
+
{items.filter(i => i.isFolder && (!folderSearchQuery || (i.title && i.title.toLowerCase().includes(folderSearchQuery.toLowerCase())))).map(folder => (
|
| 636 |
+
<button
|
| 637 |
+
key={folder.id}
|
| 638 |
+
onClick={() => {
|
| 639 |
+
setCurrentFolderId(folder.id);
|
| 640 |
+
setCurrentPage(1);
|
| 641 |
+
setView('LIST');
|
| 642 |
+
setIsFolderMenuOpen(false);
|
| 643 |
+
}}
|
| 644 |
+
className={`w-full flex items-center gap-3 px-3 py-3 rounded-xl text-sm transition-all text-left truncate ${currentFolderId === folder.id ? 'bg-primary/20 text-primary font-medium' : 'text-gray-400 hover:bg-white/5 hover:text-white'}`}
|
| 645 |
+
>
|
| 646 |
+
<Folder size={18} className="shrink-0" />
|
| 647 |
+
<span className="truncate">{folder.title}</span>
|
| 648 |
+
</button>
|
| 649 |
+
))}
|
| 650 |
+
</div>
|
| 651 |
+
</div>
|
| 652 |
+
</div>
|
| 653 |
+
</>
|
| 654 |
+
)}
|
| 655 |
+
|
| 656 |
{/* Navbar */}
|
| 657 |
<nav className="sticky top-0 z-50 bg-background/80 backdrop-blur-md border-b border-white/5">
|
| 658 |
<div className="w-full max-w-[95%] 2xl:max-w-[1800px] mx-auto px-4 sm:px-6 lg:px-8">
|
| 659 |
<div className="flex items-center justify-between h-20">
|
| 660 |
+
<div className="flex items-center gap-4">
|
| 661 |
+
<div className="relative">
|
| 662 |
+
<Button
|
| 663 |
+
variant="secondary"
|
| 664 |
+
onClick={() => setIsFolderMenuOpen(!isFolderMenuOpen)}
|
| 665 |
+
className="bg-surface border border-white/5 hover:bg-surfaceHover !px-3 justify-center flex items-center gap-2"
|
| 666 |
+
title="Carpetas"
|
| 667 |
+
>
|
| 668 |
+
<Folder size={20} className={isFolderMenuOpen ? "text-primary" : ""} />
|
| 669 |
+
</Button>
|
| 670 |
+
</div>
|
| 671 |
+
|
| 672 |
+
<div
|
| 673 |
+
className="flex items-center gap-2 cursor-pointer group"
|
| 674 |
+
onClick={() => {
|
| 675 |
+
setView('LIST');
|
| 676 |
+
setSearchQuery('');
|
| 677 |
+
setCurrentFolderId(null);
|
| 678 |
+
setCurrentPage(1);
|
| 679 |
+
}}
|
| 680 |
+
>
|
| 681 |
+
<div className="p-2 bg-surface rounded-lg group-hover:bg-primary/20 transition-colors">
|
| 682 |
+
<Layers className="text-primary" size={24} />
|
| 683 |
+
</div>
|
| 684 |
+
<span className="text-lg sm:text-xl font-bold tracking-tight text-white">
|
| 685 |
+
CodeBy<span className="text-primary">Dante</span>
|
| 686 |
+
</span>
|
| 687 |
</div>
|
|
|
|
|
|
|
|
|
|
| 688 |
</div>
|
| 689 |
|
| 690 |
{view === 'LIST' && (
|
Dockerfile
CHANGED
|
@@ -1,33 +1,33 @@
|
|
| 1 |
-
# --- STAGE 1: Build the React Frontend ---
|
| 2 |
-
FROM node:18 AS build-stage
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
COPY package*.json ./
|
| 5 |
-
RUN npm install
|
| 6 |
-
COPY . .
|
| 7 |
-
RUN npm run build
|
| 8 |
-
|
| 9 |
-
# --- STAGE 2: Run the Python Bot + FastAPI Server ---
|
| 10 |
-
FROM python:3.11-slim
|
| 11 |
-
WORKDIR /app
|
| 12 |
-
|
| 13 |
-
# Instalar dependencias del sistema
|
| 14 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 15 |
-
build-essential \
|
| 16 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
-
|
| 18 |
-
# Copiar requerimientos e instalar
|
| 19 |
-
COPY requirements.txt .
|
| 20 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
-
|
| 22 |
-
# Copiar el build del frontend
|
| 23 |
-
COPY --from=build-stage /app/dist /app/dist
|
| 24 |
-
|
| 25 |
-
# Copiar el código del bot
|
| 26 |
-
COPY bot_telegram /app/bot_telegram
|
| 27 |
-
WORKDIR /app/bot_telegram
|
| 28 |
-
|
| 29 |
-
# Exponer el puerto de Hugging Face (7860)
|
| 30 |
-
EXPOSE 7860
|
| 31 |
-
|
| 32 |
-
# El comando de inicio será correr el bot
|
| 33 |
-
CMD ["python", "bot.py"]
|
|
|
|
| 1 |
+
# --- STAGE 1: Build the React Frontend ---
|
| 2 |
+
FROM node:18 AS build-stage
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
COPY package*.json ./
|
| 5 |
+
RUN npm install
|
| 6 |
+
COPY . .
|
| 7 |
+
RUN npm run build
|
| 8 |
+
|
| 9 |
+
# --- STAGE 2: Run the Python Bot + FastAPI Server ---
|
| 10 |
+
FROM python:3.11-slim
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
|
| 13 |
+
# Instalar dependencias del sistema
|
| 14 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 15 |
+
build-essential \
|
| 16 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 17 |
+
|
| 18 |
+
# Copiar requerimientos e instalar
|
| 19 |
+
COPY requirements.txt .
|
| 20 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 21 |
+
|
| 22 |
+
# Copiar el build del frontend
|
| 23 |
+
COPY --from=build-stage /app/dist /app/dist
|
| 24 |
+
|
| 25 |
+
# Copiar el código del bot
|
| 26 |
+
COPY bot_telegram /app/bot_telegram
|
| 27 |
+
WORKDIR /app/bot_telegram
|
| 28 |
+
|
| 29 |
+
# Exponer el puerto de Hugging Face (7860)
|
| 30 |
+
EXPOSE 7860
|
| 31 |
+
|
| 32 |
+
# El comando de inicio será correr el bot
|
| 33 |
+
CMD ["python", "bot.py"]
|
bot_telegram/.env
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
TELEGRAM_BOT_TOKEN=8675706224:AAHqF9lk88MFCn3kUx_4dU_FNU1e7bF5Dv8
|
| 2 |
-
TELEGRAM_API_ID=33226415
|
| 3 |
-
TELEGRAM_API_HASH=01999dae3e5348c7ab0dbcc6f7f4edc5
|
| 4 |
-
TELEGRAM_CHANNEL_ID=-1003976391937
|
| 5 |
-
PORT=8080
|
|
|
|
| 1 |
+
TELEGRAM_BOT_TOKEN=8675706224:AAHqF9lk88MFCn3kUx_4dU_FNU1e7bF5Dv8
|
| 2 |
+
TELEGRAM_API_ID=33226415
|
| 3 |
+
TELEGRAM_API_HASH=01999dae3e5348c7ab0dbcc6f7f4edc5
|
| 4 |
+
TELEGRAM_CHANNEL_ID=-1003976391937
|
| 5 |
+
PORT=8080
|
bot_telegram/README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
| 1 |
-
# Telegram Bot (Python) para CodeByDante
|
| 2 |
-
|
| 3 |
-
Este bot usa **Pyrogram (MTProto)** para gestionar sesiones persistentes y permitir subidas de archivos desde tu página web.
|
| 4 |
-
|
| 5 |
-
## Estructura
|
| 6 |
-
- `bot.py`: Código principal (Bot + API).
|
| 7 |
-
- `sessions/`: Aquí se guarda el archivo `.session` generado automáticamente.
|
| 8 |
-
- `.env`: Configuración de credenciales.
|
| 9 |
-
|
| 10 |
-
## Instalación
|
| 11 |
-
Si no has instalado las dependencias:
|
| 12 |
-
```bash
|
| 13 |
-
pip install pyrogram tgcrypto fastapi uvicorn python-dotenv
|
| 14 |
-
```
|
| 15 |
-
|
| 16 |
-
## Configuración
|
| 17 |
-
1. Edita el archivo `.env`.
|
| 18 |
-
2. Asegúrate de tener los valores correctos de `API_ID`, `API_HASH` y `BOT_TOKEN`.
|
| 19 |
-
3. El `CHANNEL_ID` debe ser el ID del canal donde el bot es admin.
|
| 20 |
-
|
| 21 |
-
## Ejecución
|
| 22 |
-
```bash
|
| 23 |
-
python bot.py
|
| 24 |
-
```
|
| 25 |
-
|
| 26 |
-
Al iniciar por primera vez, se creará el archivo `bot_session.session` dentro de la carpeta `sessions/`.
|
|
|
|
| 1 |
+
# Telegram Bot (Python) para CodeByDante
|
| 2 |
+
|
| 3 |
+
Este bot usa **Pyrogram (MTProto)** para gestionar sesiones persistentes y permitir subidas de archivos desde tu página web.
|
| 4 |
+
|
| 5 |
+
## Estructura
|
| 6 |
+
- `bot.py`: Código principal (Bot + API).
|
| 7 |
+
- `sessions/`: Aquí se guarda el archivo `.session` generado automáticamente.
|
| 8 |
+
- `.env`: Configuración de credenciales.
|
| 9 |
+
|
| 10 |
+
## Instalación
|
| 11 |
+
Si no has instalado las dependencias:
|
| 12 |
+
```bash
|
| 13 |
+
pip install pyrogram tgcrypto fastapi uvicorn python-dotenv
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
## Configuración
|
| 17 |
+
1. Edita el archivo `.env`.
|
| 18 |
+
2. Asegúrate de tener los valores correctos de `API_ID`, `API_HASH` y `BOT_TOKEN`.
|
| 19 |
+
3. El `CHANNEL_ID` debe ser el ID del canal donde el bot es admin.
|
| 20 |
+
|
| 21 |
+
## Ejecución
|
| 22 |
+
```bash
|
| 23 |
+
python bot.py
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
Al iniciar por primera vez, se creará el archivo `bot_session.session` dentro de la carpeta `sessions/`.
|
bot_telegram/bot.py
CHANGED
|
@@ -1,118 +1,118 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import asyncio
|
| 3 |
-
from contextlib import asynccontextmanager
|
| 4 |
-
from telethon import TelegramClient, events
|
| 5 |
-
from fastapi import FastAPI, UploadFile, File
|
| 6 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
-
from fastapi.staticfiles import StaticFiles
|
| 8 |
-
from fastapi.responses import FileResponse
|
| 9 |
-
import uvicorn
|
| 10 |
-
from dotenv import load_dotenv
|
| 11 |
-
|
| 12 |
-
# 1. Configuración
|
| 13 |
-
load_dotenv()
|
| 14 |
-
|
| 15 |
-
API_ID = int(os.getenv("TELEGRAM_API_ID", "0"))
|
| 16 |
-
API_HASH = os.getenv("TELEGRAM_API_HASH", "")
|
| 17 |
-
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN", "")
|
| 18 |
-
CHANNEL_ID = int(os.getenv("TELEGRAM_CHANNEL_ID", "0"))
|
| 19 |
-
|
| 20 |
-
# FORZAMOS el puerto 7860 para Hugging Face (NO CAMBIAR)
|
| 21 |
-
PORT = 7860
|
| 22 |
-
|
| 23 |
-
if not os.path.exists("sessions"):
|
| 24 |
-
os.makedirs("sessions")
|
| 25 |
-
|
| 26 |
-
# 2. Inicializar Cliente de Telethon
|
| 27 |
-
client = TelegramClient('sessions/bot_session', API_ID, API_HASH)
|
| 28 |
-
|
| 29 |
-
# --- CICLO DE VIDA (LIFESPAN) ---
|
| 30 |
-
# Esto asegura que el bot arranque sin importar cómo se inicie el servidor
|
| 31 |
-
@asynccontextmanager
|
| 32 |
-
async def lifespan(app: FastAPI):
|
| 33 |
-
print("--- INICIANDO SISTEMA HÍBRIDO ---")
|
| 34 |
-
print(f"Puerto detectado: {PORT}")
|
| 35 |
-
try:
|
| 36 |
-
print("Iniciando Bot de Telegram...")
|
| 37 |
-
await client.start(bot_token=BOT_TOKEN)
|
| 38 |
-
print("¡Bot en línea y escuchando!")
|
| 39 |
-
except Exception as e:
|
| 40 |
-
print(f"ERROR AL INICIAR BOT: {e}")
|
| 41 |
-
|
| 42 |
-
yield
|
| 43 |
-
|
| 44 |
-
print("Apagando sistema...")
|
| 45 |
-
await client.disconnect()
|
| 46 |
-
|
| 47 |
-
# 3. Servidor API con FastAPI
|
| 48 |
-
app_api = FastAPI(lifespan=lifespan)
|
| 49 |
-
|
| 50 |
-
app_api.add_middleware(
|
| 51 |
-
CORSMiddleware,
|
| 52 |
-
allow_origins=["*"],
|
| 53 |
-
allow_methods=["*"],
|
| 54 |
-
allow_headers=["*"],
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
# --- COMANDOS DEL BOT ---
|
| 58 |
-
|
| 59 |
-
@client.on(events.NewMessage(pattern='/start'))
|
| 60 |
-
async def start_handler(event):
|
| 61 |
-
parts = event.raw_text.split()
|
| 62 |
-
if len(parts) > 1:
|
| 63 |
-
try:
|
| 64 |
-
msg_id = int(parts[1])
|
| 65 |
-
await client.forward_messages(event.chat_id, msg_id, CHANNEL_ID)
|
| 66 |
-
return
|
| 67 |
-
except:
|
| 68 |
-
pass
|
| 69 |
-
await event.respond('¡Hola! Soy el bot de CodeByDante. Usa la web para descargar tus archivos.')
|
| 70 |
-
|
| 71 |
-
# --- ENDPOINTS DE LA API ---
|
| 72 |
-
|
| 73 |
-
@app_api.post("/upload")
|
| 74 |
-
async def upload_file(file: UploadFile = File(...)):
|
| 75 |
-
try:
|
| 76 |
-
file_path = f"temp_{file.filename}"
|
| 77 |
-
with open(file_path, "wb") as buffer:
|
| 78 |
-
content = await file.read()
|
| 79 |
-
buffer.write(content)
|
| 80 |
-
|
| 81 |
-
print(f"Subiendo '{file.filename}' a Telegram...")
|
| 82 |
-
sent_msg = await client.send_file(CHANNEL_ID, file_path)
|
| 83 |
-
os.remove(file_path)
|
| 84 |
-
|
| 85 |
-
return {
|
| 86 |
-
"status": "success",
|
| 87 |
-
"message_id": sent_msg.id,
|
| 88 |
-
"channel_id": CHANNEL_ID
|
| 89 |
-
}
|
| 90 |
-
except Exception as e:
|
| 91 |
-
print(f"Error en upload: {e}")
|
| 92 |
-
return {"status": "error", "message": str(e)}
|
| 93 |
-
|
| 94 |
-
# --- SERVIR FRONTEND ---
|
| 95 |
-
|
| 96 |
-
dist_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "dist"))
|
| 97 |
-
|
| 98 |
-
if os.path.exists(dist_path):
|
| 99 |
-
print(f"Sirviendo frontend desde: {dist_path}")
|
| 100 |
-
app_api.mount("/assets", StaticFiles(directory=os.path.join(dist_path, "assets")), name="assets")
|
| 101 |
-
|
| 102 |
-
@app_api.get("/")
|
| 103 |
-
async def serve_index():
|
| 104 |
-
return FileResponse(os.path.join(dist_path, "index.html"))
|
| 105 |
-
|
| 106 |
-
@app_api.get("/{full_path:path}")
|
| 107 |
-
async def serve_spa(full_path: str):
|
| 108 |
-
local_file = os.path.join(dist_path, full_path)
|
| 109 |
-
if os.path.exists(local_file) and os.path.isfile(local_file):
|
| 110 |
-
return FileResponse(local_file)
|
| 111 |
-
return FileResponse(os.path.join(dist_path, "index.html"))
|
| 112 |
-
else:
|
| 113 |
-
@app_api.get("/")
|
| 114 |
-
async def hello():
|
| 115 |
-
return {"message": "Servidor activo. Carpeta 'dist' no encontrada."}
|
| 116 |
-
|
| 117 |
-
if __name__ == '__main__':
|
| 118 |
-
uvicorn.run(app_api, host="0.0.0.0", port=PORT)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import asyncio
|
| 3 |
+
from contextlib import asynccontextmanager
|
| 4 |
+
from telethon import TelegramClient, events
|
| 5 |
+
from fastapi import FastAPI, UploadFile, File
|
| 6 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
+
from fastapi.staticfiles import StaticFiles
|
| 8 |
+
from fastapi.responses import FileResponse
|
| 9 |
+
import uvicorn
|
| 10 |
+
from dotenv import load_dotenv
|
| 11 |
+
|
| 12 |
+
# 1. Configuración
|
| 13 |
+
load_dotenv()
|
| 14 |
+
|
| 15 |
+
API_ID = int(os.getenv("TELEGRAM_API_ID", "0"))
|
| 16 |
+
API_HASH = os.getenv("TELEGRAM_API_HASH", "")
|
| 17 |
+
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN", "")
|
| 18 |
+
CHANNEL_ID = int(os.getenv("TELEGRAM_CHANNEL_ID", "0"))
|
| 19 |
+
|
| 20 |
+
# FORZAMOS el puerto 7860 para Hugging Face (NO CAMBIAR)
|
| 21 |
+
PORT = 7860
|
| 22 |
+
|
| 23 |
+
if not os.path.exists("sessions"):
|
| 24 |
+
os.makedirs("sessions")
|
| 25 |
+
|
| 26 |
+
# 2. Inicializar Cliente de Telethon
|
| 27 |
+
client = TelegramClient('sessions/bot_session', API_ID, API_HASH)
|
| 28 |
+
|
| 29 |
+
# --- CICLO DE VIDA (LIFESPAN) ---
|
| 30 |
+
# Esto asegura que el bot arranque sin importar cómo se inicie el servidor
|
| 31 |
+
@asynccontextmanager
|
| 32 |
+
async def lifespan(app: FastAPI):
|
| 33 |
+
print("--- INICIANDO SISTEMA HÍBRIDO ---")
|
| 34 |
+
print(f"Puerto detectado: {PORT}")
|
| 35 |
+
try:
|
| 36 |
+
print("Iniciando Bot de Telegram...")
|
| 37 |
+
await client.start(bot_token=BOT_TOKEN)
|
| 38 |
+
print("¡Bot en línea y escuchando!")
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(f"ERROR AL INICIAR BOT: {e}")
|
| 41 |
+
|
| 42 |
+
yield
|
| 43 |
+
|
| 44 |
+
print("Apagando sistema...")
|
| 45 |
+
await client.disconnect()
|
| 46 |
+
|
| 47 |
+
# 3. Servidor API con FastAPI
|
| 48 |
+
app_api = FastAPI(lifespan=lifespan)
|
| 49 |
+
|
| 50 |
+
app_api.add_middleware(
|
| 51 |
+
CORSMiddleware,
|
| 52 |
+
allow_origins=["*"],
|
| 53 |
+
allow_methods=["*"],
|
| 54 |
+
allow_headers=["*"],
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# --- COMANDOS DEL BOT ---
|
| 58 |
+
|
| 59 |
+
@client.on(events.NewMessage(pattern='/start'))
|
| 60 |
+
async def start_handler(event):
|
| 61 |
+
parts = event.raw_text.split()
|
| 62 |
+
if len(parts) > 1:
|
| 63 |
+
try:
|
| 64 |
+
msg_id = int(parts[1])
|
| 65 |
+
await client.forward_messages(event.chat_id, msg_id, CHANNEL_ID)
|
| 66 |
+
return
|
| 67 |
+
except:
|
| 68 |
+
pass
|
| 69 |
+
await event.respond('¡Hola! Soy el bot de CodeByDante. Usa la web para descargar tus archivos.')
|
| 70 |
+
|
| 71 |
+
# --- ENDPOINTS DE LA API ---
|
| 72 |
+
|
| 73 |
+
@app_api.post("/upload")
|
| 74 |
+
async def upload_file(file: UploadFile = File(...)):
|
| 75 |
+
try:
|
| 76 |
+
file_path = f"temp_{file.filename}"
|
| 77 |
+
with open(file_path, "wb") as buffer:
|
| 78 |
+
content = await file.read()
|
| 79 |
+
buffer.write(content)
|
| 80 |
+
|
| 81 |
+
print(f"Subiendo '{file.filename}' a Telegram...")
|
| 82 |
+
sent_msg = await client.send_file(CHANNEL_ID, file_path)
|
| 83 |
+
os.remove(file_path)
|
| 84 |
+
|
| 85 |
+
return {
|
| 86 |
+
"status": "success",
|
| 87 |
+
"message_id": sent_msg.id,
|
| 88 |
+
"channel_id": CHANNEL_ID
|
| 89 |
+
}
|
| 90 |
+
except Exception as e:
|
| 91 |
+
print(f"Error en upload: {e}")
|
| 92 |
+
return {"status": "error", "message": str(e)}
|
| 93 |
+
|
| 94 |
+
# --- SERVIR FRONTEND ---
|
| 95 |
+
|
| 96 |
+
dist_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "dist"))
|
| 97 |
+
|
| 98 |
+
if os.path.exists(dist_path):
|
| 99 |
+
print(f"Sirviendo frontend desde: {dist_path}")
|
| 100 |
+
app_api.mount("/assets", StaticFiles(directory=os.path.join(dist_path, "assets")), name="assets")
|
| 101 |
+
|
| 102 |
+
@app_api.get("/")
|
| 103 |
+
async def serve_index():
|
| 104 |
+
return FileResponse(os.path.join(dist_path, "index.html"))
|
| 105 |
+
|
| 106 |
+
@app_api.get("/{full_path:path}")
|
| 107 |
+
async def serve_spa(full_path: str):
|
| 108 |
+
local_file = os.path.join(dist_path, full_path)
|
| 109 |
+
if os.path.exists(local_file) and os.path.isfile(local_file):
|
| 110 |
+
return FileResponse(local_file)
|
| 111 |
+
return FileResponse(os.path.join(dist_path, "index.html"))
|
| 112 |
+
else:
|
| 113 |
+
@app_api.get("/")
|
| 114 |
+
async def hello():
|
| 115 |
+
return {"message": "Servidor activo. Carpeta 'dist' no encontrada."}
|
| 116 |
+
|
| 117 |
+
if __name__ == '__main__':
|
| 118 |
+
uvicorn.run(app_api, host="0.0.0.0", port=PORT)
|
bot_telegram/go.mod
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
module bot_telegram
|
| 2 |
-
|
| 3 |
-
go 1.26.1
|
| 4 |
-
|
| 5 |
-
require (
|
| 6 |
-
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 // indirect
|
| 7 |
-
github.com/joho/godotenv v1.5.1 // indirect
|
| 8 |
-
)
|
|
|
|
| 1 |
+
module bot_telegram
|
| 2 |
+
|
| 3 |
+
go 1.26.1
|
| 4 |
+
|
| 5 |
+
require (
|
| 6 |
+
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 // indirect
|
| 7 |
+
github.com/joho/godotenv v1.5.1 // indirect
|
| 8 |
+
)
|
bot_telegram/go.sum
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
|
| 2 |
-
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
|
| 3 |
-
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
| 4 |
-
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
|
|
|
| 1 |
+
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
|
| 2 |
+
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
|
| 3 |
+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
| 4 |
+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
bot_telegram/main.go
CHANGED
|
@@ -1,123 +1,123 @@
|
|
| 1 |
-
package main
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"fmt"
|
| 5 |
-
"io"
|
| 6 |
-
"log"
|
| 7 |
-
"net/http"
|
| 8 |
-
"os"
|
| 9 |
-
"strconv"
|
| 10 |
-
|
| 11 |
-
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
| 12 |
-
"github.com/joho/godotenv"
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
func main() {
|
| 16 |
-
// 1. Cargar variables de entorno
|
| 17 |
-
err := godotenv.Load()
|
| 18 |
-
if err != nil {
|
| 19 |
-
log.Println("Aviso: No se encontró archivo .env, usando variables de sistema")
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
token := os.Getenv("TELEGRAM_BOT_TOKEN")
|
| 23 |
-
channelIDStr := os.Getenv("TELEGRAM_CHANNEL_ID")
|
| 24 |
-
port := os.Getenv("PORT")
|
| 25 |
-
if port == "" {
|
| 26 |
-
port = "8080"
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
if token == "" || token == "tu_token_aqui" {
|
| 30 |
-
log.Fatal("ERROR: TELEGRAM_BOT_TOKEN no configurado en .env")
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
channelID, _ := strconv.ParseInt(channelIDStr, 10, 64)
|
| 34 |
-
|
| 35 |
-
// 2. Inicializar Bot de Telegram
|
| 36 |
-
bot, err := tgbotapi.NewBotAPI(token)
|
| 37 |
-
if err != nil {
|
| 38 |
-
log.Panic(err)
|
| 39 |
-
}
|
| 40 |
-
|
| 41 |
-
bot.Debug = true
|
| 42 |
-
log.Printf("Bot autorizado en la cuenta: %s", bot.Self.UserName)
|
| 43 |
-
|
| 44 |
-
// 3. Goroutine para manejar mensajes entrantes (Útil para obtener IDs de canales)
|
| 45 |
-
go func() {
|
| 46 |
-
u := tgbotapi.NewUpdate(0)
|
| 47 |
-
u.Timeout = 60
|
| 48 |
-
updates := bot.GetUpdatesChan(u)
|
| 49 |
-
|
| 50 |
-
for update := range updates {
|
| 51 |
-
if update.Message != nil {
|
| 52 |
-
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
| 53 |
-
|
| 54 |
-
// Responder con el ID del chat si el usuario envía /id
|
| 55 |
-
if update.Message.Text == "/id" {
|
| 56 |
-
msg := tgbotapi.NewMessage(update.Message.Chat.ID, fmt.Sprintf("El ID de este chat es: %d", update.Message.Chat.ID))
|
| 57 |
-
bot.Send(msg)
|
| 58 |
-
}
|
| 59 |
-
}
|
| 60 |
-
}
|
| 61 |
-
}()
|
| 62 |
-
|
| 63 |
-
// 4. Servidor HTTP para recibir archivos de la Web
|
| 64 |
-
http.HandleFunc("/upload", func(w http.ResponseWriter, r *http.Request) {
|
| 65 |
-
// Habilitar CORS para que tu página web pueda conectar
|
| 66 |
-
w.Header().Set("Access-Control-Allow-Origin", "*")
|
| 67 |
-
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
| 68 |
-
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
| 69 |
-
|
| 70 |
-
if r.Method == "OPTIONS" {
|
| 71 |
-
return
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
if r.Method != "POST" {
|
| 75 |
-
http.Error(w, "Método no permitido", http.StatusMethodNotAllowed)
|
| 76 |
-
return
|
| 77 |
-
}
|
| 78 |
-
|
| 79 |
-
// Recibir el archivo del formulario
|
| 80 |
-
file, header, err := r.FormFile("file")
|
| 81 |
-
if err != nil {
|
| 82 |
-
http.Error(w, "Error al recibir archivo: "+err.Error(), http.StatusBadRequest)
|
| 83 |
-
return
|
| 84 |
-
}
|
| 85 |
-
defer file.Close()
|
| 86 |
-
|
| 87 |
-
log.Printf("Recibiendo archivo: %s (%d bytes)", header.Filename, header.Size)
|
| 88 |
-
|
| 89 |
-
// Preparar el envío a Telegram
|
| 90 |
-
fileBytes, err := io.ReadAll(file)
|
| 91 |
-
if err != nil {
|
| 92 |
-
http.Error(w, "Error al leer archivo", http.StatusInternalServerError)
|
| 93 |
-
return
|
| 94 |
-
}
|
| 95 |
-
|
| 96 |
-
// Crear el archivo para Telegram
|
| 97 |
-
// Puedes usar NewDocument (genérico) o NewVideo según el tipo
|
| 98 |
-
fileData := tgbotapi.FileBytes{
|
| 99 |
-
Name: header.Filename,
|
| 100 |
-
Bytes: fileBytes,
|
| 101 |
-
}
|
| 102 |
-
|
| 103 |
-
// Enviamos como documento por defecto para no perder calidad
|
| 104 |
-
docMsg := tgbotapi.NewDocument(channelID, fileData)
|
| 105 |
-
docMsg.Caption = "Archivo subido desde CodeByDante: " + header.Filename
|
| 106 |
-
|
| 107 |
-
sentMsg, err := bot.Send(docMsg)
|
| 108 |
-
if err != nil {
|
| 109 |
-
http.Error(w, "Error al enviar a Telegram: "+err.Error(), http.StatusInternalServerError)
|
| 110 |
-
return
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
// Responder con el ID del mensaje para guardarlo en Firebase
|
| 114 |
-
response := fmt.Sprintf("{\"status\": \"success\", \"message_id\": %d, \"channel_id\": %d}", sentMsg.MessageID, channelID)
|
| 115 |
-
w.Header().Set("Content-Type", "application/json")
|
| 116 |
-
w.Write([]byte(response))
|
| 117 |
-
|
| 118 |
-
log.Printf("Archivo enviado con éxito a Telegram. MessageID: %d", sentMsg.MessageID)
|
| 119 |
-
})
|
| 120 |
-
|
| 121 |
-
log.Printf("Servidor API escuchando en el puerto %s...", port)
|
| 122 |
-
log.Fatal(http.ListenAndServe(":"+port, nil))
|
| 123 |
-
}
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
"io"
|
| 6 |
+
"log"
|
| 7 |
+
"net/http"
|
| 8 |
+
"os"
|
| 9 |
+
"strconv"
|
| 10 |
+
|
| 11 |
+
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
| 12 |
+
"github.com/joho/godotenv"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
func main() {
|
| 16 |
+
// 1. Cargar variables de entorno
|
| 17 |
+
err := godotenv.Load()
|
| 18 |
+
if err != nil {
|
| 19 |
+
log.Println("Aviso: No se encontró archivo .env, usando variables de sistema")
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
token := os.Getenv("TELEGRAM_BOT_TOKEN")
|
| 23 |
+
channelIDStr := os.Getenv("TELEGRAM_CHANNEL_ID")
|
| 24 |
+
port := os.Getenv("PORT")
|
| 25 |
+
if port == "" {
|
| 26 |
+
port = "8080"
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
if token == "" || token == "tu_token_aqui" {
|
| 30 |
+
log.Fatal("ERROR: TELEGRAM_BOT_TOKEN no configurado en .env")
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
channelID, _ := strconv.ParseInt(channelIDStr, 10, 64)
|
| 34 |
+
|
| 35 |
+
// 2. Inicializar Bot de Telegram
|
| 36 |
+
bot, err := tgbotapi.NewBotAPI(token)
|
| 37 |
+
if err != nil {
|
| 38 |
+
log.Panic(err)
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
bot.Debug = true
|
| 42 |
+
log.Printf("Bot autorizado en la cuenta: %s", bot.Self.UserName)
|
| 43 |
+
|
| 44 |
+
// 3. Goroutine para manejar mensajes entrantes (Útil para obtener IDs de canales)
|
| 45 |
+
go func() {
|
| 46 |
+
u := tgbotapi.NewUpdate(0)
|
| 47 |
+
u.Timeout = 60
|
| 48 |
+
updates := bot.GetUpdatesChan(u)
|
| 49 |
+
|
| 50 |
+
for update := range updates {
|
| 51 |
+
if update.Message != nil {
|
| 52 |
+
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
| 53 |
+
|
| 54 |
+
// Responder con el ID del chat si el usuario envía /id
|
| 55 |
+
if update.Message.Text == "/id" {
|
| 56 |
+
msg := tgbotapi.NewMessage(update.Message.Chat.ID, fmt.Sprintf("El ID de este chat es: %d", update.Message.Chat.ID))
|
| 57 |
+
bot.Send(msg)
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}()
|
| 62 |
+
|
| 63 |
+
// 4. Servidor HTTP para recibir archivos de la Web
|
| 64 |
+
http.HandleFunc("/upload", func(w http.ResponseWriter, r *http.Request) {
|
| 65 |
+
// Habilitar CORS para que tu página web pueda conectar
|
| 66 |
+
w.Header().Set("Access-Control-Allow-Origin", "*")
|
| 67 |
+
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
| 68 |
+
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
| 69 |
+
|
| 70 |
+
if r.Method == "OPTIONS" {
|
| 71 |
+
return
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
if r.Method != "POST" {
|
| 75 |
+
http.Error(w, "Método no permitido", http.StatusMethodNotAllowed)
|
| 76 |
+
return
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// Recibir el archivo del formulario
|
| 80 |
+
file, header, err := r.FormFile("file")
|
| 81 |
+
if err != nil {
|
| 82 |
+
http.Error(w, "Error al recibir archivo: "+err.Error(), http.StatusBadRequest)
|
| 83 |
+
return
|
| 84 |
+
}
|
| 85 |
+
defer file.Close()
|
| 86 |
+
|
| 87 |
+
log.Printf("Recibiendo archivo: %s (%d bytes)", header.Filename, header.Size)
|
| 88 |
+
|
| 89 |
+
// Preparar el envío a Telegram
|
| 90 |
+
fileBytes, err := io.ReadAll(file)
|
| 91 |
+
if err != nil {
|
| 92 |
+
http.Error(w, "Error al leer archivo", http.StatusInternalServerError)
|
| 93 |
+
return
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
// Crear el archivo para Telegram
|
| 97 |
+
// Puedes usar NewDocument (genérico) o NewVideo según el tipo
|
| 98 |
+
fileData := tgbotapi.FileBytes{
|
| 99 |
+
Name: header.Filename,
|
| 100 |
+
Bytes: fileBytes,
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// Enviamos como documento por defecto para no perder calidad
|
| 104 |
+
docMsg := tgbotapi.NewDocument(channelID, fileData)
|
| 105 |
+
docMsg.Caption = "Archivo subido desde CodeByDante: " + header.Filename
|
| 106 |
+
|
| 107 |
+
sentMsg, err := bot.Send(docMsg)
|
| 108 |
+
if err != nil {
|
| 109 |
+
http.Error(w, "Error al enviar a Telegram: "+err.Error(), http.StatusInternalServerError)
|
| 110 |
+
return
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// Responder con el ID del mensaje para guardarlo en Firebase
|
| 114 |
+
response := fmt.Sprintf("{\"status\": \"success\", \"message_id\": %d, \"channel_id\": %d}", sentMsg.MessageID, channelID)
|
| 115 |
+
w.Header().Set("Content-Type", "application/json")
|
| 116 |
+
w.Write([]byte(response))
|
| 117 |
+
|
| 118 |
+
log.Printf("Archivo enviado con éxito a Telegram. MessageID: %d", sentMsg.MessageID)
|
| 119 |
+
})
|
| 120 |
+
|
| 121 |
+
log.Printf("Servidor API escuchando en el puerto %s...", port)
|
| 122 |
+
log.Fatal(http.ListenAndServe(":"+port, nil))
|
| 123 |
+
}
|
bot_telegram/sessions/bot_session.session
CHANGED
|
Binary files a/bot_telegram/sessions/bot_session.session and b/bot_telegram/sessions/bot_session.session differ
|
|
|
components/AdminLoginModal.tsx
CHANGED
|
@@ -1,158 +1,158 @@
|
|
| 1 |
-
import React, { useState, useEffect } from 'react';
|
| 2 |
-
import { Lock, X, KeyRound } from 'lucide-react';
|
| 3 |
-
import { Button } from './Button';
|
| 4 |
-
|
| 5 |
-
interface AdminLoginModalProps {
|
| 6 |
-
isOpen: boolean;
|
| 7 |
-
onClose: () => void;
|
| 8 |
-
onSuccess: () => void;
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
export const AdminLoginModal: React.FC<AdminLoginModalProps> = ({ isOpen, onClose, onSuccess }) => {
|
| 12 |
-
const [password, setPassword] = useState('');
|
| 13 |
-
const [error, setError] = useState(false);
|
| 14 |
-
const [isAnimating, setIsAnimating] = useState(false);
|
| 15 |
-
|
| 16 |
-
useEffect(() => {
|
| 17 |
-
if (isOpen) {
|
| 18 |
-
setIsAnimating(true);
|
| 19 |
-
setPassword('');
|
| 20 |
-
setError(false);
|
| 21 |
-
} else {
|
| 22 |
-
setTimeout(() => setIsAnimating(false), 200);
|
| 23 |
-
}
|
| 24 |
-
}, [isOpen]);
|
| 25 |
-
|
| 26 |
-
if (!isOpen && !isAnimating) return null;
|
| 27 |
-
|
| 28 |
-
const handleLogin = async () => {
|
| 29 |
-
try {
|
| 30 |
-
console.log('[AdminLogin] Starting login process...');
|
| 31 |
-
|
| 32 |
-
if (!password) {
|
| 33 |
-
console.log('[AdminLogin] No password entered');
|
| 34 |
-
setError(true);
|
| 35 |
-
return;
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
if (!window.crypto || !window.crypto.subtle) {
|
| 39 |
-
console.error('[AdminLogin] Crypto API not available', { crypto: !!window.crypto, subtle: !!window.crypto?.subtle });
|
| 40 |
-
alert('Error crítico: Tu navegador no soporta la encriptación necesaria (crypto.subtle). Por favor usa un navegador moderno o contexto seguro (HTTPS/localhost).');
|
| 41 |
-
return;
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
const encoder = new TextEncoder();
|
| 45 |
-
const data = encoder.encode(password);
|
| 46 |
-
|
| 47 |
-
console.log('[AdminLogin] Hashing password...');
|
| 48 |
-
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
| 49 |
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
| 50 |
-
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
| 51 |
-
|
| 52 |
-
console.log('[AdminLogin] Hash generated:', hashHex);
|
| 53 |
-
|
| 54 |
-
// Hash for 'codebydante069012*'
|
| 55 |
-
const expectedHash = '19362a1b321cd1b4fe5a625b8a6647a371beebebd3daddccdb2ed271a9a7ee5d';
|
| 56 |
-
|
| 57 |
-
if (hashHex === expectedHash) {
|
| 58 |
-
console.log('[AdminLogin] Password correct!');
|
| 59 |
-
onSuccess();
|
| 60 |
-
onClose();
|
| 61 |
-
} else {
|
| 62 |
-
console.warn('[AdminLogin] Password incorrect. Expected:', expectedHash, 'Got:', hashHex);
|
| 63 |
-
setError(true);
|
| 64 |
-
}
|
| 65 |
-
} catch (e: any) {
|
| 66 |
-
console.error('[AdminLogin] Unexpected error:', e);
|
| 67 |
-
alert(`Error inesperado: ${e.message || e}`);
|
| 68 |
-
}
|
| 69 |
-
};
|
| 70 |
-
|
| 71 |
-
const handleKeyDown = (e: React.KeyboardEvent) => {
|
| 72 |
-
if (e.key === 'Enter') {
|
| 73 |
-
handleLogin();
|
| 74 |
-
}
|
| 75 |
-
};
|
| 76 |
-
|
| 77 |
-
return (
|
| 78 |
-
<div
|
| 79 |
-
className={`fixed inset-0 z-50 flex items-center justify-center p-4 transition-all duration-300 ${isOpen ? 'opacity-100 backdrop-blur-sm bg-black/50' : 'opacity-0 pointer-events-none'
|
| 80 |
-
}`}
|
| 81 |
-
>
|
| 82 |
-
<div
|
| 83 |
-
className={`bg-[#1a1a1a] border border-white/10 rounded-2xl w-full max-w-md overflow-hidden shadow-2xl transition-all duration-300 transform ${isOpen ? 'scale-100 translate-y-0' : 'scale-95 translate-y-4'
|
| 84 |
-
}`}
|
| 85 |
-
>
|
| 86 |
-
{/* Header */}
|
| 87 |
-
<div className="flex items-center justify-between p-6 border-b border-white/5">
|
| 88 |
-
<div className="flex items-center gap-3">
|
| 89 |
-
<div className="p-2 bg-primary/20 rounded-lg">
|
| 90 |
-
<Lock className="w-6 h-6 text-primary" />
|
| 91 |
-
</div>
|
| 92 |
-
<div>
|
| 93 |
-
<h2 className="text-lg font-bold text-white">Acceso Administrativo</h2>
|
| 94 |
-
<p className="text-xs text-gray-400">Introduce la credencial de seguridad</p>
|
| 95 |
-
</div>
|
| 96 |
-
</div>
|
| 97 |
-
<button
|
| 98 |
-
onClick={onClose}
|
| 99 |
-
className="text-gray-400 hover:text-white transition-colors p-1"
|
| 100 |
-
>
|
| 101 |
-
<X size={20} />
|
| 102 |
-
</button>
|
| 103 |
-
</div>
|
| 104 |
-
|
| 105 |
-
{/* Content */}
|
| 106 |
-
<div className="p-6 space-y-4">
|
| 107 |
-
<div className="bg-primary/5 border border-primary/20 rounded-lg p-3 text-xs text-primary/80">
|
| 108 |
-
<p>Esta zona está protegida. Solo personal autorizado.</p>
|
| 109 |
-
</div>
|
| 110 |
-
|
| 111 |
-
<div className="space-y-2">
|
| 112 |
-
<label className="text-sm font-medium text-gray-300 flex items-center gap-2">
|
| 113 |
-
<KeyRound size={14} /> Tu Clave Maestra
|
| 114 |
-
</label>
|
| 115 |
-
<input
|
| 116 |
-
type="password"
|
| 117 |
-
value={password}
|
| 118 |
-
onChange={(e) => {
|
| 119 |
-
setPassword(e.target.value);
|
| 120 |
-
setError(false);
|
| 121 |
-
}}
|
| 122 |
-
onKeyDown={handleKeyDown}
|
| 123 |
-
className={`w-full bg-black/40 border rounded-lg px-4 py-3 text-white placeholder-gray-600 outline-none focus:ring-1 transition-all ${error
|
| 124 |
-
? 'border-red-500 focus:border-red-500 focus:ring-red-500/20'
|
| 125 |
-
: 'border-white/10 focus:border-primary focus:ring-primary/20'
|
| 126 |
-
}`}
|
| 127 |
-
placeholder="••••••••••••••"
|
| 128 |
-
autoFocus
|
| 129 |
-
/>
|
| 130 |
-
{error && (
|
| 131 |
-
<p className="text-xs text-red-500 animate-pulse">
|
| 132 |
-
Acceso denegado. Credencial inválida.
|
| 133 |
-
</p>
|
| 134 |
-
)}
|
| 135 |
-
</div>
|
| 136 |
-
</div>
|
| 137 |
-
|
| 138 |
-
{/* Footer */}
|
| 139 |
-
<div className="p-6 pt-0 flex gap-3">
|
| 140 |
-
<Button
|
| 141 |
-
variant="danger"
|
| 142 |
-
onClick={onClose}
|
| 143 |
-
className="flex-1 bg-white/5 border-white/10 hover:bg-white/10"
|
| 144 |
-
>
|
| 145 |
-
Cancelar
|
| 146 |
-
</Button>
|
| 147 |
-
<Button
|
| 148 |
-
variant="primary"
|
| 149 |
-
onClick={handleLogin}
|
| 150 |
-
className="flex-1"
|
| 151 |
-
>
|
| 152 |
-
Acceder
|
| 153 |
-
</Button>
|
| 154 |
-
</div>
|
| 155 |
-
</div>
|
| 156 |
-
</div>
|
| 157 |
-
);
|
| 158 |
-
};
|
|
|
|
| 1 |
+
import React, { useState, useEffect } from 'react';
|
| 2 |
+
import { Lock, X, KeyRound } from 'lucide-react';
|
| 3 |
+
import { Button } from './Button';
|
| 4 |
+
|
| 5 |
+
interface AdminLoginModalProps {
|
| 6 |
+
isOpen: boolean;
|
| 7 |
+
onClose: () => void;
|
| 8 |
+
onSuccess: () => void;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
export const AdminLoginModal: React.FC<AdminLoginModalProps> = ({ isOpen, onClose, onSuccess }) => {
|
| 12 |
+
const [password, setPassword] = useState('');
|
| 13 |
+
const [error, setError] = useState(false);
|
| 14 |
+
const [isAnimating, setIsAnimating] = useState(false);
|
| 15 |
+
|
| 16 |
+
useEffect(() => {
|
| 17 |
+
if (isOpen) {
|
| 18 |
+
setIsAnimating(true);
|
| 19 |
+
setPassword('');
|
| 20 |
+
setError(false);
|
| 21 |
+
} else {
|
| 22 |
+
setTimeout(() => setIsAnimating(false), 200);
|
| 23 |
+
}
|
| 24 |
+
}, [isOpen]);
|
| 25 |
+
|
| 26 |
+
if (!isOpen && !isAnimating) return null;
|
| 27 |
+
|
| 28 |
+
const handleLogin = async () => {
|
| 29 |
+
try {
|
| 30 |
+
console.log('[AdminLogin] Starting login process...');
|
| 31 |
+
|
| 32 |
+
if (!password) {
|
| 33 |
+
console.log('[AdminLogin] No password entered');
|
| 34 |
+
setError(true);
|
| 35 |
+
return;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
if (!window.crypto || !window.crypto.subtle) {
|
| 39 |
+
console.error('[AdminLogin] Crypto API not available', { crypto: !!window.crypto, subtle: !!window.crypto?.subtle });
|
| 40 |
+
alert('Error crítico: Tu navegador no soporta la encriptación necesaria (crypto.subtle). Por favor usa un navegador moderno o contexto seguro (HTTPS/localhost).');
|
| 41 |
+
return;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
const encoder = new TextEncoder();
|
| 45 |
+
const data = encoder.encode(password);
|
| 46 |
+
|
| 47 |
+
console.log('[AdminLogin] Hashing password...');
|
| 48 |
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
| 49 |
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
| 50 |
+
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
| 51 |
+
|
| 52 |
+
console.log('[AdminLogin] Hash generated:', hashHex);
|
| 53 |
+
|
| 54 |
+
// Hash for 'codebydante069012*'
|
| 55 |
+
const expectedHash = '19362a1b321cd1b4fe5a625b8a6647a371beebebd3daddccdb2ed271a9a7ee5d';
|
| 56 |
+
|
| 57 |
+
if (hashHex === expectedHash) {
|
| 58 |
+
console.log('[AdminLogin] Password correct!');
|
| 59 |
+
onSuccess();
|
| 60 |
+
onClose();
|
| 61 |
+
} else {
|
| 62 |
+
console.warn('[AdminLogin] Password incorrect. Expected:', expectedHash, 'Got:', hashHex);
|
| 63 |
+
setError(true);
|
| 64 |
+
}
|
| 65 |
+
} catch (e: any) {
|
| 66 |
+
console.error('[AdminLogin] Unexpected error:', e);
|
| 67 |
+
alert(`Error inesperado: ${e.message || e}`);
|
| 68 |
+
}
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
const handleKeyDown = (e: React.KeyboardEvent) => {
|
| 72 |
+
if (e.key === 'Enter') {
|
| 73 |
+
handleLogin();
|
| 74 |
+
}
|
| 75 |
+
};
|
| 76 |
+
|
| 77 |
+
return (
|
| 78 |
+
<div
|
| 79 |
+
className={`fixed inset-0 z-50 flex items-center justify-center p-4 transition-all duration-300 ${isOpen ? 'opacity-100 backdrop-blur-sm bg-black/50' : 'opacity-0 pointer-events-none'
|
| 80 |
+
}`}
|
| 81 |
+
>
|
| 82 |
+
<div
|
| 83 |
+
className={`bg-[#1a1a1a] border border-white/10 rounded-2xl w-full max-w-md overflow-hidden shadow-2xl transition-all duration-300 transform ${isOpen ? 'scale-100 translate-y-0' : 'scale-95 translate-y-4'
|
| 84 |
+
}`}
|
| 85 |
+
>
|
| 86 |
+
{/* Header */}
|
| 87 |
+
<div className="flex items-center justify-between p-6 border-b border-white/5">
|
| 88 |
+
<div className="flex items-center gap-3">
|
| 89 |
+
<div className="p-2 bg-primary/20 rounded-lg">
|
| 90 |
+
<Lock className="w-6 h-6 text-primary" />
|
| 91 |
+
</div>
|
| 92 |
+
<div>
|
| 93 |
+
<h2 className="text-lg font-bold text-white">Acceso Administrativo</h2>
|
| 94 |
+
<p className="text-xs text-gray-400">Introduce la credencial de seguridad</p>
|
| 95 |
+
</div>
|
| 96 |
+
</div>
|
| 97 |
+
<button
|
| 98 |
+
onClick={onClose}
|
| 99 |
+
className="text-gray-400 hover:text-white transition-colors p-1"
|
| 100 |
+
>
|
| 101 |
+
<X size={20} />
|
| 102 |
+
</button>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
{/* Content */}
|
| 106 |
+
<div className="p-6 space-y-4">
|
| 107 |
+
<div className="bg-primary/5 border border-primary/20 rounded-lg p-3 text-xs text-primary/80">
|
| 108 |
+
<p>Esta zona está protegida. Solo personal autorizado.</p>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
<div className="space-y-2">
|
| 112 |
+
<label className="text-sm font-medium text-gray-300 flex items-center gap-2">
|
| 113 |
+
<KeyRound size={14} /> Tu Clave Maestra
|
| 114 |
+
</label>
|
| 115 |
+
<input
|
| 116 |
+
type="password"
|
| 117 |
+
value={password}
|
| 118 |
+
onChange={(e) => {
|
| 119 |
+
setPassword(e.target.value);
|
| 120 |
+
setError(false);
|
| 121 |
+
}}
|
| 122 |
+
onKeyDown={handleKeyDown}
|
| 123 |
+
className={`w-full bg-black/40 border rounded-lg px-4 py-3 text-white placeholder-gray-600 outline-none focus:ring-1 transition-all ${error
|
| 124 |
+
? 'border-red-500 focus:border-red-500 focus:ring-red-500/20'
|
| 125 |
+
: 'border-white/10 focus:border-primary focus:ring-primary/20'
|
| 126 |
+
}`}
|
| 127 |
+
placeholder="••••••••••••••"
|
| 128 |
+
autoFocus
|
| 129 |
+
/>
|
| 130 |
+
{error && (
|
| 131 |
+
<p className="text-xs text-red-500 animate-pulse">
|
| 132 |
+
Acceso denegado. Credencial inválida.
|
| 133 |
+
</p>
|
| 134 |
+
)}
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
|
| 138 |
+
{/* Footer */}
|
| 139 |
+
<div className="p-6 pt-0 flex gap-3">
|
| 140 |
+
<Button
|
| 141 |
+
variant="danger"
|
| 142 |
+
onClick={onClose}
|
| 143 |
+
className="flex-1 bg-white/5 border-white/10 hover:bg-white/10"
|
| 144 |
+
>
|
| 145 |
+
Cancelar
|
| 146 |
+
</Button>
|
| 147 |
+
<Button
|
| 148 |
+
variant="primary"
|
| 149 |
+
onClick={handleLogin}
|
| 150 |
+
className="flex-1"
|
| 151 |
+
>
|
| 152 |
+
Acceder
|
| 153 |
+
</Button>
|
| 154 |
+
</div>
|
| 155 |
+
</div>
|
| 156 |
+
</div>
|
| 157 |
+
);
|
| 158 |
+
};
|
components/BulkCategoryModal.tsx
CHANGED
|
@@ -1,95 +1,95 @@
|
|
| 1 |
-
import React, { useState } from 'react';
|
| 2 |
-
import { X, Sparkles, Check, Hash } from 'lucide-react';
|
| 3 |
-
import { Button } from './Button';
|
| 4 |
-
|
| 5 |
-
interface BulkCategoryModalProps {
|
| 6 |
-
isOpen: boolean;
|
| 7 |
-
onClose: () => void;
|
| 8 |
-
onApply: (categories: string[]) => void;
|
| 9 |
-
selectionCount: number;
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
export const BulkCategoryModal: React.FC<BulkCategoryModalProps> = ({ isOpen, onClose, onApply, selectionCount }) => {
|
| 13 |
-
const [categories, setCategories] = useState<string[]>([]);
|
| 14 |
-
const [categoryInput, setCategoryInput] = useState('');
|
| 15 |
-
|
| 16 |
-
if (!isOpen) return null;
|
| 17 |
-
|
| 18 |
-
return (
|
| 19 |
-
<div className="fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm px-4">
|
| 20 |
-
<div className="bg-[#1e1e1e] rounded-xl shadow-2xl w-full max-w-lg border border-white/10 animate-fade-in overflow-hidden">
|
| 21 |
-
<div className="flex items-center justify-between p-4 border-b border-white/10 bg-white/5">
|
| 22 |
-
<h2 className="text-lg font-bold text-white flex items-center gap-2">
|
| 23 |
-
<Hash size={18} className="text-primary" /> Aplicar Categorías en Masa
|
| 24 |
-
</h2>
|
| 25 |
-
<button
|
| 26 |
-
onClick={onClose}
|
| 27 |
-
className="text-gray-400 hover:text-white transition-colors"
|
| 28 |
-
>
|
| 29 |
-
<X size={20} />
|
| 30 |
-
</button>
|
| 31 |
-
</div>
|
| 32 |
-
|
| 33 |
-
<div className="p-6">
|
| 34 |
-
<p className="text-sm text-gray-400 mb-6">
|
| 35 |
-
Añade las categorías que deseas aplicar a las {selectionCount} entradas seleccionadas. Las categorías existentes se conservarán.
|
| 36 |
-
</p>
|
| 37 |
-
|
| 38 |
-
<div className="mb-4">
|
| 39 |
-
<div className="flex flex-wrap gap-2 mb-2">
|
| 40 |
-
{categories.map((cat, idx) => (
|
| 41 |
-
<span key={idx} className="flex items-center gap-1 text-sm text-primary bg-primary/10 px-3 py-1 rounded-lg border border-primary/30 uppercase tracking-wide font-medium">
|
| 42 |
-
{cat}
|
| 43 |
-
<button
|
| 44 |
-
type="button"
|
| 45 |
-
onClick={() => setCategories(categories.filter((_, i) => i !== idx))}
|
| 46 |
-
className="ml-1 hover:text-red-400 focus:outline-none"
|
| 47 |
-
>
|
| 48 |
-
<X size={12} />
|
| 49 |
-
</button>
|
| 50 |
-
</span>
|
| 51 |
-
))}
|
| 52 |
-
</div>
|
| 53 |
-
<div className="relative">
|
| 54 |
-
<Sparkles size={16} className="absolute left-3 top-1/2 -translate-y-1/2 text-primary" />
|
| 55 |
-
<input
|
| 56 |
-
type="text"
|
| 57 |
-
autoFocus
|
| 58 |
-
className="w-full bg-background border border-white/10 rounded-lg p-3 pl-10 text-white focus:border-primary outline-none focus:ring-1 focus:ring-primary transition-colors"
|
| 59 |
-
value={categoryInput}
|
| 60 |
-
onChange={(e) => setCategoryInput(e.target.value)}
|
| 61 |
-
onKeyDown={(e) => {
|
| 62 |
-
if (e.key === 'Enter') {
|
| 63 |
-
e.preventDefault();
|
| 64 |
-
const val = categoryInput.trim();
|
| 65 |
-
if (val && !categories.includes(val)) {
|
| 66 |
-
setCategories([...categories, val]);
|
| 67 |
-
setCategoryInput('');
|
| 68 |
-
}
|
| 69 |
-
}
|
| 70 |
-
}}
|
| 71 |
-
placeholder="Escribe una categoría y presiona Enter..."
|
| 72 |
-
/>
|
| 73 |
-
</div>
|
| 74 |
-
</div>
|
| 75 |
-
|
| 76 |
-
<div className="flex justify-end gap-3 mt-8">
|
| 77 |
-
<Button variant="outline" onClick={onClose} className="px-6 border-white/10">
|
| 78 |
-
Cancelar
|
| 79 |
-
</Button>
|
| 80 |
-
<Button
|
| 81 |
-
onClick={() => {
|
| 82 |
-
onApply(categories);
|
| 83 |
-
setCategories([]);
|
| 84 |
-
setCategoryInput('');
|
| 85 |
-
}}
|
| 86 |
-
disabled={categories.length === 0}
|
| 87 |
-
>
|
| 88 |
-
<Check size={18} /> Aplicar a {selectionCount} items
|
| 89 |
-
</Button>
|
| 90 |
-
</div>
|
| 91 |
-
</div>
|
| 92 |
-
</div>
|
| 93 |
-
</div>
|
| 94 |
-
);
|
| 95 |
-
};
|
|
|
|
| 1 |
+
import React, { useState } from 'react';
|
| 2 |
+
import { X, Sparkles, Check, Hash } from 'lucide-react';
|
| 3 |
+
import { Button } from './Button';
|
| 4 |
+
|
| 5 |
+
interface BulkCategoryModalProps {
|
| 6 |
+
isOpen: boolean;
|
| 7 |
+
onClose: () => void;
|
| 8 |
+
onApply: (categories: string[]) => void;
|
| 9 |
+
selectionCount: number;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
export const BulkCategoryModal: React.FC<BulkCategoryModalProps> = ({ isOpen, onClose, onApply, selectionCount }) => {
|
| 13 |
+
const [categories, setCategories] = useState<string[]>([]);
|
| 14 |
+
const [categoryInput, setCategoryInput] = useState('');
|
| 15 |
+
|
| 16 |
+
if (!isOpen) return null;
|
| 17 |
+
|
| 18 |
+
return (
|
| 19 |
+
<div className="fixed inset-0 z-[100] flex items-center justify-center bg-black/60 backdrop-blur-sm px-4">
|
| 20 |
+
<div className="bg-[#1e1e1e] rounded-xl shadow-2xl w-full max-w-lg border border-white/10 animate-fade-in overflow-hidden">
|
| 21 |
+
<div className="flex items-center justify-between p-4 border-b border-white/10 bg-white/5">
|
| 22 |
+
<h2 className="text-lg font-bold text-white flex items-center gap-2">
|
| 23 |
+
<Hash size={18} className="text-primary" /> Aplicar Categorías en Masa
|
| 24 |
+
</h2>
|
| 25 |
+
<button
|
| 26 |
+
onClick={onClose}
|
| 27 |
+
className="text-gray-400 hover:text-white transition-colors"
|
| 28 |
+
>
|
| 29 |
+
<X size={20} />
|
| 30 |
+
</button>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<div className="p-6">
|
| 34 |
+
<p className="text-sm text-gray-400 mb-6">
|
| 35 |
+
Añade las categorías que deseas aplicar a las {selectionCount} entradas seleccionadas. Las categorías existentes se conservarán.
|
| 36 |
+
</p>
|
| 37 |
+
|
| 38 |
+
<div className="mb-4">
|
| 39 |
+
<div className="flex flex-wrap gap-2 mb-2">
|
| 40 |
+
{categories.map((cat, idx) => (
|
| 41 |
+
<span key={idx} className="flex items-center gap-1 text-sm text-primary bg-primary/10 px-3 py-1 rounded-lg border border-primary/30 uppercase tracking-wide font-medium">
|
| 42 |
+
{cat}
|
| 43 |
+
<button
|
| 44 |
+
type="button"
|
| 45 |
+
onClick={() => setCategories(categories.filter((_, i) => i !== idx))}
|
| 46 |
+
className="ml-1 hover:text-red-400 focus:outline-none"
|
| 47 |
+
>
|
| 48 |
+
<X size={12} />
|
| 49 |
+
</button>
|
| 50 |
+
</span>
|
| 51 |
+
))}
|
| 52 |
+
</div>
|
| 53 |
+
<div className="relative">
|
| 54 |
+
<Sparkles size={16} className="absolute left-3 top-1/2 -translate-y-1/2 text-primary" />
|
| 55 |
+
<input
|
| 56 |
+
type="text"
|
| 57 |
+
autoFocus
|
| 58 |
+
className="w-full bg-background border border-white/10 rounded-lg p-3 pl-10 text-white focus:border-primary outline-none focus:ring-1 focus:ring-primary transition-colors"
|
| 59 |
+
value={categoryInput}
|
| 60 |
+
onChange={(e) => setCategoryInput(e.target.value)}
|
| 61 |
+
onKeyDown={(e) => {
|
| 62 |
+
if (e.key === 'Enter') {
|
| 63 |
+
e.preventDefault();
|
| 64 |
+
const val = categoryInput.trim();
|
| 65 |
+
if (val && !categories.includes(val)) {
|
| 66 |
+
setCategories([...categories, val]);
|
| 67 |
+
setCategoryInput('');
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
}}
|
| 71 |
+
placeholder="Escribe una categoría y presiona Enter..."
|
| 72 |
+
/>
|
| 73 |
+
</div>
|
| 74 |
+
</div>
|
| 75 |
+
|
| 76 |
+
<div className="flex justify-end gap-3 mt-8">
|
| 77 |
+
<Button variant="outline" onClick={onClose} className="px-6 border-white/10">
|
| 78 |
+
Cancelar
|
| 79 |
+
</Button>
|
| 80 |
+
<Button
|
| 81 |
+
onClick={() => {
|
| 82 |
+
onApply(categories);
|
| 83 |
+
setCategories([]);
|
| 84 |
+
setCategoryInput('');
|
| 85 |
+
}}
|
| 86 |
+
disabled={categories.length === 0}
|
| 87 |
+
>
|
| 88 |
+
<Check size={18} /> Aplicar a {selectionCount} items
|
| 89 |
+
</Button>
|
| 90 |
+
</div>
|
| 91 |
+
</div>
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
);
|
| 95 |
+
};
|
components/ConfirmModal.tsx
CHANGED
|
@@ -1,75 +1,75 @@
|
|
| 1 |
-
import React from 'react';
|
| 2 |
-
import { Button } from './Button';
|
| 3 |
-
import { AlertCircle, Trash2 } from 'lucide-react';
|
| 4 |
-
|
| 5 |
-
interface ConfirmModalProps {
|
| 6 |
-
isOpen: boolean;
|
| 7 |
-
onClose: () => void;
|
| 8 |
-
onConfirm: () => void;
|
| 9 |
-
title: string;
|
| 10 |
-
message: string;
|
| 11 |
-
confirmText?: string;
|
| 12 |
-
cancelText?: string;
|
| 13 |
-
isDestructive?: boolean;
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
export const ConfirmModal: React.FC<ConfirmModalProps> = ({
|
| 17 |
-
isOpen,
|
| 18 |
-
onClose,
|
| 19 |
-
onConfirm,
|
| 20 |
-
title,
|
| 21 |
-
message,
|
| 22 |
-
confirmText = 'Aceptar',
|
| 23 |
-
cancelText = 'Cancelar',
|
| 24 |
-
isDestructive = false
|
| 25 |
-
}) => {
|
| 26 |
-
if (!isOpen) return null;
|
| 27 |
-
|
| 28 |
-
return (
|
| 29 |
-
<>
|
| 30 |
-
<div
|
| 31 |
-
className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 animate-in fade-in duration-200"
|
| 32 |
-
onClick={onClose}
|
| 33 |
-
/>
|
| 34 |
-
|
| 35 |
-
<div className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-sm bg-[#1a1a1a] shadow-[0_0_50px_rgba(0,0,0,0.5)] z-50 rounded-2xl overflow-hidden border border-white/10 animate-in zoom-in-95 duration-200">
|
| 36 |
-
<div className="p-6">
|
| 37 |
-
<div className="flex items-center gap-3 mb-4">
|
| 38 |
-
{isDestructive ? (
|
| 39 |
-
<div className="p-2.5 bg-red-500/10 rounded-xl text-red-500">
|
| 40 |
-
<Trash2 size={24} />
|
| 41 |
-
</div>
|
| 42 |
-
) : (
|
| 43 |
-
<div className="p-2.5 bg-primary/10 rounded-xl text-primary">
|
| 44 |
-
<AlertCircle size={24} />
|
| 45 |
-
</div>
|
| 46 |
-
)}
|
| 47 |
-
<h2 className="text-xl font-bold text-white tracking-tight">{title}</h2>
|
| 48 |
-
</div>
|
| 49 |
-
|
| 50 |
-
<p className="text-gray-400 mb-8 leading-relaxed">
|
| 51 |
-
{message}
|
| 52 |
-
</p>
|
| 53 |
-
|
| 54 |
-
<div className="flex justify-end gap-3">
|
| 55 |
-
<button
|
| 56 |
-
onClick={onClose}
|
| 57 |
-
className="px-4 py-2 text-sm font-medium text-gray-400 hover:text-white hover:bg-white/5 rounded-xl transition-colors"
|
| 58 |
-
>
|
| 59 |
-
{cancelText}
|
| 60 |
-
</button>
|
| 61 |
-
<Button
|
| 62 |
-
onClick={() => {
|
| 63 |
-
onConfirm();
|
| 64 |
-
onClose();
|
| 65 |
-
}}
|
| 66 |
-
className={`!py-2 !px-5 ${isDestructive ? 'bg-red-500 hover:bg-red-600 text-white shadow-lg shadow-red-500/20' : ''}`}
|
| 67 |
-
>
|
| 68 |
-
{confirmText}
|
| 69 |
-
</Button>
|
| 70 |
-
</div>
|
| 71 |
-
</div>
|
| 72 |
-
</div>
|
| 73 |
-
</>
|
| 74 |
-
);
|
| 75 |
-
};
|
|
|
|
| 1 |
+
import React from 'react';
|
| 2 |
+
import { Button } from './Button';
|
| 3 |
+
import { AlertCircle, Trash2 } from 'lucide-react';
|
| 4 |
+
|
| 5 |
+
interface ConfirmModalProps {
|
| 6 |
+
isOpen: boolean;
|
| 7 |
+
onClose: () => void;
|
| 8 |
+
onConfirm: () => void;
|
| 9 |
+
title: string;
|
| 10 |
+
message: string;
|
| 11 |
+
confirmText?: string;
|
| 12 |
+
cancelText?: string;
|
| 13 |
+
isDestructive?: boolean;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const ConfirmModal: React.FC<ConfirmModalProps> = ({
|
| 17 |
+
isOpen,
|
| 18 |
+
onClose,
|
| 19 |
+
onConfirm,
|
| 20 |
+
title,
|
| 21 |
+
message,
|
| 22 |
+
confirmText = 'Aceptar',
|
| 23 |
+
cancelText = 'Cancelar',
|
| 24 |
+
isDestructive = false
|
| 25 |
+
}) => {
|
| 26 |
+
if (!isOpen) return null;
|
| 27 |
+
|
| 28 |
+
return (
|
| 29 |
+
<>
|
| 30 |
+
<div
|
| 31 |
+
className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 animate-in fade-in duration-200"
|
| 32 |
+
onClick={onClose}
|
| 33 |
+
/>
|
| 34 |
+
|
| 35 |
+
<div className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-sm bg-[#1a1a1a] shadow-[0_0_50px_rgba(0,0,0,0.5)] z-50 rounded-2xl overflow-hidden border border-white/10 animate-in zoom-in-95 duration-200">
|
| 36 |
+
<div className="p-6">
|
| 37 |
+
<div className="flex items-center gap-3 mb-4">
|
| 38 |
+
{isDestructive ? (
|
| 39 |
+
<div className="p-2.5 bg-red-500/10 rounded-xl text-red-500">
|
| 40 |
+
<Trash2 size={24} />
|
| 41 |
+
</div>
|
| 42 |
+
) : (
|
| 43 |
+
<div className="p-2.5 bg-primary/10 rounded-xl text-primary">
|
| 44 |
+
<AlertCircle size={24} />
|
| 45 |
+
</div>
|
| 46 |
+
)}
|
| 47 |
+
<h2 className="text-xl font-bold text-white tracking-tight">{title}</h2>
|
| 48 |
+
</div>
|
| 49 |
+
|
| 50 |
+
<p className="text-gray-400 mb-8 leading-relaxed">
|
| 51 |
+
{message}
|
| 52 |
+
</p>
|
| 53 |
+
|
| 54 |
+
<div className="flex justify-end gap-3">
|
| 55 |
+
<button
|
| 56 |
+
onClick={onClose}
|
| 57 |
+
className="px-4 py-2 text-sm font-medium text-gray-400 hover:text-white hover:bg-white/5 rounded-xl transition-colors"
|
| 58 |
+
>
|
| 59 |
+
{cancelText}
|
| 60 |
+
</button>
|
| 61 |
+
<Button
|
| 62 |
+
onClick={() => {
|
| 63 |
+
onConfirm();
|
| 64 |
+
onClose();
|
| 65 |
+
}}
|
| 66 |
+
className={`!py-2 !px-5 ${isDestructive ? 'bg-red-500 hover:bg-red-600 text-white shadow-lg shadow-red-500/20' : ''}`}
|
| 67 |
+
>
|
| 68 |
+
{confirmText}
|
| 69 |
+
</Button>
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
</>
|
| 74 |
+
);
|
| 75 |
+
};
|
components/DetailView.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { ArrowLeft, Download, ExternalLink, Trash2, Edit2, Plus, Save, X, Check,
|
|
| 8 |
import { ConfirmDialog } from './ConfirmDialog';
|
| 9 |
import { Editor } from '@tiptap/react';
|
| 10 |
import { FishAudioPlayer } from './FishAudioPlayer';
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
interface DetailViewProps {
|
|
@@ -113,11 +114,11 @@ export const DetailView: React.FC<DetailViewProps> = ({ item, onBack, onUpdate,
|
|
| 113 |
setEditingBlockId(null);
|
| 114 |
};
|
| 115 |
|
| 116 |
-
const handleAddBlockImmediately = () => {
|
| 117 |
const newBlock: ContentBlock = {
|
| 118 |
id: Date.now().toString(),
|
| 119 |
-
type:
|
| 120 |
-
content: {
|
| 121 |
type: 'doc',
|
| 122 |
content: [
|
| 123 |
{
|
|
@@ -438,12 +439,21 @@ export const DetailView: React.FC<DetailViewProps> = ({ item, onBack, onUpdate,
|
|
| 438 |
<div className="border-t border-white/10 pt-6">
|
| 439 |
<div className="flex items-center justify-between mb-4">
|
| 440 |
<label className="block text-sm font-medium text-gray-400">Bloques de Contenido</label>
|
| 441 |
-
<
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
</div>
|
| 448 |
|
| 449 |
<div className="space-y-3">
|
|
@@ -453,7 +463,10 @@ export const DetailView: React.FC<DetailViewProps> = ({ item, onBack, onUpdate,
|
|
| 453 |
<div className="flex items-center gap-2">
|
| 454 |
<span className="text-xs font-medium text-gray-500">Bloque {index + 1}</span>
|
| 455 |
{block.type === 'markdown' && (
|
| 456 |
-
<span className="text-[10px] px-1.5 py-0.5 bg-primary/20 text-primary rounded border border-primary/30">
|
|
|
|
|
|
|
|
|
|
| 457 |
)}
|
| 458 |
</div>
|
| 459 |
<div className="flex items-center gap-2">
|
|
@@ -467,19 +480,28 @@ export const DetailView: React.FC<DetailViewProps> = ({ item, onBack, onUpdate,
|
|
| 467 |
</div>
|
| 468 |
</div>
|
| 469 |
<div className="p-4">
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
</div>
|
| 484 |
</div>
|
| 485 |
))}
|
|
@@ -638,13 +660,17 @@ export const DetailView: React.FC<DetailViewProps> = ({ item, onBack, onUpdate,
|
|
| 638 |
<div className="space-y-6 mb-8">
|
| 639 |
{editedItem.blocks.map((block) => (
|
| 640 |
<div key={block.id} className={`${getCardClasses(editedItem.cardStyle)} h-fit rounded-xl overflow-hidden p-6 transition-all duration-300`}>
|
| 641 |
-
|
| 642 |
-
content={block.content}
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
</div>
|
| 649 |
))}
|
| 650 |
</div>
|
|
@@ -816,13 +842,17 @@ export const DetailView: React.FC<DetailViewProps> = ({ item, onBack, onUpdate,
|
|
| 816 |
<div className="space-y-6 mb-8">
|
| 817 |
{item.blocks.map((block, blockIdx) => (
|
| 818 |
<div key={block.id} className={`${getCardClasses(item.cardStyle)} h-fit rounded-xl overflow-hidden p-6 transition-all duration-300 relative group/block`}>
|
| 819 |
-
|
| 820 |
-
content={block.content}
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 826 |
</div>
|
| 827 |
))}
|
| 828 |
</div>
|
|
|
|
| 8 |
import { ConfirmDialog } from './ConfirmDialog';
|
| 9 |
import { Editor } from '@tiptap/react';
|
| 10 |
import { FishAudioPlayer } from './FishAudioPlayer';
|
| 11 |
+
import { MarkdownRenderer } from './MarkdownRenderer';
|
| 12 |
|
| 13 |
|
| 14 |
interface DetailViewProps {
|
|
|
|
| 114 |
setEditingBlockId(null);
|
| 115 |
};
|
| 116 |
|
| 117 |
+
const handleAddBlockImmediately = (blockType: 'markdown' | 'raw-markdown' = 'markdown') => {
|
| 118 |
const newBlock: ContentBlock = {
|
| 119 |
id: Date.now().toString(),
|
| 120 |
+
type: blockType,
|
| 121 |
+
content: blockType === 'raw-markdown' ? '' : {
|
| 122 |
type: 'doc',
|
| 123 |
content: [
|
| 124 |
{
|
|
|
|
| 439 |
<div className="border-t border-white/10 pt-6">
|
| 440 |
<div className="flex items-center justify-between mb-4">
|
| 441 |
<label className="block text-sm font-medium text-gray-400">Bloques de Contenido</label>
|
| 442 |
+
<div className="flex gap-4">
|
| 443 |
+
<button
|
| 444 |
+
onClick={() => handleAddBlockImmediately('markdown')}
|
| 445 |
+
className="flex items-center gap-2 text-primary hover:text-white transition-colors text-sm font-medium"
|
| 446 |
+
>
|
| 447 |
+
<Plus size={16} /> Añadir Bloque
|
| 448 |
+
</button>
|
| 449 |
+
<button
|
| 450 |
+
onClick={() => handleAddBlockImmediately('raw-markdown')}
|
| 451 |
+
className="flex items-center gap-2 text-[#bb86fc] hover:text-white transition-colors text-sm font-medium"
|
| 452 |
+
title="Bloque de Markdown puro"
|
| 453 |
+
>
|
| 454 |
+
<Plus size={16} /> Añadir Bloque MD
|
| 455 |
+
</button>
|
| 456 |
+
</div>
|
| 457 |
</div>
|
| 458 |
|
| 459 |
<div className="space-y-3">
|
|
|
|
| 463 |
<div className="flex items-center gap-2">
|
| 464 |
<span className="text-xs font-medium text-gray-500">Bloque {index + 1}</span>
|
| 465 |
{block.type === 'markdown' && (
|
| 466 |
+
<span className="text-[10px] px-1.5 py-0.5 bg-primary/20 text-primary rounded border border-primary/30">Rich Text</span>
|
| 467 |
+
)}
|
| 468 |
+
{block.type === 'raw-markdown' && (
|
| 469 |
+
<span className="text-[10px] px-1.5 py-0.5 bg-purple-500/20 text-purple-400 rounded border border-purple-500/30">Markdown</span>
|
| 470 |
)}
|
| 471 |
</div>
|
| 472 |
<div className="flex items-center gap-2">
|
|
|
|
| 480 |
</div>
|
| 481 |
</div>
|
| 482 |
<div className="p-4">
|
| 483 |
+
{block.type === 'raw-markdown' ? (
|
| 484 |
+
<textarea
|
| 485 |
+
value={typeof block.content === 'string' ? block.content : ''}
|
| 486 |
+
onChange={(e) => handleBlockUpdate(block.id, e.target.value)}
|
| 487 |
+
className="w-full min-h-[150px] bg-background border border-white/10 rounded-lg p-3 text-gray-300 font-mono text-sm focus:border-primary focus:ring-1 focus:ring-primary outline-none transition-colors"
|
| 488 |
+
placeholder="Escribe tu código Markdown aquí..."
|
| 489 |
+
/>
|
| 490 |
+
) : (
|
| 491 |
+
<TipTapEditor
|
| 492 |
+
content={block.content}
|
| 493 |
+
onUpdate={(content) => handleBlockUpdate(block.id, content)}
|
| 494 |
+
isEditable={true}
|
| 495 |
+
editorRef={activeEditorRef}
|
| 496 |
+
autoFocus={false}
|
| 497 |
+
showToolbarOnFocus={true}
|
| 498 |
+
onBlockDoubleClick={(type, idx) => handleBlockDoubleClick(type, idx, block.id)}
|
| 499 |
+
dense={true}
|
| 500 |
+
className="min-h-[40px]"
|
| 501 |
+
cardStyle={editedItem.cardStyle || 'bordered'}
|
| 502 |
+
onCardStyleChange={(style) => setEditedItem(prev => ({ ...prev, cardStyle: style }))}
|
| 503 |
+
/>
|
| 504 |
+
)}
|
| 505 |
</div>
|
| 506 |
</div>
|
| 507 |
))}
|
|
|
|
| 660 |
<div className="space-y-6 mb-8">
|
| 661 |
{editedItem.blocks.map((block) => (
|
| 662 |
<div key={block.id} className={`${getCardClasses(editedItem.cardStyle)} h-fit rounded-xl overflow-hidden p-6 transition-all duration-300`}>
|
| 663 |
+
{block.type === 'raw-markdown' ? (
|
| 664 |
+
<MarkdownRenderer content={typeof block.content === 'string' ? block.content : ''} />
|
| 665 |
+
) : (
|
| 666 |
+
<TipTapEditor
|
| 667 |
+
content={block.content}
|
| 668 |
+
onUpdate={() => { }}
|
| 669 |
+
isEditable={false}
|
| 670 |
+
dense={true}
|
| 671 |
+
className="min-h-[40px]"
|
| 672 |
+
/>
|
| 673 |
+
)}
|
| 674 |
</div>
|
| 675 |
))}
|
| 676 |
</div>
|
|
|
|
| 842 |
<div className="space-y-6 mb-8">
|
| 843 |
{item.blocks.map((block, blockIdx) => (
|
| 844 |
<div key={block.id} className={`${getCardClasses(item.cardStyle)} h-fit rounded-xl overflow-hidden p-6 transition-all duration-300 relative group/block`}>
|
| 845 |
+
{block.type === 'raw-markdown' ? (
|
| 846 |
+
<MarkdownRenderer content={typeof block.content === 'string' ? block.content : ''} />
|
| 847 |
+
) : (
|
| 848 |
+
<TipTapEditor
|
| 849 |
+
content={block.content}
|
| 850 |
+
onUpdate={() => { }}
|
| 851 |
+
isEditable={false}
|
| 852 |
+
dense={true}
|
| 853 |
+
className="min-h-[40px]"
|
| 854 |
+
/>
|
| 855 |
+
)}
|
| 856 |
</div>
|
| 857 |
))}
|
| 858 |
</div>
|
components/FishAudioPlayer.tsx
CHANGED
|
@@ -1,101 +1,101 @@
|
|
| 1 |
-
import React, { useState, useEffect } from 'react';
|
| 2 |
-
import { Play, Pause, Volume2, Loader2 } from 'lucide-react';
|
| 3 |
-
|
| 4 |
-
interface FishAudioPlayerProps {
|
| 5 |
-
modelId: string;
|
| 6 |
-
className?: string;
|
| 7 |
-
}
|
| 8 |
-
|
| 9 |
-
export const FishAudioPlayer: React.FC<FishAudioPlayerProps> = ({ modelId, className = "" }) => {
|
| 10 |
-
const [audioUrl, setAudioUrl] = useState<string | null>(null);
|
| 11 |
-
const [loading, setLoading] = useState(true);
|
| 12 |
-
const [error, setError] = useState<string | null>(null);
|
| 13 |
-
const [isPlaying, setIsPlaying] = useState(false);
|
| 14 |
-
const audioRef = React.useRef<HTMLAudioElement | null>(null);
|
| 15 |
-
|
| 16 |
-
useEffect(() => {
|
| 17 |
-
const fetchModel = async () => {
|
| 18 |
-
try {
|
| 19 |
-
setLoading(true);
|
| 20 |
-
const response = await fetch(`https://api.fish.audio/model/${modelId}`);
|
| 21 |
-
if (!response.ok) throw new Error('Failed to fetch model info');
|
| 22 |
-
const data = await response.json();
|
| 23 |
-
|
| 24 |
-
if (data.samples && data.samples.length > 0 && data.samples[0].audio) {
|
| 25 |
-
setAudioUrl(data.samples[0].audio);
|
| 26 |
-
} else {
|
| 27 |
-
setError('No audio sample found');
|
| 28 |
-
}
|
| 29 |
-
} catch (err) {
|
| 30 |
-
console.error('Error loading Fish Audio:', err);
|
| 31 |
-
setError('Error loading preview');
|
| 32 |
-
} finally {
|
| 33 |
-
setLoading(false);
|
| 34 |
-
}
|
| 35 |
-
};
|
| 36 |
-
|
| 37 |
-
if (modelId) {
|
| 38 |
-
fetchModel();
|
| 39 |
-
}
|
| 40 |
-
}, [modelId]);
|
| 41 |
-
|
| 42 |
-
const togglePlay = () => {
|
| 43 |
-
if (!audioRef.current) return;
|
| 44 |
-
|
| 45 |
-
if (isPlaying) {
|
| 46 |
-
audioRef.current.pause();
|
| 47 |
-
} else {
|
| 48 |
-
audioRef.current.play();
|
| 49 |
-
}
|
| 50 |
-
setIsPlaying(!isPlaying);
|
| 51 |
-
};
|
| 52 |
-
|
| 53 |
-
if (loading) {
|
| 54 |
-
return (
|
| 55 |
-
<div className={`flex items-center gap-3 p-4 bg-white/5 rounded-xl border border-white/10 animate-pulse ${className}`}>
|
| 56 |
-
<div className="w-10 h-10 rounded-full bg-white/10 flex items-center justify-center">
|
| 57 |
-
<Loader2 className="animate-spin text-primary" size={20} />
|
| 58 |
-
</div>
|
| 59 |
-
<div className="flex-1 space-y-2">
|
| 60 |
-
<div className="h-2 bg-white/10 rounded w-1/3"></div>
|
| 61 |
-
<div className="h-1 bg-white/5 rounded w-full"></div>
|
| 62 |
-
</div>
|
| 63 |
-
</div>
|
| 64 |
-
);
|
| 65 |
-
}
|
| 66 |
-
|
| 67 |
-
if (error || !audioUrl) {
|
| 68 |
-
return null; // Don't show anything if there's an error
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
return (
|
| 72 |
-
<div className={`flex items-center gap-4 p-4 bg-primary/5 rounded-xl border border-primary/20 group hover:bg-primary/10 transition-all duration-300 ${className}`}>
|
| 73 |
-
<button
|
| 74 |
-
onClick={togglePlay}
|
| 75 |
-
className="w-12 h-12 rounded-full bg-primary text-background flex items-center justify-center hover:scale-105 active:scale-95 transition-transform shadow-lg shadow-primary/20"
|
| 76 |
-
>
|
| 77 |
-
{isPlaying ? <Pause size={24} fill="currentColor" /> : <Play size={24} fill="currentColor" className="ml-1" />}
|
| 78 |
-
</button>
|
| 79 |
-
|
| 80 |
-
<div className="flex-1">
|
| 81 |
-
<div className="flex items-center justify-between mb-1">
|
| 82 |
-
<span className="text-xs font-bold text-primary uppercase tracking-wider">Demo de Voz</span>
|
| 83 |
-
<Volume2 size={14} className="text-primary/60" />
|
| 84 |
-
</div>
|
| 85 |
-
<div className="relative h-1.5 bg-white/10 rounded-full overflow-hidden">
|
| 86 |
-
<div className={`absolute inset-0 bg-primary/30 ${isPlaying ? 'animate-shimmer' : ''}`} style={{ width: '100%', backgroundSize: '200% 100%' }}></div>
|
| 87 |
-
{/* We could add a proper progress bar here if we wanted to be more fancy */}
|
| 88 |
-
</div>
|
| 89 |
-
</div>
|
| 90 |
-
|
| 91 |
-
<audio
|
| 92 |
-
ref={audioRef}
|
| 93 |
-
src={audioUrl}
|
| 94 |
-
onEnded={() => setIsPlaying(false)}
|
| 95 |
-
onPause={() => setIsPlaying(false)}
|
| 96 |
-
onPlay={() => setIsPlaying(true)}
|
| 97 |
-
className="hidden"
|
| 98 |
-
/>
|
| 99 |
-
</div>
|
| 100 |
-
);
|
| 101 |
-
};
|
|
|
|
| 1 |
+
import React, { useState, useEffect } from 'react';
|
| 2 |
+
import { Play, Pause, Volume2, Loader2 } from 'lucide-react';
|
| 3 |
+
|
| 4 |
+
interface FishAudioPlayerProps {
|
| 5 |
+
modelId: string;
|
| 6 |
+
className?: string;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export const FishAudioPlayer: React.FC<FishAudioPlayerProps> = ({ modelId, className = "" }) => {
|
| 10 |
+
const [audioUrl, setAudioUrl] = useState<string | null>(null);
|
| 11 |
+
const [loading, setLoading] = useState(true);
|
| 12 |
+
const [error, setError] = useState<string | null>(null);
|
| 13 |
+
const [isPlaying, setIsPlaying] = useState(false);
|
| 14 |
+
const audioRef = React.useRef<HTMLAudioElement | null>(null);
|
| 15 |
+
|
| 16 |
+
useEffect(() => {
|
| 17 |
+
const fetchModel = async () => {
|
| 18 |
+
try {
|
| 19 |
+
setLoading(true);
|
| 20 |
+
const response = await fetch(`https://api.fish.audio/model/${modelId}`);
|
| 21 |
+
if (!response.ok) throw new Error('Failed to fetch model info');
|
| 22 |
+
const data = await response.json();
|
| 23 |
+
|
| 24 |
+
if (data.samples && data.samples.length > 0 && data.samples[0].audio) {
|
| 25 |
+
setAudioUrl(data.samples[0].audio);
|
| 26 |
+
} else {
|
| 27 |
+
setError('No audio sample found');
|
| 28 |
+
}
|
| 29 |
+
} catch (err) {
|
| 30 |
+
console.error('Error loading Fish Audio:', err);
|
| 31 |
+
setError('Error loading preview');
|
| 32 |
+
} finally {
|
| 33 |
+
setLoading(false);
|
| 34 |
+
}
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
if (modelId) {
|
| 38 |
+
fetchModel();
|
| 39 |
+
}
|
| 40 |
+
}, [modelId]);
|
| 41 |
+
|
| 42 |
+
const togglePlay = () => {
|
| 43 |
+
if (!audioRef.current) return;
|
| 44 |
+
|
| 45 |
+
if (isPlaying) {
|
| 46 |
+
audioRef.current.pause();
|
| 47 |
+
} else {
|
| 48 |
+
audioRef.current.play();
|
| 49 |
+
}
|
| 50 |
+
setIsPlaying(!isPlaying);
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
if (loading) {
|
| 54 |
+
return (
|
| 55 |
+
<div className={`flex items-center gap-3 p-4 bg-white/5 rounded-xl border border-white/10 animate-pulse ${className}`}>
|
| 56 |
+
<div className="w-10 h-10 rounded-full bg-white/10 flex items-center justify-center">
|
| 57 |
+
<Loader2 className="animate-spin text-primary" size={20} />
|
| 58 |
+
</div>
|
| 59 |
+
<div className="flex-1 space-y-2">
|
| 60 |
+
<div className="h-2 bg-white/10 rounded w-1/3"></div>
|
| 61 |
+
<div className="h-1 bg-white/5 rounded w-full"></div>
|
| 62 |
+
</div>
|
| 63 |
+
</div>
|
| 64 |
+
);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
if (error || !audioUrl) {
|
| 68 |
+
return null; // Don't show anything if there's an error
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
return (
|
| 72 |
+
<div className={`flex items-center gap-4 p-4 bg-primary/5 rounded-xl border border-primary/20 group hover:bg-primary/10 transition-all duration-300 ${className}`}>
|
| 73 |
+
<button
|
| 74 |
+
onClick={togglePlay}
|
| 75 |
+
className="w-12 h-12 rounded-full bg-primary text-background flex items-center justify-center hover:scale-105 active:scale-95 transition-transform shadow-lg shadow-primary/20"
|
| 76 |
+
>
|
| 77 |
+
{isPlaying ? <Pause size={24} fill="currentColor" /> : <Play size={24} fill="currentColor" className="ml-1" />}
|
| 78 |
+
</button>
|
| 79 |
+
|
| 80 |
+
<div className="flex-1">
|
| 81 |
+
<div className="flex items-center justify-between mb-1">
|
| 82 |
+
<span className="text-xs font-bold text-primary uppercase tracking-wider">Demo de Voz</span>
|
| 83 |
+
<Volume2 size={14} className="text-primary/60" />
|
| 84 |
+
</div>
|
| 85 |
+
<div className="relative h-1.5 bg-white/10 rounded-full overflow-hidden">
|
| 86 |
+
<div className={`absolute inset-0 bg-primary/30 ${isPlaying ? 'animate-shimmer' : ''}`} style={{ width: '100%', backgroundSize: '200% 100%' }}></div>
|
| 87 |
+
{/* We could add a proper progress bar here if we wanted to be more fancy */}
|
| 88 |
+
</div>
|
| 89 |
+
</div>
|
| 90 |
+
|
| 91 |
+
<audio
|
| 92 |
+
ref={audioRef}
|
| 93 |
+
src={audioUrl}
|
| 94 |
+
onEnded={() => setIsPlaying(false)}
|
| 95 |
+
onPause={() => setIsPlaying(false)}
|
| 96 |
+
onPlay={() => setIsPlaying(true)}
|
| 97 |
+
className="hidden"
|
| 98 |
+
/>
|
| 99 |
+
</div>
|
| 100 |
+
);
|
| 101 |
+
};
|
components/MarkdownRenderer.tsx
CHANGED
|
@@ -96,10 +96,22 @@ export const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content, onB
|
|
| 96 |
</h6>
|
| 97 |
),
|
| 98 |
p: ({ children }) => (
|
| 99 |
-
<p className="text-gray-300 mb-4 leading-relaxed">
|
| 100 |
{children}
|
| 101 |
</p>
|
| 102 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
ul: ({ children }) => (
|
| 104 |
<ul className="list-disc list-inside text-gray-300 mb-4 space-y-1 ml-4">
|
| 105 |
{children}
|
|
@@ -219,11 +231,12 @@ export const MarkdownRenderer: React.FC<MarkdownRendererProps> = ({ content, onB
|
|
| 219 |
{children}
|
| 220 |
</td>
|
| 221 |
),
|
| 222 |
-
img: ({ src, alt }) => (
|
| 223 |
<img
|
| 224 |
src={src}
|
| 225 |
alt={alt}
|
| 226 |
-
className="max-w-full
|
|
|
|
| 227 |
/>
|
| 228 |
),
|
| 229 |
}}
|
|
|
|
| 96 |
</h6>
|
| 97 |
),
|
| 98 |
p: ({ children }) => (
|
| 99 |
+
<p className="text-gray-300 mb-4 leading-relaxed [&>img]:inline-block [&>a>img]:inline-block">
|
| 100 |
{children}
|
| 101 |
</p>
|
| 102 |
),
|
| 103 |
+
div: ({ align, children, className, style, ...props }: any) => {
|
| 104 |
+
const isCenter = align === 'center';
|
| 105 |
+
return (
|
| 106 |
+
<div
|
| 107 |
+
className={`${className || ''} ${isCenter ? 'flex flex-col items-center text-center' : ''}`}
|
| 108 |
+
style={style}
|
| 109 |
+
{...props}
|
| 110 |
+
>
|
| 111 |
+
{children}
|
| 112 |
+
</div>
|
| 113 |
+
);
|
| 114 |
+
},
|
| 115 |
ul: ({ children }) => (
|
| 116 |
<ul className="list-disc list-inside text-gray-300 mb-4 space-y-1 ml-4">
|
| 117 |
{children}
|
|
|
|
| 231 |
{children}
|
| 232 |
</td>
|
| 233 |
),
|
| 234 |
+
img: ({ src, alt, ...props }) => (
|
| 235 |
<img
|
| 236 |
src={src}
|
| 237 |
alt={alt}
|
| 238 |
+
className="max-w-full inline-block align-middle"
|
| 239 |
+
{...props as any}
|
| 240 |
/>
|
| 241 |
),
|
| 242 |
}}
|
components/MoveToFolderModal.tsx
CHANGED
|
@@ -1,205 +1,205 @@
|
|
| 1 |
-
import React, { useState, useMemo } from 'react';
|
| 2 |
-
import { Button } from './Button';
|
| 3 |
-
import { FolderPlus, Folder, X, Search, MoveUp } from 'lucide-react';
|
| 4 |
-
import { DataItem } from '../types';
|
| 5 |
-
|
| 6 |
-
interface MoveToFolderModalProps {
|
| 7 |
-
isOpen: boolean;
|
| 8 |
-
onClose: () => void;
|
| 9 |
-
selectionCount: number;
|
| 10 |
-
folders: DataItem[];
|
| 11 |
-
currentFolderId: string | null;
|
| 12 |
-
onMoveToFolder: (folderId: string | null) => Promise<void>;
|
| 13 |
-
onCreateFolder: (name: string) => Promise<string>;
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
export const MoveToFolderModal: React.FC<MoveToFolderModalProps> = ({
|
| 17 |
-
isOpen,
|
| 18 |
-
onClose,
|
| 19 |
-
selectionCount,
|
| 20 |
-
folders,
|
| 21 |
-
currentFolderId,
|
| 22 |
-
onMoveToFolder,
|
| 23 |
-
onCreateFolder,
|
| 24 |
-
}) => {
|
| 25 |
-
const [searchQuery, setSearchQuery] = useState('');
|
| 26 |
-
const [newFolderName, setNewFolderName] = useState('');
|
| 27 |
-
const [isProcessing, setIsProcessing] = useState(false);
|
| 28 |
-
|
| 29 |
-
// Filter folders to not include the current one if we want to prevent moving to same folder
|
| 30 |
-
// Actually, we can move to any folder.
|
| 31 |
-
// Construir mapa jerárquico recursivo de carpetas o filtrar de forma plana si hay búsqueda
|
| 32 |
-
const filteredFolders = useMemo(() => {
|
| 33 |
-
if (searchQuery.trim() !== '') {
|
| 34 |
-
return folders
|
| 35 |
-
.filter(f => (f.title || '').toLowerCase().includes(searchQuery.toLowerCase()))
|
| 36 |
-
.map(f => ({ folder: f, depth: 0 }));
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
const buildTree = (parentId: string | null = null, depth: number = 0, seenIds = new Set<string>()): { folder: DataItem, depth: number }[] => {
|
| 40 |
-
const children = folders.filter(f => (f.parentId || null) === parentId);
|
| 41 |
-
children.sort((a, b) => (a.title || '').localeCompare(b.title || ''));
|
| 42 |
-
|
| 43 |
-
let result: { folder: DataItem, depth: number }[] = [];
|
| 44 |
-
for (const child of children) {
|
| 45 |
-
if (seenIds.has(child.id)) continue; // Prevent infinite loops
|
| 46 |
-
seenIds.add(child.id);
|
| 47 |
-
result.push({ folder: child, depth });
|
| 48 |
-
result = result.concat(buildTree(child.id, depth + 1, new Set(seenIds)));
|
| 49 |
-
}
|
| 50 |
-
return result;
|
| 51 |
-
};
|
| 52 |
-
|
| 53 |
-
return buildTree(null, 0);
|
| 54 |
-
}, [folders, searchQuery]);
|
| 55 |
-
|
| 56 |
-
if (!isOpen) return null;
|
| 57 |
-
|
| 58 |
-
const handleCreateAndMove = async () => {
|
| 59 |
-
if (!newFolderName.trim() || isProcessing) return;
|
| 60 |
-
setIsProcessing(true);
|
| 61 |
-
try {
|
| 62 |
-
const newFolderId = await onCreateFolder(newFolderName.trim());
|
| 63 |
-
await onMoveToFolder(newFolderId);
|
| 64 |
-
onClose();
|
| 65 |
-
} catch(e) {
|
| 66 |
-
console.error(e);
|
| 67 |
-
alert("Error al crear carpeta");
|
| 68 |
-
} finally {
|
| 69 |
-
setIsProcessing(false);
|
| 70 |
-
}
|
| 71 |
-
};
|
| 72 |
-
|
| 73 |
-
const handleMove = async (folderId: string | null) => {
|
| 74 |
-
if (isProcessing) return;
|
| 75 |
-
setIsProcessing(true);
|
| 76 |
-
try {
|
| 77 |
-
await onMoveToFolder(folderId);
|
| 78 |
-
onClose();
|
| 79 |
-
} catch(e) {
|
| 80 |
-
console.error(e);
|
| 81 |
-
alert("Error al mover");
|
| 82 |
-
} finally {
|
| 83 |
-
setIsProcessing(false);
|
| 84 |
-
}
|
| 85 |
-
};
|
| 86 |
-
|
| 87 |
-
return (
|
| 88 |
-
<>
|
| 89 |
-
<div
|
| 90 |
-
className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 animate-in fade-in duration-200"
|
| 91 |
-
onClick={onClose}
|
| 92 |
-
/>
|
| 93 |
-
|
| 94 |
-
<div className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md bg-[#1a1a1a] shadow-[0_0_50px_rgba(0,0,0,0.5)] z-50 rounded-2xl flex flex-col max-h-[85vh] border border-white/10 animate-in zoom-in-95 duration-200">
|
| 95 |
-
|
| 96 |
-
{/* Header */}
|
| 97 |
-
<div className="flex items-center justify-between p-5 border-b border-white/5">
|
| 98 |
-
<div>
|
| 99 |
-
<h2 className="text-xl font-bold text-white tracking-tight">Mover a...</h2>
|
| 100 |
-
<p className="text-sm text-gray-400 mt-1">{selectionCount} elementos seleccionados</p>
|
| 101 |
-
</div>
|
| 102 |
-
<button
|
| 103 |
-
onClick={onClose}
|
| 104 |
-
className="p-2 bg-white/5 hover:bg-white/10 rounded-full transition-colors text-gray-400 hover:text-white"
|
| 105 |
-
>
|
| 106 |
-
<X size={20} />
|
| 107 |
-
</button>
|
| 108 |
-
</div>
|
| 109 |
-
|
| 110 |
-
{/* Content */}
|
| 111 |
-
<div className="p-5 overflow-y-auto flex-1 custom-scrollbar">
|
| 112 |
-
|
| 113 |
-
{/* Create new folder inline */}
|
| 114 |
-
<div className="bg-surface border border-white/5 rounded-xl p-4 mb-6">
|
| 115 |
-
<h3 className="text-sm font-medium text-white mb-3 flex items-center gap-2">
|
| 116 |
-
<FolderPlus size={16} className="text-primary"/> Nueva Carpeta
|
| 117 |
-
</h3>
|
| 118 |
-
<div className="flex gap-2">
|
| 119 |
-
<input
|
| 120 |
-
type="text"
|
| 121 |
-
placeholder="Nombre de la carpeta"
|
| 122 |
-
value={newFolderName}
|
| 123 |
-
onChange={(e) => setNewFolderName(e.target.value)}
|
| 124 |
-
onKeyDown={(e) => {
|
| 125 |
-
if (e.key === 'Enter') {
|
| 126 |
-
e.preventDefault();
|
| 127 |
-
handleCreateAndMove();
|
| 128 |
-
}
|
| 129 |
-
}}
|
| 130 |
-
className="flex-1 bg-[#121212] border border-white/10 focus:border-primary rounded-lg px-3 py-2 text-sm outline-none transition-colors"
|
| 131 |
-
disabled={isProcessing}
|
| 132 |
-
/>
|
| 133 |
-
<Button
|
| 134 |
-
onClick={handleCreateAndMove}
|
| 135 |
-
disabled={!newFolderName.trim() || isProcessing}
|
| 136 |
-
className="!py-2 !px-4 whitespace-nowrap"
|
| 137 |
-
>
|
| 138 |
-
Crear y Mover
|
| 139 |
-
</Button>
|
| 140 |
-
</div>
|
| 141 |
-
</div>
|
| 142 |
-
|
| 143 |
-
{/* Search folders */}
|
| 144 |
-
<div className="mb-4 relative">
|
| 145 |
-
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500" size={16} />
|
| 146 |
-
<input
|
| 147 |
-
type="text"
|
| 148 |
-
placeholder="Buscar carpeta..."
|
| 149 |
-
value={searchQuery}
|
| 150 |
-
onChange={(e) => setSearchQuery(e.target.value)}
|
| 151 |
-
className="w-full bg-[#121212] border border-white/10 focus:border-primary rounded-lg py-2.5 pl-10 pr-4 text-sm outline-none transition-colors"
|
| 152 |
-
/>
|
| 153 |
-
</div>
|
| 154 |
-
|
| 155 |
-
{/* Folder List */}
|
| 156 |
-
<div className="space-y-2">
|
| 157 |
-
{currentFolderId !== null && !searchQuery && (
|
| 158 |
-
<button
|
| 159 |
-
onClick={() => handleMove(null)}
|
| 160 |
-
disabled={isProcessing}
|
| 161 |
-
className="w-full flex items-center gap-3 p-3 rounded-xl hover:bg-white/5 transition-colors text-left group"
|
| 162 |
-
>
|
| 163 |
-
<div className="p-2 bg-white/5 rounded-lg text-gray-400 group-hover:text-white transition-colors">
|
| 164 |
-
<MoveUp size={18} />
|
| 165 |
-
</div>
|
| 166 |
-
<span className="font-medium text-gray-300 group-hover:text-white transition-colors">Volver a la Raíz</span>
|
| 167 |
-
</button>
|
| 168 |
-
)}
|
| 169 |
-
|
| 170 |
-
{filteredFolders.length === 0 ? (
|
| 171 |
-
<p className="text-center text-sm text-gray-500 py-6">No se encontraron carpetas.</p>
|
| 172 |
-
) : (
|
| 173 |
-
filteredFolders.map(({ folder, depth }) => (
|
| 174 |
-
<button
|
| 175 |
-
key={folder.id}
|
| 176 |
-
onClick={() => handleMove(folder.id)}
|
| 177 |
-
disabled={isProcessing || folder.id === currentFolderId}
|
| 178 |
-
className={`w-full flex items-center gap-3 p-3 rounded-xl transition-all text-left group border border-transparent hover:border-white/5 ${
|
| 179 |
-
folder.id === currentFolderId ? 'opacity-50 cursor-not-allowed bg-white/5' : 'hover:bg-white/5'
|
| 180 |
-
}`}
|
| 181 |
-
>
|
| 182 |
-
{/* Espaciador de profundidad para simular el mapa/árbol */}
|
| 183 |
-
{depth > 0 && (
|
| 184 |
-
<div style={{ width: `${depth * 20}px` }} className="h-full border-l border-white/10 ml-2" />
|
| 185 |
-
)}
|
| 186 |
-
|
| 187 |
-
<div className="p-2 bg-primary/10 rounded-lg text-primary">
|
| 188 |
-
<Folder size={18} />
|
| 189 |
-
</div>
|
| 190 |
-
<div className="flex-1 overflow-hidden">
|
| 191 |
-
<span className="font-medium text-gray-300 group-hover:text-white transition-colors truncate block">
|
| 192 |
-
{folder.title}
|
| 193 |
-
{folder.id === currentFolderId && <span className="ml-2 text-xs text-primary font-normal">(Ubicación actual)</span>}
|
| 194 |
-
</span>
|
| 195 |
-
</div>
|
| 196 |
-
</button>
|
| 197 |
-
))
|
| 198 |
-
)}
|
| 199 |
-
</div>
|
| 200 |
-
|
| 201 |
-
</div>
|
| 202 |
-
</div>
|
| 203 |
-
</>
|
| 204 |
-
);
|
| 205 |
-
};
|
|
|
|
| 1 |
+
import React, { useState, useMemo } from 'react';
|
| 2 |
+
import { Button } from './Button';
|
| 3 |
+
import { FolderPlus, Folder, X, Search, MoveUp } from 'lucide-react';
|
| 4 |
+
import { DataItem } from '../types';
|
| 5 |
+
|
| 6 |
+
interface MoveToFolderModalProps {
|
| 7 |
+
isOpen: boolean;
|
| 8 |
+
onClose: () => void;
|
| 9 |
+
selectionCount: number;
|
| 10 |
+
folders: DataItem[];
|
| 11 |
+
currentFolderId: string | null;
|
| 12 |
+
onMoveToFolder: (folderId: string | null) => Promise<void>;
|
| 13 |
+
onCreateFolder: (name: string) => Promise<string>;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export const MoveToFolderModal: React.FC<MoveToFolderModalProps> = ({
|
| 17 |
+
isOpen,
|
| 18 |
+
onClose,
|
| 19 |
+
selectionCount,
|
| 20 |
+
folders,
|
| 21 |
+
currentFolderId,
|
| 22 |
+
onMoveToFolder,
|
| 23 |
+
onCreateFolder,
|
| 24 |
+
}) => {
|
| 25 |
+
const [searchQuery, setSearchQuery] = useState('');
|
| 26 |
+
const [newFolderName, setNewFolderName] = useState('');
|
| 27 |
+
const [isProcessing, setIsProcessing] = useState(false);
|
| 28 |
+
|
| 29 |
+
// Filter folders to not include the current one if we want to prevent moving to same folder
|
| 30 |
+
// Actually, we can move to any folder.
|
| 31 |
+
// Construir mapa jerárquico recursivo de carpetas o filtrar de forma plana si hay búsqueda
|
| 32 |
+
const filteredFolders = useMemo(() => {
|
| 33 |
+
if (searchQuery.trim() !== '') {
|
| 34 |
+
return folders
|
| 35 |
+
.filter(f => (f.title || '').toLowerCase().includes(searchQuery.toLowerCase()))
|
| 36 |
+
.map(f => ({ folder: f, depth: 0 }));
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
const buildTree = (parentId: string | null = null, depth: number = 0, seenIds = new Set<string>()): { folder: DataItem, depth: number }[] => {
|
| 40 |
+
const children = folders.filter(f => (f.parentId || null) === parentId);
|
| 41 |
+
children.sort((a, b) => (a.title || '').localeCompare(b.title || ''));
|
| 42 |
+
|
| 43 |
+
let result: { folder: DataItem, depth: number }[] = [];
|
| 44 |
+
for (const child of children) {
|
| 45 |
+
if (seenIds.has(child.id)) continue; // Prevent infinite loops
|
| 46 |
+
seenIds.add(child.id);
|
| 47 |
+
result.push({ folder: child, depth });
|
| 48 |
+
result = result.concat(buildTree(child.id, depth + 1, new Set(seenIds)));
|
| 49 |
+
}
|
| 50 |
+
return result;
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
return buildTree(null, 0);
|
| 54 |
+
}, [folders, searchQuery]);
|
| 55 |
+
|
| 56 |
+
if (!isOpen) return null;
|
| 57 |
+
|
| 58 |
+
const handleCreateAndMove = async () => {
|
| 59 |
+
if (!newFolderName.trim() || isProcessing) return;
|
| 60 |
+
setIsProcessing(true);
|
| 61 |
+
try {
|
| 62 |
+
const newFolderId = await onCreateFolder(newFolderName.trim());
|
| 63 |
+
await onMoveToFolder(newFolderId);
|
| 64 |
+
onClose();
|
| 65 |
+
} catch(e) {
|
| 66 |
+
console.error(e);
|
| 67 |
+
alert("Error al crear carpeta");
|
| 68 |
+
} finally {
|
| 69 |
+
setIsProcessing(false);
|
| 70 |
+
}
|
| 71 |
+
};
|
| 72 |
+
|
| 73 |
+
const handleMove = async (folderId: string | null) => {
|
| 74 |
+
if (isProcessing) return;
|
| 75 |
+
setIsProcessing(true);
|
| 76 |
+
try {
|
| 77 |
+
await onMoveToFolder(folderId);
|
| 78 |
+
onClose();
|
| 79 |
+
} catch(e) {
|
| 80 |
+
console.error(e);
|
| 81 |
+
alert("Error al mover");
|
| 82 |
+
} finally {
|
| 83 |
+
setIsProcessing(false);
|
| 84 |
+
}
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
return (
|
| 88 |
+
<>
|
| 89 |
+
<div
|
| 90 |
+
className="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 animate-in fade-in duration-200"
|
| 91 |
+
onClick={onClose}
|
| 92 |
+
/>
|
| 93 |
+
|
| 94 |
+
<div className="fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md bg-[#1a1a1a] shadow-[0_0_50px_rgba(0,0,0,0.5)] z-50 rounded-2xl flex flex-col max-h-[85vh] border border-white/10 animate-in zoom-in-95 duration-200">
|
| 95 |
+
|
| 96 |
+
{/* Header */}
|
| 97 |
+
<div className="flex items-center justify-between p-5 border-b border-white/5">
|
| 98 |
+
<div>
|
| 99 |
+
<h2 className="text-xl font-bold text-white tracking-tight">Mover a...</h2>
|
| 100 |
+
<p className="text-sm text-gray-400 mt-1">{selectionCount} elementos seleccionados</p>
|
| 101 |
+
</div>
|
| 102 |
+
<button
|
| 103 |
+
onClick={onClose}
|
| 104 |
+
className="p-2 bg-white/5 hover:bg-white/10 rounded-full transition-colors text-gray-400 hover:text-white"
|
| 105 |
+
>
|
| 106 |
+
<X size={20} />
|
| 107 |
+
</button>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
{/* Content */}
|
| 111 |
+
<div className="p-5 overflow-y-auto flex-1 custom-scrollbar">
|
| 112 |
+
|
| 113 |
+
{/* Create new folder inline */}
|
| 114 |
+
<div className="bg-surface border border-white/5 rounded-xl p-4 mb-6">
|
| 115 |
+
<h3 className="text-sm font-medium text-white mb-3 flex items-center gap-2">
|
| 116 |
+
<FolderPlus size={16} className="text-primary"/> Nueva Carpeta
|
| 117 |
+
</h3>
|
| 118 |
+
<div className="flex gap-2">
|
| 119 |
+
<input
|
| 120 |
+
type="text"
|
| 121 |
+
placeholder="Nombre de la carpeta"
|
| 122 |
+
value={newFolderName}
|
| 123 |
+
onChange={(e) => setNewFolderName(e.target.value)}
|
| 124 |
+
onKeyDown={(e) => {
|
| 125 |
+
if (e.key === 'Enter') {
|
| 126 |
+
e.preventDefault();
|
| 127 |
+
handleCreateAndMove();
|
| 128 |
+
}
|
| 129 |
+
}}
|
| 130 |
+
className="flex-1 bg-[#121212] border border-white/10 focus:border-primary rounded-lg px-3 py-2 text-sm outline-none transition-colors"
|
| 131 |
+
disabled={isProcessing}
|
| 132 |
+
/>
|
| 133 |
+
<Button
|
| 134 |
+
onClick={handleCreateAndMove}
|
| 135 |
+
disabled={!newFolderName.trim() || isProcessing}
|
| 136 |
+
className="!py-2 !px-4 whitespace-nowrap"
|
| 137 |
+
>
|
| 138 |
+
Crear y Mover
|
| 139 |
+
</Button>
|
| 140 |
+
</div>
|
| 141 |
+
</div>
|
| 142 |
+
|
| 143 |
+
{/* Search folders */}
|
| 144 |
+
<div className="mb-4 relative">
|
| 145 |
+
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-500" size={16} />
|
| 146 |
+
<input
|
| 147 |
+
type="text"
|
| 148 |
+
placeholder="Buscar carpeta..."
|
| 149 |
+
value={searchQuery}
|
| 150 |
+
onChange={(e) => setSearchQuery(e.target.value)}
|
| 151 |
+
className="w-full bg-[#121212] border border-white/10 focus:border-primary rounded-lg py-2.5 pl-10 pr-4 text-sm outline-none transition-colors"
|
| 152 |
+
/>
|
| 153 |
+
</div>
|
| 154 |
+
|
| 155 |
+
{/* Folder List */}
|
| 156 |
+
<div className="space-y-2">
|
| 157 |
+
{currentFolderId !== null && !searchQuery && (
|
| 158 |
+
<button
|
| 159 |
+
onClick={() => handleMove(null)}
|
| 160 |
+
disabled={isProcessing}
|
| 161 |
+
className="w-full flex items-center gap-3 p-3 rounded-xl hover:bg-white/5 transition-colors text-left group"
|
| 162 |
+
>
|
| 163 |
+
<div className="p-2 bg-white/5 rounded-lg text-gray-400 group-hover:text-white transition-colors">
|
| 164 |
+
<MoveUp size={18} />
|
| 165 |
+
</div>
|
| 166 |
+
<span className="font-medium text-gray-300 group-hover:text-white transition-colors">Volver a la Raíz</span>
|
| 167 |
+
</button>
|
| 168 |
+
)}
|
| 169 |
+
|
| 170 |
+
{filteredFolders.length === 0 ? (
|
| 171 |
+
<p className="text-center text-sm text-gray-500 py-6">No se encontraron carpetas.</p>
|
| 172 |
+
) : (
|
| 173 |
+
filteredFolders.map(({ folder, depth }) => (
|
| 174 |
+
<button
|
| 175 |
+
key={folder.id}
|
| 176 |
+
onClick={() => handleMove(folder.id)}
|
| 177 |
+
disabled={isProcessing || folder.id === currentFolderId}
|
| 178 |
+
className={`w-full flex items-center gap-3 p-3 rounded-xl transition-all text-left group border border-transparent hover:border-white/5 ${
|
| 179 |
+
folder.id === currentFolderId ? 'opacity-50 cursor-not-allowed bg-white/5' : 'hover:bg-white/5'
|
| 180 |
+
}`}
|
| 181 |
+
>
|
| 182 |
+
{/* Espaciador de profundidad para simular el mapa/árbol */}
|
| 183 |
+
{depth > 0 && (
|
| 184 |
+
<div style={{ width: `${depth * 20}px` }} className="h-full border-l border-white/10 ml-2" />
|
| 185 |
+
)}
|
| 186 |
+
|
| 187 |
+
<div className="p-2 bg-primary/10 rounded-lg text-primary">
|
| 188 |
+
<Folder size={18} />
|
| 189 |
+
</div>
|
| 190 |
+
<div className="flex-1 overflow-hidden">
|
| 191 |
+
<span className="font-medium text-gray-300 group-hover:text-white transition-colors truncate block">
|
| 192 |
+
{folder.title}
|
| 193 |
+
{folder.id === currentFolderId && <span className="ml-2 text-xs text-primary font-normal">(Ubicación actual)</span>}
|
| 194 |
+
</span>
|
| 195 |
+
</div>
|
| 196 |
+
</button>
|
| 197 |
+
))
|
| 198 |
+
)}
|
| 199 |
+
</div>
|
| 200 |
+
|
| 201 |
+
</div>
|
| 202 |
+
</div>
|
| 203 |
+
</>
|
| 204 |
+
);
|
| 205 |
+
};
|
components/extensions/CustomFileExtension.tsx
CHANGED
|
@@ -1,72 +1,72 @@
|
|
| 1 |
-
import { Node, mergeAttributes } from '@tiptap/core';
|
| 2 |
-
import { ReactNodeViewRenderer, NodeViewWrapper } from '@tiptap/react';
|
| 3 |
-
import React from 'react';
|
| 4 |
-
import { FileText, Send } from 'lucide-react';
|
| 5 |
-
|
| 6 |
-
// Extensión para renderizar archivos subidos de forma elegante
|
| 7 |
-
export const CustomFileExtension = Node.create({
|
| 8 |
-
name: 'customFile',
|
| 9 |
-
group: 'block',
|
| 10 |
-
atom: true,
|
| 11 |
-
|
| 12 |
-
addAttributes() {
|
| 13 |
-
return {
|
| 14 |
-
name: { default: 'Archivo' },
|
| 15 |
-
messageId: { default: null },
|
| 16 |
-
channelId: { default: null },
|
| 17 |
-
size: { default: null },
|
| 18 |
-
};
|
| 19 |
-
},
|
| 20 |
-
|
| 21 |
-
parseHTML() {
|
| 22 |
-
return [{ tag: 'div[data-type="custom-file"]' }];
|
| 23 |
-
},
|
| 24 |
-
|
| 25 |
-
renderHTML({ HTMLAttributes }) {
|
| 26 |
-
return ['div', mergeAttributes(HTMLAttributes, { 'data-type': 'custom-file' })];
|
| 27 |
-
},
|
| 28 |
-
|
| 29 |
-
addNodeView() {
|
| 30 |
-
return ReactNodeViewRenderer(FileComponent);
|
| 31 |
-
},
|
| 32 |
-
});
|
| 33 |
-
|
| 34 |
-
const FileComponent = ({ node }: any) => {
|
| 35 |
-
const { name = "Archivo sin nombre", messageId = "0" } = node.attrs || {};
|
| 36 |
-
|
| 37 |
-
const botUsername = "CodeByDantePrimebot";
|
| 38 |
-
const telegramUrl = `https://t.me/${botUsername}?start=${messageId}`;
|
| 39 |
-
|
| 40 |
-
return (
|
| 41 |
-
<NodeViewWrapper className="custom-file-node">
|
| 42 |
-
<div
|
| 43 |
-
contentEditable={false}
|
| 44 |
-
className="my-3 p-3 bg-zinc-900/90 border border-white/10 rounded-xl flex items-center justify-between gap-4 group hover:border-primary/50 transition-all shadow-lg select-none"
|
| 45 |
-
>
|
| 46 |
-
<div className="flex items-center gap-3 flex-1 min-w-0">
|
| 47 |
-
<div className="w-10 h-10 bg-primary/10 rounded-lg flex items-center justify-center text-primary shrink-0">
|
| 48 |
-
<FileText size={20} />
|
| 49 |
-
</div>
|
| 50 |
-
<div className="flex-1 min-w-0">
|
| 51 |
-
<div className="text-sm font-bold text-white truncate">
|
| 52 |
-
{name}
|
| 53 |
-
</div>
|
| 54 |
-
<div className="text-[10px] text-zinc-500 flex items-center gap-2">
|
| 55 |
-
<span>ID: {messageId}</span>
|
| 56 |
-
</div>
|
| 57 |
-
</div>
|
| 58 |
-
</div>
|
| 59 |
-
|
| 60 |
-
<a
|
| 61 |
-
href={telegramUrl}
|
| 62 |
-
target="_blank"
|
| 63 |
-
rel="noopener noreferrer"
|
| 64 |
-
className="px-4 py-2 bg-primary hover:bg-primary-hover text-white rounded-lg flex items-center gap-2 text-xs font-bold transition-all shrink-0 no-underline whitespace-nowrap"
|
| 65 |
-
>
|
| 66 |
-
<Send size={14} />
|
| 67 |
-
<span>Telegram</span>
|
| 68 |
-
</a>
|
| 69 |
-
</div>
|
| 70 |
-
</NodeViewWrapper>
|
| 71 |
-
);
|
| 72 |
-
};
|
|
|
|
| 1 |
+
import { Node, mergeAttributes } from '@tiptap/core';
|
| 2 |
+
import { ReactNodeViewRenderer, NodeViewWrapper } from '@tiptap/react';
|
| 3 |
+
import React from 'react';
|
| 4 |
+
import { FileText, Send } from 'lucide-react';
|
| 5 |
+
|
| 6 |
+
// Extensión para renderizar archivos subidos de forma elegante
|
| 7 |
+
export const CustomFileExtension = Node.create({
|
| 8 |
+
name: 'customFile',
|
| 9 |
+
group: 'block',
|
| 10 |
+
atom: true,
|
| 11 |
+
|
| 12 |
+
addAttributes() {
|
| 13 |
+
return {
|
| 14 |
+
name: { default: 'Archivo' },
|
| 15 |
+
messageId: { default: null },
|
| 16 |
+
channelId: { default: null },
|
| 17 |
+
size: { default: null },
|
| 18 |
+
};
|
| 19 |
+
},
|
| 20 |
+
|
| 21 |
+
parseHTML() {
|
| 22 |
+
return [{ tag: 'div[data-type="custom-file"]' }];
|
| 23 |
+
},
|
| 24 |
+
|
| 25 |
+
renderHTML({ HTMLAttributes }) {
|
| 26 |
+
return ['div', mergeAttributes(HTMLAttributes, { 'data-type': 'custom-file' })];
|
| 27 |
+
},
|
| 28 |
+
|
| 29 |
+
addNodeView() {
|
| 30 |
+
return ReactNodeViewRenderer(FileComponent);
|
| 31 |
+
},
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
const FileComponent = ({ node }: any) => {
|
| 35 |
+
const { name = "Archivo sin nombre", messageId = "0" } = node.attrs || {};
|
| 36 |
+
|
| 37 |
+
const botUsername = "CodeByDantePrimebot";
|
| 38 |
+
const telegramUrl = `https://t.me/${botUsername}?start=${messageId}`;
|
| 39 |
+
|
| 40 |
+
return (
|
| 41 |
+
<NodeViewWrapper className="custom-file-node">
|
| 42 |
+
<div
|
| 43 |
+
contentEditable={false}
|
| 44 |
+
className="my-3 p-3 bg-zinc-900/90 border border-white/10 rounded-xl flex items-center justify-between gap-4 group hover:border-primary/50 transition-all shadow-lg select-none"
|
| 45 |
+
>
|
| 46 |
+
<div className="flex items-center gap-3 flex-1 min-w-0">
|
| 47 |
+
<div className="w-10 h-10 bg-primary/10 rounded-lg flex items-center justify-center text-primary shrink-0">
|
| 48 |
+
<FileText size={20} />
|
| 49 |
+
</div>
|
| 50 |
+
<div className="flex-1 min-w-0">
|
| 51 |
+
<div className="text-sm font-bold text-white truncate">
|
| 52 |
+
{name}
|
| 53 |
+
</div>
|
| 54 |
+
<div className="text-[10px] text-zinc-500 flex items-center gap-2">
|
| 55 |
+
<span>ID: {messageId}</span>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
</div>
|
| 59 |
+
|
| 60 |
+
<a
|
| 61 |
+
href={telegramUrl}
|
| 62 |
+
target="_blank"
|
| 63 |
+
rel="noopener noreferrer"
|
| 64 |
+
className="px-4 py-2 bg-primary hover:bg-primary-hover text-white rounded-lg flex items-center gap-2 text-xs font-bold transition-all shrink-0 no-underline whitespace-nowrap"
|
| 65 |
+
>
|
| 66 |
+
<Send size={14} />
|
| 67 |
+
<span>Telegram</span>
|
| 68 |
+
</a>
|
| 69 |
+
</div>
|
| 70 |
+
</NodeViewWrapper>
|
| 71 |
+
);
|
| 72 |
+
};
|
components/extensions/WordBehaviorExtension.ts
CHANGED
|
@@ -1,74 +1,74 @@
|
|
| 1 |
-
import { Extension } from '@tiptap/core';
|
| 2 |
-
import { Plugin, PluginKey } from 'prosemirror-state';
|
| 3 |
-
|
| 4 |
-
export const WordBehaviorExtension = Extension.create({
|
| 5 |
-
name: 'wordBehavior',
|
| 6 |
-
|
| 7 |
-
addProseMirrorPlugins() {
|
| 8 |
-
return [
|
| 9 |
-
new Plugin({
|
| 10 |
-
key: new PluginKey('wordBehaviorPasteHandler'),
|
| 11 |
-
props: {
|
| 12 |
-
transformPastedHTML(html) {
|
| 13 |
-
// Limpia divs vacíos y saltos dobles innecesarios generados al copiar de webs
|
| 14 |
-
let cleaned = html.replace(/<div[^>]*>\s*<\/div>/gi, '');
|
| 15 |
-
// Reemplaza dobles br por un párrafo nuevo y ordenado
|
| 16 |
-
cleaned = cleaned.replace(/(<br\s*\/?>\s*){2,}/gi, '</p><p>');
|
| 17 |
-
// Elimina la proliferación de párrafos vacíos pegados accidentalmente
|
| 18 |
-
cleaned = cleaned.replace(/(<p>\s*<\/p>\s*){2,}/gi, '<p></p>');
|
| 19 |
-
// Quita los espacios inútiles al principio o fin de fragmentos
|
| 20 |
-
cleaned = cleaned.replace(/ /g, ' ');
|
| 21 |
-
|
| 22 |
-
return cleaned;
|
| 23 |
-
}
|
| 24 |
-
}
|
| 25 |
-
})
|
| 26 |
-
];
|
| 27 |
-
},
|
| 28 |
-
|
| 29 |
-
addKeyboardShortcuts() {
|
| 30 |
-
return {
|
| 31 |
-
// Shift-Enter asegura un hard break sin romper el bloque estructural actual
|
| 32 |
-
'Shift-Enter': () => {
|
| 33 |
-
return this.editor.commands.setHardBreak();
|
| 34 |
-
},
|
| 35 |
-
|
| 36 |
-
// Comportamiento de sangría al estilo procesador de textos para listas
|
| 37 |
-
'Tab': () => {
|
| 38 |
-
if (this.editor.isActive('listItem')) {
|
| 39 |
-
return this.editor.commands.sinkListItem('listItem');
|
| 40 |
-
}
|
| 41 |
-
// Previene que inserte un tabulador como espacio manual si no está en un bloque soportado
|
| 42 |
-
// Si preferimos que "Tab" ponga un espacio literal en párrafos, retornamos false
|
| 43 |
-
return false;
|
| 44 |
-
},
|
| 45 |
-
|
| 46 |
-
'Shift-Tab': () => {
|
| 47 |
-
if (this.editor.isActive('listItem')) {
|
| 48 |
-
return this.editor.commands.liftListItem('listItem');
|
| 49 |
-
}
|
| 50 |
-
return false;
|
| 51 |
-
},
|
| 52 |
-
|
| 53 |
-
'Control-Space': () => {
|
| 54 |
-
const { state } = this.editor;
|
| 55 |
-
const { selection } = state;
|
| 56 |
-
const { $from, empty } = selection;
|
| 57 |
-
|
| 58 |
-
// Si estamos al inicio de un punto de lista
|
| 59 |
-
if (empty && this.editor.isActive('listItem') && $from.parentOffset === 0) {
|
| 60 |
-
// Calculamos la posición exacta antes del listItem
|
| 61 |
-
const pos = $from.before($from.depth - 1);
|
| 62 |
-
|
| 63 |
-
// Insertamos un párrafo vacío y nos aseguramos de que no se convierta en lista
|
| 64 |
-
this.editor.chain()
|
| 65 |
-
.focus()
|
| 66 |
-
.insertContentAt(pos, { type: 'paragraph' })
|
| 67 |
-
.run();
|
| 68 |
-
return true;
|
| 69 |
-
}
|
| 70 |
-
return false;
|
| 71 |
-
}
|
| 72 |
-
};
|
| 73 |
-
}
|
| 74 |
-
});
|
|
|
|
| 1 |
+
import { Extension } from '@tiptap/core';
|
| 2 |
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
| 3 |
+
|
| 4 |
+
export const WordBehaviorExtension = Extension.create({
|
| 5 |
+
name: 'wordBehavior',
|
| 6 |
+
|
| 7 |
+
addProseMirrorPlugins() {
|
| 8 |
+
return [
|
| 9 |
+
new Plugin({
|
| 10 |
+
key: new PluginKey('wordBehaviorPasteHandler'),
|
| 11 |
+
props: {
|
| 12 |
+
transformPastedHTML(html) {
|
| 13 |
+
// Limpia divs vacíos y saltos dobles innecesarios generados al copiar de webs
|
| 14 |
+
let cleaned = html.replace(/<div[^>]*>\s*<\/div>/gi, '');
|
| 15 |
+
// Reemplaza dobles br por un párrafo nuevo y ordenado
|
| 16 |
+
cleaned = cleaned.replace(/(<br\s*\/?>\s*){2,}/gi, '</p><p>');
|
| 17 |
+
// Elimina la proliferación de párrafos vacíos pegados accidentalmente
|
| 18 |
+
cleaned = cleaned.replace(/(<p>\s*<\/p>\s*){2,}/gi, '<p></p>');
|
| 19 |
+
// Quita los espacios inútiles al principio o fin de fragmentos
|
| 20 |
+
cleaned = cleaned.replace(/ /g, ' ');
|
| 21 |
+
|
| 22 |
+
return cleaned;
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
})
|
| 26 |
+
];
|
| 27 |
+
},
|
| 28 |
+
|
| 29 |
+
addKeyboardShortcuts() {
|
| 30 |
+
return {
|
| 31 |
+
// Shift-Enter asegura un hard break sin romper el bloque estructural actual
|
| 32 |
+
'Shift-Enter': () => {
|
| 33 |
+
return this.editor.commands.setHardBreak();
|
| 34 |
+
},
|
| 35 |
+
|
| 36 |
+
// Comportamiento de sangría al estilo procesador de textos para listas
|
| 37 |
+
'Tab': () => {
|
| 38 |
+
if (this.editor.isActive('listItem')) {
|
| 39 |
+
return this.editor.commands.sinkListItem('listItem');
|
| 40 |
+
}
|
| 41 |
+
// Previene que inserte un tabulador como espacio manual si no está en un bloque soportado
|
| 42 |
+
// Si preferimos que "Tab" ponga un espacio literal en párrafos, retornamos false
|
| 43 |
+
return false;
|
| 44 |
+
},
|
| 45 |
+
|
| 46 |
+
'Shift-Tab': () => {
|
| 47 |
+
if (this.editor.isActive('listItem')) {
|
| 48 |
+
return this.editor.commands.liftListItem('listItem');
|
| 49 |
+
}
|
| 50 |
+
return false;
|
| 51 |
+
},
|
| 52 |
+
|
| 53 |
+
'Control-Space': () => {
|
| 54 |
+
const { state } = this.editor;
|
| 55 |
+
const { selection } = state;
|
| 56 |
+
const { $from, empty } = selection;
|
| 57 |
+
|
| 58 |
+
// Si estamos al inicio de un punto de lista
|
| 59 |
+
if (empty && this.editor.isActive('listItem') && $from.parentOffset === 0) {
|
| 60 |
+
// Calculamos la posición exacta antes del listItem
|
| 61 |
+
const pos = $from.before($from.depth - 1);
|
| 62 |
+
|
| 63 |
+
// Insertamos un párrafo vacío y nos aseguramos de que no se convierta en lista
|
| 64 |
+
this.editor.chain()
|
| 65 |
+
.focus()
|
| 66 |
+
.insertContentAt(pos, { type: 'paragraph' })
|
| 67 |
+
.run();
|
| 68 |
+
return true;
|
| 69 |
+
}
|
| 70 |
+
return false;
|
| 71 |
+
}
|
| 72 |
+
};
|
| 73 |
+
}
|
| 74 |
+
});
|
dist/assets/index-B8NpKCEH.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/assets/index-CC3SLb6N.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/assets/index-CdT4gFR-.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/assets/index-DBb-BcX0.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/assets/index-DLwUYtS5.css
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
@tailwind base;@tailwind components;@tailwind utilities;:root{--foreground-rgb: 0, 0, 0;--background-start-rgb: 214, 219, 220;--background-end-rgb: 255, 255, 255}@media(prefers-color-scheme:dark){:root{--foreground-rgb: 255, 255, 255;--background-start-rgb: 0, 0, 0;--background-end-rgb: 0, 0, 0}}body{color:rgb(var(--foreground-rgb));background:linear-gradient(to bottom,transparent,rgb(var(--background-end-rgb))) rgb(var(--background-start-rgb))}@layer utilities{.text-balance{text-wrap:balance}}.ProseMirror>*:first-child{margin-top:0!important}.ProseMirror p{margin-top:.5rem;margin-bottom:.5rem;line-height:1.5}.ProseMirror ul{list-style-type:disc;padding-left:1.5rem;margin:1rem 0}.ProseMirror ol{list-style-type:decimal;padding-left:1.5rem;margin:1rem 0}.ProseMirror li{margin-bottom:.25rem}::selection{background-color:#a855f740;color:inherit}.ProseMirror ::selection{background-color:#a855f740;color:inherit}.no-underline-link{text-decoration:none!important}
|
|
|
|
| 1 |
+
@tailwind base;@tailwind components;@tailwind utilities;:root{--foreground-rgb: 0, 0, 0;--background-start-rgb: 214, 219, 220;--background-end-rgb: 255, 255, 255}@media(prefers-color-scheme:dark){:root{--foreground-rgb: 255, 255, 255;--background-start-rgb: 0, 0, 0;--background-end-rgb: 0, 0, 0}}body{color:rgb(var(--foreground-rgb));background:linear-gradient(to bottom,transparent,rgb(var(--background-end-rgb))) rgb(var(--background-start-rgb))}@layer utilities{.text-balance{text-wrap:balance}}.ProseMirror>*:first-child{margin-top:0!important}.ProseMirror p{margin-top:.5rem;margin-bottom:.5rem;line-height:1.5}.ProseMirror ul{list-style-type:disc;padding-left:1.5rem;margin:1rem 0}.ProseMirror ol{list-style-type:decimal;padding-left:1.5rem;margin:1rem 0}.ProseMirror li{margin-bottom:.25rem}::selection{background-color:#a855f740;color:inherit}.ProseMirror ::selection{background-color:#a855f740;color:inherit}.no-underline-link{text-decoration:none!important}
|
dist/assets/index-N97Ka77T.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/favicon.svg
CHANGED
|
|
|
|
firestore.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
| 1 |
-
{
|
| 2 |
-
"type": "service_account",
|
| 3 |
-
"project_id": "code-by-dante",
|
| 4 |
-
"private_key_id": "8ba5d25463c11097970a9d9bd7f1921572100073",
|
| 5 |
-
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC3sbm8rIGqB6SH\n4M7sHORFh5KekZ5yGHyKEUR/IXwTHWzSBr6dkPMlGGYKznWSzfyYw8ei5+5yM8IM\nWefZnYS9/+5LPsOhsKkeEkfyGZcD3PaSI9ADu36Hzs0WmPspF20FKUZBKQIFswk6\nwD2C/nyDwfYWYFu2gZT07bdtnWVkZQ5GRUJLMJIFE2YZdEFdJIcpO2swLAmWg+en\nyrClwnrDMVbcM0gIWm6LEmc6mdQdYBEzJR+He1+yaK45ul9664CAEpRiHHIfXaPj\nu8BHB6ZAwdNFNZGpRI/DRzTuTM+QBPgVJtoCJejobhXMkJUd5eTEMkiuEArg6enQ\nwvy2O7QjAgMBAAECggEAJYZ89voWkvF0vv1ByCIuz7VeUl5VC+HMrzfP0li4y/7a\n2Bzgm7ectBtD3TlH83F5BIwaIEFZCKNiJLvJDT+MenPp7h0oQcOhCK+bWu23V+av\nyDLgr6KBuqSYaOFfjYlnkAJag70o2Jk2bXYQGs56CUB6UR/mHGZkU5SsQAxDRjq2\nDvSZaCmyu4u90PTh2d9o2yHDmrgPIZiACLHrE1OXNVcIrnbwIIppOP/tapEkfk5k\nfDBmRXlim5f1yyEoalrH6lbB6BMiDlbM8JOEO2E6X8mXxKyFgcn9RIqemMmgXHoB\n5cKrm6OkYz4452wFtf7xfuAX/WAjAGZQqnSXrdWcYQKBgQDcjzbpFbh+ssGaxqfo\nmaKkoU3pU03P9aNrKPkBwKWCbDOqY/Vfn8fyVOHsSyXODhhnsbtTJ1cmt5Tbd33L\n0MlPnknGv6wuQ1BTdqW3y8TkHMjjdDDU7d6nmUWvI/GfFeJKoaU1qbUAL2H+B2JQ\nBBocvMipe8ma5EEVSSget4A0/QKBgQDVNgyVFUkOtWYJflgIoTekEchb6pDJFdTn\n3ATHzkTsiwkIEl6Emou4foYFteLyacje6486yT2JuxCuEAsZS7Auy6Dy+3Lmv1pt\nHtTtgL1otV+qoSHp0JgtLtOlslXQN4wHyTygBKBUg3Tz8XLbSA7LDbsGbMjqggbP\nxddAKD1nnwKBgBN5xfSBCYCOkk/zeMIuRtFYuQOAap+RZjPBM3O3KiZBHbLPDsy5\n1DMO0cBGxnjSf88wP4VRNP3jOg7DF2WW8x/Hr2YQaMjRAtfL40g+gw1NiWOkT+eN\ndZrBCwkzGFPe39ONQIRjjusMRA/lYQYFxrSA6wskNiIqQ6D4i8VimLyVAoGAcTYc\n4kCGJXA+uQXEWvi34b+rgtr/fDbCcUcLpsipIm0FI6sVUxX44MMWCQw2cH+pMG0m\nBZH7whl5VuOf8ROWfpKTaNIJherPaie36lC0wlekb6bVqiCf3UYDDfWuyTvld/Dr\n5w/tzlJrFGj9kuAlMr6cs2GqIZNfaI3lqOR1DoMCgYAYFYn4YyaMmGZcSg8jN4eS\nbriWJmGIxdVswKIoPA6STxoT2nlMb9sEhwVCGQQxqRqEmHTuN4T/AAa4yaiQR72d\nZoeK55WDxgL5ZjU3vyInyA81mLqfu6wdffTWVy8jmnSO2TlnVzys5w7v/y33BDKC\nQQEW9m6rVKUeR11PfJAR5g==\n-----END PRIVATE KEY-----\n",
|
| 6 |
-
"client_email": "firebase-adminsdk-fbsvc@code-by-dante.iam.gserviceaccount.com",
|
| 7 |
-
"client_id": "115476209207501173964",
|
| 8 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 9 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
| 10 |
-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 11 |
-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40code-by-dante.iam.gserviceaccount.com",
|
| 12 |
-
"universe_domain": "googleapis.com"
|
| 13 |
-
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"type": "service_account",
|
| 3 |
+
"project_id": "code-by-dante",
|
| 4 |
+
"private_key_id": "8ba5d25463c11097970a9d9bd7f1921572100073",
|
| 5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC3sbm8rIGqB6SH\n4M7sHORFh5KekZ5yGHyKEUR/IXwTHWzSBr6dkPMlGGYKznWSzfyYw8ei5+5yM8IM\nWefZnYS9/+5LPsOhsKkeEkfyGZcD3PaSI9ADu36Hzs0WmPspF20FKUZBKQIFswk6\nwD2C/nyDwfYWYFu2gZT07bdtnWVkZQ5GRUJLMJIFE2YZdEFdJIcpO2swLAmWg+en\nyrClwnrDMVbcM0gIWm6LEmc6mdQdYBEzJR+He1+yaK45ul9664CAEpRiHHIfXaPj\nu8BHB6ZAwdNFNZGpRI/DRzTuTM+QBPgVJtoCJejobhXMkJUd5eTEMkiuEArg6enQ\nwvy2O7QjAgMBAAECggEAJYZ89voWkvF0vv1ByCIuz7VeUl5VC+HMrzfP0li4y/7a\n2Bzgm7ectBtD3TlH83F5BIwaIEFZCKNiJLvJDT+MenPp7h0oQcOhCK+bWu23V+av\nyDLgr6KBuqSYaOFfjYlnkAJag70o2Jk2bXYQGs56CUB6UR/mHGZkU5SsQAxDRjq2\nDvSZaCmyu4u90PTh2d9o2yHDmrgPIZiACLHrE1OXNVcIrnbwIIppOP/tapEkfk5k\nfDBmRXlim5f1yyEoalrH6lbB6BMiDlbM8JOEO2E6X8mXxKyFgcn9RIqemMmgXHoB\n5cKrm6OkYz4452wFtf7xfuAX/WAjAGZQqnSXrdWcYQKBgQDcjzbpFbh+ssGaxqfo\nmaKkoU3pU03P9aNrKPkBwKWCbDOqY/Vfn8fyVOHsSyXODhhnsbtTJ1cmt5Tbd33L\n0MlPnknGv6wuQ1BTdqW3y8TkHMjjdDDU7d6nmUWvI/GfFeJKoaU1qbUAL2H+B2JQ\nBBocvMipe8ma5EEVSSget4A0/QKBgQDVNgyVFUkOtWYJflgIoTekEchb6pDJFdTn\n3ATHzkTsiwkIEl6Emou4foYFteLyacje6486yT2JuxCuEAsZS7Auy6Dy+3Lmv1pt\nHtTtgL1otV+qoSHp0JgtLtOlslXQN4wHyTygBKBUg3Tz8XLbSA7LDbsGbMjqggbP\nxddAKD1nnwKBgBN5xfSBCYCOkk/zeMIuRtFYuQOAap+RZjPBM3O3KiZBHbLPDsy5\n1DMO0cBGxnjSf88wP4VRNP3jOg7DF2WW8x/Hr2YQaMjRAtfL40g+gw1NiWOkT+eN\ndZrBCwkzGFPe39ONQIRjjusMRA/lYQYFxrSA6wskNiIqQ6D4i8VimLyVAoGAcTYc\n4kCGJXA+uQXEWvi34b+rgtr/fDbCcUcLpsipIm0FI6sVUxX44MMWCQw2cH+pMG0m\nBZH7whl5VuOf8ROWfpKTaNIJherPaie36lC0wlekb6bVqiCf3UYDDfWuyTvld/Dr\n5w/tzlJrFGj9kuAlMr6cs2GqIZNfaI3lqOR1DoMCgYAYFYn4YyaMmGZcSg8jN4eS\nbriWJmGIxdVswKIoPA6STxoT2nlMb9sEhwVCGQQxqRqEmHTuN4T/AAa4yaiQR72d\nZoeK55WDxgL5ZjU3vyInyA81mLqfu6wdffTWVy8jmnSO2TlnVzys5w7v/y33BDKC\nQQEW9m6rVKUeR11PfJAR5g==\n-----END PRIVATE KEY-----\n",
|
| 6 |
+
"client_email": "firebase-adminsdk-fbsvc@code-by-dante.iam.gserviceaccount.com",
|
| 7 |
+
"client_id": "115476209207501173964",
|
| 8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
| 11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40code-by-dante.iam.gserviceaccount.com",
|
| 12 |
+
"universe_domain": "googleapis.com"
|
| 13 |
+
}
|
install.bat
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
@echo off
|
| 2 |
-
echo [*] Instalando dependencias del proyecto...
|
| 3 |
-
echo.
|
| 4 |
-
npm install
|
| 5 |
-
echo.
|
| 6 |
-
echo [*] Instalacion completada.
|
| 7 |
-
pause
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
echo [*] Instalando dependencias del proyecto...
|
| 3 |
+
echo.
|
| 4 |
+
npm install
|
| 5 |
+
echo.
|
| 6 |
+
echo [*] Instalacion completada.
|
| 7 |
+
pause
|
public/favicon.svg
CHANGED
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
telethon
|
| 2 |
-
fastapi
|
| 3 |
-
uvicorn
|
| 4 |
-
python-multipart
|
| 5 |
-
python-dotenv
|
| 6 |
-
aiofiles
|
|
|
|
| 1 |
+
telethon
|
| 2 |
+
fastapi
|
| 3 |
+
uvicorn
|
| 4 |
+
python-multipart
|
| 5 |
+
python-dotenv
|
| 6 |
+
aiofiles
|
run.bat
CHANGED
|
@@ -1,23 +1,23 @@
|
|
| 1 |
-
@echo off
|
| 2 |
-
title CodeByDante - Sistema Completo
|
| 3 |
-
|
| 4 |
-
echo ==========================================
|
| 5 |
-
echo INICIANDO SISTEMA CODEBYDANTE
|
| 6 |
-
echo ==========================================
|
| 7 |
-
|
| 8 |
-
:: 1. Iniciar la página web (React/Vite)
|
| 9 |
-
echo [1/2] Iniciando Web App...
|
| 10 |
-
start cmd /k "npm run dev"
|
| 11 |
-
|
| 12 |
-
:: 2. Iniciar el Bot de Telegram (Python)
|
| 13 |
-
echo [2/2] Iniciando Bot de Telegram...
|
| 14 |
-
cd bot_telegram
|
| 15 |
-
start cmd /k "python bot.py"
|
| 16 |
-
|
| 17 |
-
echo.
|
| 18 |
-
echo ==========================================
|
| 19 |
-
echo ¡SISTEMA EN LINEA!
|
| 20 |
-
echo Web en: http://localhost:5173 (o similar)
|
| 21 |
-
echo Bot API en: http://localhost:8080
|
| 22 |
-
echo ==========================================
|
| 23 |
-
pause
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
title CodeByDante - Sistema Completo
|
| 3 |
+
|
| 4 |
+
echo ==========================================
|
| 5 |
+
echo INICIANDO SISTEMA CODEBYDANTE
|
| 6 |
+
echo ==========================================
|
| 7 |
+
|
| 8 |
+
:: 1. Iniciar la página web (React/Vite)
|
| 9 |
+
echo [1/2] Iniciando Web App...
|
| 10 |
+
start cmd /k "npm run dev"
|
| 11 |
+
|
| 12 |
+
:: 2. Iniciar el Bot de Telegram (Python)
|
| 13 |
+
echo [2/2] Iniciando Bot de Telegram...
|
| 14 |
+
cd bot_telegram
|
| 15 |
+
start cmd /k "python bot.py"
|
| 16 |
+
|
| 17 |
+
echo.
|
| 18 |
+
echo ==========================================
|
| 19 |
+
echo ¡SISTEMA EN LINEA!
|
| 20 |
+
echo Web en: http://localhost:5173 (o similar)
|
| 21 |
+
echo Bot API en: http://localhost:8080
|
| 22 |
+
echo ==========================================
|
| 23 |
+
pause
|
types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
export interface ContentBlock {
|
| 2 |
id: string;
|
| 3 |
-
type: 'text' | 'markdown';
|
| 4 |
content: any;
|
| 5 |
}
|
| 6 |
|
|
|
|
| 1 |
export interface ContentBlock {
|
| 2 |
id: string;
|
| 3 |
+
type: 'text' | 'markdown' | 'raw-markdown';
|
| 4 |
content: any;
|
| 5 |
}
|
| 6 |
|