forked from XiaoMo/ChatGPT-Next-Web
feat: close #2447 pre-fill key/code/url
This commit is contained in:
parent
0198c5b781
commit
e5f6133127
@ -7,6 +7,8 @@ interface Commands {
|
|||||||
fill?: Command;
|
fill?: Command;
|
||||||
submit?: Command;
|
submit?: Command;
|
||||||
mask?: Command;
|
mask?: Command;
|
||||||
|
code?: Command;
|
||||||
|
settings?: Command;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useCommand(commands: Commands = {}) {
|
export function useCommand(commands: Commands = {}) {
|
||||||
|
@ -882,6 +882,41 @@ export function Chat() {
|
|||||||
submit: (text) => {
|
submit: (text) => {
|
||||||
doSubmit(text);
|
doSubmit(text);
|
||||||
},
|
},
|
||||||
|
code: (text) => {
|
||||||
|
console.log("[Command] got code from url: ", text);
|
||||||
|
showConfirm(Locale.URLCommand.Code + `code = ${text}`).then((res) => {
|
||||||
|
if (res) {
|
||||||
|
accessStore.updateCode(text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
settings: (text) => {
|
||||||
|
try {
|
||||||
|
const payload = JSON.parse(text) as {
|
||||||
|
key?: string;
|
||||||
|
url?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("[Command] got settings from url: ", payload);
|
||||||
|
|
||||||
|
if (payload.key || payload.url) {
|
||||||
|
showConfirm(
|
||||||
|
Locale.URLCommand.Settings +
|
||||||
|
`\n${JSON.stringify(payload, null, 4)}`,
|
||||||
|
).then((res) => {
|
||||||
|
if (!res) return;
|
||||||
|
if (payload.key) {
|
||||||
|
accessStore.updateToken(payload.key);
|
||||||
|
}
|
||||||
|
if (payload.url) {
|
||||||
|
accessStore.updateOpenAiUrl(payload.url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
console.error("[Command] failed to get settings from url: ", text);
|
||||||
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -326,6 +326,11 @@ const cn = {
|
|||||||
More: "查看全部",
|
More: "查看全部",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
URLCommand: {
|
||||||
|
Code: "检测到链接中已经包含访问码,是否自动填入?",
|
||||||
|
Settings: "检测到链接中包含了预制设置,是否自动填入?",
|
||||||
|
},
|
||||||
|
|
||||||
UI: {
|
UI: {
|
||||||
Confirm: "确认",
|
Confirm: "确认",
|
||||||
Cancel: "取消",
|
Cancel: "取消",
|
||||||
|
@ -344,6 +344,11 @@ const en: LocaleType = {
|
|||||||
Topic: "Topic",
|
Topic: "Topic",
|
||||||
Time: "Time",
|
Time: "Time",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
URLCommand: {
|
||||||
|
Code: "Detected access code from url, confirm to apply? ",
|
||||||
|
Settings: "Detected settings from url, confirm to apply?",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default en;
|
export default en;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user