Spaces:
Sleeping
Sleeping
File size: 5,706 Bytes
960cd20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
$(document).ready(function () {
$.ajax({
url: '/admin/get_config',
type: 'POST',
dataType: 'json',
contentType: 'application/json',
headers: {
'X-CSRFToken': $('meta[name="csrf-token"]').attr('content')
},
success: function (response) {
show_config(response);
},
error: function (response) {
}
});
$(".config-save").click(function () {
set_config();
});
}
);
function show_config(configData) {
$.each(configData.vits_config, function (key, value) {
var formattedKey = key.replace(/_/g, '-');
//为了避免id冲突,组合key作为id
var itemId = 'vits-config-' + formattedKey;
$('#vits-config').append(`
<div class="input-group mb-3 item">
<span class="input-group-text">${key}</span>
<input type="text" class="form-control" id="${itemId}" value="${value}">
</div>
`);
})
$.each(configData.w2v2_vits_config, function (key, value) {
var formattedKey = key.replace(/_/g, '-');
var itemId = 'w2v2-vits-config-' + formattedKey;
$('#w2v2-vits-config').append(`
<div class="input-group mb-3 item">
<span class="input-group-text">${key}</span>
<input type="text" class="form-control" id="${itemId}" value="${value}">
</div>
`);
})
$.each(configData.hubert_vits_config, function (key, value) {
var formattedKey = key.replace(/_/g, '-');
var itemId = 'hubert-vits-config-' + formattedKey;
$('#hubert-vits-config').append(`
<div class="input-group mb-3 item">
<span class="input-group-text">${key}</span>
<input type="text" class="form-control" id="${itemId}" value="${value}">
</div>
`);
})
$.each(configData.bert_vits2_config, function (key, value) {
var formattedKey = key.replace(/_/g, '-');
var itemId = 'bert-vits2-config-' + formattedKey;
$('#bert-vits2-config').append(`
<div class="input-group mb-3 item">
<span class="input-group-text">${key}</span>
<input type="text" class="form-control" id="${itemId}" value="${value}">
</div>
`);
})
$.each(configData.log_config, function (key, value) {
var formattedKey = key.replace(/_/g, '-');
if (key != 'logging_level') {
$('#log-config').append(`
<div class="input-group mb-3 item">
<span class="input-group-text">${key}</span>
<input type="text" class="form-control" id="${formattedKey}" value="${value}">
</div>
`);
}
});
$.each(configData.model_config, function (key, value) {
var formattedKey = key.replace(/_/g, '-');
$('#model-config').append(`
<div class="input-group mb-3 item">
<span class="input-group-text">${key}</span>
<input type="text" class="form-control" id="${formattedKey}" value="${value}">
</div>
`);
});
$.each(configData.language_identification, function (key, value) {
var formattedKey = key.replace(/_/g, '-');
$('#language-identification ' + '#' + formattedKey).val(value)
});
$.each(configData.http_service, function (key, value) {
var formattedKey = key.replace(/_/g, '-');
if (formattedKey == 'api-key-enable' || formattedKey == 'debug') {
$('#' + formattedKey).prop('checked', value);
} else {
$('#' + formattedKey).val(value);
}
});
$.each(configData.system, function (key, value) {
var formattedKey = key.replace(/_/g, '-');
if (formattedKey == 'api-key-enabled' || formattedKey == 'cache-audio') {
$('#' + formattedKey).prop('checked', value);
} else {
$('#' + formattedKey).val(value);
}
});
$.each(configData.admin, function (key, value) {
$('#' + key).val(value);
});
}
function set_config() {
var configData = {}
$('.configuration .form-label').each(function () {
var labelId = $(this).next().attr('id');
var nestedDict = {};
$('#' + labelId).find('.item').each(function () {
var itemId = $(this).find('input, select').attr('id').replace(/-/g, '_');
//还原组合key
itemId = itemId.replace(labelId.replace(/-/g, '_') + "_", "");
if ($(this).find('input').is(':checkbox')) {
// 如果是复选框,获取复选框的状态
itemValue = $(this).find('input').prop('checked');
} else {
// 如果不是复选框,获取输入框或选择框的值
itemValue = $(this).find('input, select').val();
}
nestedDict[itemId] = itemValue;
if (labelId == "system")
console.log(itemId)
});
configData[labelId.replace(/-/g, '_')] = nestedDict;
});
$.ajax({
type: "POST",
url: "/admin/set_config",
data: JSON.stringify(configData), // 将配置数据转换为JSON字符串
contentType: "application/json",
headers: {
'X-CSRFToken': $('meta[name="csrf-token"]').attr('content')
},
success: function (response) {
alert("配置已保存");
location.reload();
},
error: function (error) {
alert("保存配置时出错,请查看日志!");
}
});
return configData
}
|