43 lines
1 KiB
JavaScript
43 lines
1 KiB
JavaScript
// api_v1/scanner/scanActivityFiles.js
|
|
const fsp = require('fs/promises');
|
|
const path = require('path');
|
|
|
|
const SUPPORTED_ACTIVITY_EXTS = new Set(['.fit', '.gpx', '.tcx']);
|
|
|
|
async function* scanActivityFiles(user, cartella, absCartella, db) {
|
|
let entries = [];
|
|
try {
|
|
entries = await fsp.readdir(absCartella, { withFileTypes: true });
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
for (const e of entries) {
|
|
if (!e.isFile()) continue;
|
|
|
|
const ext = path.extname(e.name).toLowerCase();
|
|
if (!SUPPORTED_ACTIVITY_EXTS.has(ext)) continue;
|
|
|
|
const absPath = path.join(absCartella, e.name);
|
|
|
|
// 🔥 MANCAVA QUESTO
|
|
let st;
|
|
try {
|
|
st = await fsp.stat(absPath);
|
|
} catch {
|
|
continue;
|
|
}
|
|
|
|
yield {
|
|
id: `${cartella}/${e.name}`,
|
|
file_name: e.name,
|
|
relPath: e.name, // 🔥 serve per processActivityFile
|
|
absPath,
|
|
ext,
|
|
stat: st,
|
|
path: `/activities/${user}/original/${cartella}/${e.name}` // 🔥 come le foto
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = scanActivityFiles;
|