Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/enh/runner' into enh/runner
Browse files Browse the repository at this point in the history
  • Loading branch information
DawinYurtseven committed Nov 29, 2024
2 parents e197fb9 + fe262c2 commit a7b9013
Show file tree
Hide file tree
Showing 42 changed files with 224 additions and 183 deletions.
3 changes: 2 additions & 1 deletion api/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ func (r coursesRoutes) getCourseBySlug(c *gin.Context) {

if (course.IsLoggedIn() && tumLiveContext.User == nil) || (course.IsEnrolled() && !tumLiveContext.User.IsEligibleToWatchCourse(course)) {
c.AbortWithStatus(http.StatusUnauthorized)
return
}

user := tumLiveContext.User
Expand Down Expand Up @@ -1059,7 +1060,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
26 changes: 15 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
####################################################
# Not production ready, only for local development #
####################################################
version: "3.8"

services:
Expand All @@ -20,7 +23,7 @@ services:
container_name: tum-live-worker
depends_on:
- tum-live
- vod-service
#- vod-service # Omitted for local development due to size. Comment out to use voice-service
build: worker
platform: linux/amd64
environment:
Expand Down Expand Up @@ -68,16 +71,17 @@ services:
- ./init.sql:/data/application/init.sql
- mariadb-data:/var/lib/mysql
restart: always
voice-service:
container_name: tum-live-voice-service
image: ghcr.io/tum-dev/tum-live-voice-service:latest
environment:
- TRANSCRIBER=whisper
- WHISPER_MODEL=tiny
- MAX_WORKERS=10
- DEBUG=1
volumes:
- mass:/mass
# Omitted for local development due to size. Comment out to use voice-service
# voice-service:
# container_name: tum-live-voice-service
# image: ghcr.io/tum-dev/tum-live-voice-service:latest
# environment:
# - TRANSCRIBER=whisper
# - WHISPER_MODEL=tiny
# - MAX_WORKERS=10
# - DEBUG=1
# volumes:
# - mass:/mass

volumes:
recordings:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/go-gormigrate/gormigrate/v2 v2.1.1
github.com/go-ldap/ldap/v3 v3.4.6
github.com/go-sql-driver/mysql v1.7.1
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang-jwt/jwt/v4 v4.5.1
github.com/golang/glog v1.2.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/jinzhu/now v1.1.5
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGF
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
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-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
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
}
3 changes: 1 addition & 2 deletions model/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ const (
// Notification is a message (e.g. a feature alert) that is displayed to users
type Notification struct {
Model

Title *string `json:"title,omitempty"`
Body string `json:"-" gorm:"not null"`
Target NotificationTarget `json:"-" gorm:"not null; default:1"`
Target NotificationTarget `json:"target" gorm:"not null; default:1"`

// SanitizedBody is the body of the notification, converted from markdown to HTML
SanitizedBody string `json:"body" gorm:"-"`
Expand Down
2 changes: 1 addition & 1 deletion model/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,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
3 changes: 0 additions & 3 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ func (s PlaybackSpeedSettings) GetEnabled() (res []float32) {
}

func (u *User) GetEnabledPlaybackSpeeds() (res []float32) {
if u == nil {
return []float32{1}
}
// Possibly, this could be collapsed into a single line, but readibility suffers.
res = append(res, u.GetPlaybackSpeeds().GetEnabled()...)
res = append(res, u.GetCustomSpeeds()...)
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
}
5 changes: 5 additions & 0 deletions web/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,13 @@ func (r mainRoutes) EditCoursePage(c *gin.Context) {
if err != nil {
logger.Error("Error getting invited users for course", "err", err)
}
y, t := tum.GetCurrentSemester()

indexData := NewIndexData()
indexData.TUMLiveContext = tumLiveContext
indexData.CurrentYear = y
indexData.CurrentTerm = t

courses, err := r.CoursesDao.GetAdministeredCoursesByUserId(context.Background(), tumLiveContext.User.ID, "", 0)
if err != nil {
logger.Error("couldn't query courses for user.", "err", err)
Expand Down
5 changes: 5 additions & 0 deletions web/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
@apply text-gray-700 dark:text-gray-300;
}

/*low contrast text*/
.important-text-4 {
@apply text-gray-700 dark:text-gray-300 !important;
}

/*full contrast text*/
.text-5 {
@apply text-gray-600 dark:text-gray-400;
Expand Down
31 changes: 30 additions & 1 deletion web/template/admin/admin_tabs/edit-course.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{{- /*gotype: github.com/TUM-Dev/gocast/web.AdminPageData*/ -}}
{{$course := .IndexData.TUMLiveContext.Course}}
{{$lecture := .IndexData.TUMLiveContext.Stream}}
{{$currentYear := .IndexData.CurrentYear}}
{{$currentTerm := .IndexData.CurrentTerm}}

<div class="text-1 mt-4" x-data="{userId: {{.IndexData.TUMLiveContext.User.Model.ID}} }">
<div class="min-w-screen items-center justify-center">

Expand All @@ -20,6 +23,32 @@
role="alert">
Course was created successfully.
</div>
{{if (eq $course.TeachingTerm "Test")}}
<div class="p-3 text-md border border-blue-500 text-blue-500 bg-blue-100 dark:bg-blue-200 dark:border-blue-700 dark:text-blue-700 rounded-lg flex items-center" role="alert">
<div class="flex-shrink-0">
<i class="fa-solid fa-info-circle text-4 text-blue-500 dark:text-blue-700"></i>
</div>
<div class="ml-3" x-init="console.log('currentYear: {{$currentYear}}', 'currentTerm: {{$currentTerm}}', 'courseYear: {{$course.Year}}', 'courseTerm: {{$course.TeachingTerm}}')">
<div class="font-bold">Info: Test Course</div>
<div class="text-sm">
This course is your personal test course. It will not be shown in the course overview to students and is only visible to you as an admin. <br>
</div>
</div>
</div>
{{else if or (ne $course.TeachingTerm $currentTerm) (ne $course.Year $currentYear)}}
<div class="p-3 text-md border bg-yellow-100 border-yellow-600 text-yellow-600 dark:bg-yellow-200 dark:border-yellow-700 dark:text-yellow-700 rounded-lg flex items-center" role="alert">
<div class="flex-shrink-0">
<i class="fa-solid fa-warning text-4 text-yellow-500 dark:text-yellow-700"></i>
</div>
<div class="ml-3" x-init="console.log('currentYear: {{$currentYear}}', 'currentTerm: {{$currentTerm}}', 'courseYear: {{$course.Year}}', 'courseTerm: {{$course.TeachingTerm}}')">
<div class="font-bold">Warning: Outdated Semester</div>
<div class="text-sm">
This course is not from the current semester and might not be shown in the course overview to students. <br>
If this is a recurring course, please select the course from the current semester and year.
</div>
</div>
</div>
{{end}}
</div>

<label class="hidden" for="courseID">CourseID<input id="courseID" type="text" class="hidden"
Expand Down Expand Up @@ -114,4 +143,4 @@
</div>
</div>
</div>
{{end}}
{{end}}
7 changes: 6 additions & 1 deletion web/template/watch.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
class="flex justify-start items-center pt-2">
<input id="include-timestamp" type="checkbox" class="h-8 hover:cursor-pointer"
x-model="share.includeTimestamp" @change="share.setURL(false)">
<label for="include-timestamp" class="font-light text-4 text-xs ml-2">Include Timestamp</label>
<label for="include-timestamp" class="font-light text-xs ml-2 important-text-4">Include Timestamp</label>
<input x-cloak x-show="share.includeTimestamp" class="tl-input h-8 w-20 text-xs ml-2"
type="text" x-model="share.timestamp" @input="share.setURL(false);">
</div>
Expand Down Expand Up @@ -449,8 +449,13 @@
<a href="/course/{{$course.Year}}/{{$course.TeachingTerm}}/{{$course.Slug}}">
<span class="text-5 hover:text-1 hover:underline">{{$course.Name}}</span></a>
</div>
</div>

{{if $stream.Recording}}
<div>
<span class="text-5 text-sm">{{$stream.FriendlyTime}}</span>
</div>
{{end}}
{{if not $stream.Recording}}
{{template "watch-info" .}}
{{end}}
Expand Down
6 changes: 5 additions & 1 deletion web/ts/notification-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export function createNotification(body: string, target: number, title: string |
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(notification),
body: JSON.stringify({
title: notification.title,
body: notification.body,
target: Number(notification.target),
}),
})
.then((r) => r.json())
.then((r) => {
Expand Down
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
Loading

0 comments on commit a7b9013

Please sign in to comment.