Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
gentee committed Apr 6, 2021
2 parents 0d2bfcb + b249efa commit e123162
Show file tree
Hide file tree
Showing 18 changed files with 1,003 additions and 452 deletions.
80 changes: 77 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
package main

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"strings"
"time"

"eonza/lib"
"eonza/script"
es "eonza/script"
"eonza/users"

"github.com/gentee/gentee"
Expand Down Expand Up @@ -59,6 +62,11 @@ type TasksResponse struct {
Error string `json:"error,omitempty"`
}

type Feedback struct {
Like int `json:"like"`
Feedback string `json:"feedback"`
}

func jsonError(c echo.Context, err interface{}) error {
return c.JSON(http.StatusOK, Response{Error: fmt.Sprint(err)})
}
Expand Down Expand Up @@ -89,7 +97,7 @@ func compileHandle(c echo.Context) error {
title = val
}
}
header := script.Header{
header := es.Header{
Name: name,
Lang: langCode,
}
Expand Down Expand Up @@ -131,7 +139,40 @@ func runHandle(c echo.Context) error {
return jsonError(c, err)
}
if console {
return c.Blob(http.StatusOK, ``, rs.Data)
return c.Blob(http.StatusOK, ``, rs.Encoded)
}
return c.JSON(http.StatusOK, RunResponse{Success: true, Port: rs.Port, ID: rs.ID})
}

func runScriptHandle(c echo.Context) error {
var (
postScript es.PostScript
err error
)
if err = c.Bind(&postScript); err != nil {
return jsonError(c, err)
}
if !strings.HasPrefix(c.Request().Host, Localhost+`:`) && tasks[postScript.TaskID] == nil {
return echo.NewHTTPError(http.StatusForbidden, "Access denied")
}
rs := RunScript{
Name: postScript.Script,
Open: !postScript.Silent,
Console: false,
Data: postScript.Data,
User: users.User{
ID: postScript.TaskID,
Nickname: GetTaskName(postScript.TaskID),
RoleID: users.ScriptsID,
},
Role: users.Role{
ID: users.ScriptsID,
Name: users.ScriptsRole,
},
IP: c.RealIP(),
}
if err := systemRun(&rs); err != nil {
return jsonError(c, err)
}
return c.JSON(http.StatusOK, RunResponse{Success: true, Port: rs.Port, ID: rs.ID})
}
Expand Down Expand Up @@ -329,3 +370,36 @@ func trialHandle(c echo.Context) error {
}
return proSettingsHandle(c)
}

func feedbackHandle(c echo.Context) error {
var (
feedback Feedback
resp *http.Response
body []byte
err error
)
if err = c.Bind(&feedback); err != nil {
return jsonError(c, err)
}
// user := c.(*Auth).User
jsonValue, err := json.Marshal(feedback)
if err == nil {
resp, err = http.Post(appInfo.Homepage+"feedback",
"application/json", bytes.NewBuffer(jsonValue))
if err == nil {
if body, err = ioutil.ReadAll(resp.Body); err == nil {
var answer Response
if err = json.Unmarshal(body, &answer); err == nil {
if len(answer.Error) > 0 {
err = fmt.Errorf(answer.Error)
}
}
}
resp.Body.Close()
}
}
if err != nil {
return jsonError(c, err)
}
return jsonSuccess(c)
}
933 changes: 517 additions & 416 deletions assets.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ func AuthHandle(next echo.HandlerFunc) echo.HandlerFunc {
if url == `/` {
c.Request().URL.Path = `login`
} else if url != `/api/login` && url != `/api/taskstatus` && url != `/api/sys` &&
url != `/api/notification` {
url != `/api/notification` && url != `/api/runscript` && url != `/api/event` &&
url != `/api/randid` {
return AccessDenied(http.StatusUnauthorized)
}
}
Expand Down
2 changes: 1 addition & 1 deletion const.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main

const (
// Version of the application
Version = "1.15.0"
Version = "1.16.0"
// DefPort is the default web-server port
DefPort = 3234
// DefTheme is the default web-server theme
Expand Down
2 changes: 1 addition & 1 deletion make.g
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ run {

$ /home/ak/go/bin/esc -ignore "\.git|LICENSE|README.md" -o assets.go ../eonza-assets
// $ go install -ldflags "-s -w" -tags "eonza standard"
$ go install -tags "tray" -ldflags "-s -w -X main.VerType=%{vertype} -X main.CompileDate=%{Format(`YYYY-MM-DD`,Now())}"
$ go install -tags "tray" -ldflags "-s -w -X main.CompileDate=%{Format(`YYYY-MM-DD`,Now())}"
// $ go install -ldflags "-s -w -X main.VerType=%{vertype} -X main.CompileDate=%{Format(`YYYY-MM-DD`,Now())}"
$ cp ${GOPATH}/bin/eonza /home/ak/app/eonza-dev/eonza
$ cp ${GOPATH}/bin/eonza /home/ak/app/eonza/eonza
Expand Down
12 changes: 9 additions & 3 deletions notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,18 @@ func AutoCheckUpdate() {
}

func latestVerHandle(c echo.Context) error {
if err := CheckUpdates(); err != nil {
return jsonError(c, err)
if len(c.QueryParam(`cache`)) == 0 {
if err := CheckUpdates(); err != nil {
return jsonError(c, err)
}
}
var lastChecked string
if nfyData.Update.LastChecked.Year() > 2019 {
lastChecked = nfyData.Update.LastChecked.Format(TimeFormat)
}
return c.JSON(http.StatusOK, LatestResponse{
Version: nfyData.Update.Version,
Notify: GetNewVersion(GetLangCode(c.(*Auth).User)),
LastChecked: nfyData.Update.LastChecked.Format(TimeFormat),
LastChecked: lastChecked,
})
}
16 changes: 8 additions & 8 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ type Render struct {
PortShift int64
Favs []Fav
Nfy *NfyResponse
Update VerUpdate
Pro bool
ProActive bool
DefLists []DefList
User *users.User
Twofa bool
// Update VerUpdate
Pro bool
ProActive bool
DefLists []DefList
User *users.User
Twofa bool
// ProSettings ProSettings
// Port int
/* Params map[string]string
Expand Down Expand Up @@ -190,8 +190,8 @@ func RenderPage(c echo.Context, url string) (string, error) {
render.PortShift = cfg.PortShift
render.Favs = userSettings[user.ID].Favs
render.Nfy = NfyList(false, user.ID, user.RoleID)
render.Update = nfyData.Update
render.Update.Notify = GetNewVersion(GetLangCode(c.(*Auth).User))
// render.Update = nfyData.Update
// render.Update.Notify = GetNewVersion(GetLangCode(c.(*Auth).User))
render.Pro = Pro && !cfg.playground
render.ProActive = IsProActive()
render.DefLists = defaultList
Expand Down
10 changes: 6 additions & 4 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ type RunScript struct {
User users.User
Role users.Role
IP string
Data string

// Result fields
ID uint32
Port int
Data []byte
ID uint32
Port int
Encoded []byte
}

func systemRun(rs *RunScript) error {
Expand Down Expand Up @@ -69,6 +70,7 @@ func systemRun(rs *RunScript) error {
AssetsDir: cfg.AssetsDir,
LogDir: cfg.Log.Dir,
CDN: cfg.CDN,
Data: rs.Data,
Console: rs.Console,
IsPlayground: cfg.playground,
IP: rs.IP,
Expand Down Expand Up @@ -130,7 +132,7 @@ func systemRun(rs *RunScript) error {
return err
}
if rs.Console {
rs.Data = data.Bytes()
rs.Encoded = data.Bytes()
}
rs.Port = header.HTTP.Port
rs.ID = header.TaskID
Expand Down
Loading

0 comments on commit e123162

Please sign in to comment.