| 587 | } |
| 588 | |
| 589 | func uploadUnsignedApp(c echo.Context) error { |
| 590 | profileId := c.FormValue(formNames.FormProfileId) |
| 591 | profile, ok := storage.Profiles.GetById(profileId) |
| 592 | if !ok { |
| 593 | return errors.New("no profile with id " + profileId) |
| 594 | } |
| 595 | builderId := c.FormValue(formNames.FormBuilderId) |
| 596 | builder, ok := config.Current.Builder[builderId] |
| 597 | if !ok { |
| 598 | return errors.New("no builder with id " + builderId) |
| 599 | } |
| 600 | |
| 601 | var file io.ReadCloser |
| 602 | var fileName string |
| 603 | fileId := c.FormValue(formNames.FormFileId) |
| 604 | fileUrl := c.FormValue(formNames.FormFileUrl) |
| 605 | if fileUrl != "" { |
| 606 | resp, err := http.Get(fileUrl) |
| 607 | if err != nil || resp.StatusCode < 200 || resp.StatusCode > 299 { |
| 608 | return c.String(400, "Failed to download app from url: "+err.Error()) |
| 609 | } |
| 610 | file = resp.Body |
| 611 | defer file.Close() |
| 612 | fileName = filepath.Base(fileUrl) |
| 613 | } else if app, ok := storage.Apps.Get(fileId); ok { |
| 614 | readonlyFile, err := app.GetFile(storage.AppUnsignedFile) |
| 615 | if err != nil { |
| 616 | return err |
| 617 | } |
| 618 | file = readonlyFile |
| 619 | defer file.Close() |
| 620 | fileName, err = app.GetString(storage.AppName) |
| 621 | if err != nil { |
| 622 | return err |
| 623 | } |
| 624 | } else if upload, ok := storage.Uploads.Get(fileId); ok { |
| 625 | defer storage.Uploads.Delete(fileId) |
| 626 | readonlyFile, err := upload.GetData() |
| 627 | if err != nil { |
| 628 | return err |
| 629 | } |
| 630 | file = readonlyFile |
| 631 | defer file.Close() |
| 632 | info, err := upload.GetInfo() |
| 633 | if err != nil { |
| 634 | return err |
| 635 | } |
| 636 | fileName = info.MetaData["filename"] |
| 637 | } else { |
| 638 | return errors.New("no app upload file with id " + fileId) |
| 639 | } |
| 640 | |
| 641 | signArgs := "" |
| 642 | if c.FormValue(formNames.FormAllDevices) != "" { |
| 643 | signArgs += " -a" |
| 644 | } |
| 645 | if c.FormValue(formNames.FormMac) != "" { |
| 646 | signArgs += " -m" |