This commit is contained in:
valere
2025-12-31 16:31:53 +01:00
parent afb20fe75f
commit 9001025837
16 changed files with 3508 additions and 20277 deletions

View File

@@ -10,8 +10,25 @@ export default eventHandler(async (event) => {
try {
let allTracks: any[] = []
let files = await fs.promises.readdir(dirPath)
files = files.filter((f) => !f.startsWith('.') && !f.endsWith('.jpg'))
const items = await fs.promises.readdir(dirPath, { withFileTypes: true })
// Process files
const files = items
.filter((item) => item.isFile() && !item.name.startsWith('.') && !item.name.endsWith('.jpg'))
.map((item) => item.name)
// Process folders
const folders = items
.filter((item) => item.isDirectory() && !item.name.startsWith('.'))
.map((folder, index) => ({
id: `folder-${index}`,
boxId: 'ESFOLDER',
title: folder.name.replace(/_/g, ' ').trim(),
type: 'folder',
order: 0,
date: new Date(),
card: getCardFromDate(new Date())
}))
const tracks = files.map((file, index) => {
const EXT_RE = /\.(mp3|flac|wav|opus)$/i
@@ -59,11 +76,14 @@ export default eventHandler(async (event) => {
})
tracks.sort((a, b) => b.date.getTime() - a.date.getTime())
// assign a stable order after sort (1..N)
tracks.forEach((t, i) => (t.order = i + 1))
allTracks.push(...tracks)
// Combine folders and tracks
const allItems = [...folders, ...tracks]
return allTracks
// Sort by date (newest first) and assign order
allItems.sort((a, b) => b.date.getTime() - a.date.getTime())
allItems.forEach((item, i) => (item.order = i + 1))
return allItems
} catch (error) {
return {
success: false,