@@ -45,10 +45,13 @@ func (t *Thunder) IsReady() bool {
45
45
if err != nil {
46
46
return false
47
47
}
48
- if _ , ok := storage .(* thunder.Thunder ); ! ok {
49
- return false
48
+ if _ , ok := storage .(* thunder.Thunder ); ok {
49
+ return true
50
+ }
51
+ if _ , ok := storage .(* thunder.ThunderExpert ); ok {
52
+ return true
50
53
}
51
- return true
54
+ return false
52
55
}
53
56
54
57
func (t * Thunder ) AddURL (args * tool.AddUrlArgs ) (string , error ) {
@@ -58,11 +61,6 @@ func (t *Thunder) AddURL(args *tool.AddUrlArgs) (string, error) {
58
61
if err != nil {
59
62
return "" , err
60
63
}
61
- thunderDriver , ok := storage .(* thunder.Thunder )
62
- if ! ok {
63
- return "" , fmt .Errorf ("unsupported storage driver for offline download, only Thunder is supported" )
64
- }
65
-
66
64
ctx := context .Background ()
67
65
68
66
if err := op .MakeDir (ctx , storage , actualPath ); err != nil {
@@ -74,7 +72,15 @@ func (t *Thunder) AddURL(args *tool.AddUrlArgs) (string, error) {
74
72
return "" , err
75
73
}
76
74
77
- task , err := thunderDriver .OfflineDownload (ctx , args .Url , parentDir , "" )
75
+ var task * thunder.OfflineTask
76
+ if thunderDriver , ok := storage .(* thunder.Thunder ); ok {
77
+ task , err = thunderDriver .OfflineDownload (ctx , args .Url , parentDir , "" )
78
+ } else if expertDriver , ok := storage .(* thunder.ThunderExpert ); ok {
79
+ task , err = expertDriver .OfflineDownload (ctx , args .Url , parentDir , "" )
80
+ } else {
81
+ return "" , fmt .Errorf ("unsupported storage driver for offline download, only Thunder or Thunder Expert is supported" )
82
+ }
83
+
78
84
if err != nil {
79
85
return "" , fmt .Errorf ("failed to add offline download task: %w" , err )
80
86
}
@@ -87,28 +93,29 @@ func (t *Thunder) Remove(task *tool.DownloadTask) error {
87
93
if err != nil {
88
94
return err
89
95
}
90
- thunderDriver , ok := storage .(* thunder.Thunder )
91
- if ! ok {
92
- return fmt .Errorf ("unsupported storage driver for offline download, only Thunder is supported" )
96
+ if thunderDriver , ok := storage .(* thunder.Thunder ); ok {
97
+ err = thunderDriver .DeleteOfflineTasks (context .Background (), []string {task .GID }, false )
98
+ } else if expertDriver , ok := storage .(* thunder.ThunderExpert ); ok {
99
+ err = expertDriver .DeleteOfflineTasks (context .Background (), []string {task .GID }, false )
100
+ } else {
101
+ return fmt .Errorf ("unsupported storage driver for offline download, only Thunder or Thunder Expert is supported" )
93
102
}
94
- ctx := context .Background ()
95
- err = thunderDriver .DeleteOfflineTasks (ctx , []string {task .GID }, false )
96
- if err != nil {
97
- return err
98
- }
99
- return nil
103
+ return err
100
104
}
101
105
102
106
func (t * Thunder ) Status (task * tool.DownloadTask ) (* tool.Status , error ) {
103
107
storage , _ , err := op .GetStorageAndActualPath (task .TempDir )
104
108
if err != nil {
105
109
return nil , err
106
110
}
107
- thunderDriver , ok := storage .(* thunder.Thunder )
108
- if ! ok {
109
- return nil , fmt .Errorf ("unsupported storage driver for offline download, only Thunder is supported" )
111
+ var tasks []thunder.OfflineTask
112
+ if thunderDriver , ok := storage .(* thunder.Thunder ); ok {
113
+ tasks , err = t .GetTasks (thunderDriver )
114
+ } else if expertDriver , ok := storage .(* thunder.ThunderExpert ); ok {
115
+ tasks , err = t .GetTasks (expertDriver )
116
+ } else {
117
+ return nil , fmt .Errorf ("unsupported storage driver for offline download, only Thunder or Thunder Expert is supported" )
110
118
}
111
- tasks , err := t .GetTasks (thunderDriver )
112
119
if err != nil {
113
120
return nil , err
114
121
}
0 commit comments