Skip to content

Commit

Permalink
Merge pull request #29 from CMU-17313Q/developingCode
Browse files Browse the repository at this point in the history
merge changes from project 1 in file "groups.data.js"
  • Loading branch information
khalifat3 authored Sep 19, 2024
2 parents 8baa8a3 + a72ede9 commit fe805df
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
Binary file added dump.rdb
Binary file not shown.
59 changes: 36 additions & 23 deletions src/groups/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fe805df

Please sign in to comment.