github.com/cs3org/reva/v2@v2.27.7/pkg/app/provider/demo/demo.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package demo 20 21 import ( 22 "context" 23 "fmt" 24 25 appprovider "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1" 26 appregistry "github.com/cs3org/go-cs3apis/cs3/app/registry/v1beta1" 27 provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" 28 "github.com/cs3org/reva/v2/pkg/app" 29 "github.com/cs3org/reva/v2/pkg/app/provider/registry" 30 "github.com/cs3org/reva/v2/pkg/storagespace" 31 "github.com/mitchellh/mapstructure" 32 ) 33 34 func init() { 35 registry.Register("demo", New) 36 } 37 38 type demoProvider struct { 39 iframeUIProvider string 40 } 41 42 func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.ViewMode, token, language string) (*appprovider.OpenInAppURL, error) { 43 url := fmt.Sprintf("<iframe src=%s/open/%s?view-mode=%s&access-token=%s />", p.iframeUIProvider, storagespace.FormatResourceID(resource.Id), viewMode.String(), token) 44 return &appprovider.OpenInAppURL{ 45 AppUrl: url, 46 Method: "GET", 47 }, nil 48 } 49 50 func (p *demoProvider) GetAppProviderInfo(ctx context.Context) (*appregistry.ProviderInfo, error) { 51 return &appregistry.ProviderInfo{ 52 Name: "demo-app", 53 }, nil 54 } 55 56 type config struct { 57 IFrameUIProvider string `mapstructure:"iframe_ui_provider"` 58 } 59 60 func parseConfig(m map[string]interface{}) (*config, error) { 61 c := &config{} 62 if err := mapstructure.Decode(m, c); err != nil { 63 return nil, err 64 } 65 return c, nil 66 } 67 68 // New returns an implementation to of the app.Provider interface that 69 // connects to an application in the backend. 70 func New(m map[string]interface{}) (app.Provider, error) { 71 c, err := parseConfig(m) 72 if err != nil { 73 return nil, err 74 } 75 return &demoProvider{iframeUIProvider: c.IFrameUIProvider}, nil 76 }