Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
gentee committed Mar 23, 2021
2 parents 117331d + fe9ec0a commit 0d2bfcb
Show file tree
Hide file tree
Showing 20 changed files with 1,269 additions and 716 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Alexey Krivonogov
Copyright (c) 2019-21 Alexey Krivonogov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
117 changes: 14 additions & 103 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,116 +106,34 @@ func compileHandle(c echo.Context) error {
}

func runHandle(c echo.Context) error {
var (
item *Script
src string
console bool
)
var console bool
open := true
name := c.QueryParam(`name`)
if len(c.QueryParam(`silent`)) > 0 || cfg.HTTP.Host != Localhost {
open = false
}
if len(c.QueryParam(`console`)) > 0 {
console = true
}
port, err := getPort()
if err != nil {
return jsonError(c, err)
}
if item = getScript(name); item == nil {
return jsonError(c, Lang(DefLang, `erropen`, name))
}
user := c.(*Auth).User
if err = ScriptAccess(item.Settings.Name, item.Settings.Path, user.RoleID); err != nil {
return jsonError(c, err)
}
if item.Settings.Unrun {
return jsonError(c, Lang(DefLang, `errnorun`, name))
}
if err = AddHistoryRun(user.ID, name); err != nil {
return jsonError(c, err)
}
langCode := GetLangCode(user)
title := item.Settings.Title
if langTitle := strings.Trim(title, `#`); langTitle != title {
if val, ok := item.Langs[langCode][langTitle]; ok {
title = val
} else if val, ok := item.Langs[LangDefCode][langTitle]; ok {
title = val
}
}
role, _ := GetRole(user.RoleID)
header := script.Header{
Name: name,
Title: title,
AssetsDir: cfg.AssetsDir,
LogDir: cfg.Log.Dir,
CDN: cfg.CDN,
Console: console,
IsPlayground: cfg.playground,
IP: c.RealIP(),
User: *user,
Role: role,
ClaimKey: cfg.HTTP.JWTKey + sessionKey,
IsPro: storage.Trial.Mode > TrialOff,
Constants: storage.Settings.Constants,
Lang: langCode,
TaskID: lib.RndNum(),
ServerPort: cfg.HTTP.Port,
HTTP: &lib.HTTPConfig{
Host: cfg.HTTP.Host,
Port: port,
Open: open,
Theme: cfg.HTTP.Theme,
Access: cfg.HTTP.Access,
},
}
if header.IsPlayground {
header.Playground = &cfg.Playground
tasksLimit := cfg.Playground.Tasks
for _, item := range tasks {
if item.Status < TaskFinished {
tasksLimit--
}
}
if tasksLimit <= 0 {
return jsonError(c, Lang(GetLangId(c.(*Auth).User), `errtasklimit`, cfg.Playground.Tasks))
}
}
if src, err = GenSource(item, &header); err != nil {
rs := RunScript{
Name: c.QueryParam(`name`),
Open: open,
Console: console,
User: *user,
Role: role,
IP: c.RealIP(),
}
if err := systemRun(&rs); err != nil {
return jsonError(c, err)
}
if storage.Settings.IncludeSrc {
if header.SourceCode, err = lib.GzipCompress([]byte(src)); err != nil {
return jsonError(c, err)
}
}
data, err := script.Encode(header, src)
if err != nil {
return jsonError(c, err)
}
if storage.Trial.Mode == TrialOn {
now := time.Now()
if storage.Trial.Last.Day() != now.Day() {
storage.Trial.Count++
storage.Trial.Last = now
if storage.Trial.Count > TrialDays {
storage.Trial.Mode = TrialDisabled
SetActive(false)
}
if err = SaveStorage(); err != nil {
return jsonError(c, err)
}
}
}
if err = NewTask(header); err != nil {
if err := AddHistoryRun(user.ID, rs.Name); err != nil {
return jsonError(c, err)
}
if console {
return c.Blob(http.StatusOK, ``, data.Bytes())
return c.Blob(http.StatusOK, ``, rs.Data)
}
return c.JSON(http.StatusOK, RunResponse{Success: true, Port: header.HTTP.Port, ID: header.TaskID})
return c.JSON(http.StatusOK, RunResponse{Success: true, Port: rs.Port, ID: rs.ID})
}

func pingHandle(c echo.Context) error {
Expand Down Expand Up @@ -336,14 +254,7 @@ func tasksHandle(c echo.Context) error {
(taskFlag&0x100 == 0x100 && user.ID == item.UserID) ||
(taskFlag&0x200 == 0x200 && user.RoleID == item.RoleID)
var userName, roleName string
if IsProActive() {
if user, ok := GetUser(item.UserID); ok {
userName = user.Nickname
}
if role, ok := GetRole(item.RoleID); ok {
roleName = role.Name
}
}
userName, roleName = GetUserRole(item.UserID, item.RoleID)
listInfo = append(listInfo, TaskInfo{
ID: item.ID,
Status: item.Status,
Expand Down
4 changes: 2 additions & 2 deletions appinfo.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2020 Alexey Krivonogov. All rights reserved.
// Copyright 2020-21 Alexey Krivonogov. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.

package main

var appInfo = AppInfo{
Title: `Eonza`,
Copyright: `© Alexey Krivonogov, 2020`,
Copyright: `© Alexey Krivonogov, 2020-21`,
Homepage: `https://www.eonza.org/`,
Email: `[email protected]`,
Issue: `https://github.com/gentee/eonza/issues`,
Expand Down
Loading

0 comments on commit 0d2bfcb

Please sign in to comment.