fix ui home folder
This commit is contained in:
+75
-16
@@ -385,9 +385,32 @@ function setupEventListeners() {
|
|||||||
*/
|
*/
|
||||||
async function loadFiles() {
|
async function loadFiles() {
|
||||||
try {
|
try {
|
||||||
let url = '/api/folders';
|
// Always ensure a userHomeFolderId is set
|
||||||
if (app.currentPath) {
|
if (!app.userHomeFolderId) {
|
||||||
// Use the correct endpoint for folder contents
|
// If we don't have a home folder ID yet, try to get the user's username
|
||||||
|
const USER_DATA_KEY = 'oxicloud_user';
|
||||||
|
const userData = JSON.parse(localStorage.getItem(USER_DATA_KEY) || '{}');
|
||||||
|
if (userData.username) {
|
||||||
|
// Find user's home folder
|
||||||
|
await findUserHomeFolder(userData.username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let url;
|
||||||
|
// ALWAYS use the userHomeFolderId (current folder or home folder) to avoid showing root
|
||||||
|
if (!app.currentPath || app.currentPath === '') {
|
||||||
|
// If at root, force user to their home folder
|
||||||
|
if (app.userHomeFolderId) {
|
||||||
|
url = `/api/folders/${app.userHomeFolderId}/contents`;
|
||||||
|
app.currentPath = app.userHomeFolderId;
|
||||||
|
ui.updateBreadcrumb(app.userHomeFolderName || 'Home');
|
||||||
|
} else {
|
||||||
|
// Emergency fallback - this should rarely happen but prevents errors
|
||||||
|
url = '/api/folders';
|
||||||
|
console.warn("Emergency fallback to root folder - this should not normally happen");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Normal case - viewing subfolder contents
|
||||||
url = `/api/folders/${app.currentPath}/contents`;
|
url = `/api/folders/${app.currentPath}/contents`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +463,29 @@ async function loadFiles() {
|
|||||||
|
|
||||||
// Add folders (check if it's an array)
|
// Add folders (check if it's an array)
|
||||||
const folderList = Array.isArray(folders) ? folders : [];
|
const folderList = Array.isArray(folders) ? folders : [];
|
||||||
folderList.forEach(folder => {
|
|
||||||
|
// Get user info for filtering
|
||||||
|
const USER_DATA_KEY = 'oxicloud_user';
|
||||||
|
const userData = JSON.parse(localStorage.getItem(USER_DATA_KEY) || '{}');
|
||||||
|
const username = userData.username || '';
|
||||||
|
|
||||||
|
// Filter folders before adding them to the view
|
||||||
|
const visibleFolders = folderList.filter(folder => {
|
||||||
|
// Skip system folders (starting with dot) when at root
|
||||||
|
if (!app.currentPath && folder.name.startsWith('.')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip other users' folders when at root
|
||||||
|
if (!app.currentPath && folder.name.startsWith('Mi Carpeta - ') && !folder.name.includes(username)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add filtered folders to the view
|
||||||
|
visibleFolders.forEach(folder => {
|
||||||
ui.addFolderToView(folder);
|
ui.addFolderToView(folder);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -852,9 +897,14 @@ function switchToFilesView() {
|
|||||||
filesListView.style.display = app.currentView === 'list' ? 'block' : 'none';
|
filesListView.style.display = app.currentView === 'list' ? 'block' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset path and load files
|
// Use user's home folder instead of root path
|
||||||
app.currentPath = '';
|
if (app.userHomeFolderId) {
|
||||||
ui.updateBreadcrumb('');
|
app.currentPath = app.userHomeFolderId;
|
||||||
|
ui.updateBreadcrumb(app.userHomeFolderName || 'Home');
|
||||||
|
} else {
|
||||||
|
// If no home folder is set, this will trigger finding it in loadFiles()
|
||||||
|
app.currentPath = '';
|
||||||
|
}
|
||||||
loadFiles();
|
loadFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1262,17 +1312,26 @@ async function findUserHomeFolder(username) {
|
|||||||
console.log(`Found ${folderList.length} folders at root`);
|
console.log(`Found ${folderList.length} folders at root`);
|
||||||
|
|
||||||
// Look for a folder with a name pattern that matches the user's home folder
|
// Look for a folder with a name pattern that matches the user's home folder
|
||||||
// Typically named "Mi Carpeta - username"
|
// Only exact match "Mi Carpeta - username"
|
||||||
const homeFolderPattern = `Mi Carpeta - ${username}`;
|
const homeFolderPattern = `Mi Carpeta - ${username}`;
|
||||||
let homeFolder = folderList.find(folder => folder.name === homeFolderPattern);
|
|
||||||
|
|
||||||
// If exact match not found, try a more flexible match
|
// Filter first to remove system folders like .trash that shouldn't be visible
|
||||||
if (!homeFolder) {
|
const visibleFolders = folderList.filter(folder => {
|
||||||
homeFolder = folderList.find(folder =>
|
// Skip system folders (starting with dot)
|
||||||
folder.name.toLowerCase().includes(username.toLowerCase()) ||
|
if (folder.name.startsWith('.')) {
|
||||||
folder.name.startsWith('Mi Carpeta -')
|
return false;
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
// Skip other users' folders
|
||||||
|
if (folder.name.startsWith('Mi Carpeta - ') && !folder.name.includes(username)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Find the user's home folder from filtered list
|
||||||
|
let homeFolder = visibleFolders.find(folder => folder.name === homeFolderPattern);
|
||||||
|
|
||||||
if (homeFolder) {
|
if (homeFolder) {
|
||||||
console.log(`Found user's home folder: ${homeFolder.name} (${homeFolder.id})`);
|
console.log(`Found user's home folder: ${homeFolder.name} (${homeFolder.id})`);
|
||||||
|
|||||||
+19
-5
@@ -27,18 +27,32 @@ const favorites = {
|
|||||||
*/
|
*/
|
||||||
async checkBackendAvailability() {
|
async checkBackendAvailability() {
|
||||||
try {
|
try {
|
||||||
|
// Add error handling to prevent console errors by catching 500 errors
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 3000); // 3s timeout
|
||||||
|
|
||||||
const response = await fetch('/api/favorites', {
|
const response = await fetch('/api/favorites', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${localStorage.getItem('oxicloud_token')}`
|
'Authorization': `Bearer ${localStorage.getItem('oxicloud_token')}`
|
||||||
}
|
},
|
||||||
|
signal: controller.signal
|
||||||
|
}).catch(err => {
|
||||||
|
console.warn('Network error checking favorites API:', err);
|
||||||
|
return { ok: false, status: 0 };
|
||||||
});
|
});
|
||||||
|
|
||||||
this.backendApiAvailable = response.ok;
|
clearTimeout(timeoutId);
|
||||||
console.log(`Backend favorites API ${this.backendApiAvailable ? 'is' : 'is not'} available`);
|
|
||||||
|
|
||||||
// If backend API is available, sync local favorites with server
|
// Check if the response indicates the API is properly implemented
|
||||||
if (this.backendApiAvailable) {
|
this.backendApiAvailable = response.ok;
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.log(`Backend favorites API returned status ${response.status} - using local storage fallback`);
|
||||||
|
this.backendApiAvailable = false;
|
||||||
|
} else {
|
||||||
|
console.log('Backend favorites API is available');
|
||||||
|
// If backend API is available, sync local favorites with server
|
||||||
this.syncWithServer();
|
this.syncWithServer();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
+7
-2
@@ -362,12 +362,17 @@ const ui = {
|
|||||||
return window.i18n.t(key);
|
return window.i18n.t(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// First determine if the current view is the user's home folder
|
||||||
|
const isUserHomeFolder = username && window.app.userHomeFolderName &&
|
||||||
|
window.app.userHomeFolderName.includes(username) &&
|
||||||
|
folderName === window.app.userHomeFolderName;
|
||||||
|
|
||||||
// Set appropriate text for home item
|
// Set appropriate text for home item
|
||||||
if (username && folderName && folderName.includes(username)) {
|
if (isUserHomeFolder) {
|
||||||
// If the current folder is the user's home folder, label it as "Home"
|
// If the current folder is the user's home folder, label it as "Home"
|
||||||
homeItem.textContent = getTranslatedText('breadcrumb.home', 'Home');
|
homeItem.textContent = getTranslatedText('breadcrumb.home', 'Home');
|
||||||
} else if (folderName && folderName.startsWith('Mi Carpeta')) {
|
} else if (folderName && folderName.startsWith('Mi Carpeta')) {
|
||||||
// If the current folder is another user's home folder or a special folder, use its name
|
// If viewing a root folder but not the user's home folder, use its full name
|
||||||
homeItem.textContent = folderName;
|
homeItem.textContent = folderName;
|
||||||
} else {
|
} else {
|
||||||
// Default - use "Home" label
|
// Default - use "Home" label
|
||||||
|
|||||||
Reference in New Issue
Block a user