Spaces:
Sleeping
Sleeping
Upload 111 files
Browse files
internal/routes/stream.go
CHANGED
|
@@ -43,9 +43,13 @@ func getStreamRoute(ctx *gin.Context) {
|
|
| 43 |
}
|
| 44 |
|
| 45 |
worker := bot.GetNextWorker()
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
file, err := utils.TimeFuncWithResult(log, "FileFromMessage", func() (*types.File, error) {
|
| 48 |
-
|
|
|
|
| 49 |
})
|
| 50 |
if err != nil {
|
| 51 |
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
@@ -65,7 +69,7 @@ func getStreamRoute(ctx *gin.Context) {
|
|
| 65 |
|
| 66 |
// for photo messages
|
| 67 |
if file.FileSize == 0 {
|
| 68 |
-
res, err := worker.Client.API().UploadGetFile(
|
| 69 |
Location: file.Location,
|
| 70 |
Offset: 0,
|
| 71 |
Limit: 1024 * 1024,
|
|
@@ -127,7 +131,8 @@ func getStreamRoute(ctx *gin.Context) {
|
|
| 127 |
ctx.Header("Content-Disposition", fmt.Sprintf("%s; filename=\"%s\"", disposition, file.FileName))
|
| 128 |
|
| 129 |
if r.Method != "HEAD" {
|
| 130 |
-
|
|
|
|
| 131 |
if err != nil {
|
| 132 |
log.Error("Failed to create stream pipe", zap.Error(err))
|
| 133 |
return
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
worker := bot.GetNextWorker()
|
| 46 |
+
log.Sugar().Infof("✅ Asignando petición de stream (MessageID: %d) al worker: @%s", messageID, worker.Self.Username)
|
| 47 |
+
|
| 48 |
+
reqCtx := r.Context()
|
| 49 |
|
| 50 |
file, err := utils.TimeFuncWithResult(log, "FileFromMessage", func() (*types.File, error) {
|
| 51 |
+
// Pasa el contexto de la petición real para que si el cliente cierra la ventana, se aborte el fetch
|
| 52 |
+
return utils.FileFromMessage(reqCtx, worker.Client, messageID)
|
| 53 |
})
|
| 54 |
if err != nil {
|
| 55 |
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
|
|
| 69 |
|
| 70 |
// for photo messages
|
| 71 |
if file.FileSize == 0 {
|
| 72 |
+
res, err := worker.Client.API().UploadGetFile(reqCtx, &tg.UploadGetFileRequest{
|
| 73 |
Location: file.Location,
|
| 74 |
Offset: 0,
|
| 75 |
Limit: 1024 * 1024,
|
|
|
|
| 131 |
ctx.Header("Content-Disposition", fmt.Sprintf("%s; filename=\"%s\"", disposition, file.FileName))
|
| 132 |
|
| 133 |
if r.Method != "HEAD" {
|
| 134 |
+
// Pasamos el reqCtx aquí para que corte la Tubería y las peticiones si el usuario se desconecta
|
| 135 |
+
pipe, err := stream.NewStreamPipe(reqCtx, worker.Client, file.Location, start, end, log)
|
| 136 |
if err != nil {
|
| 137 |
log.Error("Failed to create stream pipe", zap.Error(err))
|
| 138 |
return
|