mirror of
https://github.com/documize/community.git
synced 2025-07-21 22:29:41 +02:00
refactored smart section code
This commit is contained in:
parent
5acfae3d0d
commit
3defc062bd
40 changed files with 172 additions and 306 deletions
|
@ -8,7 +8,7 @@ The mission is to bring software dev inspired features (refactoring, testing, li
|
||||||
|
|
||||||
## Latest version
|
## Latest version
|
||||||
|
|
||||||
v1.50.1
|
v1.50.2
|
||||||
|
|
||||||
## OS Support
|
## OS Support
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/documize/community/core/api/convert/html"
|
"github.com/documize/community/core/api/convert/html"
|
||||||
"github.com/documize/community/core/api/plugins"
|
"github.com/documize/community/core/api/plugins"
|
||||||
api "github.com/documize/community/core/convapi"
|
api "github.com/documize/community/core/convapi"
|
||||||
|
@ -53,7 +54,7 @@ func Convert(ctx context.Context, xtn string, fileRequest *api.DocumentConversio
|
||||||
/* TODO add sanitisation for body & title HTML
|
/* TODO add sanitisation for body & title HTML
|
||||||
var titlePolicy, bodyPolicy *bluemonday.Policy
|
var titlePolicy, bodyPolicy *bluemonday.Policy
|
||||||
|
|
||||||
func init() {
|
func xxx() {
|
||||||
policy := bluemonday.UGCPolicy()
|
policy := bluemonday.UGCPolicy()
|
||||||
policy.RequireNoFollowOnLinks(true)
|
policy.RequireNoFollowOnLinks(true)
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ import (
|
||||||
"github.com/documize/community/core/api/util"
|
"github.com/documize/community/core/api/util"
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/log"
|
||||||
"github.com/documize/community/core/secrets"
|
"github.com/documize/community/core/secrets"
|
||||||
"github.com/documize/community/core/section/provider"
|
|
||||||
"github.com/documize/community/core/web"
|
"github.com/documize/community/core/web"
|
||||||
|
"github.com/documize/community/domain/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Authenticate user based up HTTP Authorization header.
|
// Authenticate user based up HTTP Authorization header.
|
||||||
|
|
|
@ -23,34 +23,6 @@ import (
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// var jwtKey string
|
|
||||||
|
|
||||||
// func init() {
|
|
||||||
// env.GetString(&jwtKey, "salt", false, "the salt string used to encode JWT tokens, if not set a random value will be generated",
|
|
||||||
// func(t *string, n string) bool {
|
|
||||||
// if jwtKey == "" {
|
|
||||||
// b := make([]byte, 17)
|
|
||||||
// _, err := rand.Read(b)
|
|
||||||
// if err != nil {
|
|
||||||
// jwtKey = err.Error()
|
|
||||||
// log.Error("problem using crypto/rand", err)
|
|
||||||
// return false
|
|
||||||
// }
|
|
||||||
// for k, v := range b {
|
|
||||||
// if (v >= 'a' && v <= 'z') || (v >= 'A' && v <= 'Z') || (v >= '0' && v <= '0') {
|
|
||||||
// b[k] = v
|
|
||||||
// } else {
|
|
||||||
// s := fmt.Sprintf("%x", v)
|
|
||||||
// b[k] = s[0]
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// jwtKey = string(b)
|
|
||||||
// log.Info("Please set DOCUMIZESALT or use -salt with this value: " + jwtKey)
|
|
||||||
// }
|
|
||||||
// return true
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Generates JSON Web Token (http://jwt.io)
|
// Generates JSON Web Token (http://jwt.io)
|
||||||
func generateJWT(user, org, domain string) string {
|
func generateJWT(user, org, domain string) string {
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||||
|
|
|
@ -24,9 +24,9 @@ import (
|
||||||
"github.com/documize/community/core/api/request"
|
"github.com/documize/community/core/api/request"
|
||||||
"github.com/documize/community/core/api/util"
|
"github.com/documize/community/core/api/util"
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/log"
|
||||||
"github.com/documize/community/core/section/provider"
|
|
||||||
"github.com/documize/community/core/streamutil"
|
"github.com/documize/community/core/streamutil"
|
||||||
"github.com/documize/community/core/uniqueid"
|
"github.com/documize/community/core/uniqueid"
|
||||||
|
"github.com/documize/community/domain/section/provider"
|
||||||
htmldiff "github.com/documize/html-diff"
|
htmldiff "github.com/documize/html-diff"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,9 +21,9 @@ import (
|
||||||
"github.com/documize/community/core/api/request"
|
"github.com/documize/community/core/api/request"
|
||||||
"github.com/documize/community/core/api/util"
|
"github.com/documize/community/core/api/util"
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/log"
|
||||||
"github.com/documize/community/core/section/provider"
|
|
||||||
"github.com/documize/community/core/streamutil"
|
"github.com/documize/community/core/streamutil"
|
||||||
"github.com/documize/community/core/uniqueid"
|
"github.com/documize/community/core/uniqueid"
|
||||||
|
"github.com/documize/community/domain/section/provider"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -26,30 +26,6 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
// var port, certFile, keyFile, forcePort2SSL string
|
|
||||||
|
|
||||||
// Product details app edition and version
|
|
||||||
// var Product env.ProdInfo
|
|
||||||
|
|
||||||
// func init() {
|
|
||||||
// // Product.Major = "1"
|
|
||||||
// // Product.Minor = "50"
|
|
||||||
// // Product.Patch = "0"
|
|
||||||
// // Product.Version = fmt.Sprintf("%s.%s.%s", Product.Major, Product.Minor, Product.Patch)
|
|
||||||
// // Product.Edition = "Community"
|
|
||||||
// // Product.Title = fmt.Sprintf("%s Edition", Product.Edition)
|
|
||||||
// // Product.License = env.License{}
|
|
||||||
// // Product.License.Seats = 1
|
|
||||||
// // Product.License.Valid = true
|
|
||||||
// // Product.License.Trial = false
|
|
||||||
// // Product.License.Edition = "Community"
|
|
||||||
|
|
||||||
// // env.GetString(&certFile, "cert", false, "the cert.pem file used for https", nil)
|
|
||||||
// // env.GetString(&keyFile, "key", false, "the key.pem file used for https", nil)
|
|
||||||
// // env.GetString(&port, "port", false, "http/https port number", nil)
|
|
||||||
// // env.GetString(&forcePort2SSL, "forcesslport", false, "redirect given http port number to TLS", nil)
|
|
||||||
// }
|
|
||||||
|
|
||||||
var testHost string // used during automated testing
|
var testHost string // used during automated testing
|
||||||
|
|
||||||
// Serve the Documize endpoint.
|
// Serve the Documize endpoint.
|
||||||
|
|
|
@ -31,13 +31,6 @@ import (
|
||||||
var PluginFile = "DB" // this points to the database
|
var PluginFile = "DB" // this points to the database
|
||||||
var insecure = "false"
|
var insecure = "false"
|
||||||
|
|
||||||
// func init() {
|
|
||||||
// env.GetString(&PluginFile, "plugin", false,
|
|
||||||
// "the JSON file describing plugins, default 'DB' uses the database config table 'FILEPLUGINS' entry", nil)
|
|
||||||
// env.GetString(&insecure, "insecure", false,
|
|
||||||
// "if 'true' allow https endpoints with invalid certificates (only for testing)", nil)
|
|
||||||
// }
|
|
||||||
|
|
||||||
type infoLog struct{}
|
type infoLog struct{}
|
||||||
|
|
||||||
func (i infoLog) Write(b []byte) (int, error) {
|
func (i infoLog) Write(b []byte) (int, error) {
|
||||||
|
|
|
@ -45,85 +45,6 @@ func (dr *databaseRequest) MakeTx() (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// func init() {
|
|
||||||
// var err error
|
|
||||||
|
|
||||||
// env.GetString(&connectionString, "db", true,
|
|
||||||
// `'username:password@protocol(hostname:port)/databasename" for example "fred:bloggs@tcp(localhost:3306)/documize"`,
|
|
||||||
// func(*string, string) bool {
|
|
||||||
|
|
||||||
// Db, err = sqlx.Open("mysql", stdConn(connectionString))
|
|
||||||
|
|
||||||
// if err != nil {
|
|
||||||
// log.Error("Unable to setup database", err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Db.SetMaxIdleConns(30)
|
|
||||||
// Db.SetMaxOpenConns(100)
|
|
||||||
// Db.SetConnMaxLifetime(time.Second * 14400)
|
|
||||||
|
|
||||||
// err = Db.Ping()
|
|
||||||
|
|
||||||
// if err != nil {
|
|
||||||
// log.Error("Unable to connect to database, connection string should be of the form: '"+
|
|
||||||
// "username:password@tcp(host:3306)/database'", err)
|
|
||||||
// os.Exit(2)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // go into setup mode if required
|
|
||||||
// if web.SiteMode != web.SiteModeOffline {
|
|
||||||
// if database.Check(Db, connectionString) {
|
|
||||||
// if err := database.Migrate(true /* the config table exists */); err != nil {
|
|
||||||
// log.Error("Unable to run database migration: ", err)
|
|
||||||
// os.Exit(2)
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// log.Info("database.Check(Db) !OK, going into setup mode")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return false // value not changed
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var stdParams = map[string]string{
|
|
||||||
// "charset": "utf8",
|
|
||||||
// "parseTime": "True",
|
|
||||||
// "maxAllowedPacket": "4194304", // 4194304 // 16777216 = 16MB
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func stdConn(cs string) string {
|
|
||||||
// queryBits := strings.Split(cs, "?")
|
|
||||||
// ret := queryBits[0] + "?"
|
|
||||||
// retFirst := true
|
|
||||||
// if len(queryBits) == 2 {
|
|
||||||
// paramBits := strings.Split(queryBits[1], "&")
|
|
||||||
// for _, pb := range paramBits {
|
|
||||||
// found := false
|
|
||||||
// if assignBits := strings.Split(pb, "="); len(assignBits) == 2 {
|
|
||||||
// _, found = stdParams[strings.TrimSpace(assignBits[0])]
|
|
||||||
// }
|
|
||||||
// if !found { // if we can't work out what it is, put it through
|
|
||||||
// if retFirst {
|
|
||||||
// retFirst = false
|
|
||||||
// } else {
|
|
||||||
// ret += "&"
|
|
||||||
// }
|
|
||||||
// ret += pb
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// for k, v := range stdParams {
|
|
||||||
// if retFirst {
|
|
||||||
// retFirst = false
|
|
||||||
// } else {
|
|
||||||
// ret += "&"
|
|
||||||
// }
|
|
||||||
// ret += k + "=" + v
|
|
||||||
// }
|
|
||||||
// return ret
|
|
||||||
// }
|
|
||||||
|
|
||||||
type baseManager struct {
|
type baseManager struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
||||||
//
|
|
||||||
// This software (Documize Community Edition) is licensed under
|
|
||||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
||||||
//
|
|
||||||
// You can operate outside the AGPL restrictions by purchasing
|
|
||||||
// Documize Enterprise Edition and obtaining a commercial license
|
|
||||||
// by contacting <sales@documize.com>.
|
|
||||||
//
|
|
||||||
// https://documize.com
|
|
||||||
|
|
||||||
package section
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/documize/community/core/log"
|
|
||||||
"github.com/documize/community/core/section/airtable"
|
|
||||||
"github.com/documize/community/core/section/code"
|
|
||||||
"github.com/documize/community/core/section/gemini"
|
|
||||||
"github.com/documize/community/core/section/github"
|
|
||||||
"github.com/documize/community/core/section/markdown"
|
|
||||||
"github.com/documize/community/core/section/papertrail"
|
|
||||||
"github.com/documize/community/core/section/provider"
|
|
||||||
"github.com/documize/community/core/section/table"
|
|
||||||
"github.com/documize/community/core/section/trello"
|
|
||||||
"github.com/documize/community/core/section/wysiwyg"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Register sections
|
|
||||||
func Register() {
|
|
||||||
provider.Register("code", &code.Provider{})
|
|
||||||
provider.Register("gemini", &gemini.Provider{})
|
|
||||||
provider.Register("github", &github.Provider{})
|
|
||||||
provider.Register("markdown", &markdown.Provider{})
|
|
||||||
provider.Register("papertrail", &papertrail.Provider{})
|
|
||||||
provider.Register("table", &table.Provider{})
|
|
||||||
provider.Register("trello", &trello.Provider{})
|
|
||||||
provider.Register("wysiwyg", &wysiwyg.Provider{})
|
|
||||||
provider.Register("airtable", &airtable.Provider{})
|
|
||||||
p := provider.List()
|
|
||||||
log.Info(fmt.Sprintf("Documize registered %d sections and tabs", len(p)))
|
|
||||||
}
|
|
|
@ -14,11 +14,13 @@ package airtable
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/core/env"
|
||||||
|
"github.com/documize/community/domain/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider represents Airtable
|
// Provider represents Airtable
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
Runtime env.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta describes us
|
// Meta describes us
|
|
@ -14,11 +14,13 @@ package code
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/core/env"
|
||||||
|
"github.com/documize/community/domain/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider represents code snippet
|
// Provider represents code snippet
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
Runtime env.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta describes us.
|
// Meta describes us.
|
|
@ -20,12 +20,13 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/domain/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider represents Gemini
|
// Provider represents Gemini
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
Runtime env.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta describes us.
|
// Meta describes us.
|
||||||
|
@ -87,29 +88,29 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
|
func (p *Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
|
||||||
var c = geminiConfig{}
|
var c = geminiConfig{}
|
||||||
err := json.Unmarshal([]byte(config), &c)
|
err := json.Unmarshal([]byte(config), &c)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to read Gemini config", err)
|
p.Runtime.Log.Error("Unable to read Gemini config", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Clean(ctx)
|
c.Clean(ctx)
|
||||||
|
|
||||||
if len(c.URL) == 0 {
|
if len(c.URL) == 0 {
|
||||||
log.Info("Gemini.Refresh received empty URL")
|
p.Runtime.Log.Info("Gemini.Refresh received empty URL")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.Username) == 0 {
|
if len(c.Username) == 0 {
|
||||||
log.Info("Gemini.Refresh received empty username")
|
p.Runtime.Log.Info("Gemini.Refresh received empty username")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.APIKey) == 0 {
|
if len(c.APIKey) == 0 {
|
||||||
log.Info("Gemini.Refresh received empty API key")
|
p.Runtime.Log.Info("Gemini.Refresh received empty API key")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,16 +137,15 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData st
|
||||||
|
|
||||||
dec := json.NewDecoder(res.Body)
|
dec := json.NewDecoder(res.Body)
|
||||||
err = dec.Decode(&items)
|
err = dec.Decode(&items)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
p.Runtime.Log.Error("unable to Decode gemini items", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
j, err := json.Marshal(items)
|
j, err := json.Marshal(items)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to marshall gemini items", err)
|
p.Runtime.Log.Error("unable to marshal gemini items", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +196,6 @@ func auth(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
provider.WriteError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -215,7 +214,6 @@ func auth(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
err = dec.Decode(&g)
|
err = dec.Decode(&g)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
provider.WriteError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -288,7 +286,6 @@ func workspace(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
err = dec.Decode(&workspace)
|
err = dec.Decode(&workspace)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
provider.WriteError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -334,7 +331,6 @@ func items(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
filter, err := json.Marshal(config.Filter)
|
filter, err := json.Marshal(config.Filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
provider.WriteError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -348,7 +344,6 @@ func items(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
provider.WriteError(w, "gemini", err)
|
provider.WriteError(w, "gemini", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -374,7 +369,6 @@ func items(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func secs(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
func secs(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
sec, err := getSecrets(ctx)
|
sec, _ := getSecrets(ctx)
|
||||||
log.IfErr(err)
|
|
||||||
provider.WriteJSON(w, sec)
|
provider.WriteJSON(w, sec)
|
||||||
}
|
}
|
|
@ -14,8 +14,7 @@ package gemini
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/domain/section/provider"
|
||||||
"github.com/documize/community/core/section/provider"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// the HTML that is rendered by this section.
|
// the HTML that is rendered by this section.
|
||||||
|
@ -108,7 +107,7 @@ func (c *geminiConfig) SaveSecrets(ctx *provider.Context) {
|
||||||
sec.APIKey = strings.TrimSpace(c.APIKey)
|
sec.APIKey = strings.TrimSpace(c.APIKey)
|
||||||
sec.Username = strings.TrimSpace(c.Username)
|
sec.Username = strings.TrimSpace(c.Username)
|
||||||
sec.URL = strings.TrimSpace(c.URL)
|
sec.URL = strings.TrimSpace(c.URL)
|
||||||
log.IfErr(ctx.MarshalSecrets(sec))
|
ctx.MarshalSecrets(sec)
|
||||||
}
|
}
|
||||||
|
|
||||||
type secrets struct {
|
type secrets struct {
|
|
@ -15,15 +15,13 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
//"fmt"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/domain/section/provider"
|
||||||
|
|
||||||
gogithub "github.com/google/go-github/github"
|
gogithub "github.com/google/go-github/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,6 +43,7 @@ func init() {
|
||||||
|
|
||||||
// Provider represents GitHub
|
// Provider represents GitHub
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
Runtime env.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta describes us.
|
// Meta describes us.
|
||||||
|
@ -59,7 +58,6 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
||||||
|
|
||||||
if len(method) == 0 {
|
if len(method) == 0 {
|
||||||
msg := "missing method name"
|
msg := "missing method name"
|
||||||
log.ErrorString("github: " + msg)
|
|
||||||
provider.WriteMessage(w, "gitub", msg)
|
provider.WriteMessage(w, "gitub", msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -80,9 +78,8 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := "Bad body"
|
p.Runtime.Log.Error("bad body", errors.New("Missing body"))
|
||||||
log.ErrorString("github: " + msg)
|
provider.WriteMessage(w, "github", "bad body")
|
||||||
provider.WriteMessage(w, "github", msg)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +87,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
||||||
|
|
||||||
// write the new one, direct from JS
|
// write the new one, direct from JS
|
||||||
if err = ctx.SaveSecrets(string(body)); err != nil {
|
if err = ctx.SaveSecrets(string(body)); err != nil {
|
||||||
log.Error("github settoken configuration", err)
|
p.Runtime.Log.Error("github settoken configuration", err)
|
||||||
provider.WriteError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -104,7 +101,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
||||||
err = json.Unmarshal(body, &config)
|
err = json.Unmarshal(body, &config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github Command Unmarshal", err)
|
p.Runtime.Log.Error("github Command Unmarshal", err)
|
||||||
provider.WriteError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -127,7 +124,7 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// token now invalid, so wipe it
|
// token now invalid, so wipe it
|
||||||
ctx.SaveSecrets("") // ignore error, already in an error state
|
ctx.SaveSecrets("") // ignore error, already in an error state
|
||||||
log.Error("github check token validation", err)
|
p.Runtime.Log.Error("github check token validation", err)
|
||||||
provider.WriteError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -135,11 +132,11 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
if listFailed(method, config, client, w) {
|
if listFailed(p.Runtime, method, config, client, w) {
|
||||||
|
|
||||||
gr := githubRender{}
|
gr := githubRender{}
|
||||||
for _, rep := range reports {
|
for _, rep := range reports {
|
||||||
log.IfErr(rep.refresh(&gr, &config, client))
|
rep.refresh(&gr, &config, client)
|
||||||
}
|
}
|
||||||
provider.WriteJSON(w, &gr)
|
provider.WriteJSON(w, &gr)
|
||||||
|
|
||||||
|
@ -153,9 +150,8 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
|
||||||
var c = githubConfig{}
|
var c = githubConfig{}
|
||||||
|
|
||||||
err := json.Unmarshal([]byte(configJSON), &c)
|
err := json.Unmarshal([]byte(configJSON), &c)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to unmarshall github config", err)
|
p.Runtime.Log.Error("unable to unmarshall github config", err)
|
||||||
return "internal configuration error '" + err.Error() + "'"
|
return "internal configuration error '" + err.Error() + "'"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +162,7 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
|
||||||
|
|
||||||
byts, err := json.Marshal(refreshReportData(&c, client))
|
byts, err := json.Marshal(refreshReportData(&c, client))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to marshall github data", err)
|
p.Runtime.Log.Error("unable to marshall github data", err)
|
||||||
return "internal configuration error '" + err.Error() + "'"
|
return "internal configuration error '" + err.Error() + "'"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +173,7 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
|
||||||
func refreshReportData(c *githubConfig, client *gogithub.Client) *githubRender {
|
func refreshReportData(c *githubConfig, client *gogithub.Client) *githubRender {
|
||||||
var gr = githubRender{}
|
var gr = githubRender{}
|
||||||
for _, rep := range reports {
|
for _, rep := range reports {
|
||||||
log.IfErr(rep.refresh(&gr, c, client))
|
rep.refresh(&gr, c, client)
|
||||||
}
|
}
|
||||||
return &gr
|
return &gr
|
||||||
}
|
}
|
||||||
|
@ -192,7 +188,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
err = json.Unmarshal([]byte(config), &c)
|
err = json.Unmarshal([]byte(config), &c)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to unmarshall github config", err)
|
p.Runtime.Log.Error("unable to unmarshall github config", err)
|
||||||
return "Please delete and recreate this Github section."
|
return "Please delete and recreate this Github section."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +204,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(data), &payload)
|
err = json.Unmarshal([]byte(data), &payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to unmarshall github data", err)
|
p.Runtime.Log.Error("unable to unmarshall github data", err)
|
||||||
return "Please delete and recreate this Github section."
|
return "Please delete and recreate this Github section."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,12 +218,12 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
rep, ok := reports[repID]
|
rep, ok := reports[repID]
|
||||||
if !ok {
|
if !ok {
|
||||||
msg := "github report not found for: " + repID
|
msg := "github report not found for: " + repID
|
||||||
log.ErrorString(msg)
|
p.Runtime.Log.Info(msg)
|
||||||
return "Documize internal error: " + msg
|
return "Documize internal error: " + msg
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = rep.render(&payload, &c); err != nil {
|
if err = rep.render(&payload, &c); err != nil {
|
||||||
log.Error("unable to render "+repID, err)
|
p.Runtime.Log.Error("unable to render "+repID, err)
|
||||||
return "Documize internal github render " + repID + " error: " + err.Error() + "<BR>" + data
|
return "Documize internal github render " + repID + " error: " + err.Error() + "<BR>" + data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +232,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
t, err = t.Parse(rep.template)
|
t, err = t.Parse(rep.template)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github render template.Parse error:", err)
|
p.Runtime.Log.Error("github render template.Parse error:", err)
|
||||||
//for k, v := range strings.Split(rep.template, "\n") {
|
//for k, v := range strings.Split(rep.template, "\n") {
|
||||||
// fmt.Println("DEBUG", k+1, v)
|
// fmt.Println("DEBUG", k+1, v)
|
||||||
//}
|
//}
|
||||||
|
@ -246,7 +242,7 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
err = t.Execute(buffer, payload)
|
err = t.Execute(buffer, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github render template.Execute error:", err)
|
p.Runtime.Log.Error("github render template.Execute error:", err)
|
||||||
return "Documize internal github template.Execute error: " + err.Error()
|
return "Documize internal github template.Execute error: " + err.Error()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,27 +15,26 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/domain/section/provider"
|
||||||
|
|
||||||
gogithub "github.com/google/go-github/github"
|
gogithub "github.com/google/go-github/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
func listFailed(method string, config githubConfig, client *gogithub.Client, w http.ResponseWriter) (failed bool) {
|
func listFailed(rt env.Runtime, method string, config githubConfig, client *gogithub.Client, w http.ResponseWriter) (failed bool) {
|
||||||
switch method { // which list to choose?
|
switch method { // which list to choose?
|
||||||
|
|
||||||
case "owners":
|
case "owners":
|
||||||
|
|
||||||
me, _, err := client.Users.Get("")
|
me, _, err := client.Users.Get("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github get user details:", err)
|
rt.Log.Error("github get user details:", err)
|
||||||
provider.WriteError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
orgs, _, err := client.Organizations.List("", nil)
|
orgs, _, err := client.Organizations.List("", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github get user's organisations:", err)
|
rt.Log.Error("github get user's organisations:", err)
|
||||||
provider.WriteError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -59,7 +58,7 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h
|
||||||
|
|
||||||
me, _, err := client.Users.Get("")
|
me, _, err := client.Users.Get("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github get user details:", err)
|
rt.Log.Error("github get user details:", err)
|
||||||
provider.WriteError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,7 @@ func listFailed(method string, config githubConfig, client *gogithub.Client, w h
|
||||||
repos, _, err = client.Repositories.ListByOrg(config.Owner, opt)
|
repos, _, err = client.Repositories.ListByOrg(config.Owner, opt)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("github get user/org repositories:", err)
|
rt.Log.Error("github get user/org repositories:", err)
|
||||||
provider.WriteError(w, "github", err)
|
provider.WriteError(w, "github", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -15,11 +15,13 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/blackfriday"
|
"github.com/documize/blackfriday"
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/core/env"
|
||||||
|
"github.com/documize/community/domain/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider represents Markdown
|
// Provider represents Markdown
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
Runtime env.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta describes us
|
// Meta describes us
|
|
@ -21,14 +21,15 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/domain/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
const me = "papertrail"
|
const me = "papertrail"
|
||||||
|
|
||||||
// Provider represents Papertrail
|
// Provider represents Papertrail
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
Runtime env.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta describes us.
|
// Meta describes us.
|
||||||
|
@ -116,19 +117,19 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
||||||
|
|
||||||
switch method {
|
switch method {
|
||||||
case "auth":
|
case "auth":
|
||||||
auth(ctx, config, w, r)
|
auth(p.Runtime, ctx, config, w, r)
|
||||||
case "options":
|
case "options":
|
||||||
options(config, w, r)
|
options(config, w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
|
func (p *Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
|
||||||
var c = papertrailConfig{}
|
var c = papertrailConfig{}
|
||||||
err := json.Unmarshal([]byte(config), &c)
|
err := json.Unmarshal([]byte(config), &c)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to read Papertrail config", err)
|
p.Runtime.Log.Error("unable to read Papertrail config", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,21 +138,21 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData st
|
||||||
c.APIToken = ctx.GetSecrets("APIToken")
|
c.APIToken = ctx.GetSecrets("APIToken")
|
||||||
|
|
||||||
if len(c.APIToken) == 0 {
|
if len(c.APIToken) == 0 {
|
||||||
log.Error("missing API token", err)
|
p.Runtime.Log.Error("missing API token", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := fetchEvents(c)
|
result, err := fetchEvents(p.Runtime, c)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Papertrail fetchEvents failed", err)
|
p.Runtime.Log.Error("Papertrail fetchEvents failed", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
j, err := json.Marshal(result)
|
j, err := json.Marshal(result)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to marshal Papaertrail events", err)
|
p.Runtime.Log.Error("unable to marshal Papaertrail events", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,8 +160,8 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) (newData st
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func auth(ctx *provider.Context, config papertrailConfig, w http.ResponseWriter, r *http.Request) {
|
func auth(rt env.Runtime, ctx *provider.Context, config papertrailConfig, w http.ResponseWriter, r *http.Request) {
|
||||||
result, err := fetchEvents(config)
|
result, err := fetchEvents(rt, config)
|
||||||
|
|
||||||
if result == nil {
|
if result == nil {
|
||||||
err = errors.New("nil result of papertrail query")
|
err = errors.New("nil result of papertrail query")
|
||||||
|
@ -168,7 +169,7 @@ func auth(ctx *provider.Context, config papertrailConfig, w http.ResponseWriter,
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
log.IfErr(ctx.SaveSecrets(`{"APIToken":""}`)) // invalid token, so reset it
|
ctx.SaveSecrets(`{"APIToken":""}`) // invalid token, so reset it
|
||||||
|
|
||||||
if err.Error() == "forbidden" {
|
if err.Error() == "forbidden" {
|
||||||
provider.WriteForbidden(w)
|
provider.WriteForbidden(w)
|
||||||
|
@ -179,7 +180,7 @@ func auth(ctx *provider.Context, config papertrailConfig, w http.ResponseWriter,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.IfErr(ctx.SaveSecrets(`{"APIToken":"` + config.APIToken + `"}`))
|
ctx.SaveSecrets(`{"APIToken":"` + config.APIToken + `"}`)
|
||||||
|
|
||||||
provider.WriteJSON(w, result)
|
provider.WriteJSON(w, result)
|
||||||
}
|
}
|
||||||
|
@ -252,7 +253,7 @@ func options(config papertrailConfig, w http.ResponseWriter, r *http.Request) {
|
||||||
provider.WriteJSON(w, options)
|
provider.WriteJSON(w, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchEvents(config papertrailConfig) (result interface{}, err error) {
|
func fetchEvents(rt env.Runtime, config papertrailConfig) (result interface{}, err error) {
|
||||||
var filter string
|
var filter string
|
||||||
if len(config.Query) > 0 {
|
if len(config.Query) > 0 {
|
||||||
filter = fmt.Sprintf("q=%s", url.QueryEscape(config.Query))
|
filter = fmt.Sprintf("q=%s", url.QueryEscape(config.Query))
|
||||||
|
@ -268,7 +269,7 @@ func fetchEvents(config papertrailConfig) (result interface{}, err error) {
|
||||||
var req *http.Request
|
var req *http.Request
|
||||||
req, err = http.NewRequest("GET", "https://papertrailapp.com/api/v1/events/search.json?"+filter, nil)
|
req, err = http.NewRequest("GET", "https://papertrailapp.com/api/v1/events/search.json?"+filter, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("new request", err)
|
rt.Log.Error("new request", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req.Header.Set("X-Papertrail-Token", config.APIToken)
|
req.Header.Set("X-Papertrail-Token", config.APIToken)
|
||||||
|
@ -278,12 +279,12 @@ func fetchEvents(config papertrailConfig) (result interface{}, err error) {
|
||||||
res, err = client.Do(req)
|
res, err = client.Do(req)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("message", err)
|
rt.Log.Error("message", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode != http.StatusOK {
|
if res.StatusCode != http.StatusOK {
|
||||||
log.Error("forbidden", err)
|
rt.Log.Error("forbidden", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +294,7 @@ func fetchEvents(config papertrailConfig) (result interface{}, err error) {
|
||||||
err = dec.Decode(&result)
|
err = dec.Decode(&result)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to read result", err)
|
rt.Log.Error("unable to read result", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
45
domain/section/register.go
Normal file
45
domain/section/register.go
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||||
|
//
|
||||||
|
// This software (Documize Community Edition) is licensed under
|
||||||
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||||
|
//
|
||||||
|
// You can operate outside the AGPL restrictions by purchasing
|
||||||
|
// Documize Enterprise Edition and obtaining a commercial license
|
||||||
|
// by contacting <sales@documize.com>.
|
||||||
|
//
|
||||||
|
// https://documize.com
|
||||||
|
|
||||||
|
package section
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/documize/community/core/env"
|
||||||
|
"github.com/documize/community/domain/section/airtable"
|
||||||
|
"github.com/documize/community/domain/section/code"
|
||||||
|
"github.com/documize/community/domain/section/gemini"
|
||||||
|
"github.com/documize/community/domain/section/github"
|
||||||
|
"github.com/documize/community/domain/section/markdown"
|
||||||
|
"github.com/documize/community/domain/section/papertrail"
|
||||||
|
"github.com/documize/community/domain/section/provider"
|
||||||
|
"github.com/documize/community/domain/section/table"
|
||||||
|
"github.com/documize/community/domain/section/trello"
|
||||||
|
"github.com/documize/community/domain/section/wysiwyg"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Register sections
|
||||||
|
func Register(rt env.Runtime) {
|
||||||
|
provider.Register("code", &code.Provider{Runtime: rt})
|
||||||
|
provider.Register("gemini", &gemini.Provider{Runtime: rt})
|
||||||
|
provider.Register("github", &github.Provider{Runtime: rt})
|
||||||
|
provider.Register("markdown", &markdown.Provider{Runtime: rt})
|
||||||
|
provider.Register("papertrail", &papertrail.Provider{Runtime: rt})
|
||||||
|
provider.Register("table", &table.Provider{Runtime: rt})
|
||||||
|
provider.Register("code", &code.Provider{Runtime: rt})
|
||||||
|
provider.Register("trello", &trello.Provider{Runtime: rt})
|
||||||
|
provider.Register("wysiwyg", &wysiwyg.Provider{Runtime: rt})
|
||||||
|
provider.Register("airtable", &airtable.Provider{Runtime: rt})
|
||||||
|
|
||||||
|
p := provider.List()
|
||||||
|
rt.Log.Info(fmt.Sprintf("Registered %d sections", len(p)))
|
||||||
|
}
|
|
@ -14,11 +14,13 @@ package table
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/core/env"
|
||||||
|
"github.com/documize/community/domain/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider represents Table
|
// Provider represents Table
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
Runtime env.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta describes us
|
// Meta describes us
|
|
@ -20,8 +20,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/community/core/api/request"
|
"github.com/documize/community/core/api/request"
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/domain/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
var meta provider.TypeMeta
|
var meta provider.TypeMeta
|
||||||
|
@ -36,8 +36,9 @@ func init() {
|
||||||
meta.PageType = "tab"
|
meta.PageType = "tab"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provider represents GitHub
|
// Provider represents Trello
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
Runtime env.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta describes us.
|
// Meta describes us.
|
||||||
|
@ -46,7 +47,7 @@ func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command stub.
|
// Command stub.
|
||||||
func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
method := query.Get("method")
|
method := query.Get("method")
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
config.AppKey = request.ConfigString(meta.ConfigHandle(), "appKey")
|
config.AppKey = request.ConfigString(meta.ConfigHandle(), "appKey")
|
||||||
|
|
||||||
if len(config.AppKey) == 0 {
|
if len(config.AppKey) == 0 {
|
||||||
log.ErrorString("missing trello App Key")
|
p.Runtime.Log.Info("missing trello App Key")
|
||||||
provider.WriteMessage(w, "trello", "Missing appKey")
|
provider.WriteMessage(w, "trello", "Missing appKey")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -91,9 +92,9 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
render, err := getCards(config)
|
render, err := getCards(config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.IfErr(err)
|
p.Runtime.Log.Error("failed to render cards", err)
|
||||||
provider.WriteError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
log.IfErr(ctx.SaveSecrets("")) // failure means our secrets are invalid
|
ctx.SaveSecrets("") // failure means our secrets are invalid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,9 +104,9 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
render, err := getBoards(config)
|
render, err := getBoards(config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.IfErr(err)
|
p.Runtime.Log.Error("failed to render board", err)
|
||||||
provider.WriteError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
log.IfErr(ctx.SaveSecrets("")) // failure means our secrets are invalid
|
ctx.SaveSecrets("") // failure means our secrets are invalid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +116,9 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
render, err := getLists(config)
|
render, err := getLists(config)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.IfErr(err)
|
p.Runtime.Log.Error("failed to get Trello lists", err)
|
||||||
provider.WriteError(w, "trello", err)
|
provider.WriteError(w, "trello", err)
|
||||||
log.IfErr(ctx.SaveSecrets("")) // failure means our secrets are invalid
|
ctx.SaveSecrets("") // failure means our secrets are invalid
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +137,7 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
return
|
return
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.ErrorString("trello unknown method name: " + method)
|
p.Runtime.Log.Info("unknown trello method called: " + method)
|
||||||
provider.WriteMessage(w, "trello", "missing method name")
|
provider.WriteMessage(w, "trello", "missing method name")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -145,8 +146,11 @@ func (*Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.R
|
||||||
var s secrets
|
var s secrets
|
||||||
s.Token = config.Token
|
s.Token = config.Token
|
||||||
b, e := json.Marshal(s)
|
b, e := json.Marshal(s)
|
||||||
log.IfErr(e)
|
if err != nil {
|
||||||
log.IfErr(ctx.SaveSecrets(string(b)))
|
p.Runtime.Log.Error("failed save Trello secrets", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.SaveSecrets(string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render just sends back HMTL as-is.
|
// Render just sends back HMTL as-is.
|
||||||
|
@ -176,7 +180,7 @@ func (*Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh just sends back data as-is.
|
// Refresh just sends back data as-is.
|
||||||
func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
|
func (p *Provider) Refresh(ctx *provider.Context, config, data string) string {
|
||||||
var c = trelloConfig{}
|
var c = trelloConfig{}
|
||||||
json.Unmarshal([]byte(config), &c)
|
json.Unmarshal([]byte(config), &c)
|
||||||
|
|
||||||
|
@ -189,7 +193,7 @@ func (*Provider) Refresh(ctx *provider.Context, config, data string) string {
|
||||||
j, err := json.Marshal(refreshed)
|
j, err := json.Marshal(refreshed)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("unable to marshall trello cards", err)
|
p.Runtime.Log.Error("failed to marshal trello data", err)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +228,6 @@ func getBoards(config trelloConfig) (boards []trelloBoard, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +253,6 @@ func getLists(config trelloConfig) (lists []trelloList, err error) {
|
||||||
err = dec.Decode(&lists)
|
err = dec.Decode(&lists)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,13 @@ package wysiwyg
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/documize/community/core/section/provider"
|
"github.com/documize/community/core/env"
|
||||||
|
"github.com/documize/community/domain/section/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Provider represents WYSIWYG
|
// Provider represents WYSIWYG
|
||||||
type Provider struct {
|
type Provider struct {
|
||||||
|
Runtime env.Runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
// Meta describes us
|
// Meta describes us
|
|
@ -19,49 +19,49 @@ import (
|
||||||
"github.com/documize/community/core/api/endpoint"
|
"github.com/documize/community/core/api/endpoint"
|
||||||
"github.com/documize/community/core/api/request"
|
"github.com/documize/community/core/api/request"
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/documize/community/core/section"
|
"github.com/documize/community/domain/section"
|
||||||
"github.com/documize/community/edition/boot"
|
"github.com/documize/community/edition/boot"
|
||||||
"github.com/documize/community/edition/logging"
|
"github.com/documize/community/edition/logging"
|
||||||
_ "github.com/documize/community/embed" // the compressed front-end code and static data
|
_ "github.com/documize/community/embed" // the compressed front-end code and static data
|
||||||
_ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes
|
_ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
var rt env.Runtime
|
||||||
|
|
||||||
|
func main() {
|
||||||
// runtime stores server/application level information
|
// runtime stores server/application level information
|
||||||
runtime := env.Runtime{}
|
rt := env.Runtime{}
|
||||||
|
|
||||||
// wire up logging implementation
|
// wire up logging implementation
|
||||||
runtime.Log = logging.NewLogger()
|
rt.Log = logging.NewLogger()
|
||||||
|
|
||||||
// define product edition details
|
// define product edition details
|
||||||
runtime.Product = env.ProdInfo{}
|
rt.Product = env.ProdInfo{}
|
||||||
runtime.Product.Major = "1"
|
rt.Product.Major = "1"
|
||||||
runtime.Product.Minor = "50"
|
rt.Product.Minor = "50"
|
||||||
runtime.Product.Patch = "1"
|
rt.Product.Patch = "2"
|
||||||
runtime.Product.Version = fmt.Sprintf("%s.%s.%s", runtime.Product.Major, runtime.Product.Minor, runtime.Product.Patch)
|
rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch)
|
||||||
runtime.Product.Edition = "Community"
|
rt.Product.Edition = "Community"
|
||||||
runtime.Product.Title = fmt.Sprintf("%s Edition", runtime.Product.Edition)
|
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)
|
||||||
runtime.Product.License = env.License{}
|
rt.Product.License = env.License{}
|
||||||
runtime.Product.License.Seats = 1
|
rt.Product.License.Seats = 1
|
||||||
runtime.Product.License.Valid = true
|
rt.Product.License.Valid = true
|
||||||
runtime.Product.License.Trial = false
|
rt.Product.License.Trial = false
|
||||||
runtime.Product.License.Edition = "Community"
|
rt.Product.License.Edition = "Community"
|
||||||
|
|
||||||
// parse settings from command line and environment
|
// parse settings from command line and environment
|
||||||
runtime.Flags = env.ParseFlags()
|
rt.Flags = env.ParseFlags()
|
||||||
flagsOK := boot.InitRuntime(&runtime)
|
flagsOK := boot.InitRuntime(&rt)
|
||||||
|
|
||||||
if flagsOK {
|
if flagsOK {
|
||||||
// runtime.Log = runtime.Log.SetDB(runtime.Db)
|
// runtime.Log = runtime.Log.SetDB(runtime.Db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// temp code repair
|
// temp code repair
|
||||||
api.Runtime = runtime
|
api.Runtime = rt
|
||||||
request.Db = runtime.Db
|
request.Db = rt.Db
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
section.Register(rt)
|
||||||
section.Register()
|
|
||||||
|
|
||||||
ready := make(chan struct{}, 1) // channel is used for testing
|
ready := make(chan struct{}, 1) // channel is used for testing
|
||||||
endpoint.Serve(ready)
|
endpoint.Serve(ready)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "documize",
|
"name": "documize",
|
||||||
"version": "1.50.1",
|
"version": "1.50.2",
|
||||||
"description": "The Document IDE",
|
"description": "The Document IDE",
|
||||||
"private": true,
|
"private": true,
|
||||||
"repository": "",
|
"repository": "",
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
{
|
{
|
||||||
"community":
|
"community":
|
||||||
{
|
{
|
||||||
"version": "1.50.1",
|
"version": "1.50.2",
|
||||||
"major": 1,
|
"major": 1,
|
||||||
"minor": 50,
|
"minor": 50,
|
||||||
"patch": 1
|
"patch": 2
|
||||||
},
|
},
|
||||||
"enterprise":
|
"enterprise":
|
||||||
{
|
{
|
||||||
"version": "1.52.1",
|
"version": "1.52.2",
|
||||||
"major": 1,
|
"major": 1,
|
||||||
"minor": 52,
|
"minor": 52,
|
||||||
"patch": 1
|
"patch": 2
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue