chore: update Angular cache and TypeScript build info
This commit is contained in:
@@ -427,6 +427,80 @@ app.get('/api/files/by-date-range', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Bookmarks API - reads/writes <vault>/.obsidian/bookmarks.json
|
||||
app.use(express.json());
|
||||
|
||||
function ensureBookmarksStorage() {
|
||||
const obsidianDir = path.join(vaultDir, '.obsidian');
|
||||
if (!fs.existsSync(obsidianDir)) {
|
||||
fs.mkdirSync(obsidianDir, { recursive: true });
|
||||
}
|
||||
|
||||
const bookmarksPath = path.join(obsidianDir, 'bookmarks.json');
|
||||
if (!fs.existsSync(bookmarksPath)) {
|
||||
const emptyDoc = { items: [] };
|
||||
const initialContent = JSON.stringify(emptyDoc, null, 2);
|
||||
fs.writeFileSync(bookmarksPath, initialContent, 'utf-8');
|
||||
}
|
||||
|
||||
return { obsidianDir, bookmarksPath };
|
||||
}
|
||||
|
||||
// Ensure bookmarks storage is ready on startup
|
||||
ensureBookmarksStorage();
|
||||
|
||||
app.get('/api/vault/bookmarks', (req, res) => {
|
||||
try {
|
||||
const { bookmarksPath } = ensureBookmarksStorage();
|
||||
const content = fs.readFileSync(bookmarksPath, 'utf-8');
|
||||
const doc = JSON.parse(content);
|
||||
const rev = calculateSimpleHash(content);
|
||||
|
||||
res.json({ ...doc, rev });
|
||||
} catch (error) {
|
||||
console.error('Failed to load bookmarks:', error);
|
||||
res.status(500).json({ error: 'Unable to load bookmarks.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.put('/api/vault/bookmarks', (req, res) => {
|
||||
try {
|
||||
const { bookmarksPath } = ensureBookmarksStorage();
|
||||
const ifMatch = req.headers['if-match'];
|
||||
|
||||
// Check for conflicts if If-Match header is present
|
||||
if (ifMatch) {
|
||||
const currentContent = fs.readFileSync(bookmarksPath, 'utf-8');
|
||||
const currentRev = calculateSimpleHash(currentContent);
|
||||
|
||||
if (ifMatch !== currentRev) {
|
||||
return res.status(409).json({ error: 'Conflict: File modified externally' });
|
||||
}
|
||||
}
|
||||
|
||||
// Write bookmarks
|
||||
const content = JSON.stringify(req.body, null, 2);
|
||||
fs.writeFileSync(bookmarksPath, content, 'utf-8');
|
||||
|
||||
const newRev = calculateSimpleHash(content);
|
||||
res.json({ rev: newRev });
|
||||
} catch (error) {
|
||||
console.error('Failed to save bookmarks:', error);
|
||||
res.status(500).json({ error: 'Unable to save bookmarks.' });
|
||||
}
|
||||
});
|
||||
|
||||
// Simple hash function for rev generation
|
||||
function calculateSimpleHash(content) {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < content.length; i++) {
|
||||
const char = content.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + char;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return Math.abs(hash).toString(36) + '-' + content.length;
|
||||
}
|
||||
|
||||
// Servir l'index.html pour toutes les routes (SPA)
|
||||
const sendIndex = (req, res) => {
|
||||
const indexPath = path.join(distDir, 'index.html');
|
||||
|
||||
Reference in New Issue
Block a user