support update proxies

This commit is contained in:
2024-01-11 13:11:12 +08:00
parent 83ad03eca3
commit 18792a395c
11 changed files with 69 additions and 276 deletions

View File

@@ -17,20 +17,19 @@ var loadClientInfo = (function ($) {
}).done(function (result) {
if (result.success) {
var proxies = [];
result.data.proxies.forEach(function (proxy){
result.data.proxies.forEach(function (proxy) {
var items = flatJSON(proxy.ProxyConfigurer);
proxies.push(expandJSON(items))
})
var visitors = [];
result.data.visitors.forEach(function (visitor){
result.data.visitors.forEach(function (visitor) {
var items = flatJSON(visitor.VisitorConfigurer);
visitors.push(expandJSON(items))
})
var newD = $.extend({},result.data,true);
newD.proxies = proxies;
newD.visitors = visitors;
console.log(TOML.stringify(newD))
window.clientConfig = $.extend(true, {}, result.data);
window.clientConfig.proxies = proxies;
window.clientConfig.visitors = visitors;
renderClientInfo(result.data);
} else {
layui.layer.msg(result.message);

View File

@@ -219,8 +219,8 @@ var loadProxyInfo = (function ($) {
},
success: function (layero, index, that) {
//get and set old name for update form
var oldNameKey = layero.find('#oldName').attr('name');
basicData[oldNameKey] = basicData.name;
var originalNameKey = layero.find('#originalNameKey').attr('name');
basicData[originalNameKey] = basicData.name;
layui.form.val('addProxyForm', flatJSON(basicData));
proxyPopupSuccess();
}
@@ -259,22 +259,26 @@ var loadProxyInfo = (function ($) {
*/
function addOrUpdate(data, index, update) {
var loading = layui.layer.load();
var url = '';
var originalNameKey = $('#originalNameKey').attr('name');
var proxies = clientConfig.proxies;
if (update) {
url = '/update?type=' + currentProxyType;
for (var i = 0; i < proxies.length; i++) {
if (data[originalNameKey] === proxies[i].name) {
delete data[originalNameKey];
proxies[i] = expandJSON(data);
}
}
} else {
url = '/add?type=' + currentProxyType;
proxies.push(expandJSON(data));
}
var tomlStr = TOML.stringify(expandJSON(data));
//todo get all proxy and replace or add a new proxy in it
var tomlStr = TOML.stringify(clientConfig);
$.ajax({
url: url,
url: '/update',
type: 'post',
contentType: 'application/json',
data: JSON.stringify(expandJSON(data)),
contentType: 'text/plain',
data: tomlStr,
success: function (result) {
if (result.success) {
layui.layer.close(index);

View File

@@ -1,3 +1,4 @@
window.clientConfig = {};
(function ($) {
$(function () {
function init() {

View File

@@ -1,4 +1,4 @@
(function (){
(function () {
//param names in Basic tab
var basicParams = [
{
@@ -24,10 +24,10 @@
defaultValue: '-'
}, {
name: 'transport.useEncryption',
defaultValue: 'true',
defaultValue: 'false',
}, {
name: 'transport.useCompression',
defaultValue: 'true',
defaultValue: 'false',
}
];
var mapParams = [{
@@ -177,6 +177,7 @@
return flat(obj);
}
window.basicParams = basicParams;
window.expandJSONKeys = expandJSONKeys;
window.expandJSON = expandJSON;
window.flatJSON = flatJSON;

View File

@@ -336,7 +336,13 @@ module.exports = Parser
module.exports = stringify
module.exports.value = stringifyInline
function stringify(obj, separator) {
/**
*
* @param obj json object
* @param options {{separator: string, indentSize: number}} options
* @returns {string|null}
*/
function stringify(obj, options) {
if (obj === null) throw typeError('null')
if (obj === void (0)) throw typeError('undefined')
if (typeof obj !== 'object') throw typeError(typeof obj)
@@ -345,7 +351,19 @@ function stringify(obj, separator) {
if (obj == null) return null
const type = tomlType(obj)
if (type !== 'table') throw typeError(type)
return stringifyObject('', '', obj, separator)
var defaultOptions = {
separator: '',
indentSize: 0,
}
if (options == null)
options = defaultOptions
else
options = {
separator: options.separator || defaultOptions.separator,
indentSize: options.indentSize || defaultOptions.indentSize,
}
return stringifyObject('', '', obj, options)
}
function typeError (type) {
@@ -371,7 +389,7 @@ function toJSON (obj) {
return nobj
}
function stringifyObject (prefix, indent, obj, separator) {
function stringifyObject (prefix, indent, obj, options) {
obj = toJSON(obj)
let inlineKeys
let complexKeys
@@ -382,13 +400,13 @@ function stringifyObject (prefix, indent, obj, separator) {
inlineKeys.forEach(key => {
var type = tomlType(obj[key])
if (type !== 'undefined' && type !== 'null') {
result.push(inlineIndent + stringifyKey(key) + ' = ' + stringifyAnyInline(obj[key], true, separator))
result.push(inlineIndent + stringifyKey(key) + ' = ' + stringifyAnyInline(obj[key], true, options))
}
})
if (result.length > 0) result.push('')
const complexIndent = prefix && inlineKeys.length > 0 ? indent + ' ' : ''
const complexIndent = prefix && inlineKeys.length > 0 ? (indent + ''.padStart(options.indentSize, ' ')) : ''
complexKeys.forEach(key => {
result.push(stringifyComplex(prefix, complexIndent, key, obj[key], separator))
result.push(stringifyComplex(prefix, complexIndent, key, obj[key], options))
})
return result.join('\n')
}
@@ -479,7 +497,7 @@ function stringifyMultilineString (str) {
return '"""\n' + escaped + '"""'
}
function stringifyAnyInline (value, multilineOk, separator) {
function stringifyAnyInline (value, multilineOk, options) {
let type = tomlType(value)
if (type === 'string') {
if (multilineOk && /\n/.test(value)) {
@@ -488,10 +506,10 @@ function stringifyAnyInline (value, multilineOk, separator) {
type = 'string-literal'
}
}
return stringifyInline(value, type, separator)
return stringifyInline(value, type, options)
}
function stringifyInline (value, type, separator) {
function stringifyInline (value, type, options) {
/* istanbul ignore if */
if (!type) type = tomlType(value)
switch (type) {
@@ -502,9 +520,9 @@ function stringifyInline (value, type, separator) {
case 'string-literal':
return stringifyLiteralString(value)
case 'integer':
return stringifyInteger(value, separator)
return stringifyInteger(value, options.separator)
case 'float':
return stringifyFloat(value, separator)
return stringifyFloat(value, options.separator)
case 'boolean':
return stringifyBoolean(value)
case 'datetime':
@@ -569,19 +587,19 @@ function stringifyInlineTable (value) {
return '{ ' + result.join(', ') + (result.length > 0 ? ' ' : '') + '}'
}
function stringifyComplex (prefix, indent, key, value, separator) {
function stringifyComplex (prefix, indent, key, value, options) {
const valueType = tomlType(value)
/* istanbul ignore else */
if (valueType === 'array') {
return stringifyArrayOfTables(prefix, indent, key, value, separator)
return stringifyArrayOfTables(prefix, indent, key, value, options)
} else if (valueType === 'table') {
return stringifyComplexTable(prefix, indent, key, value, separator)
return stringifyComplexTable(prefix, indent, key, value, options)
} else {
throw typeError(valueType)
}
}
function stringifyArrayOfTables (prefix, indent, key, values, separator) {
function stringifyArrayOfTables (prefix, indent, key, values, options) {
values = toJSON(values)
const firstValueType = tomlType(values[0])
/* istanbul ignore if */
@@ -591,18 +609,18 @@ function stringifyArrayOfTables (prefix, indent, key, values, separator) {
values.forEach(table => {
if (result.length > 0) result += '\n'
result += indent + '[[' + fullKey + ']]\n'
result += stringifyObject(fullKey + '.', indent, table, separator)
result += stringifyObject(fullKey + '.', indent, table, options)
})
return result
}
function stringifyComplexTable (prefix, indent, key, value, separator) {
function stringifyComplexTable (prefix, indent, key, value, options) {
const fullKey = prefix + stringifyKey(key)
let result = ''
if (getInlineKeys(value).length > 0) {
result += indent + '[' + fullKey + ']\n'
}
return result + stringifyObject(fullKey + '.', indent, value, separator)
return result + stringifyObject(fullKey + '.', indent, value, options)
}
},{}],10:[function(require,module,exports){