Open
Show file tree
Hide file tree
Changes from 1 commit
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Failed to load files.
Previous commit
Next commit
feat: update version and add daily challenge feature
  • Loading branch information
@XzZZzX02
XzZZzX02 committedNov 16, 2024
commit beefdc6c5b5e40c1d73767a3df33f69992c6ad8e
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
import {getUrl, getDailyQueryStr, getDailyProblemID} from "../shared";
import {LcAxios} from "../utils/httpUtils";

export const queryDailyChallenge = async (): Promise<string> => {
return LcAxios(getUrl("graphql"), {
method: "POST",
data: {
query: getDailyQueryStr(),
variables: {},
operationName: 'questionOfToday'
},
}).then((res) => getDailyProblemID(res));
};
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
// Licensed under the MIT license.

import * as vscode from "vscode";
import { AxiosResponse } from "axios";

export interface IQuickItemEx<T> extends vscode.QuickPickItem {
value: T;
Expand DownExpand Up@@ -156,3 +157,51 @@ export const getUrl = (key: string) => {
return urls[key];
}
};

export const getEndpoint = (): string => {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
return leetCodeConfig.get<string>("endpoint", Endpoint.LeetCode);
}


export const getDailyQueryStr = (): string => {
const dailyQueryStrs = {
LeetCode: `
query questionOfToday {
activeDailyCodingChallengeQuestion {
question {
frontendQuestionId: questionFrontendId
}
}
}
`,
LeetCodeCN: `
query questionOfToday {
todayRecord {
question {
frontendQuestionId: questionFrontendId
}
}
}
`
}
const point: string = getEndpoint();
switch (point) {
case Endpoint.LeetCodeCN:
return dailyQueryStrs.LeetCodeCN;
case Endpoint.LeetCode:
return dailyQueryStrs.LeetCode;
}
return "";
}

export const getDailyProblemID = (res: AxiosResponse<any, any>): string => {
const point = getEndpoint();
switch (point) {
case Endpoint.LeetCodeCN:
return res.data.data.todayRecord[0].question.frontendQuestionId;
case Endpoint.LeetCode:
return res.data.data.todayRecord[0].question.frontendQuestionId;
}
return "";
}