@jsnote-zeina/local-api 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/routes/cells.js +22 -21
- package/package.json +3 -4
package/dist/routes/cells.js
CHANGED
|
@@ -37,39 +37,40 @@ const createCellsRouter = (filename, dir) => {
|
|
|
37
37
|
const router = express_1.default.Router();
|
|
38
38
|
router.use(express_1.default.json());
|
|
39
39
|
const fullPath = path_1.default.join(dir, filename);
|
|
40
|
+
const isLocalApiError = (err) => {
|
|
41
|
+
return typeof err === 'object' && err !== null && typeof err.code === 'string';
|
|
42
|
+
};
|
|
40
43
|
router.get('/cells', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
const isLocalApiError = (err) => {
|
|
42
|
-
return typeof err.code === 'string';
|
|
43
|
-
};
|
|
44
44
|
try {
|
|
45
|
-
// Read the file
|
|
46
45
|
const result = yield promises_1.default.readFile(fullPath, { encoding: 'utf-8' });
|
|
47
46
|
res.send(JSON.parse(result));
|
|
48
47
|
}
|
|
49
48
|
catch (err) {
|
|
50
|
-
if (isLocalApiError(err)) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
res.send(JSON.stringify(defaultCells));
|
|
49
|
+
if (isLocalApiError(err) && err.code === 'ENOENT') {
|
|
50
|
+
try {
|
|
51
|
+
yield promises_1.default.writeFile(fullPath, JSON.stringify(defaultCells), 'utf-8');
|
|
52
|
+
res.send(defaultCells);
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
catch (writeErr) {
|
|
55
|
+
console.error('Failed to seed notebook file:', writeErr);
|
|
56
|
+
res.status(500).send({ error: 'Failed to create notebook file' });
|
|
58
57
|
}
|
|
58
|
+
return;
|
|
59
59
|
}
|
|
60
|
+
console.error('Failed to read notebook file:', err);
|
|
61
|
+
res.status(500).send({ error: 'Failed to read notebook file' });
|
|
60
62
|
}
|
|
61
|
-
// If read throws an error
|
|
62
|
-
// Insprect the error, see if it says that file doesn't exist
|
|
63
|
-
// Parse a list of cells out of it
|
|
64
|
-
// Send list of cells back to browser
|
|
65
63
|
}));
|
|
66
64
|
router.post('/cells', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
try {
|
|
66
|
+
const { cells } = req.body;
|
|
67
|
+
yield promises_1.default.writeFile(fullPath, JSON.stringify(cells), 'utf-8');
|
|
68
|
+
res.send({ status: 'ok' });
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.error('Failed to write notebook file:', err);
|
|
72
|
+
res.status(500).send({ error: 'Failed to save notebook file' });
|
|
73
|
+
}
|
|
73
74
|
}));
|
|
74
75
|
return router;
|
|
75
76
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsnote-zeina/local-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -23,10 +23,9 @@
|
|
|
23
23
|
"typescript": "^5.4.5"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@jsnote-zeina/local-client": "^1.0.
|
|
26
|
+
"@jsnote-zeina/local-client": "^1.0.1",
|
|
27
27
|
"cors": "^2.8.5",
|
|
28
28
|
"express": "^4.19.2",
|
|
29
29
|
"http-proxy-middleware": "^3.0.0"
|
|
30
|
-
}
|
|
31
|
-
"gitHead": "c917f9837ac91b26442e0c1b41444228d240e5af"
|
|
30
|
+
}
|
|
32
31
|
}
|