Clean up
This commit is contained in:
16
go.mod
16
go.mod
@@ -1,19 +1,3 @@
|
|||||||
module github.com/debridmediamanager.com/zurg
|
module github.com/debridmediamanager.com/zurg
|
||||||
|
|
||||||
go 1.21.3
|
go 1.21.3
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/go-sql-driver/mysql v1.7.1
|
|
||||||
github.com/qianbin/directcache v0.9.7
|
|
||||||
github.com/zeebo/xxh3 v1.0.2
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
|
||||||
github.com/dgraph-io/ristretto v0.1.1 // indirect
|
|
||||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
|
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
|
|
||||||
)
|
|
||||||
|
|||||||
35
go.sum
35
go.sum
@@ -1,35 +0,0 @@
|
|||||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/dgraph-io/ristretto v0.1.1 h1:6CWw5tJNgpegArSHpNHJKldNeq03FQCwYvfMVWajOK8=
|
|
||||||
github.com/dgraph-io/ristretto v0.1.1/go.mod h1:S1GPSBCYCIhmVNfcth17y2zZtQT6wzkzgwUve0VDWWA=
|
|
||||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
|
||||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
|
||||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
|
||||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
|
||||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
|
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/qianbin/directcache v0.9.7 h1:DH6MdmU0fVjcKry57ju7U6akTFDBnLhHd0xOHZDq948=
|
|
||||||
github.com/qianbin/directcache v0.9.7/go.mod h1:gZBpa9NqO1Qz7wZKO7t7atBA76bT8X0eM01PdveW4qc=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
|
||||||
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
|
||||||
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
|
||||||
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
|
|
||||||
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
|
|
||||||
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 h1:k5II8e6QD8mITdi+okbbmR/cIyEbeXLBhy5Ha4nevyc=
|
|
||||||
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
|
|||||||
}
|
}
|
||||||
|
|
||||||
filenameV2, linkFragment := davextra.ExtractLinkFragment(filename)
|
filenameV2, linkFragment := davextra.ExtractLinkFragment(filename)
|
||||||
link := findLinkByFragment(torrents, filenameV2, linkFragment)
|
link := getLink(torrents, filenameV2, linkFragment)
|
||||||
if link == "" {
|
if link == "" {
|
||||||
log.Println("Link not found")
|
log.Println("Link not found")
|
||||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||||
@@ -50,27 +50,25 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
|
|||||||
}
|
}
|
||||||
resp := realdebrid.RetryUntilOk(unrestrictFn)
|
resp := realdebrid.RetryUntilOk(unrestrictFn)
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
// TODO: Delete the link from the database
|
// TODO: Readd the file
|
||||||
|
// when unrestricting fails, it means the file is not available anymore
|
||||||
|
// if it's the only file, tough luck
|
||||||
log.Println("Cannot unrestrict link")
|
log.Println("Cannot unrestrict link")
|
||||||
http.Error(w, "Cannot find file", http.StatusNotFound)
|
http.Error(w, "Cannot find file", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if resp.Filename != filenameV2 {
|
if resp.Filename != filenameV2 {
|
||||||
// TODO: Redo the logic to handle mismatch
|
// TODO: Redo the logic to handle mismatch
|
||||||
// Filename mismatch
|
|
||||||
// [SRS] Pokemon S22E01-35 1080p WEBRip AAC 2.0 x264 CC.rar
|
// [SRS] Pokemon S22E01-35 1080p WEBRip AAC 2.0 x264 CC.rar
|
||||||
// Pokemon.S22E24.The.Secret.Princess.DUBBED.1080p.WEBRip.AAC.2.0.x264-SRS.mkv
|
// Pokemon.S22E24.The.Secret.Princess.DUBBED.1080p.WEBRip.AAC.2.0.x264-SRS.mkv
|
||||||
// Filename mismatch
|
|
||||||
// Adventure.Time.S06E10.Something.Big.1080p.HMAX.WEBRip.DD.2.0.H.265.-EDGE2020.mkv
|
|
||||||
// Adventure.Time.S06E03.James.II.1080p.HMAX.WEBRip.DD.2.0.H.265.-EDGE2020.mkv
|
|
||||||
// Action: schedule a "cleanup" job for the parent torrent
|
// Action: schedule a "cleanup" job for the parent torrent
|
||||||
log.Println("Filename mismatch", resp.Filename, filenameV2)
|
log.Println("Filename mismatch", resp.Filename, filenameV2)
|
||||||
}
|
}
|
||||||
http.Redirect(w, r, resp.Download, http.StatusFound)
|
http.Redirect(w, r, resp.Download, http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
// findLinkByFragment finds a link by a fragment, it might be wrong
|
// getLink finds a link by a fragment, it might be wrong
|
||||||
func findLinkByFragment(torrents []torrent.Torrent, filename, fragment string) string {
|
func getLink(torrents []torrent.Torrent, filename, fragment string) string {
|
||||||
for _, torrent := range torrents {
|
for _, torrent := range torrents {
|
||||||
for _, file := range torrent.SelectedFiles {
|
for _, file := range torrent.SelectedFiles {
|
||||||
fname := filepath.Base(file.Path)
|
fname := filepath.Base(file.Path)
|
||||||
|
|||||||
@@ -51,32 +51,32 @@ func handleRoot(w http.ResponseWriter, r *http.Request) ([]byte, error) {
|
|||||||
|
|
||||||
// handleListOfTorrents handles a PROPFIND request to the /torrents directory
|
// handleListOfTorrents handles a PROPFIND request to the /torrents directory
|
||||||
func handleListOfTorrents(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) ([]byte, error) {
|
func handleListOfTorrents(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) ([]byte, error) {
|
||||||
allTorrents := t.GetAll()
|
torrents := t.GetAll()
|
||||||
allTorrentsResponse, err := createMultiTorrentResponse(allTorrents)
|
resp, err := createMultiTorrentResponse(torrents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot read directory (/torrents): %v\n", err.Error())
|
log.Printf("Cannot read directory (/torrents): %v\n", err.Error())
|
||||||
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return xml.MarshalIndent(allTorrentsResponse, "", " ")
|
return xml.MarshalIndent(resp, "", " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleSingleTorrent handles a PROPFIND request to a single torrent directory
|
// handleSingleTorrent handles a PROPFIND request to a single torrent directory
|
||||||
func handleSingleTorrent(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) ([]byte, error) {
|
func handleSingleTorrent(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) ([]byte, error) {
|
||||||
requestPath := path.Clean(r.URL.Path)
|
requestPath := path.Clean(r.URL.Path)
|
||||||
torrentName := path.Base(requestPath)
|
torrentName := path.Base(requestPath)
|
||||||
foundTorrents := findAllTorrentsWithName(t, torrentName)
|
torrents := findAllTorrentsWithName(t, torrentName)
|
||||||
if len(foundTorrents) == 0 {
|
if len(torrents) == 0 {
|
||||||
log.Println("Cannot find directory", requestPath)
|
log.Println("Cannot find directory", requestPath)
|
||||||
http.Error(w, "Cannot find directory", http.StatusNotFound)
|
http.Error(w, "Cannot find directory", http.StatusNotFound)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
var torrentResponse *dav.MultiStatus
|
var resp *dav.MultiStatus
|
||||||
torrentResponse, err := createCombinedTorrentResponse(foundTorrents, t)
|
resp, err := createCombinedTorrentResponse(torrents, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot read directory (%s): %v\n", requestPath, err.Error())
|
log.Printf("Cannot read directory (%s): %v\n", requestPath, err.Error())
|
||||||
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
http.Error(w, "Cannot read directory", http.StatusInternalServerError)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return xml.MarshalIndent(torrentResponse, "", " ")
|
return xml.MarshalIndent(resp, "", " ")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user