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

Fixed non working admin download #1388

Open
wants to merge 2 commits into
base: dev
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
2 changes: 1 addition & 1 deletion api/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ func (r coursesRoutes) fetchLectures(c *gin.Context) {
tlctx := c.MustGet("TUMLiveContext").(tools.TUMLiveContext)

lectureHalls := r.LectureHallsDao.GetAllLectureHalls()
streams := tlctx.Course.AdminJson(lectureHalls)
streams := tools.AdminCourseJson(tlctx.Course, lectureHalls, tlctx.User)

c.JSON(http.StatusOK, gin.H{
"streams": streams,
Expand Down
10 changes: 0 additions & 10 deletions model/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"log"
"time"

"github.com/gin-gonic/gin"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -332,12 +331,3 @@ func (c Course) IsLoggedIn() bool {
func (c Course) IsEnrolled() bool {
return c.Visibility == "enrolled"
}

// AdminJson is the JSON representation of a courses streams for the admin panel
func (c Course) AdminJson(lhs []LectureHall) []gin.H {
var res []gin.H
for _, s := range c.Streams {
res = append(res, s.getJson(lhs, c))
}
return res
}
2 changes: 1 addition & 1 deletion model/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (s Stream) Color() string {
}
}

func (s Stream) getJson(lhs []LectureHall, course Course) gin.H {
func (s Stream) GetJson(lhs []LectureHall, course Course) gin.H {
var files []gin.H
for _, file := range s.Files {
files = append(files, gin.H{
Expand Down
20 changes: 20 additions & 0 deletions tools/json-generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tools

import (
"github.com/TUM-Dev/gocast/model"
"github.com/gin-gonic/gin"
)

// AdminCourseJson is the JSON representation of a courses streams for the admin panel
func AdminCourseJson(c *model.Course, lhs []model.LectureHall, u *model.User) []gin.H {
var res []gin.H
streams := c.Streams
for _, s := range streams {
err := SetSignedPlaylists(&s, u, true)
if err != nil {
logger.Error("Could not sign playlist for admin", "err", err)
}
res = append(res, s.GetJson(lhs, *c))
}
return res
}
3 changes: 1 addition & 2 deletions worker/api/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"errors"
"fmt"
"github.com/joschahenningsen/thumbgen"
"net"
"os"
"os/exec"
"time"

"github.com/joschahenningsen/thumbgen"

"github.com/u2takey/go-utils/uuid"

"github.com/TUM-Dev/gocast/worker/cfg"
Expand Down
6 changes: 2 additions & 4 deletions worker/api/api_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package api

import (
"context"
"testing"

"github.com/TUM-Dev/gocast/worker/cfg"
"github.com/TUM-Dev/gocast/worker/pb"
"testing"
)

var mockServer = server{}
Expand All @@ -17,8 +16,7 @@ func setup() {
func TestServer_RequestStream(t *testing.T) {
setup()
_, err := mockServer.RequestStream(context.Background(), &pb.StreamRequest{
WorkerId: "234",
})
WorkerId: "234"})
if err == nil {
t.Errorf("Request with wrong WorkerID should be rejected")
return
Expand Down
5 changes: 3 additions & 2 deletions worker/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ func SetConfig() {
if PersistDir == "" {
PersistDir = "."
}
err := os.MkdirAll(PersistDir, 0o755)
err := os.MkdirAll(PersistDir, 0755)
if err != nil {
log.Error(err)
}
err = os.MkdirAll(LogDir, 0o755)
err = os.MkdirAll(LogDir, 0755)
if err != nil {
log.Warn("Could not create log directory: ", err)
}
Expand Down Expand Up @@ -112,4 +112,5 @@ func SetConfig() {
defer sentry.Recover()
log.AddHook(sentryhook.New([]log.Level{log.PanicLevel, log.FatalLevel, log.ErrorLevel, log.WarnLevel}))
}

}
3 changes: 1 addition & 2 deletions worker/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"encoding/base64"
"fmt"
"time"

"github.com/TUM-Dev/gocast/worker/pb"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials/insecure"
"time"
)

// interactively test your implementation here
Expand Down
26 changes: 11 additions & 15 deletions worker/cmd/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ package main
import (
"context"
"fmt"
"net/http"
_ "net/http/pprof"
"os"
"os/exec"
"os/signal"
"syscall"
"time"

"github.com/TUM-Dev/gocast/worker/api"
"github.com/TUM-Dev/gocast/worker/cfg"
"github.com/TUM-Dev/gocast/worker/pb"
Expand All @@ -21,18 +13,23 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials/insecure"
"net/http"
_ "net/http/pprof"
"os"
"os/exec"
"os/signal"
"syscall"
"time"
)

// OsSignal contains the current os signal received.
// Application exits when it's terminating (kill, int, sigusr, term)
var (
OsSignal chan os.Signal
VersionTag = "dev"
)
var OsSignal chan os.Signal
var VersionTag = "dev"

// prepare checks if the required dependencies are installed
func prepare() {
// check if ffmpeg is installed
//check if ffmpeg is installed
_, err := exec.LookPath("ffmpeg")
if err != nil {
log.Fatal("ffmpeg is not installed")
Expand All @@ -49,8 +46,7 @@ func main() {
BaseDelay: 1 * time.Second,
Multiplier: 1.6,
MaxDelay: 30 * time.Second,
},
}), grpc.WithBlock())
}}), grpc.WithBlock())
if err != nil {
log.Fatalf("Could not connect to main base: %v", err)
}
Expand Down
16 changes: 7 additions & 9 deletions worker/edge/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"crypto/rsa"
"encoding/json"
"fmt"
"github.com/golang-jwt/jwt/v4"
"github.com/prometheus/client_golang/prometheus/promhttp"
"io"
"log"
"mime"
Expand All @@ -22,9 +24,6 @@ import (
"sync"
"syscall"
"time"

"github.com/golang-jwt/jwt/v4"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

var (
Expand All @@ -35,15 +34,13 @@ var (
inflight = make(map[string]*sync.Mutex)

allowedRe = regexp.MustCompile(`^/[a-zA-Z0-9]+/([a-zA-Z0-9_]+/)*[a-zA-Z0-9_]+\.(ts|m3u8)$`) // e.g. /vm123/live/stream/1234.ts
// allowedRe = regexp.MustCompile("^.*$") // e.g. /vm123/live/strean/1234.ts
//allowedRe = regexp.MustCompile("^.*$") // e.g. /vm123/live/strean/1234.ts
)

var port = ":8089"

var (
originPort = "8085"
originProto = "http://"
)
var originPort = "8085"
var originProto = "http://"

var VersionTag = "dev"

Expand Down Expand Up @@ -230,6 +227,7 @@ func vodHandler(w http.ResponseWriter, r *http.Request) {
}
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/vod")
f, err := os.Open(path.Join(vodPath, path.Clean(r.URL.Path)))

if err != nil {
err404Playlists.WithLabelValues(claims.StreamID, claims.Playlist).Inc()
w.WriteHeader(http.StatusNotFound)
Expand Down Expand Up @@ -374,7 +372,7 @@ func fetchFile(host, file string) error {
return fmt.Errorf("parse file path: %s", file)
}
d := filepath.Dir(diskDir)
err = os.MkdirAll(d, 0o755)
err = os.MkdirAll(d, 0755)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion worker/edge/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ require (
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
golang.org/x/sys v0.11.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
6 changes: 2 additions & 4 deletions worker/edge/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand All @@ -12,7 +11,6 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
Expand All @@ -29,5 +27,5 @@ golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
5 changes: 2 additions & 3 deletions worker/edge/metrics.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package main

import (
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"sync"
"time"
)

var (
Expand Down
34 changes: 17 additions & 17 deletions worker/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ go 1.21

// Direct dependencies
require (
github.com/getsentry/sentry-go v0.25.0
github.com/getsentry/sentry-go v0.23.0
github.com/golang/protobuf v1.5.3 // indirect
github.com/icza/gox v0.0.0-20230924165045-adcb03233bb5
github.com/icza/gox v0.0.0-20230330130131-23e1aaac139e
github.com/iris-contrib/go.uuid v2.0.0+incompatible
github.com/joschahenningsen/thumbgen v0.1.2
github.com/robfig/cron/v3 v3.0.1
github.com/shirou/gopsutil/v3 v3.23.12
github.com/shirou/gopsutil/v3 v3.23.7
github.com/sirupsen/logrus v1.9.3
github.com/tidwall/gjson v1.17.0
golang.org/x/sync v0.7.0
google.golang.org/grpc v1.60.1
google.golang.org/protobuf v1.33.0
github.com/tidwall/gjson v1.16.0
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
)

require (
Expand All @@ -26,25 +26,25 @@ require (
// Indirect dependencies
require (
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/lufia/plan9stats v0.0.0-20231016141302-07b5767bb0ed // indirect
github.com/lufia/plan9stats v0.0.0-20230326075908-cb1d2100619a // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/u2takey/go-utils v0.3.1
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
)

require (
github.com/felixge/fgprof v0.9.3 // indirect
github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/pprof v0.0.0-20230811205829-9131a7e9cc17 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
golang.org/x/image v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
golang.org/x/image v0.11.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230814215434-ca7cfce7776a // indirect
)
Loading
Loading