chore: update Angular TypeScript build info cache
This commit is contained in:
@@ -449,6 +449,106 @@ function ensureBookmarksStorage() {
|
||||
// Ensure bookmarks storage is ready on startup
|
||||
ensureBookmarksStorage();
|
||||
|
||||
// Graph config API - reads/writes <vault>/.obsidian/graph.json
|
||||
function ensureGraphStorage() {
|
||||
const obsidianDir = path.join(vaultDir, '.obsidian');
|
||||
if (!fs.existsSync(obsidianDir)) {
|
||||
fs.mkdirSync(obsidianDir, { recursive: true });
|
||||
}
|
||||
|
||||
const graphPath = path.join(obsidianDir, 'graph.json');
|
||||
if (!fs.existsSync(graphPath)) {
|
||||
// Create default graph config matching Obsidian defaults
|
||||
const defaultConfig = {
|
||||
'collapse-filter': false,
|
||||
search: '',
|
||||
showTags: false,
|
||||
showAttachments: false,
|
||||
hideUnresolved: false,
|
||||
showOrphans: true,
|
||||
'collapse-color-groups': false,
|
||||
colorGroups: [],
|
||||
'collapse-display': false,
|
||||
showArrow: false,
|
||||
textFadeMultiplier: 0,
|
||||
nodeSizeMultiplier: 1,
|
||||
lineSizeMultiplier: 1,
|
||||
'collapse-forces': false,
|
||||
centerStrength: 0.5,
|
||||
repelStrength: 10,
|
||||
linkStrength: 1,
|
||||
linkDistance: 250,
|
||||
scale: 1,
|
||||
close: false
|
||||
};
|
||||
const initialContent = JSON.stringify(defaultConfig, null, 2);
|
||||
fs.writeFileSync(graphPath, initialContent, 'utf-8');
|
||||
}
|
||||
|
||||
return { obsidianDir, graphPath };
|
||||
}
|
||||
|
||||
// Ensure graph storage is ready on startup
|
||||
ensureGraphStorage();
|
||||
|
||||
app.get('/api/vault/graph', (req, res) => {
|
||||
try {
|
||||
const { graphPath } = ensureGraphStorage();
|
||||
const content = fs.readFileSync(graphPath, 'utf-8');
|
||||
const config = JSON.parse(content);
|
||||
const rev = calculateSimpleHash(content);
|
||||
|
||||
res.json({ config, rev });
|
||||
} catch (error) {
|
||||
console.error('Failed to load graph config:', error);
|
||||
res.status(500).json({ error: 'Unable to load graph config.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.put('/api/vault/graph', (req, res) => {
|
||||
try {
|
||||
const { graphPath } = ensureGraphStorage();
|
||||
const ifMatch = req.headers['if-match'];
|
||||
|
||||
// Check for conflicts if If-Match header is present
|
||||
if (ifMatch) {
|
||||
const currentContent = fs.readFileSync(graphPath, 'utf-8');
|
||||
const currentRev = calculateSimpleHash(currentContent);
|
||||
|
||||
if (ifMatch !== currentRev) {
|
||||
return res.status(409).json({ error: 'Conflict: File modified externally' });
|
||||
}
|
||||
}
|
||||
|
||||
// Create backup before writing
|
||||
const backupPath = graphPath + '.bak';
|
||||
if (fs.existsSync(graphPath)) {
|
||||
fs.copyFileSync(graphPath, backupPath);
|
||||
}
|
||||
|
||||
// Atomic write: write to temp file, then rename
|
||||
const tempPath = graphPath + '.tmp';
|
||||
const content = JSON.stringify(req.body, null, 2);
|
||||
|
||||
try {
|
||||
fs.writeFileSync(tempPath, content, 'utf-8');
|
||||
fs.renameSync(tempPath, graphPath);
|
||||
} catch (writeError) {
|
||||
// If write failed, restore backup if it exists
|
||||
if (fs.existsSync(backupPath)) {
|
||||
fs.copyFileSync(backupPath, graphPath);
|
||||
}
|
||||
throw writeError;
|
||||
}
|
||||
|
||||
const newRev = calculateSimpleHash(content);
|
||||
res.json({ rev: newRev });
|
||||
} catch (error) {
|
||||
console.error('Failed to save graph config:', error);
|
||||
res.status(500).json({ error: 'Unable to save graph config.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/vault/bookmarks', (req, res) => {
|
||||
try {
|
||||
const { bookmarksPath } = ensureBookmarksStorage();
|
||||
|
||||
Reference in New Issue
Block a user