Skip to content

Commit

Permalink
Merge branch 'main' into v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibbp authored Dec 12, 2024
2 parents a712f09 + 0a350cb commit d9ded1b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ The `docker-compose.yml` file has comments for each environment variable. The `*
| `TEMP_DIR` | Path inside the container where temporary files are stored during archiving. Default: `/data/temp`. |
| `LOGS_DIR` | Path inside the container where log files are stored. Default: `/data/logs`. |
| `CONFIG_DIR` | Path inside the container where the config is stored. Default: `/data/config`. |
| `PATH_MIGRATION_ENABLED` | Enable path migration at startup. Default: `true`. |
| `TZ` | Timezone. |
| `DB_HOST` | Host of the database. |
| `DB_PORT` | Port of the database. |
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ services:
restart: unless-stopped
environment:
- API_URL=http://IP:PORT # Points to the API service; the container must be able to access this URL internally
- CDN_URL=http://IP:PORT # Points to the nginx service
- CDN_URL=http://IP:PORT # Can point to your nginx service, or set same as API_URL if nginx is not used
- SHOW_SSO_LOGIN_BUTTON=true # show/hide SSO login button on login page
- FORCE_SSO_AUTH=false # force SSO auth for all users (bypasses login page and redirects to SSO)
- REQUIRE_LOGIN=false # require login to view videos
Expand Down
9 changes: 5 additions & 4 deletions internal/config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ type EnvConfig struct {
DEBUG bool `env:"DEBUG, default=false"`
CookieDomain string `env:"COOKIE_DOMAIN, default="`
// customizable paths
VideosDir string `env:"VIDEOS_DIR, default=/data/videos"`
TempDir string `env:"TEMP_DIR, default=/data/temp"`
ConfigDir string `env:"CONFIG_DIR, default=/data/config"`
LogsDir string `env:"LOGS_DIR, default=/data/logs"`
VideosDir string `env:"VIDEOS_DIR, default=/data/videos"`
TempDir string `env:"TEMP_DIR, default=/data/temp"`
ConfigDir string `env:"CONFIG_DIR, default=/data/config"`
LogsDir string `env:"LOGS_DIR, default=/data/logs"`
PathMigrationEnabled bool `env:"PATH_MIGRATION_ENABLED, default=true"`
// platform variables
TwitchClientId string `env:"TWITCH_CLIENT_ID, default="`
TwitchClientSecret string `env:"TWITCH_CLIENT_SECRET, default="`
Expand Down
6 changes: 6 additions & 0 deletions internal/playlist/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ func (s *Service) SetVodDelayOnPlaylist(c echo.Context, playlistID uuid.UUID, vo
if err != nil {
return fmt.Errorf("playlist not found")
}

// If one day, we need to store more than just the delay, we should remove the deletion here
if delayMs == 0 {
return s.deleteMultistreamInfo(c, playlistID, vodID)
}

// Check if vod exists in playlist before creating new data
found := false
for _, vod := range dbPlaylist.Edges.Vods {
Expand All @@ -151,12 +153,14 @@ func (s *Service) SetVodDelayOnPlaylist(c echo.Context, playlistID uuid.UUID, vo
if !found {
return fmt.Errorf("vod not found in playlist")
}

dbMultistreamInfo, err := s.Store.Client.MultistreamInfo.Query().Where(
multistreaminfo.And(
multistreaminfo.HasPlaylistWith(playlist.ID(playlistID)),
multistreaminfo.HasVodWith(vod.ID(vodID)),
),
).Only(c.Request().Context())

if err != nil && ent.IsNotFound(err) {
_, err = s.Store.Client.MultistreamInfo.Create().SetDelayMs(delayMs).SetPlaylistID(playlistID).SetVodID(vodID).Save(c.Request().Context())
if err != nil {
Expand All @@ -170,13 +174,15 @@ func (s *Service) SetVodDelayOnPlaylist(c echo.Context, playlistID uuid.UUID, vo
}
return nil
}

func (s *Service) deleteMultistreamInfo(c echo.Context, playlistID uuid.UUID, vodID uuid.UUID) error {
_, err := s.Store.Client.MultistreamInfo.Delete().Where(
multistreaminfo.And(
multistreaminfo.HasPlaylistWith(playlist.ID(playlistID)),
multistreaminfo.HasVodWith(vod.ID(vodID)),
),
).Exec(c.Request().Context())

if err != nil {
return fmt.Errorf("error deleting multistream info: %v", err)
}
Expand Down
14 changes: 8 additions & 6 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ func SetupApplication(ctx context.Context) (*Application, error) {
})

// application migrations
// check if VideosDir changed
if err := db.VideosDirMigrate(ctx, envConfig.VideosDir); err != nil {
return nil, fmt.Errorf("error migrating videos dir: %v", err)
}
if err := db.TempDirMigrate(ctx, envConfig.TempDir); err != nil {
return nil, fmt.Errorf("error migrating videos dir: %v", err)
if envConfig.PathMigrationEnabled {
// check if VideosDir changed
if err := db.VideosDirMigrate(ctx, envConfig.VideosDir); err != nil {
return nil, fmt.Errorf("error migrating videos dir: %v", err)
}
if err := db.TempDirMigrate(ctx, envConfig.TempDir); err != nil {
return nil, fmt.Errorf("error migrating videos dir: %v", err)
}
}

// Initialize river client
Expand Down
38 changes: 38 additions & 0 deletions internal/transport/http/playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (h *Handler) GetPlaylists(c echo.Context) error {
// @Success 200 {object} ent.Playlist
// @Failure 400 {object} utils.ErrorResponse
// @Failure 500 {object} utils.ErrorResponse
// @Router /playlist/{id} [get]
func (h *Handler) GetPlaylist(c echo.Context) error {
pID, err := uuid.Parse(c.Param("id"))
if err != nil {
Expand Down Expand Up @@ -220,6 +221,43 @@ func (h *Handler) SetVodDelayOnPlaylistMultistream(c echo.Context) error {
return c.JSON(http.StatusOK, "ok")
}

// SetVodDelayOnPlaylistMultistream godoc
//
// @Summary Set delay of vod in playlist for multistream
// @Description Set delay of vod in playlist for multistream
// @Tags Playlist
// @Accept json
// @Produce json
// @Param id path string true "playlist id"
// @Param delay body SetVodDelayPlaylistRequest true "delay"
// @Success 200 {object} string
// @Failure 400 {object} utils.ErrorResponse
// @Failure 500 {object} utils.ErrorResponse
// @Router /playlist/{id} [put]
// @Security ApiKeyCookieAuth
func (h *Handler) SetVodDelayOnPlaylistMultistream(c echo.Context) error {

Check failure on line 238 in internal/transport/http/playlist.go

View workflow job for this annotation

GitHub Actions / lint

method Handler.SetVodDelayOnPlaylistMultistream already declared at internal/transport/http/playlist.go:201:19 (typecheck)

Check failure on line 238 in internal/transport/http/playlist.go

View workflow job for this annotation

GitHub Actions / lint

method Handler.SetVodDelayOnPlaylistMultistream already declared at internal/transport/http/playlist.go:201:19) (typecheck)

Check failure on line 238 in internal/transport/http/playlist.go

View workflow job for this annotation

GitHub Actions / lint

method Handler.SetVodDelayOnPlaylistMultistream already declared at internal/transport/http/playlist.go:201:19) (typecheck)

Check failure on line 238 in internal/transport/http/playlist.go

View workflow job for this annotation

GitHub Actions / test

method Handler.SetVodDelayOnPlaylistMultistream already declared at internal/transport/http/playlist.go:201:19
pID, err := uuid.Parse(c.Param("id"))
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid playlist id")
}
svdpr := new(SetVodDelayPlaylistRequest)
if err := c.Bind(svdpr); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
if err := c.Validate(svdpr); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
vID, err := uuid.Parse(svdpr.VodID)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid vod id")
}
err = h.Service.PlaylistService.SetVodDelayOnPlaylist(c, pID, vID, svdpr.DelayMs)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
return c.JSON(http.StatusOK, "ok")
}

// DeletePlaylist godoc
//
// @Summary Delete playlist
Expand Down

0 comments on commit d9ded1b

Please sign in to comment.