MCPcopy
hub / github.com/SurgeDM/Surge / handleDownloadRequestMsg

Method handleDownloadRequestMsg

internal/tui/download_requests.go:12–59  ·  view source on GitHub ↗
(msg events.DownloadRequestMsg, queueIfBusy bool)

Source from the content-addressed store, hash-verified

10)
11
12func (m RootModel) handleDownloadRequestMsg(msg events.DownloadRequestMsg, queueIfBusy bool) (tea.Model, tea.Cmd) {
13 if queueIfBusy && (m.state == ExtensionConfirmationState || m.state == DuplicateWarningState || m.state == BatchConfirmState) {
14 m.pendingRequestQueue = append(m.pendingRequestQueue, msg)
15 return m, nil
16 }
17
18 path := strings.TrimSpace(msg.Path)
19 isDefaultPath := m.isDefaultDownloadPath(path)
20 if path == "" {
21 isDefaultPath = true
22 path = m.defaultDownloadPath()
23 }
24
25 duplicate := m.checkForDuplicate(msg.URL)
26
27 if duplicate != nil && config.Resolve[bool](m.Settings.General.WarnOnDuplicate) {
28 utils.Debug("Duplicate download detected in TUI: %s", msg.URL)
29 m.pendingURL = msg.URL
30 m.pendingMirrors = msg.Mirrors
31 m.pendingHeaders = msg.Headers
32 m.pendingPath = path
33 m.pendingIsDefaultPath = isDefaultPath
34 m.pendingFilename = msg.Filename
35 m.duplicateInfo = duplicate.Filename
36 m.state = DuplicateWarningState
37 return m, nil
38 }
39
40 if m.Settings != nil && config.Resolve[bool](m.Settings.Extension.ExtensionPrompt) {
41 m.pendingURL = msg.URL
42 m.pendingMirrors = msg.Mirrors
43 m.pendingHeaders = msg.Headers
44 m.pendingPath = path
45 m.pendingIsDefaultPath = isDefaultPath
46 m.pendingFilename = msg.Filename
47 m.inputs[2].SetValue(path)
48 m.inputs[3].SetValue(msg.Filename)
49 m.focusedInput = 2
50 for i := range m.inputs {
51 m.inputs[i].Blur()
52 }
53 m.inputs[m.focusedInput].Focus()
54 m.state = ExtensionConfirmationState
55 return m, nil
56 }
57
58 return m.startDownload(msg.URL, msg.Mirrors, msg.Headers, path, isDefaultPath, msg.Filename, msg.ID)
59}
60
61func (m RootModel) handleBatchDownloadRequestMsg(msg events.BatchDownloadRequestMsg, queueIfBusy bool) (tea.Model, tea.Cmd) {
62 if queueIfBusy && (m.state == ExtensionConfirmationState || m.state == DuplicateWarningState || m.state == BatchConfirmState) {

Callers 2

updateEventsMethod · 0.95

Calls 5

isDefaultDownloadPathMethod · 0.95
defaultDownloadPathMethod · 0.95
checkForDuplicateMethod · 0.95
startDownloadMethod · 0.95
DebugFunction · 0.92

Tested by

no test coverage detected