mirror of
https://github.com/R0m1k3/noteflow.git
synced 2026-10-12 01:39:47 +02:00
Merge pull request #14 from R0m1k3/claude/dockerized-notes-todo-app-011CV1roGRbnm21wgtB2LMxP
Claude/dockerized notes todo app 011 cv1ro g rbnm21wgt b2 l mx p
This commit is contained in:
27 files changed
+5493
-36
No files matched your search
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
@@ -0,0 +1,73 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs['recommended-latest'],
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>client</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+3759
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "client",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.13.2",
|
||||
"react": "^19.2.0",
|
||||
"react-dom": "^19.2.0",
|
||||
"react-router-dom": "^7.9.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.1",
|
||||
"@types/node": "^24.10.0",
|
||||
"@types/react": "^19.2.2",
|
||||
"@types/react-dom": "^19.2.2",
|
||||
"@vitejs/plugin-react": "^5.1.0",
|
||||
"eslint": "^9.39.1",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.24",
|
||||
"globals": "^16.5.0",
|
||||
"typescript": "~5.9.3",
|
||||
"typescript-eslint": "^8.46.3",
|
||||
"vite": "^7.2.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -0,0 +1,42 @@
|
||||
#root {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.react:hover {
|
||||
filter: drop-shadow(0 0 2em #61dafbaa);
|
||||
}
|
||||
|
||||
@keyframes logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
a:nth-of-type(2) .logo {
|
||||
animation: logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { AuthProvider, useAuth } from './contexts/AuthContext';
|
||||
import Login from './pages/Login';
|
||||
import Dashboard from './pages/Dashboard';
|
||||
|
||||
// Protected Route Component
|
||||
function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
||||
const { isAuthenticated } = useAuth();
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" replace />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
// Public Route Component (redirect if already logged in)
|
||||
function PublicRoute({ children }: { children: React.ReactNode }) {
|
||||
const { isAuthenticated } = useAuth();
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
function AppRoutes() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route
|
||||
path="/login"
|
||||
element={
|
||||
<PublicRoute>
|
||||
<Login />
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Dashboard />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
);
|
||||
}
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<AuthProvider>
|
||||
<AppRoutes />
|
||||
</AuthProvider>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
@@ -0,0 +1,66 @@
|
||||
import { createContext, useContext, useState, useEffect, ReactNode } from 'react';
|
||||
import { authApi } from '../services/api';
|
||||
import type { User, AuthContextType } from '../types';
|
||||
|
||||
const AuthContext = createContext<AuthContextType | null>(null);
|
||||
|
||||
export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [token, setToken] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Récupérer le token et user du localStorage au démarrage
|
||||
const storedToken = localStorage.getItem('token');
|
||||
const storedUser = localStorage.getItem('user');
|
||||
|
||||
if (storedToken && storedUser) {
|
||||
setToken(storedToken);
|
||||
setUser(JSON.parse(storedUser));
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
}, []);
|
||||
|
||||
const login = async (username: string, password: string) => {
|
||||
const data = await authApi.login(username, password);
|
||||
|
||||
setToken(data.token);
|
||||
setUser(data.user);
|
||||
|
||||
localStorage.setItem('token', data.token);
|
||||
localStorage.setItem('user', JSON.stringify(data.user));
|
||||
};
|
||||
|
||||
const logout = () => {
|
||||
setToken(null);
|
||||
setUser(null);
|
||||
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
|
||||
authApi.logout().catch(() => {});
|
||||
};
|
||||
|
||||
const value: AuthContextType = {
|
||||
user,
|
||||
token,
|
||||
login,
|
||||
logout,
|
||||
isAuthenticated: !!token,
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <div className="loading">Chargement...</div>;
|
||||
}
|
||||
|
||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||
};
|
||||
|
||||
export const useAuth = () => {
|
||||
const context = useContext(AuthContext);
|
||||
if (!context) {
|
||||
throw new Error('useAuth must be used within AuthProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
color: #1a202c;
|
||||
background: #f7fafc;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
|
||||
:root {
|
||||
--color-primary: #667eea;
|
||||
--color-secondary: #764ba2;
|
||||
--color-text: #1a202c;
|
||||
--color-text-light: #718096;
|
||||
--color-border: #e2e8f0;
|
||||
--color-bg: #f7fafc;
|
||||
--color-card: #ffffff;
|
||||
--shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
|
||||
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
#root {
|
||||
min-height: 100vh;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,303 @@
|
||||
.dashboard {
|
||||
min-height: 100vh;
|
||||
background: #f7fafc;
|
||||
}
|
||||
|
||||
.dashboard-header {
|
||||
background: white;
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
padding: 16px 24px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.header-left h1 {
|
||||
margin: 0;
|
||||
font-size: 24px;
|
||||
color: #1a202c;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
color: #4a5568;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.btn-logout {
|
||||
padding: 8px 16px;
|
||||
background: #e2e8f0;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.btn-logout:hover {
|
||||
background: #cbd5e0;
|
||||
}
|
||||
|
||||
.dashboard-main {
|
||||
padding: 24px;
|
||||
max-width: 1800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.content-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 320px 320px;
|
||||
gap: 24px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-header h2 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #1a202c;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
padding: 8px 16px;
|
||||
background: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background: #5a67d8;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
/* Notes Section */
|
||||
.notes-section {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.notes-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.note-card {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #e2e8f0;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.note-card:hover {
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.note-card h3 {
|
||||
margin: 0 0 12px 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1a202c;
|
||||
}
|
||||
|
||||
.note-card p {
|
||||
margin: 0;
|
||||
color: #718096;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.note-todos-preview {
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid #e2e8f0;
|
||||
font-size: 13px;
|
||||
color: #667eea;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Todos Sidebar */
|
||||
.todos-sidebar,
|
||||
.rss-sidebar {
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #e2e8f0;
|
||||
padding: 20px;
|
||||
position: sticky;
|
||||
top: 88px;
|
||||
max-height: calc(100vh - 112px);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.todo-input-container {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.todo-input-container input {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: 2px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.todo-input-container input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.todos-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.todo-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px;
|
||||
background: #f7fafc;
|
||||
border-radius: 6px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.todo-item:hover {
|
||||
background: #edf2f7;
|
||||
}
|
||||
|
||||
.todo-item input[type="checkbox"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.todo-item span {
|
||||
flex: 1;
|
||||
font-size: 14px;
|
||||
color: #2d3748;
|
||||
}
|
||||
|
||||
.todo-item span.completed {
|
||||
text-decoration: line-through;
|
||||
color: #a0aec0;
|
||||
}
|
||||
|
||||
.btn-delete {
|
||||
padding: 4px 8px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: #cbd5e0;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn-delete:hover {
|
||||
background: #fed7d7;
|
||||
color: #c53030;
|
||||
}
|
||||
|
||||
/* RSS Sidebar */
|
||||
.rss-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.rss-article,
|
||||
.rss-summary {
|
||||
padding: 12px;
|
||||
background: #f7fafc;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.rss-article:hover {
|
||||
background: #edf2f7;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.rss-article h4,
|
||||
.rss-summary h4 {
|
||||
margin: 0 0 8px 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #1a202c;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.rss-article p,
|
||||
.rss-summary p {
|
||||
margin: 8px 0 0 0;
|
||||
font-size: 13px;
|
||||
color: #718096;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.article-meta,
|
||||
.summary-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 12px;
|
||||
color: #a0aec0;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
color: #a0aec0;
|
||||
font-size: 14px;
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
font-size: 18px;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 1400px) {
|
||||
.content-grid {
|
||||
grid-template-columns: 1fr 280px 280px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.content-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.todos-sidebar,
|
||||
.rss-sidebar {
|
||||
position: static;
|
||||
max-height: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import { notesApi, todosApi, rssApi, settingsApi } from '../services/api';
|
||||
import type { Note, GlobalTodo, RssArticle, RssSummary } from '../types';
|
||||
import './Dashboard.css';
|
||||
|
||||
export default function Dashboard() {
|
||||
const { user, logout } = useAuth();
|
||||
const [notes, setNotes] = useState<Note[]>([]);
|
||||
const [todos, setTodos] = useState<GlobalTodo[]>([]);
|
||||
const [rssContent, setRssContent] = useState<RssArticle[] | RssSummary[]>([]);
|
||||
const [showSummaries, setShowSummaries] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
const loadData = async () => {
|
||||
try {
|
||||
const [notesData, todosData, settings] = await Promise.all([
|
||||
notesApi.getAll(false),
|
||||
todosApi.getAll(),
|
||||
settingsApi.getAll(),
|
||||
]);
|
||||
|
||||
setNotes(notesData);
|
||||
setTodos(todosData);
|
||||
|
||||
const summaryEnabled = settings.rss_summary_enabled === '1';
|
||||
setShowSummaries(summaryEnabled);
|
||||
|
||||
if (summaryEnabled) {
|
||||
const summaries = await rssApi.getSummaries();
|
||||
setRssContent(summaries);
|
||||
} else {
|
||||
const articles = await rssApi.getArticles();
|
||||
setRssContent(articles);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erreur chargement données:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const addTodo = async (text: string) => {
|
||||
if (!text.trim()) return;
|
||||
try {
|
||||
const newTodo = await todosApi.create(text);
|
||||
setTodos([...todos, newTodo]);
|
||||
} catch (error) {
|
||||
console.error('Erreur ajout todo:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleTodo = async (id: number, completed: boolean) => {
|
||||
try {
|
||||
await todosApi.update(id, completed);
|
||||
setTodos(todos.map(t => t.id === id ? { ...t, completed } : t));
|
||||
} catch (error) {
|
||||
console.error('Erreur toggle todo:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteTodo = async (id: number) => {
|
||||
if (!window.confirm('Supprimer cette tâche ?')) return;
|
||||
try {
|
||||
await todosApi.delete(id);
|
||||
setTodos(todos.filter(t => t.id !== id));
|
||||
} catch (error) {
|
||||
console.error('Erreur suppression todo:', error);
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return <div className="loading">Chargement...</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="dashboard">
|
||||
{/* Header */}
|
||||
<header className="dashboard-header">
|
||||
<div className="header-left">
|
||||
<h1>📝 NoteFlow</h1>
|
||||
</div>
|
||||
<div className="header-right">
|
||||
<span className="user-name">{user?.username}</span>
|
||||
<button onClick={logout} className="btn-logout">
|
||||
Déconnexion
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="dashboard-main">
|
||||
<div className="content-grid">
|
||||
{/* Notes Section */}
|
||||
<section className="notes-section">
|
||||
<div className="section-header">
|
||||
<h2>Notes</h2>
|
||||
<button className="btn-primary">+ Nouvelle note</button>
|
||||
</div>
|
||||
<div className="notes-grid">
|
||||
{notes.length === 0 ? (
|
||||
<p className="empty-state">Aucune note</p>
|
||||
) : (
|
||||
notes.map(note => (
|
||||
<div key={note.id} className="note-card">
|
||||
<h3>{note.title}</h3>
|
||||
{note.content && <p>{note.content.substring(0, 150)}...</p>}
|
||||
{note.todos && note.todos.length > 0 && (
|
||||
<div className="note-todos-preview">
|
||||
{note.todos_completed}/{note.todos_count} tâches
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Todos Sidebar */}
|
||||
<aside className="todos-sidebar">
|
||||
<div className="section-header">
|
||||
<h2>✓ Todos</h2>
|
||||
</div>
|
||||
<div className="todo-input-container">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Nouvelle tâche..."
|
||||
onKeyPress={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
addTodo(e.currentTarget.value);
|
||||
e.currentTarget.value = '';
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="todos-list">
|
||||
{todos.map(todo => (
|
||||
<div key={todo.id} className="todo-item">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={todo.completed}
|
||||
onChange={(e) => toggleTodo(todo.id, e.target.checked)}
|
||||
/>
|
||||
<span className={todo.completed ? 'completed' : ''}>{todo.text}</span>
|
||||
<button onClick={() => deleteTodo(todo.id)} className="btn-delete">
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{/* RSS Sidebar */}
|
||||
<aside className="rss-sidebar">
|
||||
<div className="section-header">
|
||||
<h2>📰 Actualités</h2>
|
||||
</div>
|
||||
<div className="rss-content">
|
||||
{rssContent.length === 0 ? (
|
||||
<p className="empty-state">Aucun contenu</p>
|
||||
) : showSummaries ? (
|
||||
// Afficher les résumés
|
||||
(rssContent as RssSummary[]).map(summary => (
|
||||
<div key={summary.id} className="rss-summary">
|
||||
<h4>Résumé du {new Date(summary.created_at).toLocaleDateString('fr-FR')}</h4>
|
||||
<p>{summary.summary.substring(0, 200)}...</p>
|
||||
<div className="summary-meta">
|
||||
{summary.articles_count} articles • {summary.model.split('/')[1] || summary.model}
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
// Afficher les articles
|
||||
(rssContent as RssArticle[]).map(article => (
|
||||
<div
|
||||
key={article.id}
|
||||
className="rss-article"
|
||||
onClick={() => window.open(article.link, '_blank')}
|
||||
>
|
||||
<h4>{article.title}</h4>
|
||||
<div className="article-meta">
|
||||
<span>{article.feed_title}</span>
|
||||
<span>{new Date(article.pub_date).toLocaleDateString('fr-FR')}</span>
|
||||
</div>
|
||||
{article.description && <p>{article.description.substring(0, 100)}...</p>}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
.login-page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
background: white;
|
||||
border-radius: 16px;
|
||||
padding: 40px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
max-width: 420px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
text-align: center;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.login-header h1 {
|
||||
font-size: 32px;
|
||||
margin: 0 0 8px 0;
|
||||
color: #1a202c;
|
||||
}
|
||||
|
||||
.login-header p {
|
||||
margin: 0;
|
||||
color: #718096;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.login-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #2d3748;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
padding: 12px 16px;
|
||||
border: 2px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
font-size: 15px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.form-group input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
||||
}
|
||||
|
||||
.form-group input:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
background: #fed7d7;
|
||||
color: #c53030;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
border: 1px solid #fc8181;
|
||||
}
|
||||
|
||||
.btn-login {
|
||||
padding: 14px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.btn-login:hover:not(:disabled) {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.btn-login:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
text-align: center;
|
||||
margin-top: 24px;
|
||||
padding-top: 24px;
|
||||
border-top: 1px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.login-footer p {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
color: #718096;
|
||||
}
|
||||
|
||||
.login-footer strong {
|
||||
color: #2d3748;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import { useState, FormEvent } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAuth } from '../contexts/AuthContext';
|
||||
import './Login.css';
|
||||
|
||||
export default function Login() {
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const { login } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleSubmit = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
await login(username, password);
|
||||
navigate('/');
|
||||
} catch (err: any) {
|
||||
setError(err.response?.data?.error || 'Erreur de connexion');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="login-page">
|
||||
<div className="login-container">
|
||||
<div className="login-header">
|
||||
<h1>📝 NoteFlow</h1>
|
||||
<p>Connectez-vous pour accéder à vos notes</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="login-form">
|
||||
{error && <div className="error-message">{error}</div>}
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="username">Nom d'utilisateur</label>
|
||||
<input
|
||||
type="text"
|
||||
id="username"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
required
|
||||
autoFocus
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="password">Mot de passe</label>
|
||||
<input
|
||||
type="password"
|
||||
id="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
disabled={loading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button type="submit" className="btn-login" disabled={loading}>
|
||||
{loading ? 'Connexion...' : 'Se connecter'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="login-footer">
|
||||
<p>Compte par défaut : <strong>admin / admin</strong></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
import axios, { AxiosInstance, AxiosError } from 'axios';
|
||||
import type {
|
||||
User,
|
||||
Note,
|
||||
Todo,
|
||||
GlobalTodo,
|
||||
RssFeed,
|
||||
RssArticle,
|
||||
RssSummary,
|
||||
OpenRouterModel,
|
||||
Settings,
|
||||
NoteFile
|
||||
} from '../types';
|
||||
|
||||
// Configuration Axios
|
||||
const api: AxiosInstance = axios.create({
|
||||
baseURL: '/api',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
// Intercepteur pour ajouter le token JWT
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
// Intercepteur pour gérer les erreurs d'authentification
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error: AxiosError) => {
|
||||
if (error.response?.status === 401 || error.response?.status === 403) {
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('user');
|
||||
window.location.href = '/login';
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// === AUTH ===
|
||||
export const authApi = {
|
||||
login: async (username: string, password: string) => {
|
||||
const { data } = await api.post('/auth/login', { username, password });
|
||||
return data;
|
||||
},
|
||||
register: async (username: string, password: string) => {
|
||||
const { data } = await api.post('/auth/register', { username, password });
|
||||
return data;
|
||||
},
|
||||
logout: async () => {
|
||||
const { data } = await api.post('/auth/logout');
|
||||
return data;
|
||||
},
|
||||
};
|
||||
|
||||
// === USERS ===
|
||||
export const usersApi = {
|
||||
getAll: async (): Promise<User[]> => {
|
||||
const { data } = await api.get('/users');
|
||||
return data;
|
||||
},
|
||||
create: async (username: string, password: string, is_admin: boolean): Promise<User> => {
|
||||
const { data } = await api.post('/users', { username, password, is_admin });
|
||||
return data;
|
||||
},
|
||||
update: async (id: number, password: string): Promise<void> => {
|
||||
await api.put(`/users/${id}`, { password });
|
||||
},
|
||||
delete: async (id: number): Promise<void> => {
|
||||
await api.delete(`/users/${id}`);
|
||||
},
|
||||
};
|
||||
|
||||
// === NOTES ===
|
||||
export const notesApi = {
|
||||
getAll: async (archived: boolean = false): Promise<Note[]> => {
|
||||
const { data } = await api.get(`/notes?archived=${archived}`);
|
||||
return Array.isArray(data) ? data : [];
|
||||
},
|
||||
getOne: async (id: number): Promise<Note> => {
|
||||
const { data } = await api.get(`/notes/${id}`);
|
||||
return data;
|
||||
},
|
||||
create: async (note: Partial<Note>): Promise<Note> => {
|
||||
const { data } = await api.post('/notes', note);
|
||||
return data;
|
||||
},
|
||||
update: async (id: number, note: Partial<Note>): Promise<void> => {
|
||||
await api.put(`/notes/${id}`, note);
|
||||
},
|
||||
delete: async (id: number): Promise<void> => {
|
||||
await api.delete(`/notes/${id}`);
|
||||
},
|
||||
archive: async (id: number, archived: boolean): Promise<void> => {
|
||||
await api.put(`/notes/${id}/archive`, { archived });
|
||||
},
|
||||
uploadImage: async (id: number, file: File): Promise<{ filename: string; url: string }> => {
|
||||
const formData = new FormData();
|
||||
formData.append('image', file);
|
||||
const { data } = await api.post(`/notes/${id}/image`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
return data;
|
||||
},
|
||||
deleteImage: async (id: number): Promise<void> => {
|
||||
await api.delete(`/notes/${id}/image`);
|
||||
},
|
||||
uploadFile: async (id: number, file: File): Promise<NoteFile> => {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
const { data } = await api.post(`/notes/${id}/files`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
});
|
||||
return data;
|
||||
},
|
||||
downloadFile: async (fileId: number): Promise<void> => {
|
||||
window.open(`/api/notes/files/${fileId}/download`, '_blank');
|
||||
},
|
||||
deleteFile: async (fileId: number): Promise<void> => {
|
||||
await api.delete(`/api/notes/files/${fileId}`);
|
||||
},
|
||||
};
|
||||
|
||||
// === NOTE TODOS ===
|
||||
export const noteTodosApi = {
|
||||
create: async (noteId: number, text: string): Promise<Todo> => {
|
||||
const { data } = await api.post(`/notes/${noteId}/todos`, { text });
|
||||
return data;
|
||||
},
|
||||
update: async (id: number, completed: boolean): Promise<void> => {
|
||||
await api.put(`/notes/todos/${id}`, { completed });
|
||||
},
|
||||
delete: async (id: number): Promise<void> => {
|
||||
await api.delete(`/notes/todos/${id}`);
|
||||
},
|
||||
};
|
||||
|
||||
// === GLOBAL TODOS ===
|
||||
export const todosApi = {
|
||||
getAll: async (): Promise<GlobalTodo[]> => {
|
||||
const { data} = await api.get('/todos');
|
||||
return data;
|
||||
},
|
||||
create: async (text: string): Promise<GlobalTodo> => {
|
||||
const { data } = await api.post('/todos', { text });
|
||||
return data;
|
||||
},
|
||||
update: async (id: number, completed: boolean): Promise<void> => {
|
||||
await api.put(`/todos/${id}`, { completed });
|
||||
},
|
||||
delete: async (id: number): Promise<void> => {
|
||||
await api.delete(`/todos/${id}`);
|
||||
},
|
||||
};
|
||||
|
||||
// === RSS FEEDS ===
|
||||
export const rssApi = {
|
||||
getFeeds: async (): Promise<RssFeed[]> => {
|
||||
const { data } = await api.get('/rss/feeds');
|
||||
return data;
|
||||
},
|
||||
addFeed: async (url: string): Promise<RssFeed> => {
|
||||
const { data } = await api.post('/rss/feeds', { url });
|
||||
return data;
|
||||
},
|
||||
updateFeed: async (id: number, enabled: boolean): Promise<void> => {
|
||||
await api.put(`/rss/feeds/${id}`, { enabled });
|
||||
},
|
||||
deleteFeed: async (id: number): Promise<void> => {
|
||||
await api.delete(`/rss/feeds/${id}`);
|
||||
},
|
||||
fetchArticles: async (): Promise<{ message: string }> => {
|
||||
const { data } = await api.post('/rss/fetch');
|
||||
return data;
|
||||
},
|
||||
getArticles: async (): Promise<RssArticle[]> => {
|
||||
const { data } = await api.get('/rss/articles');
|
||||
return data || [];
|
||||
},
|
||||
getSummaries: async (): Promise<RssSummary[]> => {
|
||||
const { data } = await api.get('/rss/summaries');
|
||||
return data || [];
|
||||
},
|
||||
generateSummary: async (): Promise<{ summary: string; model: string; articles_count: number }> => {
|
||||
const { data } = await api.post('/rss/summarize');
|
||||
return data;
|
||||
},
|
||||
getModels: async (): Promise<OpenRouterModel[]> => {
|
||||
const { data } = await api.get('/rss/models');
|
||||
return data;
|
||||
},
|
||||
};
|
||||
|
||||
// === SETTINGS ===
|
||||
export const settingsApi = {
|
||||
getAll: async (): Promise<Settings> => {
|
||||
const { data } = await api.get('/settings');
|
||||
return data;
|
||||
},
|
||||
getOne: async (key: string): Promise<{ key: string; value: string }> => {
|
||||
const { data } = await api.get(`/settings/${key}`);
|
||||
return data;
|
||||
},
|
||||
update: async (key: string, value: string): Promise<void> => {
|
||||
await api.put(`/settings/${key}`, { value });
|
||||
},
|
||||
delete: async (key: string): Promise<void> => {
|
||||
await api.delete(`/settings/${key}`);
|
||||
},
|
||||
};
|
||||
|
||||
export default api;
|
||||
@@ -0,0 +1,114 @@
|
||||
// Types pour l'application NoteFlow
|
||||
|
||||
export interface User {
|
||||
id: number;
|
||||
username: string;
|
||||
is_admin: boolean;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface Note {
|
||||
id: number;
|
||||
user_id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
image_filename?: string;
|
||||
archived: boolean;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
todos?: Todo[];
|
||||
files?: NoteFile[];
|
||||
todos_count?: number;
|
||||
todos_completed?: number;
|
||||
}
|
||||
|
||||
export interface Todo {
|
||||
id: number;
|
||||
note_id: number;
|
||||
text: string;
|
||||
completed: boolean;
|
||||
position: number;
|
||||
}
|
||||
|
||||
export interface GlobalTodo {
|
||||
id: number;
|
||||
user_id: number;
|
||||
text: string;
|
||||
completed: boolean;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface NoteFile {
|
||||
id: number;
|
||||
note_id: number;
|
||||
filename: string;
|
||||
original_name: string;
|
||||
file_size: number;
|
||||
mime_type: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface RssFeed {
|
||||
id: number;
|
||||
url: string;
|
||||
title: string;
|
||||
description: string;
|
||||
enabled: boolean;
|
||||
created_at: string;
|
||||
last_fetched_at?: string;
|
||||
}
|
||||
|
||||
export interface RssArticle {
|
||||
id: number;
|
||||
feed_id: number;
|
||||
title: string;
|
||||
link: string;
|
||||
description?: string;
|
||||
pub_date: string;
|
||||
content?: string;
|
||||
feed_title: string;
|
||||
feed_url: string;
|
||||
}
|
||||
|
||||
export interface RssSummary {
|
||||
id: number;
|
||||
summary: string;
|
||||
model: string;
|
||||
articles_count: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface OpenRouterModel {
|
||||
id: string;
|
||||
name: string;
|
||||
provider: string;
|
||||
context_length?: number;
|
||||
pricing?: {
|
||||
prompt: number;
|
||||
completion: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface Settings {
|
||||
[key: string]: string;
|
||||
openrouter_api_key?: string;
|
||||
openrouter_model?: string;
|
||||
rss_summary_enabled?: string;
|
||||
rss_summary_prompt?: string;
|
||||
}
|
||||
|
||||
export interface AuthContextType {
|
||||
user: User | null;
|
||||
token: string | null;
|
||||
login: (username: string, password: string) => Promise<void>;
|
||||
logout: () => void;
|
||||
isAuthenticated: boolean;
|
||||
}
|
||||
|
||||
export interface ApiError {
|
||||
error: string;
|
||||
details?: any;
|
||||
}
|
||||
|
||||
export type NoteView = 'active' | 'archived';
|
||||
export type TodoFilter = 'all' | 'active' | 'completed';
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"types": ["vite/client"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 5173,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:3000',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/uploads': {
|
||||
target: 'http://localhost:3000',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
build: {
|
||||
outDir: '../public-react',
|
||||
},
|
||||
})
|
||||
@@ -126,6 +126,17 @@ function initDatabase() {
|
||||
)
|
||||
`);
|
||||
|
||||
// Table rss_summaries (résumés générés)
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS rss_summaries (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
summary TEXT NOT NULL,
|
||||
model TEXT,
|
||||
articles_count INTEGER DEFAULT 0,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
|
||||
// Créer les index pour la performance
|
||||
db.run('CREATE INDEX IF NOT EXISTS idx_notes_user ON notes(user_id)');
|
||||
db.run('CREATE INDEX IF NOT EXISTS idx_note_todos ON note_todos(note_id)');
|
||||
|
||||
@@ -484,6 +484,73 @@ body {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.rss-summary {
|
||||
padding: var(--spacing-lg);
|
||||
background: var(--color-background);
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid var(--color-border);
|
||||
margin-bottom: var(--spacing-md);
|
||||
}
|
||||
|
||||
.rss-summary-header {
|
||||
margin-bottom: var(--spacing-md);
|
||||
padding-bottom: var(--spacing-sm);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.rss-summary-title {
|
||||
font-size: var(--font-size-base);
|
||||
font-weight: var(--font-weight-semibold);
|
||||
color: var(--color-text-primary);
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.rss-summary-meta {
|
||||
display: flex;
|
||||
gap: var(--spacing-md);
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.rss-summary-content {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--color-text-primary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.rss-summary-content h2 {
|
||||
font-size: var(--font-size-lg);
|
||||
font-weight: var(--font-weight-bold);
|
||||
color: var(--color-text-primary);
|
||||
margin: var(--spacing-md) 0 var(--spacing-sm) 0;
|
||||
}
|
||||
|
||||
.rss-summary-content h3 {
|
||||
font-size: var(--font-size-base);
|
||||
font-weight: var(--font-weight-semibold);
|
||||
color: var(--color-text-primary);
|
||||
margin: var(--spacing-sm) 0 var(--spacing-xs) 0;
|
||||
}
|
||||
|
||||
.rss-summary-content ul,
|
||||
.rss-summary-content ol {
|
||||
margin: var(--spacing-sm) 0;
|
||||
padding-left: var(--spacing-xl);
|
||||
}
|
||||
|
||||
.rss-summary-content li {
|
||||
margin-bottom: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.rss-summary-content strong {
|
||||
font-weight: var(--font-weight-semibold);
|
||||
color: var(--color-text-primary);
|
||||
}
|
||||
|
||||
.rss-summary-content em {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 1200px) {
|
||||
.content-container {
|
||||
|
||||
+84
-12
@@ -1486,8 +1486,19 @@ async function fetchRssArticles() {
|
||||
|
||||
async function loadRssArticles() {
|
||||
try {
|
||||
const articles = await api.get('/api/rss/articles');
|
||||
renderRssArticles(articles);
|
||||
// Vérifier si les résumés sont activés
|
||||
const settings = await api.get('/api/settings');
|
||||
const summaryEnabled = settings.rss_summary_enabled === '1' || settings.rss_summary_enabled === 'true';
|
||||
|
||||
if (summaryEnabled) {
|
||||
// Charger les résumés
|
||||
const summaries = await api.get('/api/rss/summaries');
|
||||
renderRssSummaries(summaries);
|
||||
} else {
|
||||
// Charger les articles normaux
|
||||
const articles = await api.get('/api/rss/articles');
|
||||
renderRssArticles(articles);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erreur chargement articles RSS:', error);
|
||||
}
|
||||
@@ -1514,6 +1525,57 @@ function renderRssArticles(articles) {
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function renderRssSummaries(summaries) {
|
||||
const container = document.getElementById('rssArticlesList');
|
||||
if (!container) return;
|
||||
|
||||
if (!summaries || summaries.length === 0) {
|
||||
container.innerHTML = '<p class="rss-empty">Aucun résumé pour le moment</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = summaries.map(summary => `
|
||||
<div class="rss-summary">
|
||||
<div class="rss-summary-header">
|
||||
<div class="rss-summary-title">📰 Résumé ${new Date(summary.created_at).toLocaleDateString('fr-FR')}</div>
|
||||
<div class="rss-summary-meta">
|
||||
<span>${summary.articles_count} articles</span>
|
||||
${summary.model ? `<span>${escapeHtml(summary.model.split('/')[1] || summary.model)}</span>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rss-summary-content">${formatSummary(summary.summary)}</div>
|
||||
</div>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function formatSummary(summary) {
|
||||
// Convertir le Markdown de base en HTML
|
||||
let html = escapeHtml(summary);
|
||||
|
||||
// Titres
|
||||
html = html.replace(/\n## (.*?)\n/g, '<h3>$1</h3>');
|
||||
html = html.replace(/\n# (.*?)\n/g, '<h2>$1</h2>');
|
||||
|
||||
// Listes à puces
|
||||
html = html.replace(/\n- (.*?)(?=\n|$)/g, '<li>$1</li>');
|
||||
html = html.replace(/(<li>.*<\/li>)/s, '<ul>$1</ul>');
|
||||
|
||||
// Listes numérotées
|
||||
html = html.replace(/\n\d+\. (.*?)(?=\n|$)/g, '<li>$1</li>');
|
||||
|
||||
// Gras
|
||||
html = html.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
|
||||
|
||||
// Italique
|
||||
html = html.replace(/\*(.*?)\*/g, '<em>$1</em>');
|
||||
|
||||
// Sauts de ligne
|
||||
html = html.replace(/\n\n/g, '<br><br>');
|
||||
html = html.replace(/\n/g, '<br>');
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
async function summarizeRss() {
|
||||
const btn = document.getElementById('summarizeRssBtn');
|
||||
if (!btn) return;
|
||||
@@ -1525,18 +1587,28 @@ async function summarizeRss() {
|
||||
try {
|
||||
const result = await api.post('/api/rss/summarize', {});
|
||||
|
||||
// Create a new note with the summary
|
||||
const newNote = await api.post('/api/notes', {
|
||||
title: `📰 Résumé RSS - ${new Date().toLocaleDateString('fr-FR')}`,
|
||||
content: result.summary
|
||||
});
|
||||
// Vérifier si les résumés sont activés
|
||||
const settings = await api.get('/api/settings');
|
||||
const summaryEnabled = settings.rss_summary_enabled === '1' || settings.rss_summary_enabled === 'true';
|
||||
|
||||
alert('Résumé généré et sauvegardé dans une nouvelle note !');
|
||||
await loadNotes();
|
||||
if (summaryEnabled) {
|
||||
// Si les résumés sont activés, juste recharger le bloc RSS
|
||||
alert('Résumé généré avec succès !');
|
||||
await loadRssArticles();
|
||||
} else {
|
||||
// Sinon créer une note avec le résumé
|
||||
const newNote = await api.post('/api/notes', {
|
||||
title: `📰 Résumé RSS - ${new Date().toLocaleDateString('fr-FR')}`,
|
||||
content: result.summary
|
||||
});
|
||||
|
||||
// Expand the new note
|
||||
state.expandedNoteId = newNote.id;
|
||||
renderNotes();
|
||||
alert('Résumé généré et sauvegardé dans une nouvelle note !');
|
||||
await loadNotes();
|
||||
|
||||
// Expand the new note
|
||||
state.expandedNoteId = newNote.id;
|
||||
renderNotes();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erreur génération résumé RSS:', error);
|
||||
if (error.message && error.message.includes('400')) {
|
||||
|
||||
+74
-24
@@ -170,7 +170,7 @@ router.post('/fetch', requireAdmin, async (req, res) => {
|
||||
|
||||
/**
|
||||
* GET /api/rss/articles
|
||||
* Récupérer les 10 derniers articles
|
||||
* Récupérer les 5 derniers articles
|
||||
*/
|
||||
router.get('/articles', async (req, res) => {
|
||||
try {
|
||||
@@ -181,7 +181,7 @@ router.get('/articles', async (req, res) => {
|
||||
FROM rss_articles a
|
||||
JOIN rss_feeds f ON a.feed_id = f.id
|
||||
ORDER BY a.pub_date DESC
|
||||
LIMIT 10
|
||||
LIMIT 5
|
||||
`);
|
||||
|
||||
res.json(articles || []);
|
||||
@@ -193,7 +193,7 @@ router.get('/articles', async (req, res) => {
|
||||
|
||||
/**
|
||||
* POST /api/rss/summarize
|
||||
* Générer un résumé des 10 derniers articles avec OpenRouter
|
||||
* Générer un résumé des 5 derniers articles avec OpenRouter
|
||||
*/
|
||||
router.post('/summarize', requireAdmin, async (req, res) => {
|
||||
try {
|
||||
@@ -206,7 +206,7 @@ router.post('/summarize', requireAdmin, async (req, res) => {
|
||||
return res.status(400).json({ error: 'Clé API OpenRouter non configurée' });
|
||||
}
|
||||
|
||||
// Récupérer les 10 derniers articles
|
||||
// Récupérer les 5 derniers articles
|
||||
const articles = await getAll(`
|
||||
SELECT
|
||||
a.title, a.description, a.link, a.pub_date,
|
||||
@@ -214,7 +214,7 @@ router.post('/summarize', requireAdmin, async (req, res) => {
|
||||
FROM rss_articles a
|
||||
JOIN rss_feeds f ON a.feed_id = f.id
|
||||
ORDER BY a.pub_date DESC
|
||||
LIMIT 10
|
||||
LIMIT 5
|
||||
`);
|
||||
|
||||
if (articles.length === 0) {
|
||||
@@ -272,7 +272,13 @@ Format de sortie en Markdown avec des sections claires.`;
|
||||
|
||||
const summary = response.data.choices[0].message.content;
|
||||
|
||||
logger.info('Résumé généré avec succès');
|
||||
// Sauvegarder le résumé en base de données
|
||||
await runQuery(
|
||||
'INSERT INTO rss_summaries (summary, model, articles_count) VALUES (?, ?, ?)',
|
||||
[summary, selectedModel, articles.length]
|
||||
);
|
||||
|
||||
logger.info('Résumé généré et sauvegardé avec succès');
|
||||
|
||||
res.json({
|
||||
summary,
|
||||
@@ -295,30 +301,74 @@ Format de sortie en Markdown avec des sections claires.`;
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/rss/models
|
||||
* Récupérer la liste des modèles OpenRouter
|
||||
* GET /api/rss/summaries
|
||||
* Récupérer les 5 derniers résumés
|
||||
*/
|
||||
router.get('/models', requireAdmin, async (req, res) => {
|
||||
router.get('/summaries', async (req, res) => {
|
||||
try {
|
||||
// Liste des modèles populaires pour le résumé
|
||||
const models = [
|
||||
{ id: 'openai/gpt-4-turbo', name: 'GPT-4 Turbo', provider: 'OpenAI' },
|
||||
{ id: 'openai/gpt-4', name: 'GPT-4', provider: 'OpenAI' },
|
||||
{ id: 'openai/gpt-3.5-turbo', name: 'GPT-3.5 Turbo', provider: 'OpenAI' },
|
||||
{ id: 'anthropic/claude-3-opus', name: 'Claude 3 Opus', provider: 'Anthropic' },
|
||||
{ id: 'anthropic/claude-3-sonnet', name: 'Claude 3 Sonnet', provider: 'Anthropic' },
|
||||
{ id: 'anthropic/claude-3-haiku', name: 'Claude 3 Haiku', provider: 'Anthropic' },
|
||||
{ id: 'google/gemini-pro', name: 'Gemini Pro', provider: 'Google' },
|
||||
{ id: 'meta-llama/llama-3-70b-instruct', name: 'Llama 3 70B', provider: 'Meta' },
|
||||
{ id: 'mistralai/mistral-large', name: 'Mistral Large', provider: 'Mistral AI' },
|
||||
{ id: 'mistralai/mixtral-8x7b-instruct', name: 'Mixtral 8x7B', provider: 'Mistral AI' }
|
||||
];
|
||||
const summaries = await getAll(`
|
||||
SELECT id, summary, model, articles_count, created_at
|
||||
FROM rss_summaries
|
||||
ORDER BY created_at DESC
|
||||
LIMIT 5
|
||||
`);
|
||||
|
||||
res.json(models);
|
||||
res.json(summaries || []);
|
||||
} catch (error) {
|
||||
logger.error('Erreur lors de la récupération des modèles:', error);
|
||||
logger.error('Erreur lors de la récupération des résumés:', error);
|
||||
res.status(500).json({ error: 'Erreur serveur' });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/rss/models
|
||||
* Récupérer la liste des modèles OpenRouter depuis l'API
|
||||
*/
|
||||
router.get('/models', requireAdmin, async (req, res) => {
|
||||
try {
|
||||
// Récupérer les modèles depuis l'API OpenRouter
|
||||
const response = await axios.get('https://openrouter.ai/api/v1/models', {
|
||||
headers: {
|
||||
'HTTP-Referer': 'https://noteflow.app',
|
||||
'X-Title': 'NoteFlow'
|
||||
},
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
// Transformer les données en format simplifié
|
||||
const models = response.data.data.map(model => ({
|
||||
id: model.id,
|
||||
name: model.name || model.id,
|
||||
provider: model.id.split('/')[0] || 'Unknown',
|
||||
context_length: model.context_length,
|
||||
pricing: model.pricing
|
||||
}));
|
||||
|
||||
// Trier par provider puis par nom
|
||||
models.sort((a, b) => {
|
||||
if (a.provider !== b.provider) {
|
||||
return a.provider.localeCompare(b.provider);
|
||||
}
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
|
||||
res.json(models);
|
||||
} catch (error) {
|
||||
logger.error('Erreur lors de la récupération des modèles:', error);
|
||||
|
||||
// Fallback sur une liste de modèles populaires si l'API échoue
|
||||
const fallbackModels = [
|
||||
{ id: 'openai/gpt-4-turbo', name: 'GPT-4 Turbo', provider: 'openai' },
|
||||
{ id: 'openai/gpt-3.5-turbo', name: 'GPT-3.5 Turbo', provider: 'openai' },
|
||||
{ id: 'anthropic/claude-3-opus', name: 'Claude 3 Opus', provider: 'anthropic' },
|
||||
{ id: 'anthropic/claude-3-sonnet', name: 'Claude 3 Sonnet', provider: 'anthropic' },
|
||||
{ id: 'google/gemini-pro', name: 'Gemini Pro', provider: 'google' },
|
||||
{ id: 'meta-llama/llama-3-70b-instruct', name: 'Llama 3 70B', provider: 'meta-llama' },
|
||||
{ id: 'mistralai/mistral-large', name: 'Mistral Large', provider: 'mistralai' }
|
||||
];
|
||||
|
||||
res.json(fallbackModels);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in new issue
Block a user