Fix bug not letting add new instance + show mandatory fields with "*"

This commit is contained in:
Bofh 2022-12-19 01:18:37 +01:00
parent c59d25e93a
commit addb800ec5
5 changed files with 24 additions and 15 deletions

View File

@ -13,6 +13,6 @@ if (isset($data['error']))
$software = trim($_GET['software']);
$instance = trim($_GET['instance']);
filedb_put("instances/$software/$instance/config");
filedb_put("instances/$software/$instance", 'config');
$uri = preg_replace('#api/v1/config/instances.*#', '', $_SERVER['REQUEST_URI']);
header('Location: '.$uri.'#home');

View File

@ -16,8 +16,8 @@
window.consts = {
'instance_config': {
'mastodon': {
'musthave': ['instance_url','psql_host','psql_port','psql_db',
'psql_username','psql_password','redis_host','redis_port','api_authkey'],
'fields': ['*instance_url','*psql_host','*psql_port','*psql_db',
'*psql_username','*psql_password','redis_host','redis_port','*api_authkey'],
},
}
};

View File

@ -17,9 +17,11 @@
<div class="input">
<label for="software">Instance domain:</label>
<br class="sep"/>
<div class="flex">
<input type="text" name="instance"
class="w100" placeholder="example.org"/>
</div>
</div>
<br>
<input class="btn green w100"
type="submit" value="Add Instance"/>

View File

@ -595,9 +595,12 @@ function load__instance(args) {
apcontrol_title(`Instance (${hargs['instance']})`);
const config = parse_ini_config(window.vars['current_instance']['config']);
const musthave = window.consts['instance_config'][hargs['software']]['musthave'];
for (var i = 0; i < musthave.length; i++) {
if (config[musthave[i]] === undefined) {
const fields = window.consts['instance_config'][hargs['software']]['fields'];
for (var i = 0; i < fields.length; i++) {
if (!fields[i].startsWith('*'))
continue;
const f = fields[i].substr(1);
if (config[f] === undefined) {
window.view.instance.show_config();
return false;
}

View File

@ -13,7 +13,7 @@
</div>
</form>
<div id="config-item">
<label for="{field}">{placeholder}:</label>
<label for="{field}">{importantMark}{placeholder}:</label>
<input id="config_{field}" name="{field}" class="w100"
placeholder="{field}" type="text"/>
</div>
@ -25,10 +25,11 @@ window.view.instance_config = {
mastodon: function(hargs, config) {
E.element('#window-instance_config form').setAttribute('action',
`api/v1/config/put/?software=mastodon&instance=${hargs['instance']}`);
const fields = window.consts['instance_config']['mastodon']['musthave'];
const fields = window.consts['instance_config']['mastodon']['fields'];
for (var i = 0; i < fields.length; i++) {
if (config[fields[i]] !== undefined)
E.elemid(`config_${fields[i]}`).value = config[fields[i]];
const f = fields[i].startsWith('*') ? fields[i].substr(1) : fields[i];
if (config[f] !== undefined)
E.elemid(`config_${f}`).value = config[f];
}
if (config['instance_url'] === undefined) {
http.get('api/v1/network/resolve-instance?hostname='+hargs['instance'],
@ -54,11 +55,14 @@ function load__instance_config(args) {
capitalize(hargs['software']) + ` (${hargs['instance']})`);
E.template('config', function(TPL) {
var html = '';
const fields = window.consts['instance_config'][hargs['software']]['musthave'];
const fields = window.consts['instance_config'][hargs['software']]['fields'];
for (var i = 0; i < fields.length; i++) {
const field = fields[i].startsWith('*') ? fields[i].substr(1) : fields[i];
const important = fields[i].startsWith('*');
var tpl = TPL;
tpl = tpl.replaceAll('{field}', fields[i]);
tpl = tpl.replaceAll('{placeholder}', human_field_name(fields[i]));
tpl = tpl.replaceAll('{field}', field);
tpl = tpl.replaceAll('{placeholder}', human_field_name(field));
tpl = tpl.replaceAll('{importantMark}', important ? '*' : '');
html += tpl;
}
return html;