feat: archiving
This commit is contained in:
26
server.js
26
server.js
@@ -642,6 +642,32 @@ app.post('/api/links', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Archive/Unarchive a link
|
||||
app.patch('/api/links/:id/archive', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { archived } = req.body;
|
||||
|
||||
if (typeof archived !== 'boolean') {
|
||||
return res.status(400).json({ error: 'archived must be a boolean' });
|
||||
}
|
||||
|
||||
const links = await readLinks();
|
||||
const linkIndex = links.findIndex(link => link.id === id);
|
||||
|
||||
if (linkIndex === -1) {
|
||||
return res.status(404).json({ error: 'Link not found' });
|
||||
}
|
||||
|
||||
links[linkIndex].archived = archived;
|
||||
await writeLinks(links);
|
||||
|
||||
res.json(links[linkIndex]);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to update link' });
|
||||
}
|
||||
});
|
||||
|
||||
// Delete a link
|
||||
app.delete('/api/links/:id', async (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user