GET /api/folders
Returns the folder structure and contents for slideshow navigation and admin management.
Parameters
Specific folder path to get contents from. If not provided, returns root level structure.
Request Examples
curl http://localhost:3000/api/folders
curl "http://localhost:3000/api/folders?path=vacation/2023"
Response
{
"success": true,
"data": {
"currentPath": "",
"folders": [
{
"name": "vacation",
"path": "vacation",
"imageCount": 45,
"subfolderCount": 3,
"lastModified": "2023-07-20T15:30:00Z"
},
{
"name": "family-photos",
"path": "family-photos",
"imageCount": 128,
"subfolderCount": 5,
"lastModified": "2023-06-15T09:20:00Z"
}
],
"images": [
{
"name": "welcome.jpg",
"path": "welcome.jpg",
"size": 2048576,
"lastModified": "2023-05-01T12:00:00Z",
"dimensions": {
"width": 1920,
"height": 1080
}
}
],
"totalFolders": 2,
"totalImages": 1
}
}
{
"success": true,
"data": {
"currentPath": "vacation/2023",
"parentPath": "vacation",
"folders": [
{
"name": "summer",
"path": "vacation/2023/summer",
"imageCount": 23,
"subfolderCount": 0,
"lastModified": "2023-07-15T14:20:00Z"
},
{
"name": "winter",
"path": "vacation/2023/winter",
"imageCount": 18,
"subfolderCount": 0,
"lastModified": "2023-02-28T10:45:00Z"
}
],
"images": [
{
"name": "beach-sunset.jpg",
"path": "vacation/2023/beach-sunset.jpg",
"size": 3145728,
"lastModified": "2023-07-10T18:30:00Z",
"dimensions": {
"width": 2560,
"height": 1440
}
}
],
"totalFolders": 2,
"totalImages": 1
}
}
Response Fields
Current folder path being viewed
Path to parent folder (null for root level)
Array of subfolders in current directory
Array of images in current directory
Count of subfolders in current directory
Count of images in current directory
Folder Object
Full path to folder from root
Number of images in this folder (recursive)
Number of direct subfolders
ISO timestamp of last modification
Image Object
Full path to image from root
Image width and height in pixels
ISO timestamp of last modification
Status Codes
Folder contents retrieved successfully
Specified folder path does not exist
Error accessing file system
Usage Example
async function loadFolderContents(folderPath = '') {
try {
const url = folderPath
? `/api/folders?path=${encodeURIComponent(folderPath)}`
: '/api/folders';
const response = await fetch(url);
const data = await response.json();
if (data.success) {
return {
folders: data.data.folders,
images: data.data.images,
currentPath: data.data.currentPath,
parentPath: data.data.parentPath
};
} else {
throw new Error(data.error);
}
} catch (error) {
console.error('Failed to load folder:', error);
throw error;
}
}
// Build folder navigation
function buildFolderTree() {
loadFolderContents()
.then(data => {
data.folders.forEach(folder => {
console.log(`${folder.name}: ${folder.imageCount} images`);
});
})
.catch(error => {
console.error('Navigation failed:', error);
});
}
Path Handling
- Use forward slashes for folder separators
- Paths are relative to the uploads directory
- URL encode folder names with special characters
- Empty path parameter returns root level
- Invalid paths return 404 error