Removing «none» values from a custom field (issue: https://github.com/CinemaPress/CinemaPress/issues/33)

This commit is contained in:
zeldaroot 2021-10-30 17:00:18 +03:00
parent 2521ddc336
commit 2a9d3fa4bc
1 changed files with 22 additions and 0 deletions

View File

@ -172,6 +172,28 @@ function saveContent(content_raw, name, callback) {
? result.custom
: {}
: {};
Object.keys(cnt).forEach(function(key) {
if (typeof cnt[key] === 'string' && cnt[key] === 'none') {
delete cnt[key];
if (res && res[key]) delete res[key];
} else if (
typeof cnt[key] === 'object' &&
!Array.isArray(cnt[key]) &&
cnt[key]
) {
Object.keys(cnt[key]).forEach(function(key2) {
if (
typeof cnt[key][key2] === 'string' &&
cnt[key][key2] === 'none'
) {
delete cnt[key][key2];
if (res && res[key] && res[key][key2]) {
delete res[key][key2];
}
}
});
}
});
cnt = Object.assign({}, res, cnt);
content.custom = JSON.stringify(cnt);
} catch (e) {