- Implemented the `/import` command to allow users to import files from storage to Telegram. - Added support for listing files in storage and filtering based on regex patterns. - Created a batch import task to handle multiple file uploads concurrently. - Introduced progress tracking for batch imports, providing real-time updates to users. - Enhanced storage interfaces to support file listing and reading capabilities. - Updated localization files for the new import command and its usage instructions. - Added utility functions for file size formatting and speed calculation. - Refactored Telegram storage handling to support reading from non-seekable streams.
74 lines
1.3 KiB
Go
74 lines
1.3 KiB
Go
package batchimport
|
|
|
|
type TaskElementInfo interface {
|
|
FileName() string
|
|
FileSize() int64
|
|
GetSourcePath() string
|
|
SourceStorageName() string
|
|
}
|
|
|
|
func (e *TaskElement) FileName() string {
|
|
return e.FileInfo.Name
|
|
}
|
|
|
|
func (e *TaskElement) FileSize() int64 {
|
|
return e.FileInfo.Size
|
|
}
|
|
|
|
func (e *TaskElement) GetSourcePath() string {
|
|
return e.SourcePath
|
|
}
|
|
|
|
func (e *TaskElement) SourceStorageName() string {
|
|
return e.SourceStorage.Name()
|
|
}
|
|
|
|
type TaskInfo interface {
|
|
TaskID() string
|
|
TotalSize() int64
|
|
Uploaded() int64
|
|
Count() int
|
|
Processing() []TaskElementInfo
|
|
FailedFiles() []string
|
|
}
|
|
|
|
func (t *Task) TotalSize() int64 {
|
|
return t.totalSize
|
|
}
|
|
|
|
func (t *Task) Uploaded() int64 {
|
|
return t.uploaded.Load()
|
|
}
|
|
|
|
func (t *Task) Count() int {
|
|
return len(t.elems)
|
|
}
|
|
|
|
func (t *Task) Processing() []TaskElementInfo {
|
|
t.processingMu.RLock()
|
|
defer t.processingMu.RUnlock()
|
|
|
|
result := make([]TaskElementInfo, 0, len(t.processing))
|
|
for _, elem := range t.processing {
|
|
result = append(result, elem)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (t *Task) FailedFiles() []string {
|
|
t.processingMu.RLock()
|
|
defer t.processingMu.RUnlock()
|
|
|
|
result := make([]string, 0, len(t.failed))
|
|
for id := range t.failed {
|
|
// Find the element by ID
|
|
for _, elem := range t.elems {
|
|
if elem.ID == id {
|
|
result = append(result, elem.FileInfo.Name)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return result
|
|
}
|