From a72ede94db79cd167706cff72b7ec01d2ba567d8 Mon Sep 17 00:00:00 2001 From: retaj sharaf Date: Thu, 19 Sep 2024 17:25:57 +0300 Subject: [PATCH] project1 merge groups.data.js --- dump.rdb | Bin 0 -> 88 bytes src/groups/data.js | 59 +++++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 dump.rdb diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 0000000000000000000000000000000000000000..7eef42645a96498a19dd8ee1e5d01f89c03e8d0a GIT binary patch literal 88 zcmWG?b@2=~FfcUy#aWb^l3A=P;l-K50g)B_CvGkzQ2<@~(C5&+%TB@6%n literal 0 HcmV?d00001 diff --git a/src/groups/data.js b/src/groups/data.js index 5ecb9081e0..a2c0fb4f1d 100644 --- a/src/groups/data.js +++ b/src/groups/data.js @@ -7,6 +7,7 @@ const db = require('../database'); const plugins = require('../plugins'); const utils = require('../utils'); const translator = require('../translator'); +const coverPhoto = require('../coverPhoto'); const intFields = [ 'createtime', 'memberCount', 'hidden', 'system', 'private', @@ -68,35 +69,47 @@ module.exports = function (Groups) { function modifyGroup(group, fields) { if (group) { db.parseIntFields(group, intFields, fields); - escapeGroupData(group); - group.userTitleEnabled = ([null, undefined].includes(group.userTitleEnabled)) ? 1 : group.userTitleEnabled; - group.labelColor = validator.escape(String(group.labelColor || '#000000')); - group.textColor = validator.escape(String(group.textColor || '#ffffff')); - group.icon = validator.escape(String(group.icon || '')); - group.createtimeISO = utils.toISOString(group.createtime); - group.private = ([null, undefined].includes(group.private)) ? 1 : group.private; - group.memberPostCids = group.memberPostCids || ''; - group.memberPostCidsArray = group.memberPostCids.split(',').map(cid => parseInt(cid, 10)).filter(Boolean); - - group['cover:thumb:url'] = group['cover:thumb:url'] || group['cover:url']; - - if (group['cover:url']) { - group['cover:url'] = group['cover:url'].startsWith('http') ? group['cover:url'] : (nconf.get('relative_path') + group['cover:url']); - } else { - group['cover:url'] = require('../coverPhoto').getDefaultGroupCover(group.name); - } + setDefaultValues(group); + formatGroupFields(group); + setCoverUrls(group); + } +} - if (group['cover:thumb:url']) { - group['cover:thumb:url'] = group['cover:thumb:url'].startsWith('http') ? group['cover:thumb:url'] : (nconf.get('relative_path') + group['cover:thumb:url']); - } else { - group['cover:thumb:url'] = require('../coverPhoto').getDefaultGroupCover(group.name); - } +function setDefaultValues(group) { + group.userTitleEnabled = ([null, undefined].includes(group.userTitleEnabled)) ? 1 : group.userTitleEnabled; + group.private = ([null, undefined].includes(group.private)) ? 1 : group.private; + group.labelColor = validator.escape(String(group.labelColor || '#000000')); + group.textColor = validator.escape(String(group.textColor || '#ffffff')); + group.icon = validator.escape(String(group.icon || '')); +} - group['cover:position'] = validator.escape(String(group['cover:position'] || '50% 50%')); +function formatGroupFields(group) { + group.createtimeISO = utils.toISOString(group.createtime); + group.memberPostCids = group.memberPostCids || ''; + group.memberPostCidsArray = group.memberPostCids.split(',').map(cid => parseInt(cid, 10)).filter(Boolean); + group['cover:position'] = validator.escape(String(group['cover:position'] || '50% 50%')); +} + +function setCoverUrls(group) { + group['cover:thumb:url'] = group['cover:thumb:url'] || group['cover:url']; + if (group['cover:url']) { + group['cover:url'] = formatUrl(group['cover:url']); + } else { + group['cover:url'] = coverPhoto.getDefaultGroupCover(group.name); + } + + if (group['cover:thumb:url']) { + group['cover:thumb:url'] = formatUrl(group['cover:thumb:url']); + } else { + group['cover:thumb:url'] = coverPhoto.getDefaultGroupCover(group.name); } } +function formatUrl(url) { + return url.startsWith('http') ? url : (nconf.get('relative_path') + url); +} + function escapeGroupData(group) { if (group) { group.nameEncoded = encodeURIComponent(group.name);