θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions frontend/src/models/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,15 @@ const System = {
headers: baseHeaders(),
body: JSON.stringify(presetData),
})
.then((res) => {
if (!res.ok) throw new Error("Could not create slash command preset.");
return res.json();
})
.then((res) => {
return { preset: res.preset, error: null };
.then(async (res) => {
const data = await res.json();
if (!res.ok)
throw new Error(
data.message || "Error creating slash command preset."
);
return data;
})
.then((res) => ({ preset: res.preset, error: null }))
.catch((e) => {
console.error(e);
return { preset: null, error: e.message };
Expand All @@ -656,15 +658,18 @@ const System = {
headers: baseHeaders(),
body: JSON.stringify(presetData),
})
.then((res) => {
if (!res.ok) throw new Error("Could not update slash command preset.");
return res.json();
})
.then((res) => {
return { preset: res.preset, error: null };
.then(async (res) => {
const data = await res.json();
if (!res.ok)
throw new Error(
data.message || "Could not update slash command preset."
);
return data;
})
.then((res) => ({ preset: res.preset, error: null }))
.catch((e) => {
return { preset: null, error: "Failed to update this command." };
console.error(e);
return { preset: null, error: e.message };
});
},

Expand Down
26 changes: 24 additions & 2 deletions server/endpoints/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const {
} = require("../utils/middleware/chatHistoryViewable");
const { simpleSSOEnabled } = require("../utils/middleware/simpleSSOEnabled");
const { TemporaryAuthToken } = require("../models/temporaryAuthToken");
const { VALID_COMMANDS } = require("../utils/chats");

function systemEndpoints(app) {
if (!app) return;
Expand Down Expand Up @@ -1140,8 +1141,19 @@ function systemEndpoints(app) {
try {
const user = await userFromSession(request, response);
const { command, prompt, description } = reqBody(request);
const formattedCommand = SlashCommandPresets.formatCommand(
String(command)
);

if (Object.keys(VALID_COMMANDS).includes(formattedCommand)) {
return response.status(400).json({
message:
"Cannot create a preset with a command that matches a system command",
});
}

const presetData = {
command: SlashCommandPresets.formatCommand(String(command)),
command: formattedCommand,
prompt: String(prompt),
description: String(description),
};
Expand All @@ -1168,6 +1180,16 @@ function systemEndpoints(app) {
const user = await userFromSession(request, response);
const { slashCommandId } = request.params;
const { command, prompt, description } = reqBody(request);
const formattedCommand = SlashCommandPresets.formatCommand(
String(command)
);

if (Object.keys(VALID_COMMANDS).includes(formattedCommand)) {
return response.status(400).json({
message:
"Cannot update a preset to use a command that matches a system command",
});
}

// Valid user running owns the preset if user session is valid.
const ownsPreset = await SlashCommandPresets.get({
Expand All @@ -1178,7 +1200,7 @@ function systemEndpoints(app) {
return response.status(404).json({ message: "Preset not found" });

const updates = {
command: SlashCommandPresets.formatCommand(String(command)),
command: formattedCommand,
prompt: String(prompt),
description: String(description),
};
Expand Down