Skip to content

Commit b34b6ea

Browse files
committed
leetcode cli: question info not found, refresh all problems info
1 parent 72ceffd commit b34b6ea

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

leet/leetcode.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ const (
6060
// param: leetcode-cn.com/problems/k-th-symbol-in-grammar
6161
func Parse(param string) string {
6262
if match, err := regexp.MatchString(`\d+`, param); err == nil && match {
63-
stat, err := ProblemID2name(param)
63+
stat, err := ProblemID2name(param, true)
64+
if err == nil {
65+
return stat.QuestionTitleSlug
66+
}
67+
68+
stat, err = ProblemID2name(param, false)
6469
if err == nil {
6570
return stat.QuestionTitleSlug
6671
}
@@ -94,13 +99,16 @@ func ParseFromURL(param string) string {
9499
}
95100

96101
// ProblemID2name return problem info
97-
func ProblemID2name(id string) (stats QuestionStats, err error) {
102+
func ProblemID2name(id string, cache bool) (stats QuestionStats, err error) {
98103
allProblemsDir := path.Join("questions", "all_problems.json")
99-
// 文件是否存在 / 结果是否过期
100-
f, err := os.Stat(allProblemsDir)
101104

102-
if err == nil && !f.IsDir() && f.ModTime().After(time.Now().Add(-cacheDuration)) {
103-
return problemID2name(id)
105+
if cache {
106+
// 文件是否存在 / 结果是否过期
107+
f, err := os.Stat(allProblemsDir)
108+
109+
if err == nil && !f.IsDir() && f.ModTime().After(time.Now().Add(-cacheDuration)) {
110+
return problemID2name(id)
111+
}
104112
}
105113

106114
allProblemsResult, err := allProblems()

0 commit comments

Comments
 (0)