mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-02 11:57:04 +08:00
feature (config): make config look nicer
before this, our config.json didn't look user friendly with a massive:
{
"general": {
"name": null,
"port": null,
"host": "demo.filestash.app",
"secret_key": "__REDACTED__",
"force_ssl": null,
"editor": null,
"fork_button": null,
"logout": null,
"display_hidden": null,
"refresh_after_upload": null,
"upload_button": null,
"upload_pool_size": null,
"filepage_default_view": null,
"filepage_default_sort": null,
"cookie_timeout": null,
"custom_css": null,
"auto_connect": null,
"enable_image": null,
"remember_me": null
},
"features": {
"api": {
"enable": null,
"api_key": "foobar ",
"enabled": null
},
"share": {
"enable": null,
"default_access": null,
"redirect": null
},
.....
}
which now translates to a much nicer:
{
"general": {
"host": "demo.filestash.app",
"secret_key": "__REDACTED__"
},
"features": {
"api": {
"api_key": "foobar "
},
...
}
This commit is contained in:
@ -99,3 +99,28 @@ export function autocomplete(values, list) {
|
||||
.replace(/\,\s?$/, "");
|
||||
});
|
||||
}
|
||||
|
||||
export function JSONStringify(data) {
|
||||
return JSON.stringify(data, (key, value) => {
|
||||
if (value === null) return;
|
||||
else if (value === undefined) return;
|
||||
else if (value === "") return;
|
||||
else if (Array.isArray(value)) return value;
|
||||
else if (typeof(value) === "string") return value;
|
||||
else if (typeof(value) === "number") return value;
|
||||
else if (typeof(value) === "boolean") return value;
|
||||
else if (typeof(value) === "object") {
|
||||
const tmp = Object.values(value);
|
||||
if (tmp.length === 0) return;
|
||||
if (tmp.filter((n) => {
|
||||
if(JSON.stringify(n) === "{}") return false;
|
||||
else if(n === null) return false;
|
||||
return true;
|
||||
}).length === 0) return;
|
||||
return value;
|
||||
}
|
||||
const msg = `[BUG] unknown stringify value (helpers/form.js): ${value}`;
|
||||
console.error(msg);
|
||||
throw new Error(msg);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user