Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 8 additions & 10 deletions src/components/forms/CodeforcesForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { getContestDataWithCodeforcesAPI } from "../../parsers/codeforces/codefo
const CodeforcesForm = ({ setContestData, setStep }) => {
const [contestId, setContestId] = useState("");
const [isPrivate, setIsPrivate] = useState(false);
const [groupId, setGroupId] = useState("");
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 @@ -18,9 +18,9 @@ const CodeforcesForm = ({ setContestData, setStep }) => {
frozenTime,
contestId,
isPrivate,
groupId,
apiKey,
apiSecret,
asManager,
})
);
setStep("resolver");
Expand Down Expand Up @@ -62,14 +62,12 @@ const CodeforcesForm = ({ setContestData, setStep }) => {
</fieldset>

{isPrivate && (
<fieldset className="form-field">
<label>Group ID:</label>
<input
type="text"
name="cf_group_id"
required
onChange={e => setGroupId(e.target.value)}
/>
<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>
)}

Expand Down
25 changes: 12 additions & 13 deletions src/parsers/codeforces/codeforces-api-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ const buildParams = ({
method,
contestId,
isPrivate = false,
groupId = "",
apiKey = "",
apiSecret = "",
asManager = false,
}) => {
if (!isPrivate) {
return {
contestId,
};
}
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}&time=${time}#${apiSecret}`;
const hash = sha512(encodeURI(str));
return {
groupCode,
contestId,
apiKey,
time,
apiSig: rand + hash,
asManager,
};
};

Expand All @@ -38,9 +37,9 @@ export const getSubmissions = async ({
duration,
contestId,
isPrivate = false,
groupId = "",
apiKey = "",
apiSecret = "",
asManager = false,
}) => {
const { data: response } = await axios
.request({
Expand All @@ -51,9 +50,9 @@ export const getSubmissions = async ({
method: "contest.status",
contestId,
isPrivate,
groupId,
apiKey,
apiSecret,
asManager,
}),
})
.catch(error => {
Expand All @@ -68,7 +67,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 @@ -79,9 +78,9 @@ export const getContestData = async ({
frozenTime = 60,
contestId,
isPrivate = false,
groupId = "",
apiKey = "",
apiSecret = "",
asManager = false,
}) => {
const { data: response } = await axios
.request({
Expand All @@ -92,9 +91,9 @@ export const getContestData = async ({
method: "contest.standings",
contestId,
isPrivate,
groupId,
apiKey,
apiSecret,
asManager,
}),
})
.catch(error => {
Expand All @@ -116,7 +115,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 @@ -126,25 +125,25 @@ export const getContestDataWithCodeforcesAPI = async ({
frozenTime,
contestId,
isPrivate = false,
groupId = "",
apiKey = "",
apiSecret = "",
asManager = false,
}) => {
const contestData = await getContestData({
frozenTime,
contestId,
isPrivate,
groupId,
apiKey,
apiSecret,
asManager,
});
const submissions = await getSubmissions({
duration: contestData.contestData.duration,
contestId,
isPrivate,
groupId,
apiKey,
apiSecret,
asManager,
});
const JSONobject = {
contestMetadata: contestData.contestData,
Expand Down