Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trimming feature #60

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: cd
on:
workflow_run:
workflows: ["ci"]
branches-ignore: ["*"]
types:
- completed
push:
tags:
- "v*"

permissions:
contents: read

jobs:
plugin-cd:
uses: mattermost/actions-workflows/.github/workflows/plugin-cd.yml@main
secrets: inherit
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: ci
on:
schedule:
- cron: "0 0 * * *"
push:
branches:
- master
tags:
- "v*"
pull_request:

permissions:
contents: read

jobs:
plugin-ci:
uses: mattermost/actions-workflows/.github/workflows/plugin-ci.yml@main
secrets: inherit
11 changes: 10 additions & 1 deletion build/custom.mk
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# Include custom targets and environment variables here
mock:
ifneq ($(HAS_SERVER),)
go install github.com/golang/mock/[email protected]
mockgen -destination server/trim/mock_trim/mock_transcoder.go github.com/mattermost/mattermost-plugin-mattermusic/server/trim Transcoder
endif

clean_mock:
ifneq ($(HAS_SERVER),)
rm -rf ./server/trim/mock_trim
endif
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ module github.com/mattermost/mattermost-plugin-mattermusic
go 1.12

require (
github.com/mattermost/mattermost-server/v5 v5.39.0
github.com/aws/aws-sdk-go v1.43.31
github.com/golang/mock v1.6.0
github.com/mattermost/mattermost-server/v6 v6.7.2
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.1
)
1,324 changes: 1,062 additions & 262 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v6/plugin"
)

func main() {
Expand Down
7 changes: 4 additions & 3 deletions server/manifest.go

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

24 changes: 16 additions & 8 deletions server/mattermusic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"strings"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/plugin"
)

var extensionMap = map[string]string{
Expand Down Expand Up @@ -61,14 +61,22 @@ func (p *Plugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*mode
const spotifyTheme = `{"sidebarBg":"#121212","sidebarText":"#ffffff","sidebarUnreadText":"#ffffff","sidebarTextHoverBg":"#282828","sidebarTextActiveBorder":"#1bba56","sidebarTextActiveColor":"#1bba56","sidebarHeaderBg":"#121212","sidebarHeaderTextColor":"#ffffff","onlineIndicator":"#1bba56","awayIndicator":"#e0b333","dndIndicator":"#f74343","mentionBg":"#1bba56","mentionBj":"#1bba56","mentionColor":"#ffffff","centerChannelBg":"#181818","centerChannelColor":"#9d9d9d","newMessageSeparator":"#1bba56","linkColor":"#1bba56","buttonBg":"#1bba56","buttonColor":"#ffffff","errorTextColor":"#fd5960","mentionHighlightBg":"#184127","mentionHighlightLink":"#ffffff","codeTheme":"monokai"}`

func (p *Plugin) UserHasBeenCreated(c *plugin.Context, user *model.User) {
pref := model.Preference{
Category: "theme",
Name: "",
UserId: user.Id,
Value: spotifyTheme,
prefs := model.Preferences{
{
Category: "theme",
Name: "",
UserId: user.Id,
Value: spotifyTheme,
},
{
Category: "display_settings",
Name: "click_to_reply",
UserId: user.Id,
Value: "false",
},
}

err := p.API.UpdatePreferencesForUser(user.Id, model.Preferences{pref})
err := p.API.UpdatePreferencesForUser(user.Id, prefs)
if err != nil {
p.API.LogError(err.Error())
}
Expand Down
19 changes: 4 additions & 15 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"sync"

"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost-server/v6/plugin"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -105,18 +105,7 @@ func (p *Plugin) handleCreateProject(w http.ResponseWriter, r *http.Request) {
w.Write(b)
}

// handleTrim trims an audio file based on start and end params
func (p *Plugin) handleTrim(w http.ResponseWriter, r *http.Request) {
data, err := ioutil.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Error marshaling project response: "+err.Error())
return
}

// r.ParseMultipartForm(0)
// file := r.Form.Get("file")

w.WriteHeader(200)
w.Write(data)
func writeErr(w http.ResponseWriter, status int, err error) {
w.WriteHeader(status)
w.Write([]byte(err.Error()))
}
4 changes: 2 additions & 2 deletions server/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/pkg/errors"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v6/model"
)

const ProjectsKVKey = "projects"
Expand All @@ -24,7 +24,7 @@ func (p *Plugin) GetProjects() ([]*Project, error) {
}

projects := []*Project{}
err = json.Unmarshal(b, projects)
err = json.Unmarshal(b, &projects)
if err != nil {
return nil, err
}
Expand Down
99 changes: 99 additions & 0 deletions server/trim.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package main

import (
"encoding/json"
"net/http"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/mattermost/mattermost-server/v6/model"

"github.com/mattermost/mattermost-plugin-mattermusic/server/trim"
)

type trimPayload struct {
FileId string `json:"file_id"`
Start float64 `json:"start"`
End float64 `json:"end"`
}

// handleTrim trims an audio file based on start and end params
func (p *Plugin) handleTrim(w http.ResponseWriter, r *http.Request) {
userId := r.Header.Get("Mattermost-User-Id")
if userId == "" {
writeErr(w, http.StatusUnauthorized, errors.New("Unauthorized"))
return
}

payload := trimPayload{}
err := json.NewDecoder(r.Body).Decode(&payload)
if err != nil {
writeErr(w, http.StatusInternalServerError, errors.Wrap(err, "error unmarshaling trim payload"))
return
}

fileInfo, appErr := p.API.GetFileInfo(payload.FileId)
if appErr != nil {
writeErr(w, http.StatusInternalServerError, errors.Wrap(appErr, "error getting file info"))
return
}

canReadChannel := p.API.HasPermissionToChannel(userId, fileInfo.ChannelId, model.PermissionReadChannel)
if !canReadChannel {
writeErr(w, http.StatusUnauthorized, errors.Wrap(appErr, "you don't have access to this file"))
return
}

s3Path, err := getS3PathForFile(payload.FileId)
if err != nil {

}

transcoder, err := trim.GetTranscoderService()
if err != nil {

}

logger := logrus.New()
cErr, err := trim.Trim(logger, transcoder, s3Path, payload.Start, payload.End)
if err != nil {
writeErr(w, http.StatusInternalServerError, errors.Wrap(err, "error trimming file"))
return
}

go func() {
trimResponse := <-cErr
if trimResponse.Err != nil {
broadcastErrorMessage(userId, fileInfo, trimResponse.Err.Error())
} else {
newPath := trimResponse.NewPath
newFileInfo, err := p.persistNewFile(userId, fileInfo, newPath, payload)
if err != nil {
broadcastErrorMessage(userId, fileInfo, errors.Wrap(err, "failed to persist new trimmed file").Error())
return
}

broadcastSuccessMessage(userId, newFileInfo, "The file is trimmed")
}
}()
}

func (p *Plugin) persistNewFile(userId string, fileInfo *model.FileInfo, newPath string, payload trimPayload) (*model.FileInfo, error) {
// somehow create a new file for the thing in s3

return nil, errors.New("persistNewFile not implemented")
}

func broadcastErrorMessage(userId string, fileInfo *model.FileInfo, message string) {

}

func broadcastSuccessMessage(userId string, fileInfo *model.FileInfo, message string) {

}

func getS3PathForFile(fileId string) (string, error) {
// do db query
return "/path/to/file", nil
}
95 changes: 95 additions & 0 deletions server/trim/mock_trim/mock_transcoder.go

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

Loading
Loading