- Revamp decypharr arch \n
- Add callback_ur, download_folder to addContent API \n - Fix few bugs \n - More declarative UI keywords - Speed up repairs - Few other improvements/bug fixes
This commit is contained in:
+4
-4
@@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sirrobot01/decypharr/pkg/debrid/debrid"
|
||||
"github.com/sirrobot01/decypharr/pkg/debrid/store"
|
||||
)
|
||||
|
||||
var sharedClient = &http.Client{
|
||||
@@ -28,7 +28,7 @@ var sharedClient = &http.Client{
|
||||
}
|
||||
|
||||
type File struct {
|
||||
cache *debrid.Cache
|
||||
cache *store.Cache
|
||||
fileId string
|
||||
torrentName string
|
||||
|
||||
@@ -128,7 +128,7 @@ func (f *File) stream() (*http.Response, error) {
|
||||
|
||||
cleanupResp := func() {
|
||||
if resp.Body != nil {
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
_, _ = io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func (f *File) stream() (*http.Response, error) {
|
||||
if newResp.StatusCode != http.StatusOK && newResp.StatusCode != http.StatusPartialContent {
|
||||
cleanupBody := func() {
|
||||
if newResp.Body != nil {
|
||||
io.Copy(io.Discard, newResp.Body)
|
||||
_, _ = io.Copy(io.Discard, newResp.Body)
|
||||
newResp.Body.Close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package webdav
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/sirrobot01/decypharr/pkg/debrid/types"
|
||||
"golang.org/x/net/webdav"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
@@ -15,21 +17,19 @@ import (
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/sirrobot01/decypharr/internal/utils"
|
||||
"github.com/sirrobot01/decypharr/pkg/debrid/debrid"
|
||||
"github.com/sirrobot01/decypharr/pkg/debrid/types"
|
||||
"github.com/sirrobot01/decypharr/pkg/debrid/store"
|
||||
"github.com/sirrobot01/decypharr/pkg/version"
|
||||
"golang.org/x/net/webdav"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
Name string
|
||||
logger zerolog.Logger
|
||||
cache *debrid.Cache
|
||||
cache *store.Cache
|
||||
URLBase string
|
||||
RootPath string
|
||||
}
|
||||
|
||||
func NewHandler(name, urlBase string, cache *debrid.Cache, logger zerolog.Logger) *Handler {
|
||||
func NewHandler(name, urlBase string, cache *store.Cache, logger zerolog.Logger) *Handler {
|
||||
h := &Handler{
|
||||
Name: name,
|
||||
cache: cache,
|
||||
@@ -191,7 +191,7 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
|
||||
}
|
||||
name = utils.PathUnescape(path.Clean(name))
|
||||
rootDir := path.Clean(h.RootPath)
|
||||
metadataOnly := ctx.Value("metadataOnly") != nil
|
||||
metadataOnly := ctx.Value(metadataOnlyKey) != nil
|
||||
now := time.Now()
|
||||
|
||||
// 1) special case version.txt
|
||||
@@ -490,7 +490,7 @@ func (h *Handler) handleGet(w http.ResponseWriter, r *http.Request) {
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
io.Copy(w, fRaw)
|
||||
_, _ = io.Copy(w, fRaw)
|
||||
}()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
+1
-3
@@ -84,9 +84,7 @@ func filesToXML(urlPath string, fi os.FileInfo, children []os.FileInfo) stringbu
|
||||
})
|
||||
}
|
||||
|
||||
sb := builderPool.Get().(stringbuf.StringBuf)
|
||||
sb.Reset()
|
||||
defer builderPool.Put(sb)
|
||||
sb := stringbuf.New("")
|
||||
|
||||
// XML header and main element
|
||||
_, _ = sb.WriteString(`<?xml version="1.0" encoding="UTF-8"?>`)
|
||||
|
||||
+7
-11
@@ -8,21 +8,19 @@ import (
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var builderPool = sync.Pool{
|
||||
type contextKey string
|
||||
|
||||
New: func() interface{} {
|
||||
buf := stringbuf.New("")
|
||||
return buf
|
||||
},
|
||||
}
|
||||
const (
|
||||
// metadataOnlyKey is used to indicate that the request is for metadata only
|
||||
metadataOnlyKey contextKey = "metadataOnly"
|
||||
)
|
||||
|
||||
func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) {
|
||||
// Setup context for metadata only
|
||||
ctx := context.WithValue(r.Context(), "metadataOnly", true)
|
||||
ctx := context.WithValue(r.Context(), metadataOnlyKey, true)
|
||||
r = r.WithContext(ctx)
|
||||
|
||||
cleanPath := path.Clean(r.URL.Path)
|
||||
@@ -85,9 +83,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
sb := builderPool.Get().(stringbuf.StringBuf)
|
||||
sb.Reset()
|
||||
defer builderPool.Put(sb)
|
||||
sb := stringbuf.New("")
|
||||
|
||||
// XML header and main element
|
||||
_, _ = sb.WriteString(`<?xml version="1.0" encoding="UTF-8"?>`)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/sirrobot01/decypharr/internal/config"
|
||||
"github.com/sirrobot01/decypharr/pkg/service"
|
||||
"github.com/sirrobot01/decypharr/pkg/store"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -90,13 +90,12 @@ type WebDav struct {
|
||||
}
|
||||
|
||||
func New() *WebDav {
|
||||
svc := service.GetService()
|
||||
urlBase := config.Get().URLBase
|
||||
w := &WebDav{
|
||||
Handlers: make([]*Handler, 0),
|
||||
URLBase: urlBase,
|
||||
}
|
||||
for name, c := range svc.Debrid.Caches {
|
||||
for name, c := range store.GetStore().GetDebrid().GetCaches() {
|
||||
h := NewHandler(name, urlBase, c, c.GetLogger())
|
||||
w.Handlers = append(w.Handlers, h)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user