mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-04-07 14:04:30 +08:00
Fix support serverSettings
This commit is contained in:
@ -46,7 +46,7 @@
|
||||
"type" : "background",
|
||||
"initDataType" : "none",
|
||||
"buttons" : [],
|
||||
"events" : ["onContextMenuShow", "onContextMenuClick", "onToolbarMenuClick"],
|
||||
"events" : ["onAIPluginSettings", "onContextMenuShow", "onContextMenuClick", "onToolbarMenuClick"],
|
||||
|
||||
"store": {
|
||||
"background": {
|
||||
|
||||
@ -91,6 +91,16 @@ async function GetOldCustomFunctions() {
|
||||
}
|
||||
|
||||
window.Asc.plugin.init = async function() {
|
||||
// Check server settings
|
||||
if (window.Asc.plugin.info.aiPluginSettings) {
|
||||
try {
|
||||
AI.serverSettings = JSON.parse(window.Asc.plugin.info.aiPluginSettings);
|
||||
} catch (e) {
|
||||
AI.serverSettings = null;
|
||||
}
|
||||
delete window.Asc.plugin.info.aiPluginSettings;
|
||||
}
|
||||
|
||||
await initWithTranslate(1 << 1);
|
||||
clearChatState();
|
||||
|
||||
|
||||
@ -86,7 +86,14 @@
|
||||
"data" : request.body
|
||||
})
|
||||
}
|
||||
message.url = AI.PROXY_URL;
|
||||
if (AI.serverSettings){
|
||||
message.url = AI.serverSettings.proxy;
|
||||
request["headers"] = {
|
||||
"Authorization" : "Bearer " + Asc.plugin.info.jwt,
|
||||
}
|
||||
} else {
|
||||
message.url = AI.PROXY_URL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +143,7 @@
|
||||
body[i] = bodyPr[i];
|
||||
}
|
||||
|
||||
return provider.isUseProxy();
|
||||
return provider.isUseProxy() || AI.serverSettings;
|
||||
};
|
||||
|
||||
AI._getEndpointUrl = function(_provider, endpoint, model) {
|
||||
|
||||
@ -58,7 +58,11 @@
|
||||
AI.Storage.load = function() {
|
||||
let obj = null;
|
||||
try {
|
||||
obj = JSON.parse(window.localStorage.getItem(localStorageKey));
|
||||
if (AI.serverSettings) {
|
||||
obj = AI.serverSettings;
|
||||
} else {
|
||||
obj = JSON.parse(window.localStorage.getItem(localStorageKey));
|
||||
}
|
||||
} catch (e) {
|
||||
obj = AI.DEFAULT_SERVER_SETTINGS;
|
||||
|
||||
|
||||
@ -244,4 +244,6 @@
|
||||
|
||||
};
|
||||
|
||||
AI.serverSettings = null;
|
||||
|
||||
})();
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
function registerButtons(window, undefined)
|
||||
{
|
||||
window.AI = window.AI || {};
|
||||
var AI = window.AI;
|
||||
|
||||
function getToolBarButtonIcons(icon) {
|
||||
return "resources/icons/%theme-type%(light|dark)/big/" + icon + "%scale%(default).png";
|
||||
}
|
||||
@ -472,7 +475,7 @@ function registerButtons(window, undefined)
|
||||
window.buttonMainToolbar = buttonMainToolbar;
|
||||
window.getToolBarButtonIcons = getToolBarButtonIcons;
|
||||
|
||||
if (true)
|
||||
if (!AI.serverSettings)
|
||||
{
|
||||
let button1 = new Asc.ButtonToolbar(buttonMainToolbar);
|
||||
button1.text = "Settings";
|
||||
@ -548,8 +551,6 @@ function registerButtons(window, undefined)
|
||||
}
|
||||
|
||||
// register actions
|
||||
window.AI = window.AI || {};
|
||||
var AI = window.AI;
|
||||
|
||||
AI.ActionType = {
|
||||
Chat : "Chat",
|
||||
@ -629,7 +630,11 @@ function registerButtons(window, undefined)
|
||||
let obj = null;
|
||||
try
|
||||
{
|
||||
obj = JSON.parse(window.localStorage.getItem(actions_key));
|
||||
if (AI.serverSettings) {
|
||||
obj = AI.serverSettings.actions;
|
||||
} else {
|
||||
obj = JSON.parse(window.localStorage.getItem(actions_key));
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
@ -657,5 +662,5 @@ function registerButtons(window, undefined)
|
||||
}
|
||||
};
|
||||
|
||||
AI.ActionsLoad();
|
||||
AI.ActionsLoad();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user