Spaces:
Sleeping
Sleeping
Upload pages/api/pocketbase.js with huggingface_hub
Browse files- pages/api/pocketbase.js +35 -0
pages/api/pocketbase.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// In-memory mock storage for demonstration purposes
|
| 2 |
+
let mockDB = [
|
| 3 |
+
{ id: '1', name: 'Project Alpha', created: '2023-10-01' },
|
| 4 |
+
{ id: '2', name: 'Deployment Test', created: '2023-10-05' },
|
| 5 |
+
];
|
| 6 |
+
|
| 7 |
+
export default async function handler(req, res) {
|
| 8 |
+
try {
|
| 9 |
+
if (req.method === 'GET') {
|
| 10 |
+
return res.status(200).json({ items: mockDB });
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
if (req.method === 'POST') {
|
| 14 |
+
const { name } = req.body;
|
| 15 |
+
const newItem = {
|
| 16 |
+
id: Date.now().toString(),
|
| 17 |
+
name: name,
|
| 18 |
+
created: new Date().toISOString().split('T')[0]
|
| 19 |
+
};
|
| 20 |
+
mockDB.push(newItem);
|
| 21 |
+
return res.status(200).json({ success: true, item: newItem });
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
if (req.method === 'DELETE') {
|
| 25 |
+
const { id } = req.body;
|
| 26 |
+
mockDB = mockDB.filter(item => item.id !== id);
|
| 27 |
+
return res.status(200).json({ success: true });
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
return res.status(405).json({ message: 'Method not allowed' });
|
| 31 |
+
} catch (error) {
|
| 32 |
+
console.error('PocketBase Error:', error);
|
| 33 |
+
return res.status(500).json({ message: 'Internal Server Error' });
|
| 34 |
+
}
|
| 35 |
+
}
|