- Implemented a new task type for handling direct links downloads. - Added command handler for downloading multiple links via /dl command. - Introduced progress tracking for direct link downloads. - Enhanced filename parsing to support various encoding scenarios. - Updated enums to include direct links as a task type. - Refactored existing task structures to accommodate new functionality. - Improved error handling and logging throughout the download process.
51 lines
772 B
Go
51 lines
772 B
Go
package ioutil
|
|
|
|
import (
|
|
"io"
|
|
)
|
|
|
|
type ProgressWriterAt struct {
|
|
wrAt io.WriterAt
|
|
onWrite func(n int)
|
|
}
|
|
|
|
func (p *ProgressWriterAt) WriteAt(buf []byte, off int64) (n int, err error) {
|
|
n, err = p.wrAt.WriteAt(buf, off)
|
|
if n > 0 {
|
|
p.onWrite(n)
|
|
}
|
|
return
|
|
}
|
|
|
|
func NewProgressWriterAt(
|
|
wrAt io.WriterAt,
|
|
onWrite func(n int),
|
|
) *ProgressWriterAt {
|
|
return &ProgressWriterAt{
|
|
wrAt: wrAt,
|
|
onWrite: onWrite,
|
|
}
|
|
}
|
|
|
|
type ProgressWriter struct {
|
|
wr io.Writer
|
|
onWrite func(n int)
|
|
}
|
|
|
|
func (p *ProgressWriter) Write(buf []byte) (n int, err error) {
|
|
n, err = p.wr.Write(buf)
|
|
if n > 0 {
|
|
p.onWrite(n)
|
|
}
|
|
return
|
|
}
|
|
|
|
func NewProgressWriter(
|
|
wr io.Writer,
|
|
onWrite func(n int),
|
|
) *ProgressWriter {
|
|
return &ProgressWriter{
|
|
wr: wr,
|
|
onWrite: onWrite,
|
|
}
|
|
} |