chore: import upstream snapshot with attribution
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
const crypto = require('crypto');
|
||||
|
||||
const createdIds = new Set();
|
||||
|
||||
function createChallengeNode(
|
||||
challenge,
|
||||
reporter,
|
||||
{ isReloading } = { isReloading: false }
|
||||
) {
|
||||
const contentDigest = crypto
|
||||
.createHash('md5')
|
||||
.update(JSON.stringify(challenge))
|
||||
.digest('hex');
|
||||
const internal = {
|
||||
contentDigest,
|
||||
type: challenge.challengeType === 7 ? 'CertificateNode' : 'ChallengeNode'
|
||||
};
|
||||
|
||||
if (internal.type === 'ChallengeNode') {
|
||||
const { block, dashedName, superBlock } = challenge;
|
||||
const slug = `/learn/${superBlock}/${block}/${dashedName}`;
|
||||
const blockHashSlug = `/learn/${superBlock}/#${block}`;
|
||||
|
||||
challenge.fields = {
|
||||
slug,
|
||||
blockHashSlug
|
||||
};
|
||||
}
|
||||
|
||||
// Challenge id should be unique for CertificateNodes, but not for
|
||||
// ChallengeNodes
|
||||
const id =
|
||||
internal.type === 'ChallengeNode' ? challenge.fields.slug : challenge.id;
|
||||
|
||||
if (createdIds.has(id) && !isReloading) {
|
||||
throw Error(`
|
||||
Challenge slugs must be unique, but ${id} already exists.
|
||||
`);
|
||||
}
|
||||
createdIds.add(id);
|
||||
|
||||
return JSON.parse(
|
||||
JSON.stringify(
|
||||
Object.assign(
|
||||
{},
|
||||
{
|
||||
children: [],
|
||||
parent: null,
|
||||
internal,
|
||||
sourceInstanceName: 'challenge'
|
||||
},
|
||||
{ challenge },
|
||||
{
|
||||
id
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
exports.createChallengeNode = createChallengeNode;
|
||||
Reference in New Issue
Block a user