Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
qianxi66 committed Jul 16, 2024
1 parent ccc9d0e commit a79c9e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/controller/problem.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ func CreateTestCase(c echo.Context) error {
panic(errors.Wrap(err, "could not create test case"))
}
// upload to minio
utils.MustPutTestCase(*req.Sanitize, inputFile, c.Request().Context(), "problems", fmt.Sprintf("%d/input/%d.in", problem.ID, testCase.ID))
utils.MustPutTestCase(*req.Sanitize, outputFile, c.Request().Context(), "problems", fmt.Sprintf("%d/output/%d.out", problem.ID, testCase.ID))
utils.MustPutInputFile(*req.Sanitize, inputFile, c.Request().Context(), "problems", fmt.Sprintf("%d/input/%d.in", problem.ID, testCase.ID))
utils.MustPutObject(outputFile, c.Request().Context(), "problems", fmt.Sprintf("%d/output/%d.out", problem.ID, testCase.ID))

return c.JSON(http.StatusCreated, response.CreateTestCaseResponse{
Message: "SUCCESS",
Expand Down Expand Up @@ -487,11 +487,11 @@ func UpdateTestCase(c echo.Context) error {
}

if inputFile != nil {
utils.MustPutTestCase(*req.Sanitize, inputFile, c.Request().Context(), "problems", fmt.Sprintf("%d/input/%d.in", problem.ID, testCase.ID))
utils.MustPutInputFile(*req.Sanitize, inputFile, c.Request().Context(), "problems", fmt.Sprintf("%d/input/%d.in", problem.ID, testCase.ID))
testCase.InputFileName = inputFile.Filename
}
if outputFile != nil {
utils.MustPutTestCase(*req.Sanitize, outputFile, c.Request().Context(), "problems", fmt.Sprintf("%d/output/%d.out", problem.ID, testCase.ID))
utils.MustPutObject(outputFile, c.Request().Context(), "problems", fmt.Sprintf("%d/output/%d.out", problem.ID, testCase.ID))
testCase.OutputFileName = outputFile.Filename
}

Expand Down
5 changes: 3 additions & 2 deletions base/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func MustPutObject(object *multipart.FileHeader, ctx context.Context, bucket str
}
}

func MustPutTestCase(sanitize bool, object *multipart.FileHeader, ctx context.Context, bucket string, path string) {
func MustPutInputFile(sanitize bool, object *multipart.FileHeader, ctx context.Context, bucket string, path string) {
src, err := object.Open()
if err != nil {
panic(err)
Expand All @@ -80,10 +80,11 @@ func MustPutTestCase(sanitize bool, object *multipart.FileHeader, ctx context.Co
writer := bufio.NewWriter(tempFile)
for scanner.Scan() {
line := strings.ReplaceAll(scanner.Text(), "\r\n", "\n") // replace '\r\n' to '\n'
_, err := fmt.Fprint(writer, line)

if !strings.HasSuffix(line, "\n") {
line += "\n"
}
_, err := fmt.Fprint(writer, line)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit a79c9e9

Please sign in to comment.