preparePromptsForExport method now can exclude the api settings. see #624
This commit is contained in:
parent
e105ead516
commit
d0fe616e42
1 changed files with 40 additions and 3 deletions
|
|
@ -410,18 +410,55 @@ export async function getPrompts(onlyEnabled = false, includeSpecial = [], allSp
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function preparePromptsForExport(prompts){
|
export function preparePromptsForExport(prompts, include_api_settings = false){
|
||||||
let output = [...prompts];
|
let output = JSON.parse(JSON.stringify(prompts));
|
||||||
output.forEach(prompt => {
|
output.forEach(prompt => {
|
||||||
|
|
||||||
|
if(!include_api_settings){
|
||||||
|
delete prompt.api_type;
|
||||||
|
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||||
|
for (const key of Object.keys(options)) {
|
||||||
|
delete prompt[`${integration}_${key}`];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(prompt.api_type && prompt.api_type !== ''){
|
||||||
|
const activeIntegration = prompt.api_type.replace('_api', '');
|
||||||
|
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||||
|
if(integration !== activeIntegration){
|
||||||
|
for (const key of Object.keys(options)) {
|
||||||
|
delete prompt[`${integration}_${key}`];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||||
|
for (const key of Object.keys(options)) {
|
||||||
|
delete prompt[`${integration}_${key}`];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(prompt.is_default == 1){
|
if(prompt.is_default == 1){
|
||||||
|
let allowedKeys = ['id', 'enabled', 'position_compose', 'position_display', 'need_custom_text'];
|
||||||
|
if(include_api_settings){
|
||||||
|
allowedKeys.push('api_type');
|
||||||
|
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||||
|
for (const key of Object.keys(options)) {
|
||||||
|
allowedKeys.push(`${integration}_${key}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Object.keys(prompt).forEach(key => {
|
Object.keys(prompt).forEach(key => {
|
||||||
if(!['id', 'enabled', 'position_compose', 'position_display', 'need_custom_text'].includes(key)){
|
if(!allowedKeys.includes(key)){
|
||||||
delete prompt[key];
|
delete prompt[key];
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
delete prompt['idnum'];
|
delete prompt['idnum'];
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue