Skip to content

Commit 0b75246

Browse files
add to resume
1 parent 8f43bee commit 0b75246

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎xdcc/go.mod‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
2020
github.com/gorilla/websocket v1.5.0 // indirect
2121
github.com/gosimple/unidecode v1.0.1 // indirect
22+
github.com/gotd/contrib v0.13.0 // indirect
2223
github.com/igm/sockjs-go/v3 v3.0.2 // indirect
2324
github.com/orcaman/concurrent-map v1.0.0 // indirect
2425
golang.org/x/crypto v0.1.0 // indirect

‎xdcc/go.sum‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8
22
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
33
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
44
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
56
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
67
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
78
github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs=
@@ -15,6 +16,8 @@ github.com/gosimple/slug v1.13.1 h1:bQ+kpX9Qa6tHRaK+fZR0A0M2Kd7Pa5eHPPsb1JpHD+Q=
1516
github.com/gosimple/slug v1.13.1/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
1617
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
1718
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
19+
github.com/gotd/contrib v0.13.0 h1:6Qq4jFAhq8bc8DyCM3sNiVj4TUClDLEEmUZR5Lr6L5M=
20+
github.com/gotd/contrib v0.13.0/go.mod h1:Y1vtBgGhfnLKXQTCE6HzU9+quvacOAC1zxXA1/I5t9w=
1821
github.com/igm/sockjs-go/v3 v3.0.2 h1:2m0k53w0DBiGozeQUIEPR6snZFmpFpYvVsGnfLPNXbE=
1922
github.com/igm/sockjs-go/v3 v3.0.2/go.mod h1:UqchsOjeagIBFHvd+RZpLaVRbCwGilEC08EDHsD1jYE=
2023
github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HDbW65HOY=
@@ -24,6 +27,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
2427
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2528
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
2629
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
30+
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
2731
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
2832
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
2933
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=

‎xdcc/xdcc.go‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/gorilla/mux"
1313
"github.com/gosimple/slug"
14+
"github.com/gotd/contrib/http_range"
1415
"golang.org/x/exp/maps"
1516
"gopkg.in/ini.v1"
1617

@@ -83,6 +84,8 @@ type ParsedParts struct {
8384
receiverNick string
8485
senderNick string
8586
serverHostname string
87+
message irc.Message
88+
upstreamSend chan string
8689
}
8790

8891
func parseSendParams(text string) *ParsedParts {
@@ -243,6 +246,8 @@ func DCCSend(hook *webircgateway.HookIrcLine) {
243246
parts.receiverNick = client.IrcState.Nick
244247
parts.senderNick = m.Prefix.Nick
245248
parts.serverHostname = client.UpstreamConfig.Hostname
249+
parts.message = *m
250+
parts.upstreamSend = client.UpstreamSend
246251

247252
//TODO when file has no extension PARTS file
248253
lastIndex := strings.LastIndex(parts.file, ".")
@@ -255,8 +260,6 @@ func DCCSend(hook *webircgateway.HookIrcLine) {
255260
hook.Message.Command = "NOTICE"
256261
hook.Message.Params[1] = fmt.Sprintf("http://%s:3000/%s", configs.DomainName, parts.file)
257262

258-
259-
260263
configs.server.AddFile(parts.file, *parts)
261264

262265
client.SendClientSignal("data", hook.Message.ToLine())
@@ -397,6 +400,28 @@ func (s *Server) InitDispatch() {
397400
// s.ProxyCall(w, r, name)
398401

399402
parts := s.fileNames[name]
403+
ranges, err := http_range.ParseRange(r.Header.Get("Range"), int64(parts.length))
404+
if err != nil {
405+
http.Error(w, err.Error(), http.StatusBadRequest)
406+
return
407+
}
408+
if len(ranges) > 0 {
409+
r := ranges[0]
410+
offset := r.Start
411+
w.Header().Set("Content-Range", r.ContentRange(int64(parts.length)))
412+
w.WriteHeader(http.StatusPartialContent)
413+
passLine := fmt.Sprintf(
414+
"DCC RESUME %s %d %d",
415+
parts.file,
416+
parts.port,
417+
offset,
418+
)
419+
parts.message.Params[1] = passLine
420+
// message, _ := irc.ParseLine(passLine)
421+
// message.
422+
423+
parts.upstreamSend <- parts.message.ToLine()
424+
}
400425

401426
//call serveFile here
402427
if serveFile(parts, w, r) { //removed go keyword this could mean servFile can only happen once

0 commit comments

Comments
 (0)