package tenant_media import ( "quyun/v2/app/errorx" "quyun/v2/app/services" "quyun/v2/database/models" "github.com/gofiber/fiber/v3" log "github.com/sirupsen/logrus" ) // media provides media play endpoints (token-based, no JWT required). // // @provider type media struct{} // play // // @Summary 媒体播放入口(短时效 token) // @Tags TenantMedia // @Accept json // @Produce json // @Param tenantCode path string true "Tenant Code" // @Param token query string true "Play token" // // @Router /t/:tenantCode/v1/media/play [get] // @Bind tenant local key(tenant) // @Bind token query func (*media) play(ctx fiber.Ctx, tenant *models.Tenant, token string) error { log.WithFields(log.Fields{ "tenant_id": tenant.ID, }).Info("tenant_media.play") res, err := services.MediaDelivery.ResolvePlay(ctx.Context(), tenant.ID, token) if err != nil { return err } switch res.Kind { case services.MediaPlayResolutionKindLocalFile: if res.ContentType != "" { ctx.Set("Content-Type", res.ContentType) } return ctx.SendFile(res.LocalFilePath) case services.MediaPlayResolutionKindRedirect: return ctx.Redirect().To(res.RedirectURL) default: return errorx.ErrServiceUnavailable.WithMsg("unsupported play resolution") } }