@natilon/cms-server 0.10.1 → 0.11.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@natilon/cms-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Express-based CMS server with pluggable adapters for content, media, auth, and build.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"natilon-cms": "./bin/natilon-cms.mjs"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
-
"test": "node --test test
|
|
23
|
+
"test": "node --test 'test/**/*.test.mjs'"
|
|
24
24
|
},
|
|
25
25
|
"exports": {
|
|
26
26
|
".": "./src/index.mjs",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"bin"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@natilon/admin-ui": ">=0.
|
|
38
|
+
"@natilon/admin-ui": ">=0.10.0",
|
|
39
39
|
"express": "^4.21.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -122,6 +122,13 @@ export function createFsJsonContent({
|
|
|
122
122
|
const slug = data.slug || data.id || `new-${Date.now()}`;
|
|
123
123
|
const fileName = `${sanitize(data.lang || "en")}-${sanitize(slug)}.json`;
|
|
124
124
|
const filePath = pagePath(collection, fileName);
|
|
125
|
+
if (fs.existsSync(filePath)) {
|
|
126
|
+
const err = new Error(
|
|
127
|
+
`An entry already exists for "${data.lang || "en"}/${slug}". Change the slug or language.`,
|
|
128
|
+
);
|
|
129
|
+
err.status = 409;
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
125
132
|
const dir = path.dirname(filePath);
|
|
126
133
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
127
134
|
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
@@ -254,6 +254,13 @@ export function createGitHubContent({ token, owner, repo, branch, pagesDir, comm
|
|
|
254
254
|
const slug = data.slug || data.id || `new-${Date.now()}`;
|
|
255
255
|
const fileName = `${sanitize(data.lang || "en")}-${sanitize(slug)}.json`;
|
|
256
256
|
const path = contentPath(collection, fileName);
|
|
257
|
+
if (await getFileSha(path)) {
|
|
258
|
+
const err = new Error(
|
|
259
|
+
`An entry already exists for "${data.lang || "en"}/${slug}". Change the slug or language.`,
|
|
260
|
+
);
|
|
261
|
+
err.status = 409;
|
|
262
|
+
throw err;
|
|
263
|
+
}
|
|
257
264
|
const result = await apiPut(`/contents/${path}`, {
|
|
258
265
|
message: commitMsg(commitMessage),
|
|
259
266
|
content: encodeContent(data),
|
package/src/routes.mjs
CHANGED
|
@@ -150,8 +150,13 @@ export const apiRoutes = [
|
|
|
150
150
|
path: "/api/collections/:collection",
|
|
151
151
|
auth: "any",
|
|
152
152
|
handler: async ({ adapters, params, body }) => {
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
try {
|
|
154
|
+
const result = await adapters.content.createPage(params.collection, body);
|
|
155
|
+
return ok({ ok: true, file: result.file });
|
|
156
|
+
} catch (err) {
|
|
157
|
+
if (err.status === 409) return { status: 409, json: { error: err.message } };
|
|
158
|
+
throw err;
|
|
159
|
+
}
|
|
155
160
|
},
|
|
156
161
|
},
|
|
157
162
|
|