-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9838936
commit a135435
Showing
27 changed files
with
370 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package handlers | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/limanmys/render-engine/internal/liman" | ||
) | ||
|
||
func ExtensionRunner(c *fiber.Ctx) error { | ||
/*if len(c.FormValue("extension_id")) < 1 { | ||
return fiber.NewError(fiber.StatusNotFound, "Extension not found") | ||
} | ||
extension, err := liman.GetExtension(&models.Extension{ | ||
ID: c.FormValue("extension_id"), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
if extension.Status == "0" { | ||
return fiber.NewError(fiber.StatusServiceUnavailable, "Extension is unavailable right now, please try again later.") | ||
} | ||
if extension.RequireKey == "true" { | ||
credentials, err := liman.GetCredentials( | ||
&models.User{ | ||
ID: c.Locals("user_id").(string), | ||
}, | ||
&models.Server{ | ||
ID: c.FormValue("server_id"), | ||
}, | ||
) | ||
if err != nil || len(credentials.Username) < 1 { | ||
return fiber.NewError(fiber.StatusForbidden, "You need a key to use this extension, please add it through the case.") | ||
} | ||
} */ | ||
|
||
settings := liman.GetSettings(c.Locals("user_id").(string), c.FormValue("server_id"), c.FormValue("extension_id")) | ||
|
||
return c.JSON(settings) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package models | ||
|
||
type CommandParams struct { | ||
TargetFunction string | ||
User string | ||
Extension string | ||
Server string | ||
RequestData map[string]string | ||
Token string | ||
BaseURL string | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package models | ||
|
||
type Settings struct { | ||
ID string `json:"id"` | ||
ServerID string `json:"server_id"` | ||
UserID string `json:"user_id"` | ||
Name string `json:"name"` | ||
Value string `json:"value"` | ||
CreatedAt string `json:"created_at"` | ||
UpdatedAt string `json:"updated_at"` | ||
} | ||
|
||
func (Settings) TableName() string { | ||
return "user_settings" | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package liman | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/limanmys/render-engine/app/models" | ||
"github.com/limanmys/render-engine/internal/database" | ||
) | ||
|
||
func AuthWithToken(token string) (string, error) { | ||
tokenObj := &models.Token{} | ||
|
||
err := database.Connection().First(&tokenObj, "token = ?", token).Error | ||
|
||
if err != nil || len(tokenObj.UserID) < 1 { | ||
return "", errors.New("Authorization token is not valid.") | ||
} | ||
|
||
return tokenObj.UserID, nil | ||
} | ||
|
||
func AuthWithAccessToken(token string) (string, error) { | ||
tokenObj := &models.AccessToken{} | ||
|
||
err := database.Connection().First(&tokenObj, "token = ?", token).Error | ||
|
||
if err != nil || len(tokenObj.UserID) < 1 { | ||
return "", errors.New("Authorization token is not valid.") | ||
} | ||
|
||
return tokenObj.UserID, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package liman | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
"github.com/limanmys/render-engine/app/models" | ||
"github.com/limanmys/render-engine/internal/database" | ||
) | ||
|
||
func GetExtension(extension *models.Extension) (*models.Extension, error) { | ||
result := database.Connection().First(&extension) | ||
|
||
if result.Error != nil { | ||
return nil, fiber.NewError(fiber.StatusNotFound, "Cannot found extension with this id") | ||
} | ||
|
||
if result.RowsAffected > 0 { | ||
return extension, nil | ||
} | ||
|
||
return nil, fiber.NewError(fiber.StatusNotFound, "Cannot found extension with this id") | ||
} | ||
|
||
func GetExtensionJSON(extension *models.Extension) (map[string]any, error) { | ||
fileName := "" | ||
if len(extension.Name) > 0 { | ||
fileName = strings.ToLower(extension.Name) | ||
} else { | ||
extObject, err := GetExtension(extension) | ||
fileName = strings.ToLower(extObject.Name) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
jsonFile, err := ioutil.ReadFile(fmt.Sprintf("/liman/extensions/%s/db.json", fileName)) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
extJson := make(map[string]any) | ||
json.Unmarshal(jsonFile, &extJson) | ||
|
||
return extJson, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package liman | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/limanmys/render-engine/app/models" | ||
"github.com/limanmys/render-engine/internal/database" | ||
) | ||
|
||
func GetServer(server *models.Server) (*models.Server, error) { | ||
result := database.Connection().First(&server) | ||
|
||
if result.Error != nil { | ||
return nil, fiber.NewError(fiber.StatusNotFound, "Cannot found server with this id") | ||
} | ||
|
||
if result.RowsAffected > 0 { | ||
return server, nil | ||
} | ||
|
||
return nil, fiber.NewError(fiber.StatusNotFound, "Cannot found server with this id") | ||
} |
Oops, something went wrong.