mktcms 0.2.11 → 0.2.13
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/module.json
CHANGED
|
@@ -6,6 +6,7 @@ const { path } = usePathParam();
|
|
|
6
6
|
const { data: content } = await useFetch(`/api/admin/txt?path=${path}`);
|
|
7
7
|
const isSaving = ref(false);
|
|
8
8
|
const savingSuccessful = ref(false);
|
|
9
|
+
const commitMessage = ref("Inhaltliche \xC4nderungen");
|
|
9
10
|
async function saveContent() {
|
|
10
11
|
if (content.value === void 0) return;
|
|
11
12
|
isSaving.value = true;
|
|
@@ -13,7 +14,8 @@ async function saveContent() {
|
|
|
13
14
|
await useFetch(`/api/admin/txt?path=${path}`, {
|
|
14
15
|
method: "POST",
|
|
15
16
|
body: {
|
|
16
|
-
text: content.value
|
|
17
|
+
text: content.value,
|
|
18
|
+
commitMessage: commitMessage.value
|
|
17
19
|
}
|
|
18
20
|
});
|
|
19
21
|
isSaving.value = false;
|
|
@@ -28,9 +30,27 @@ async function saveContent() {
|
|
|
28
30
|
class="w-full h-24 resize-y border border-gray-300 p-2 box-border font-mono"
|
|
29
31
|
/>
|
|
30
32
|
|
|
33
|
+
<div class="mt-3">
|
|
34
|
+
<label
|
|
35
|
+
for="commit-message"
|
|
36
|
+
class="block mb-1"
|
|
37
|
+
>
|
|
38
|
+
Kommentar / Änderungsgrund
|
|
39
|
+
</label>
|
|
40
|
+
<input
|
|
41
|
+
id="commit-message"
|
|
42
|
+
v-model="commitMessage"
|
|
43
|
+
type="text"
|
|
44
|
+
required
|
|
45
|
+
class="w-full border border-gray-200 rounded-sm px-3 py-2"
|
|
46
|
+
placeholder="Inhaltliche Änderungen"
|
|
47
|
+
>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
31
50
|
<button
|
|
32
51
|
type="button"
|
|
33
52
|
class="button w-full justify-center mt-3"
|
|
53
|
+
:disabled="!commitMessage.trim() || isSaving"
|
|
34
54
|
@click="saveContent"
|
|
35
55
|
>
|
|
36
56
|
<span v-if="isSaving">Speichern...</span>
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { defineEventHandler, getValidatedQuery, readValidatedBody } from "h3";
|
|
3
3
|
import { useStorage } from "nitropack/runtime";
|
|
4
|
+
import syncGitContent from "../../utils/syncGitContent.js";
|
|
4
5
|
const querySchema = z.object({
|
|
5
6
|
path: z.string().min(1)
|
|
6
7
|
});
|
|
7
8
|
const bodySchema = z.object({
|
|
8
|
-
text: z.string()
|
|
9
|
+
text: z.string(),
|
|
10
|
+
commitMessage: z.string().trim().min(1)
|
|
9
11
|
});
|
|
10
12
|
export default defineEventHandler(async (event) => {
|
|
11
13
|
const { path } = await getValidatedQuery(event, (query) => querySchema.parse(query));
|
|
12
|
-
const { text } = await readValidatedBody(event, (body) => bodySchema.parse(body));
|
|
14
|
+
const { text, commitMessage } = await readValidatedBody(event, (body) => bodySchema.parse(body));
|
|
13
15
|
const decodedPath = decodeURIComponent(path);
|
|
14
16
|
const storage = useStorage("content");
|
|
15
17
|
await storage.setItem(decodedPath, text);
|
|
18
|
+
try {
|
|
19
|
+
await syncGitContent(commitMessage, [decodedPath]);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("Git-Fehler:", error);
|
|
22
|
+
}
|
|
16
23
|
return { success: true };
|
|
17
24
|
});
|
|
@@ -10,8 +10,9 @@ function toStorageFilePath(file) {
|
|
|
10
10
|
}
|
|
11
11
|
export default async function syncGitContent(commitMessage, files) {
|
|
12
12
|
const { git, authUrl } = createAuthenticatedGitClient();
|
|
13
|
+
const currentBranch = (await git.branchLocal()).current;
|
|
13
14
|
try {
|
|
14
|
-
await git.raw(["pull", "--rebase", "--autostash", authUrl]);
|
|
15
|
+
await git.raw(["pull", "--rebase", "--autostash", authUrl, currentBranch]);
|
|
15
16
|
} catch (error) {
|
|
16
17
|
throw new Error(toGitErrorMessage(error, "Git pull failed"));
|
|
17
18
|
}
|
|
@@ -27,16 +28,15 @@ export default async function syncGitContent(commitMessage, files) {
|
|
|
27
28
|
throw new Error(toGitErrorMessage(error, "Git commit failed"));
|
|
28
29
|
}
|
|
29
30
|
try {
|
|
30
|
-
await git.push([authUrl]);
|
|
31
|
+
await git.push([authUrl, `HEAD:${currentBranch}`]);
|
|
31
32
|
} catch (error) {
|
|
32
33
|
throw new Error(toGitErrorMessage(error, "Git push failed"));
|
|
33
34
|
}
|
|
34
35
|
try {
|
|
35
|
-
const currentBranch = (await git.branchLocal()).current;
|
|
36
36
|
const remotes = await git.getRemotes(true);
|
|
37
37
|
const hasOriginRemote = remotes.some((remote) => remote.name === "origin");
|
|
38
38
|
if (hasOriginRemote) {
|
|
39
|
-
await git.
|
|
39
|
+
await git.raw(["update-ref", `refs/remotes/origin/${currentBranch}`, "HEAD"]);
|
|
40
40
|
}
|
|
41
41
|
} catch (error) {
|
|
42
42
|
throw new Error(toGitErrorMessage(error, "Git status refresh failed"));
|