Skip to content

Commit

Permalink
rest: no copy file download
Browse files Browse the repository at this point in the history
  • Loading branch information
criyle committed Feb 3, 2024
1 parent 8025bd3 commit c29d0ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions cmd/go-judge/rest_executor/file_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ func (f *fileHandle) fileIDGet(c *gin.Context) {
c.AbortWithStatus(http.StatusNotFound)
return
}
typ := mime.TypeByExtension(path.Ext(name))
c.Header("Content-Type", typ)

fi, ok := file.(*envexec.FileInput) // fast path
if ok {
c.FileAttachment(fi.Path, name)
return
}

r, err := envexec.FileToReader(file)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
Expand All @@ -79,8 +88,6 @@ func (f *fileHandle) fileIDGet(c *gin.Context) {
c.AbortWithError(http.StatusInternalServerError, err)
return
}

typ := mime.TypeByExtension(path.Ext(name))
c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", name))
c.Data(http.StatusOK, typ, content)
}
Expand Down
2 changes: 1 addition & 1 deletion env/winc/environment_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (e *Environment) Execve(ctx context.Context, param envexec.ExecveParam) (pr
result.ExitStatus = int(exitCode)

// collect usage
t, m, err := getJobOjbectUsage(hJob)
t, m, err := getJobObjectUsage(hJob)
if err != nil {
procSet.result = runner.Result{Status: runner.StatusRunnerError, Error: err.Error()}
return
Expand Down

0 comments on commit c29d0ad

Please sign in to comment.