Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* to query entries from Contentful API. */
if (isomorphy.isServerSide()) {
return this.private.ss.queryEntries(query);
}
/* At client-side we send HTTP request to Community App server,
* which proxies it to Contentful API via the same server-side service
* used above. */
let url = this.private.baseUrl;
url += this.private.preview ? '/preview' : '/published';
url += '/entries';
if (query) url += `?${qs.stringify(query)}`;
const res = await fetch(url);
if (!res.ok) {
const error = new Error('Failed to get entries.');
logger.error(error);
}
return res.json();
}
function ArticleAssetsLoader(props) {
const {
article, articleCard, preview, spaceName, environment,
} = props;
// handle forum posts
const { contentAuthor } = article;
if (!contentAuthor) {
logger.error("'contentAuthor' property should be required but is missing");
}
const contentAuthorIds = contentAuthor.map(obj => obj.sys.id);
if (articleCard.theme === 'Forum post' && contentAuthorIds.length !== 0) {
return (
{
const avatars = [];
let authors = contentAuthorIds.map((id, index) => {
const author = data.entries.items[id].fields;
// adding `key` property so it can be used as key
// when looping over authors in `ArticleCard.jsx`
author.id = id;
fireErrorMessage(
'ERROR: Failed to submit!',
'Please, try to submit from https://software.topcoder.com or email you submission to support@topcoder.com',
);
return {
...state,
submitErrorMsg: 'Failed to submit',
isSubmitting: false,
submitDone: false,
};
}
if (payload.message) {
/* payload message is present when upload of file fails due to any reason so
* handle this special case for error */
logger.error(`Failed to submit for the challenge - ${payload.message}`);
return {
...state,
submitErrorMsg: payload.message || 'Failed to submit',
isSubmitting: false,
submitDone: false,
};
}
/* TODO: I am not sure, whether this code is just wrong, or does it handle
* only specific errors, returned from API for design submissions? I am
* adding a more generic failure handling code just above. */
if (payload.result && !payload.result.success) {
return {
...state,
submitErrorMsg: payload.result.content.message || 'Failed to submit',
isSubmitting: false,
function onGetDraftChallengesDone(state, { error, payload }) {
if (error) {
logger.error(payload);
return state;
}
const { uuid, challenges: loaded } = payload;
if (uuid !== state.loadingDraftChallengesUUID) return state;
const ids = new Set();
loaded.forEach(item => ids.add(item.id));
/* Fetching 0 page of draft challenges also drops any draft challenges
* loaded to the state before. */
const filter = state.lastRequestedPageOfDraftChallenges
? item => !ids.has(item.id)
: item => !ids.has(item.id) && item.status !== 'DRAFT';
const challenges = state.challenges
.filter(filter).concat(loaded);
function onGetActiveChallengesDone(state, { error, payload }) {
if (error) {
logger.error(payload);
return state;
}
const { uuid, challenges: loaded } = payload;
if (uuid !== state.loadingActiveChallengesUUID) return state;
/* Once all active challenges are fetched from the API, we remove from the
* store any active challenges stored there previously, and also any
* challenges with IDs matching any challenges loaded now as active. */
const ids = new Set();
loaded.forEach(item => ids.add(item.id));
/* Fetching 0 page of active challenges also drops any active challenges
* loaded to the state before. */
const filter = state.lastRequestedPageOfActiveChallenges
? item => !ids.has(item.id)
: item => !ids.has(item.id) && item.status !== 'ACTIVE';
function onSubmitDone(state, { error, payload }) {
if (error) {
/* TODO: Some more details for the log will be handy, but no time to care
* about right now. */
logger.error('Failed to submit for the challenge');
fireErrorMessage(
'ERROR: Failed to submit!',
'Please, try to submit from https://software.topcoder.com or email you submission to support@topcoder.com',
);
return {
...state,
submitErrorMsg: 'Failed to submit',
isSubmitting: false,
submitDone: false,
};
}
/* TODO: I am not sure, whether this code is just wrong, or does it handle
* only specific errors, returned from API for design submissions? I am
* adding a more generic failure handling code just above. */
if (payload.error) {
function onGetPastChallengesDone(state, { error, payload }) {
if (error) {
logger.error(payload);
return state;
}
const { uuid, challenges: loaded, frontFilter } = payload;
if (uuid !== state.loadingPastChallengesUUID) return state;
const ids = new Set();
loaded.forEach(item => ids.add(item.id));
/* Fetching 0 page of past challenges also drops any past challenges
* loaded to the state before. */
const filter = state.lastRequestedPageOfPastChallenges
? item => !ids.has(item.id)
: item => !ids.has(item.id) && item.status !== 'COMPLETED' && item.status !== 'PAST';
const challenges = state.challenges.filter(filter).concat(loaded);
const now = Date.now();
const cached = getMetadata.cache[communityId];
if (cached && now - cached.timestamp < getMetadata.maxage) {
return _.cloneDeep(cached.data);
}
let metadata;
const uri = path.resolve(
__dirname, '../tc-communities',
communityId, 'metadata.json',
);
try {
metadata = JSON.parse(fs.readFileSync(uri, 'utf8'));
} catch (error) {
const msg = `Failed to get metadata for ${communityId} community`;
logger.error(msg, error);
throw new Error(msg);
}
const challengeGroupIds = _.get(metadata, 'challengeFilter.groupIds');
if (challengeGroupIds) {
metadata.challengeFilter.groupIds = await extendByChildGroups(
challengeGroupIds,
);
}
if (metadata.authorizedGroupIds) {
metadata.authorizedGroupIds = await extendByChildGroups(
metadata.authorizedGroupIds,
);
}
if (metadata.groupIds) {
metadata.groupIds = await extendByChildGroups(metadata.groupIds);
function onGetChallengeSubtracksDone(state, action) {
if (action.error) logger.error(action.payload);
return {
...state,
challengeSubtracks: action.error ? [] : action.payload,
challengeSubtracksMap: action.error ? {} : _.keyBy(action.payload, 'subTrack'),
loadingChallengeSubtracks: false,
};
}
function onGetChallengeSubtracksDone(state, action) {
if (action.error) logger.error(action.payload);
return {
...state,
challengeSubtracks: action.error ? [] : action.payload,
challengeSubtracksMap: action.error ? {} : _.keyBy(action.payload, 'subTrack'),
loadingChallengeSubtracks: false,
};
}