Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/forms/CodeforcesForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CodeforcesForm = ({ setContestData, setStep }) => {
const [apiKey, setApiKey] = useState("");
const [apiSecret, setApiSecret] = useState("");
const [frozenTime, setFrozenTime] = useState(60);
const [asManager, setAsManager] = useState(false);

const handleSubmit = async event => {
event.preventDefault();
Expand All @@ -21,6 +22,7 @@ const CodeforcesForm = ({ setContestData, setStep }) => {
groupId,
apiKey,
apiSecret,
asManager,
})
);
setStep("resolver");
Expand Down Expand Up @@ -61,6 +63,16 @@ const CodeforcesForm = ({ setContestData, setStep }) => {
</label>
</fieldset>

{isPrivate && (
<fieldset className="form-field form-switch">
<label>Are You Manager? </label>
<label className="switch">
<input type="checkbox" onChange={e => setAsManager(e.target.checked)} />
<span className="slider round"></span>
</label>
</fieldset>
)}

{isPrivate && (
<fieldset className="form-field">
<label>Group ID:</label>
Expand Down
15 changes: 12 additions & 3 deletions src/parsers/codeforces/codeforces-api-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const buildParams = ({
groupId = "",
apiKey = "",
apiSecret = "",
asManager = false,
}) => {
if (!isPrivate) {
return {
Expand All @@ -17,14 +18,15 @@ const buildParams = ({
const time = `${Math.floor(Date.now() / 1000)}`;
const groupCode = groupId;
const rand = "123456";
const str = `${rand}/${method}?apiKey=${apiKey}&contestId=${contestId}&groupCode=${groupCode}&time=${time}#${apiSecret}`;
const str = `${rand}/${method}?apiKey=${apiKey}&asManager=${asManager}&contestId=${contestId}&groupCode=${groupCode}&time=${time}#${apiSecret}`;
const hash = sha512(encodeURI(str));
return {
groupCode,
Comment thread
MosaabGKA marked this conversation as resolved.
Outdated
contestId,
apiKey,
time,
apiSig: rand + hash,
asManager,
};
};

Expand All @@ -41,6 +43,7 @@ export const getSubmissions = async ({
groupId = "",
apiKey = "",
apiSecret = "",
asManager = false,
}) => {
const { data: response } = await axios
.request({
Expand All @@ -54,6 +57,7 @@ export const getSubmissions = async ({
groupId,
apiKey,
apiSecret,
asManager,
}),
})
.catch(error => {
Expand All @@ -68,7 +72,7 @@ export const getSubmissions = async ({
return {
timeSubmitted: Math.floor(submission.relativeTimeSeconds / 60),
contestantName:
submission.author.teamName || submission.author.members[0].handle || "NO_TEAM_NAME",
submission.author.teamName || submission.author.members[0].name || submission.author.members[0].handle || "NO_TEAM_NAME",
problemIndex: submission.problem.index,
verdict: submission.verdict,
};
Expand All @@ -82,6 +86,7 @@ export const getContestData = async ({
groupId = "",
apiKey = "",
apiSecret = "",
asManager = false,
}) => {
const { data: response } = await axios
.request({
Expand All @@ -95,6 +100,7 @@ export const getContestData = async ({
groupId,
apiKey,
apiSecret,
asManager,
}),
})
.catch(error => {
Expand All @@ -116,7 +122,7 @@ export const getContestData = async ({
contestants: response.result.rows.map((row, index) => {
return {
id: index,
name: row.party.teamName || row.party.members[0].handle || `NO_TEAM_NAME_${id}`,
name: row.party.teamName || row.party.members[0].name || row.party.members[0].handle || `NO_TEAM_NAME_${id}`,
};
}),
};
Expand All @@ -129,6 +135,7 @@ export const getContestDataWithCodeforcesAPI = async ({
groupId = "",
apiKey = "",
apiSecret = "",
asManager = false,
}) => {
const contestData = await getContestData({
frozenTime,
Expand All @@ -137,6 +144,7 @@ export const getContestDataWithCodeforcesAPI = async ({
groupId,
apiKey,
apiSecret,
asManager,
});
const submissions = await getSubmissions({
duration: contestData.contestData.duration,
Expand All @@ -145,6 +153,7 @@ export const getContestDataWithCodeforcesAPI = async ({
groupId,
apiKey,
apiSecret,
asManager,
});
const JSONobject = {
contestMetadata: contestData.contestData,
Expand Down