chore: update Angular cache with new TypeScript definitions
This commit is contained in:
@@ -222,6 +222,101 @@ if (!fs.existsSync(distDir)) {
|
||||
// Servir les fichiers statiques de l'application Angular
|
||||
app.use(express.static(distDir));
|
||||
|
||||
// Exposer les fichiers de la voûte pour un accès direct si nécessaire
|
||||
app.use('/vault', express.static(vaultDir));
|
||||
|
||||
// Résolution des attachements: recherche le fichier en remontant les dossiers depuis la note, puis dans la voûte
|
||||
app.get('/api/attachments/resolve', (req, res) => {
|
||||
try {
|
||||
const rawName = typeof req.query.name === 'string' ? req.query.name.trim() : '';
|
||||
if (!rawName) {
|
||||
return res.status(400).type('text/plain').send('Missing required query parameter: name');
|
||||
}
|
||||
|
||||
const sanitize = (value) => value.replace(/\\/g, '/').replace(/^[/]+|[/]+$/g, '');
|
||||
const name = sanitize(rawName);
|
||||
const noteRelPath = typeof req.query.note === 'string' ? sanitize(req.query.note) : '';
|
||||
const baseRaw = typeof req.query.base === 'string' ? req.query.base : '';
|
||||
const baseRel = sanitize(baseRaw);
|
||||
|
||||
const candidateDirs = new Set();
|
||||
|
||||
const addCandidate = (dir, extra) => {
|
||||
const dirSegments = sanitize(dir);
|
||||
const extraSegments = sanitize(extra);
|
||||
if (dirSegments && extraSegments) {
|
||||
candidateDirs.add(`${dirSegments}/${extraSegments}`);
|
||||
} else if (dirSegments) {
|
||||
candidateDirs.add(dirSegments);
|
||||
} else if (extraSegments) {
|
||||
candidateDirs.add(extraSegments);
|
||||
} else {
|
||||
candidateDirs.add('');
|
||||
}
|
||||
};
|
||||
|
||||
// Dossiers parents de la note
|
||||
if (noteRelPath) {
|
||||
const segments = noteRelPath.split('/');
|
||||
segments.pop(); // retirer le nom de fichier
|
||||
while (segments.length >= 0) {
|
||||
const currentDir = segments.join('/');
|
||||
addCandidate(currentDir, baseRel);
|
||||
addCandidate(currentDir, '');
|
||||
if (!segments.length) break;
|
||||
segments.pop();
|
||||
}
|
||||
}
|
||||
|
||||
// Si base est défini, tenter aussi directement depuis la racine
|
||||
if (baseRel) {
|
||||
addCandidate('', baseRel);
|
||||
}
|
||||
|
||||
// Toujours ajouter la racine seule en dernier recours
|
||||
addCandidate('', '');
|
||||
|
||||
for (const dir of candidateDirs) {
|
||||
const absoluteDir = dir ? path.join(vaultDir, dir) : vaultDir;
|
||||
const candidatePath = path.join(absoluteDir, name);
|
||||
try {
|
||||
if (fs.existsSync(candidatePath) && fs.statSync(candidatePath).isFile()) {
|
||||
return res.sendFile(candidatePath);
|
||||
}
|
||||
} catch {
|
||||
// Ignorer et poursuivre
|
||||
}
|
||||
}
|
||||
|
||||
// Recherche exhaustive en dernier recours (coût plus élevé)
|
||||
const stack = [vaultDir];
|
||||
const nameLower = name.toLowerCase();
|
||||
while (stack.length) {
|
||||
const currentDir = stack.pop();
|
||||
let entries = [];
|
||||
try {
|
||||
entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(currentDir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
stack.push(fullPath);
|
||||
} else if (entry.isFile() && entry.name.toLowerCase() === nameLower) {
|
||||
return res.sendFile(fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res.status(404).type('text/plain').send(`‼️Attachement ${rawName} introuvable`);
|
||||
} catch (error) {
|
||||
console.error('Attachment resolve error:', error);
|
||||
return res.status(500).type('text/plain').send('Attachment resolver internal error');
|
||||
}
|
||||
});
|
||||
|
||||
// API endpoint pour la santé
|
||||
app.get('/api/health', (req, res) => {
|
||||
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
||||
|
||||
Reference in New Issue
Block a user