-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add server part for global settings #1
- Loading branch information
1 parent
303547f
commit 4334ab7
Showing
11 changed files
with
2,096 additions
and
88 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,33 @@ | ||
all: | ||
make prepare | ||
make linux | ||
make macos | ||
make windows | ||
make webapp | ||
make pack | ||
|
||
prepare: | ||
rm -f mattermost-vimeo-plugin.tar.gz | ||
rm -rf mattermost-vimeo-plugin | ||
mkdir -p mattermost-vimeo-plugin | ||
mkdir -p mattermost-vimeo-plugin/client | ||
mkdir -p mattermost-vimeo-plugin/server | ||
|
||
linux: | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o mattermost-vimeo-plugin/server/plugin-linux-amd64 server/plugin.go | ||
|
||
macos: | ||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o mattermost-vimeo-plugin/server/plugin-darwin-amd64 server/plugin.go | ||
|
||
windows: | ||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o mattermost-vimeo-plugin/server/plugin-windows-amd64 server/plugin.go | ||
|
||
webapp: | ||
mkdir -p dist | ||
npm install | ||
./node_modules/.bin/webpack --mode=production | ||
|
||
pack: | ||
cp -r dist/main.js mattermost-vimeo-plugin/client | ||
cp plugin.json mattermost-vimeo-plugin/ | ||
tar -czvf mattermost-vimeo-plugin.tar.gz mattermost-vimeo-plugin |
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,112 @@ | ||
import React from 'react'; | ||
import axios from 'axios'; | ||
|
||
class PluginSettings { | ||
constructor(data) { | ||
/** | ||
* @type {number} | ||
*/ | ||
this.width = data.width == null ? 600 : data.width; | ||
/** | ||
* @type {number} | ||
*/ | ||
this.height = data.height == null ? 340 : data.height; | ||
} | ||
} | ||
|
||
class PostWillRenderEmbed extends React.Component { | ||
static plugin; | ||
/** | ||
* @type {PluginSettings} | ||
*/ | ||
static settings; | ||
|
||
render() { | ||
let title = ''; | ||
let description = ''; | ||
let iframeWidth = 600, iframeHeight = 340; | ||
|
||
try { | ||
iframeWidth = PostWillRenderEmbed.settings.width; | ||
iframeHeight = PostWillRenderEmbed.settings.height; | ||
} catch { | ||
try { | ||
iframeWidth = PostWillRenderEmbed.plugin.props.iframeWidth; | ||
iframeHeight = PostWillRenderEmbed.plugin.props.iframeHeight; | ||
} catch { } | ||
} | ||
|
||
try { | ||
title = this.props.embed.data.title; | ||
description = this.props.embed.data.description; | ||
} catch { | ||
} | ||
|
||
let url = ''; | ||
if (!this.props.embed.url.includes('player.vimeo.com')) { | ||
url = this.props.embed.url.replace('vimeo.com', 'player.vimeo.com/video'); | ||
} else { | ||
url = this.props.embed.url; | ||
} | ||
|
||
return ( | ||
<div> | ||
<h5> | ||
Vimeo - | ||
<a href={this.props.embed.url} target="_blank"> | ||
{title} | ||
</a> | ||
</h5> | ||
<div> | ||
<small>{description}</small> | ||
</div> | ||
<iframe src={url} width={iframeWidth} height={iframeHeight}> | ||
</iframe> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
class VimeoPlugin { | ||
static apiUrl = '/plugins/vimeo'; | ||
|
||
initialize(registry, store) { | ||
PostWillRenderEmbed.plugin = store.getState().plugins.plugins.vimeo; | ||
axios.get(`${VimeoPlugin.apiUrl}/settings`) | ||
.then(res => { | ||
/** | ||
* @type {PluginSettings} | ||
*/ | ||
PostWillRenderEmbed.settings = new PluginSettings(res.data); | ||
registry.registerPostWillRenderEmbedComponent( | ||
this.handleEmbed, | ||
PostWillRenderEmbed, | ||
false, | ||
); | ||
}) | ||
.catch(err => { | ||
/** | ||
* @type {PluginSettings} | ||
*/ | ||
PostWillRenderEmbed.settings = new PluginSettings(); | ||
registry.registerPostWillRenderEmbedComponent( | ||
this.handleEmbed, | ||
PostWillRenderEmbed, | ||
false, | ||
); | ||
}); | ||
} | ||
|
||
handleEmbed(embed) { | ||
if (embed.type == 'opengraph' && embed.url.includes('vimeo.com')) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
uninitialize() { | ||
// No clean up required. | ||
} | ||
} | ||
|
||
window.registerPlugin('vimeo', new VimeoPlugin()); |
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,63 @@ | ||
module mattermost-plugin-vimeo | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/mattermost/mattermost-server/v6 v6.2.1 | ||
) | ||
|
||
require ( | ||
github.com/blang/semver v3.5.1+incompatible // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dustin/go-humanize v1.0.0 // indirect | ||
github.com/dyatlov/go-opengraph v0.0.0-20210112100619-dae8665a5b09 // indirect | ||
github.com/fatih/color v1.13.0 // indirect | ||
github.com/francoispqt/gojay v1.2.13 // indirect | ||
github.com/go-asn1-ber/asn1-ber v1.5.3 // indirect | ||
github.com/go-sql-driver/mysql v1.6.0 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/gorilla/websocket v1.4.2 // indirect | ||
github.com/hashicorp/go-hclog v1.0.0 // indirect | ||
github.com/hashicorp/go-plugin v1.4.3 // indirect | ||
github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect | ||
github.com/lib/pq v1.10.3 // indirect | ||
github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 // indirect | ||
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d // indirect | ||
github.com/mattermost/logr/v2 v2.0.15 // indirect | ||
github.com/mattn/go-colorable v0.1.11 // indirect | ||
github.com/mattn/go-isatty v0.0.14 // indirect | ||
github.com/minio/md5-simd v1.1.2 // indirect | ||
github.com/minio/minio-go/v7 v7.0.14 // indirect | ||
github.com/minio/sha256-simd v1.0.0 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/mitchellh/go-testing-interface v1.14.1 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/oklog/run v1.1.0 // indirect | ||
github.com/pborman/uuid v1.2.1 // indirect | ||
github.com/pelletier/go-toml v1.9.4 // indirect | ||
github.com/philhofer/fwd v1.1.1 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rs/xid v1.3.0 // indirect | ||
github.com/sirupsen/logrus v1.8.1 // indirect | ||
github.com/stretchr/testify v1.7.0 // indirect | ||
github.com/tinylib/msgp v1.1.6 // indirect | ||
github.com/wiggin77/merror v1.0.3 // indirect | ||
github.com/wiggin77/srslog v1.0.1 // indirect | ||
github.com/yuin/goldmark v1.4.1 // indirect | ||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect | ||
golang.org/x/net v0.0.0-20211006190231-62292e806868 // indirect | ||
golang.org/x/sys v0.0.0-20211006225509-1a26e0398eed // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
google.golang.org/genproto v0.0.0-20211005153810-c76a74d43a8e // indirect | ||
google.golang.org/grpc v1.41.0 // indirect | ||
google.golang.org/protobuf v1.27.1 // indirect | ||
gopkg.in/ini.v1 v1.63.2 // indirect | ||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
) |
Oops, something went wrong.