Some improvements to beta
This commit is contained in:
@@ -211,7 +211,7 @@ func (r *RealDebrid) handleRarArchive(t *types.Torrent, data torrentInfo, select
|
|||||||
fileMap := make(map[string]*types.File)
|
fileMap := make(map[string]*types.File)
|
||||||
for i := range selectedFiles {
|
for i := range selectedFiles {
|
||||||
// RD converts special chars to '_' for RAR file paths
|
// RD converts special chars to '_' for RAR file paths
|
||||||
// TOOD: there might be more special chars to replace
|
// @TODO: there might be more special chars to replace
|
||||||
safeName := strings.NewReplacer("|", "_", "\"", "_", "\\", "_", "?", "_", "*", "_", ":", "_", "<", "_", ">", "_").Replace(selectedFiles[i].Name)
|
safeName := strings.NewReplacer("|", "_", "\"", "_", "\\", "_", "?", "_", "*", "_", ":", "_", "<", "_", ">", "_").Replace(selectedFiles[i].Name)
|
||||||
fileMap[safeName] = &selectedFiles[i]
|
fileMap[safeName] = &selectedFiles[i]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -228,11 +228,14 @@ func (c *Cache) Start(ctx context.Context) error {
|
|||||||
return fmt.Errorf("failed to create cache directory: %w", err)
|
return fmt.Errorf("failed to create cache directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.logger.Info().Msgf("Started indexing...")
|
||||||
|
|
||||||
if err := c.Sync(ctx); err != nil {
|
if err := c.Sync(ctx); err != nil {
|
||||||
return fmt.Errorf("failed to sync cache: %w", err)
|
return fmt.Errorf("failed to sync cache: %w", err)
|
||||||
}
|
}
|
||||||
// Fire the ready channel
|
// Fire the ready channel
|
||||||
close(c.ready)
|
close(c.ready)
|
||||||
|
c.logger.Info().Msgf("Indexing complete, %d torrents loaded", len(c.torrents.getAll()))
|
||||||
|
|
||||||
// initial download links
|
// initial download links
|
||||||
go c.refreshDownloadLinks(ctx)
|
go c.refreshDownloadLinks(ctx)
|
||||||
@@ -241,7 +244,7 @@ func (c *Cache) Start(ctx context.Context) error {
|
|||||||
c.logger.Error().Err(err).Msg("Failed to start cache worker")
|
c.logger.Error().Err(err).Msg("Failed to start cache worker")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.repairChan = make(chan RepairRequest, 100)
|
c.repairChan = make(chan RepairRequest, 100) // Initialize the repair channel, max 100 requests buffered
|
||||||
go c.repairWorker(ctx)
|
go c.repairWorker(ctx)
|
||||||
|
|
||||||
cfg := config.Get()
|
cfg := config.Get()
|
||||||
@@ -398,9 +401,11 @@ func (c *Cache) Sync(ctx context.Context) error {
|
|||||||
if len(deletedTorrents) > 0 {
|
if len(deletedTorrents) > 0 {
|
||||||
c.logger.Info().Msgf("Found %d deleted torrents", len(deletedTorrents))
|
c.logger.Info().Msgf("Found %d deleted torrents", len(deletedTorrents))
|
||||||
for _, id := range deletedTorrents {
|
for _, id := range deletedTorrents {
|
||||||
if _, ok := cachedTorrents[id]; ok {
|
// Remove from cache and debrid service
|
||||||
c.deleteTorrent(id, false) // delete from cache
|
delete(cachedTorrents, id)
|
||||||
}
|
// Remove the json file from disk
|
||||||
|
c.removeFile(id, false)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,13 +757,13 @@ func (c *Cache) deleteTorrent(id string, removeFromDebrid bool) bool {
|
|||||||
if torrent, ok := c.torrents.getByID(id); ok {
|
if torrent, ok := c.torrents.getByID(id); ok {
|
||||||
c.torrents.removeId(id) // Delete id from cache
|
c.torrents.removeId(id) // Delete id from cache
|
||||||
defer func() {
|
defer func() {
|
||||||
c.removeFromDB(id)
|
c.removeFile(id, false)
|
||||||
if removeFromDebrid {
|
if removeFromDebrid {
|
||||||
_ = c.client.DeleteTorrent(id) // Skip error handling, we don't care if it fails
|
_ = c.client.DeleteTorrent(id) // Skip error handling, we don't care if it fails
|
||||||
}
|
}
|
||||||
}() // defer delete from debrid
|
}() // defer delete from debrid
|
||||||
|
|
||||||
torrentName := torrent.Name
|
torrentName := c.GetTorrentFolder(torrent.Torrent)
|
||||||
|
|
||||||
if t, ok := c.torrents.getByName(torrentName); ok {
|
if t, ok := c.torrents.getByName(torrentName); ok {
|
||||||
|
|
||||||
@@ -795,7 +800,7 @@ func (c *Cache) DeleteTorrents(ids []string) {
|
|||||||
c.listingDebouncer.Call(true)
|
c.listingDebouncer.Call(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) removeFromDB(torrentId string) {
|
func (c *Cache) removeFile(torrentId string, moveToTrash bool) {
|
||||||
// Moves the torrent file to the trash
|
// Moves the torrent file to the trash
|
||||||
filePath := filepath.Join(c.dir, torrentId+".json")
|
filePath := filepath.Join(c.dir, torrentId+".json")
|
||||||
|
|
||||||
@@ -804,6 +809,14 @@ func (c *Cache) removeFromDB(torrentId string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !moveToTrash {
|
||||||
|
// If not moving to trash, delete the file directly
|
||||||
|
if err := os.Remove(filePath); err != nil {
|
||||||
|
c.logger.Error().Err(err).Msgf("Failed to remove file: %s", filePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
// Move the file to the trash
|
// Move the file to the trash
|
||||||
trashPath := filepath.Join(c.dir, "trash", torrentId+".json")
|
trashPath := filepath.Join(c.dir, "trash", torrentId+".json")
|
||||||
if err := os.MkdirAll(filepath.Dir(trashPath), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(trashPath), 0755); err != nil {
|
||||||
|
|||||||
+1
-1
@@ -276,7 +276,7 @@ func (q *QBit) handleAddTorrentTags(w http.ResponseWriter, r *http.Request) {
|
|||||||
request.JSONResponse(w, nil, http.StatusOK)
|
request.JSONResponse(w, nil, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *QBit) handleremoveTorrentTags(w http.ResponseWriter, r *http.Request) {
|
func (q *QBit) handleRemoveTorrentTags(w http.ResponseWriter, r *http.Request) {
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to parse form data", http.StatusBadRequest)
|
http.Error(w, "Failed to parse form data", http.StatusBadRequest)
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ func (q *QBit) Routes() http.Handler {
|
|||||||
r.Post("/createCategory", q.handleCreateCategory)
|
r.Post("/createCategory", q.handleCreateCategory)
|
||||||
r.Post("/setCategory", q.handleSetCategory)
|
r.Post("/setCategory", q.handleSetCategory)
|
||||||
r.Post("/addTags", q.handleAddTorrentTags)
|
r.Post("/addTags", q.handleAddTorrentTags)
|
||||||
r.Post("/removeTags", q.handleremoveTorrentTags)
|
r.Post("/removeTags", q.handleRemoveTorrentTags)
|
||||||
r.Post("/createTags", q.handleCreateTags)
|
r.Post("/createTags", q.handleCreateTags)
|
||||||
r.Get("/tags", q.handleGetTags)
|
r.Get("/tags", q.handleGetTags)
|
||||||
r.Get("/pause", q.handleTorrentsPause)
|
r.Get("/pause", q.handleTorrentsPause)
|
||||||
|
|||||||
@@ -135,8 +135,3 @@ func (q *QBit) addTags(tags []string) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *QBit) removeTags(tags []string) bool {
|
|
||||||
q.Tags = utils.RemoveItem(q.Tags, tags...)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|||||||
+9
-11
@@ -439,9 +439,9 @@ func (r *Repair) repairArr(job *Job, _arr string, tmdbId string) ([]arr.ContentF
|
|||||||
return brokenItems, nil
|
return brokenItems, nil
|
||||||
}
|
}
|
||||||
// Check first media to confirm mounts are accessible
|
// Check first media to confirm mounts are accessible
|
||||||
if !r.isMediaAccessible(media) {
|
if err := r.checkMountUp(media); err != nil {
|
||||||
r.logger.Info().Msgf("Skipping repair. Parent directory not accessible. Check your mounts")
|
r.logger.Error().Err(err).Msgf("Mount check failed for %s", a.Name)
|
||||||
return brokenItems, nil
|
return brokenItems, fmt.Errorf("mount check failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mutex for brokenItems
|
// Mutex for brokenItems
|
||||||
@@ -504,8 +504,8 @@ func (r *Repair) repairArr(job *Job, _arr string, tmdbId string) ([]arr.ContentF
|
|||||||
return brokenItems, nil
|
return brokenItems, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// isMediaAccessible checks if the mounts are accessible
|
// checkMountUp checks if the mounts are accessible
|
||||||
func (r *Repair) isMediaAccessible(media []arr.Content) bool {
|
func (r *Repair) checkMountUp(media []arr.Content) error {
|
||||||
firstMedia := media[0]
|
firstMedia := media[0]
|
||||||
for _, m := range media {
|
for _, m := range media {
|
||||||
if len(m.Files) > 0 {
|
if len(m.Files) > 0 {
|
||||||
@@ -515,23 +515,21 @@ func (r *Repair) isMediaAccessible(media []arr.Content) bool {
|
|||||||
}
|
}
|
||||||
files := firstMedia.Files
|
files := firstMedia.Files
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
return false
|
return fmt.Errorf("no files found in media %s", firstMedia.Title)
|
||||||
}
|
}
|
||||||
firstFile := files[0]
|
firstFile := files[0]
|
||||||
symlinkPath := getSymlinkTarget(firstFile.Path)
|
symlinkPath := getSymlinkTarget(firstFile.Path)
|
||||||
|
|
||||||
if symlinkPath == "" {
|
if symlinkPath == "" {
|
||||||
r.logger.Debug().Msgf("No symlink target found for %s", firstFile.Path)
|
return fmt.Errorf("no symlink target found for %s", firstFile.Path)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
r.logger.Debug().Msgf("Checking symlink parent directory for %s", symlinkPath)
|
r.logger.Debug().Msgf("Checking symlink parent directory for %s", symlinkPath)
|
||||||
|
|
||||||
parentSymlink := filepath.Dir(filepath.Dir(symlinkPath)) // /mnt/zurg/torrents/movie/movie.mkv -> /mnt/zurg/torrents
|
parentSymlink := filepath.Dir(filepath.Dir(symlinkPath)) // /mnt/zurg/torrents/movie/movie.mkv -> /mnt/zurg/torrents
|
||||||
if _, err := os.Stat(parentSymlink); os.IsNotExist(err) {
|
if _, err := os.Stat(parentSymlink); os.IsNotExist(err) {
|
||||||
r.logger.Debug().Msgf("Cannot access parent directory %s for %s", parentSymlink, firstFile.Path)
|
return fmt.Errorf("parent directory %s not accessible for %s", parentSymlink, firstFile.Path)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repair) getBrokenFiles(job *Job, media arr.Content) []arr.ContentFile {
|
func (r *Repair) getBrokenFiles(job *Job, media arr.Content) []arr.ContentFile {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ type File struct {
|
|||||||
reader io.ReadCloser
|
reader io.ReadCloser
|
||||||
seekPending bool
|
seekPending bool
|
||||||
content []byte
|
content []byte
|
||||||
|
isRar bool
|
||||||
name string
|
name string
|
||||||
metadataOnly bool
|
metadataOnly bool
|
||||||
|
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ func (h *Handler) OpenFile(ctx context.Context, name string, flag int, perm os.F
|
|||||||
size: file.Size,
|
size: file.Size,
|
||||||
link: file.Link,
|
link: file.Link,
|
||||||
metadataOnly: metadataOnly,
|
metadataOnly: metadataOnly,
|
||||||
|
isRar: file.IsRar,
|
||||||
modTime: cached.AddedOn,
|
modTime: cached.AddedOn,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -409,6 +410,8 @@ func (h *Handler) serveDirectory(w http.ResponseWriter, r *http.Request, file we
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
|
||||||
func (h *Handler) handleGet(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) handleGet(w http.ResponseWriter, r *http.Request) {
|
||||||
fRaw, err := h.OpenFile(r.Context(), r.URL.Path, os.O_RDONLY, 0)
|
fRaw, err := h.OpenFile(r.Context(), r.URL.Path, os.O_RDONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -458,7 +461,8 @@ func (h *Handler) handleGet(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
file.downloadLink = link
|
file.downloadLink = link
|
||||||
if h.cache.StreamWithRclone() {
|
// If the torrent file is not a RAR file and users enabled proxy streaming
|
||||||
|
if !file.isRar && h.cache.StreamWithRclone() {
|
||||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||||
w.Header().Set("Pragma", "no-cache")
|
w.Header().Set("Pragma", "no-cache")
|
||||||
w.Header().Set("Expires", "0")
|
w.Header().Set("Expires", "0")
|
||||||
|
|||||||
Reference in New Issue
Block a user