diff --git a/app/api/nextcloud/status/route.ts b/app/api/nextcloud/status/route.ts index 4a3b2aa4..7d6437a9 100644 --- a/app/api/nextcloud/status/route.ts +++ b/app/api/nextcloud/status/route.ts @@ -124,7 +124,25 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi if (cachedCredentials) { const cacheAge = Date.now() - cachedCredentials.timestamp; if (cacheAge < 5 * 60 * 1000) { // 5 minutes cache - return cachedCredentials.password; + // Verify the cached credentials still work + const verifyResponse = await fetch(`${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(username)}/`, { + method: 'PROPFIND', + headers: { + 'Authorization': `Basic ${Buffer.from(`${username}:${cachedCredentials.password}`).toString('base64')}`, + 'Depth': '1', + 'Content-Type': 'application/xml', + }, + body: '', + }); + + if (verifyResponse.ok) { + console.log('Using cached credentials'); + return cachedCredentials.password; + } + + // If verification failed, remove from cache + console.log('Cached credentials verification failed'); + credentialsCache.delete(userId); } } @@ -145,7 +163,23 @@ async function getWebDAVCredentials(nextcloudUrl: string, username: string, admi throw new Error(`Failed to get user info: ${userInfoResponse.status} ${userInfoResponse.statusText}`); } - // Generate a new password + // Try to use the admin password first + const adminVerifyResponse = await fetch(`${nextcloudUrl}/remote.php/dav/files/${encodeURIComponent(username)}/`, { + method: 'PROPFIND', + headers: { + 'Authorization': `Basic ${Buffer.from(`${username}:${adminPassword}`).toString('base64')}`, + 'Depth': '1', + 'Content-Type': 'application/xml', + }, + body: '', + }); + + if (adminVerifyResponse.ok) { + console.log('Using admin password for WebDAV access'); + return adminPassword; + } + + // If admin password doesn't work, generate a new password const newPassword = Math.random().toString(36).slice(-12); console.log('Setting new password for user'); diff --git a/components/carnet/navigation.tsx b/components/carnet/navigation.tsx index 8e7c99d3..6d2a2b9f 100644 --- a/components/carnet/navigation.tsx +++ b/components/carnet/navigation.tsx @@ -1,7 +1,7 @@ "use client"; import React, { useState } from 'react'; -import { Search, BookOpen, Tag, Trash2, Star, Archive, X, Folder } from 'lucide-react'; +import { Search, BookOpen, Tag, Trash2, Star, Archive, X, Folder, FileText, Calendar, Heart, Users, LucideIcon } from 'lucide-react'; import { PaneLayout } from '@/app/carnet/page'; interface NavigationProps { @@ -11,9 +11,31 @@ interface NavigationProps { onFolderSelect: (folder: string) => void; } +type FolderType = 'Notes' | 'Diary' | 'Health' | 'Contacts'; + +interface FolderConfig { + icon: LucideIcon; + order: number; +} + +// Define folder order and icons +const FOLDER_CONFIG: Record = { + 'Notes': { icon: FileText, order: 1 }, + 'Diary': { icon: Calendar, order: 2 }, + 'Health': { icon: Heart, order: 3 }, + 'Contacts': { icon: Users, order: 4 } +}; + export default function Navigation({ layout, onLayoutChange, nextcloudFolders, onFolderSelect }: NavigationProps) { const [searchQuery, setSearchQuery] = useState(''); + // Sort folders according to the specified order + const sortedFolders = [...nextcloudFolders].sort((a, b) => { + const orderA = (FOLDER_CONFIG[a as FolderType]?.order) || 999; + const orderB = (FOLDER_CONFIG[b as FolderType]?.order) || 999; + return orderA - orderB; + }); + return (
{/* Search */} @@ -78,19 +100,23 @@ export default function Navigation({ layout, onLayoutChange, nextcloudFolders, o
{/* Nextcloud Folders Section */} - {nextcloudFolders.length > 0 && ( + {sortedFolders.length > 0 && (

Vues

- {nextcloudFolders.map((folder) => ( -
- - {folder} -
- ))} + {sortedFolders.map((folder) => { + const Icon = FOLDER_CONFIG[folder as FolderType]?.icon || Folder; + return ( +
onFolderSelect(folder)} + > + + {folder} +
+ ); + })}
)}