Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
feat: plugin upload and deletion (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Aug 4, 2021
1 parent da7506e commit 8742dba
Show file tree
Hide file tree
Showing 146 changed files with 4,347 additions and 2,055 deletions.
10 changes: 6 additions & 4 deletions go.mod
@@ -1,7 +1,7 @@
module github.com/reearth/reearth-backend

require (
cloud.google.com/go v0.80.0
cloud.google.com/go v0.87.0
cloud.google.com/go/storage v1.14.0
github.com/99designs/gqlgen v0.13.0
github.com/99designs/gqlgen-contrib v0.1.1-0.20200601100547-7a955d321bbd
Expand All @@ -22,6 +22,7 @@ require (
github.com/joho/godotenv v1.3.0
github.com/jonas-p/go-shp v0.1.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/kennygrant/sanitize v1.2.4
github.com/klauspost/compress v1.10.10 // indirect
github.com/labstack/echo/v4 v4.2.1
github.com/labstack/gommon v0.3.0
Expand All @@ -33,6 +34,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/smartystreets/assertions v1.1.1 // indirect
github.com/spf13/afero v1.6.0
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/tidwall/pretty v1.0.1 // indirect
Expand All @@ -47,10 +49,10 @@ require (
go.opentelemetry.io/otel v0.7.0
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/text v0.3.5
golang.org/x/text v0.3.6
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/tools v0.1.0
golang.org/x/tools v0.1.5
google.golang.org/api v0.51.0
gopkg.in/go-playground/colors.v1 v1.2.0
gopkg.in/h2non/gock.v1 v1.1.0
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
108 changes: 86 additions & 22 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/adapter/graphql/container.go
Expand Up @@ -70,7 +70,7 @@ func NewContainer(r *repo.Container, g *gateway.Container, conf ContainerConfig)
SceneController: NewSceneController(
SceneControllerConfig{
SceneInput: func() interfaces.Scene {
return interactor.NewScene(r)
return interactor.NewScene(r, g)
},
},
),
Expand Down
20 changes: 18 additions & 2 deletions internal/adapter/graphql/controller_plugin.go
Expand Up @@ -2,9 +2,13 @@ package graphql

import (
"context"
"errors"

"github.com/reearth/reearth-backend/internal/usecase"
"github.com/reearth/reearth-backend/internal/usecase/interfaces"
"github.com/reearth/reearth-backend/pkg/id"
"github.com/reearth/reearth-backend/pkg/plugin"
"github.com/reearth/reearth-backend/pkg/scene"
)

type PluginControllerConfig struct {
Expand All @@ -27,13 +31,25 @@ func (c *PluginController) usecase() interfaces.Plugin {
}

func (c *PluginController) Upload(ctx context.Context, ginput *UploadPluginInput, operator *usecase.Operator) (*UploadPluginPayload, error) {
res, err := c.usecase().Upload(ctx, ginput.File.File, operator)
var p *plugin.Plugin
var s *scene.Scene
var err error

if ginput.File != nil {
p, s, err = c.usecase().Upload(ctx, ginput.File.File, id.SceneID(ginput.SceneID), operator)
} else if ginput.URL != nil {
p, s, err = c.usecase().UploadFromRemote(ctx, ginput.URL, id.SceneID(ginput.SceneID), operator)
} else {
return nil, errors.New("either file or url is required")
}
if err != nil {
return nil, err
}

return &UploadPluginPayload{
Plugin: toPlugin(res),
Plugin: toPlugin(p),
Scene: toScene(s),
ScenePlugin: toScenePlugin(s.PluginSystem().Plugin(p.ID())),
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/adapter/graphql/controller_scene.go
Expand Up @@ -109,7 +109,7 @@ func (c *SceneController) UninstallPlugin(ctx context.Context, ginput *Uninstall
return nil, err
}

return &UninstallPluginPayload{Scene: toScene(scene)}, nil
return &UninstallPluginPayload{PluginID: ginput.PluginID, Scene: toScene(scene)}, nil
}

func (c *SceneController) UpgradePlugin(ctx context.Context, ginput *UpgradePluginInput, operator *usecase.Operator) (*UpgradePluginPayload, error) {
Expand Down
6 changes: 4 additions & 2 deletions internal/adapter/graphql/convert.go
@@ -1,6 +1,8 @@
package graphql

import (
"io"

"github.com/99designs/gqlgen/graphql"
"github.com/reearth/reearth-backend/internal/usecase"
"github.com/reearth/reearth-backend/internal/usecase/interfaces"
Expand Down Expand Up @@ -68,8 +70,8 @@ func fromFile(f *graphql.Upload) *file.File {
return nil
}
return &file.File{
Content: f.File,
Name: f.Filename,
Content: io.NopCloser(f.File),
Path: f.Filename,
Size: f.Size,
ContentType: f.ContentType,
}
Expand Down
1 change: 1 addition & 0 deletions internal/adapter/graphql/convert_plugin.go
Expand Up @@ -29,6 +29,7 @@ func toPlugin(p *plugin.Plugin) *Plugin {

return &Plugin{
ID: pid,
SceneID: pid.Scene().IDRef(),
Name: p.Name().String(),
Description: p.Description().String(),
AllTranslatedDescription: p.Description(),
Expand Down
14 changes: 10 additions & 4 deletions internal/adapter/graphql/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/app/file.go
Expand Up @@ -47,9 +47,9 @@ func serveFiles(
)

ec.GET(
"/plugins/:name/:version/:filename",
"/plugins/:plugin/:filename",
fileHandler(func(ctx echo.Context) (io.Reader, string, error) {
pid, err := id.PluginIDFrom(ctx.Param("name") + "#" + ctx.Param("version"))
pid, err := id.PluginIDFrom(ctx.Param("plugin"))
if err != nil {
return nil, "", rerror.ErrNotFound
}
Expand Down
17 changes: 3 additions & 14 deletions internal/app/repo.go
Expand Up @@ -7,12 +7,12 @@ import (

"github.com/reearth/reearth-backend/internal/infrastructure/github"
"github.com/reearth/reearth-backend/internal/infrastructure/google"
"github.com/spf13/afero"

"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
mongotrace "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver"

"github.com/reearth/reearth-backend/internal/infrastructure/adapter"
"github.com/reearth/reearth-backend/internal/infrastructure/auth0"
"github.com/reearth/reearth-backend/internal/infrastructure/fs"
"github.com/reearth/reearth-backend/internal/infrastructure/gcs"
Expand Down Expand Up @@ -41,23 +41,12 @@ func initReposAndGateways(ctx context.Context, conf *Config, debug bool) (*repo.
log.Fatalln(fmt.Sprintf("Failed to init mongo: %+v", err))
}

// Plugin and PropertySchema
if debug {
repos.Plugin = adapter.NewPlugin([]repo.Plugin{
fs.NewPlugin("data"),
repos.Plugin,
}, repos.Plugin)
repos.PropertySchema = adapter.NewPropertySchema([]repo.PropertySchema{
fs.NewPropertySchema("data"),
repos.PropertySchema,
}, repos.PropertySchema)
}

// File
datafs := afero.NewBasePathFs(afero.NewOsFs(), "data")
var fileRepo gateway.File
if conf.GCS.BucketName == "" {
log.Infoln("file: local storage is used")
fileRepo, err = fs.NewFile("data", conf.AssetBaseURL)
fileRepo, err = fs.NewFile(datafs, conf.AssetBaseURL)
} else {
log.Infof("file: GCS storage is used: %s\n", conf.GCS.BucketName)
fileRepo, err = gcs.NewFile(conf.GCS.BucketName, conf.AssetBaseURL, conf.GCS.PublicationCacheControl)
Expand Down

0 comments on commit 8742dba

Please sign in to comment.