diff --git a/README.md b/README.md index 86b3e1a..3d06683 100644 --- a/README.md +++ b/README.md @@ -465,7 +465,7 @@ This tool uses `problem.xml` for uploading all package content. Useful for migration between `polygon.lksh.ru` and `polygon.codeforces.com`. -Designed to replace ~~legacy~~ [polygon-cli](https://github.com/kunyavskiy/polygon-cli) tool. +Designed designed as an alternative to [polygon-cli](https://github.com/kunyavskiy/polygon-cli). **Ensure that the problem you are uploading the package into is empty.** @@ -473,7 +473,7 @@ Designed to replace ~~legacy~~ [polygon-cli](https://github.com/kunyavskiy/polyg - If problem has testsets other than `tests`, you should create them manually, [issue](https://github.com/Codeforces/polygon-issue-tracking/issues/549); - If problem is interactive, set `Is problem interactive` checkbox manually; -- If problem has statements resources, upload them manually; +- If problem has statement resources, upload them manually; - If problem has custom input/output, set it manually; - If problem has [FreeMaker](https://freemarker.apache.org) generator, it will expand; - If problem has stresses, unpload them manually; @@ -517,6 +517,7 @@ Matching uses natural order (`test.1.in`, `test.2.in`, ..., `test.10.in`, ...). - `ok` - correct solution - `incor` - incorrect solution - `sample` - sample (append, not replace) +- `image` - statement resource (likely image) ### Flags - `-i` - problem id (required) diff --git a/cmd/wooda/main.go b/cmd/wooda/main.go index 37a3c68..056df1c 100644 --- a/cmd/wooda/main.go +++ b/cmd/wooda/main.go @@ -23,6 +23,7 @@ func main() { wooda.ModeSolutionCorrect, wooda.ModeSolutionIncorrect, wooda.ModeSample, + wooda.ModeImage, } parser := argparse.NewParser("wooda", "Upload problem files filtered by glob to Polygon.") diff --git a/polygon/api.go b/polygon/api.go index 29ab8a6..4f8567f 100644 --- a/polygon/api.go +++ b/polygon/api.go @@ -88,12 +88,18 @@ func buildRequest(method, link string, params url.Values) (*http.Request, error) writer := multipart.NewWriter(buf) for k, vals := range params { for _, v := range vals { - if err := writer.WriteField(k, v); err != nil { + wr, err := writer.CreateFormFile(k, k) + if err != nil { + return nil, err + } + if _, err := wr.Write([]byte(v)); err != nil { return nil, err } } } - writer.Close() + if err := writer.Close(); err != nil { + return nil, err + } req, err := http.NewRequestWithContext(context.TODO(), method, link, buf) if err != nil { return nil, err @@ -438,11 +444,11 @@ func (p *Polygon) SaveTestGroup(tgr TestGroupRequest) error { return err } -func (p *Polygon) SaveStatementResource(pID int, name, file string) error { - link, params := p.buildURL("problem.saveScript", url.Values{ +func (p *Polygon) SaveStatementResource(pID int, name, data string) error { + link, params := p.buildURL("problem.saveStatementResource", url.Values{ "problemId": []string{strconv.Itoa(pID)}, "name": []string{name}, - "file": []string{file}, + "file": []string{data}, }) _, err := p.makeQuery(http.MethodPost, link, params) diff --git a/polygon/wooda/wooda.go b/polygon/wooda/wooda.go index 8c0ebf2..c273898 100644 --- a/polygon/wooda/wooda.go +++ b/polygon/wooda/wooda.go @@ -21,6 +21,7 @@ const ( ModeSolutionCorrect = "ok" ModeSolutionIncorrect = "incor" ModeSample = "sample" + ModeImage = "image" // statement resource ) var ( @@ -71,6 +72,8 @@ func (w *Wooda) Resolve(path string) error { return w.resolveSolution(path, file, polygon.TagIncorrect) case ModeSample: return w.resolveTest(path, file, true) + case ModeImage: + return w.resolveImage(path, file) default: return fmt.Errorf("%w: %s", ErrUnknownMode, w.mode) } @@ -164,3 +167,7 @@ func (w *Wooda) resolveSolution(path, data string, tag polygon.SolutionTag) erro return w.client.SaveSolution(sr) } + +func (w *Wooda) resolveImage(path, data string) error { + return w.client.SaveStatementResource(w.pID, filepath.Base(path), data) +}