mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 19:36:36 +08:00
b9b7b7052a
- Organizer: add move/copy/hardlink/symlink transfer modes (default move), per-request target_path/transfer_mode overrides, and honor organize.target_dir / organize.transfer_mode settings. - keep_seeding (default on): escalate move->hardlink (cross-device->copy) so the qBittorrent source stays in place and continues seeding after organize. - qBittorrent SetLocation + POST /downloads/relocate to migrate whole torrents while keeping them seeding. - Scanner: FileID (device:inode) hardlink dedup to avoid duplicate recognition and double-counted storage; extract single-file ingest. - Watcher: recursive watch + incremental per-file ingest/remove instead of full re-scan; periodic full library scan now gated behind scan.periodic_enabled (default off) to reduce disk wear. - Telegram bot: handle callback_query in polling, declare allowed_updates in webhook, answer callbacks. - Frontend: settings for transfer mode / keep_seeding / periodic scan; organize panel target dir + transfer mode overrides. - Tests for transfer modes, organizer resolution, SetLocation, inode dedup, incremental ingest/remove. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
// Package handler — media file organizer endpoints.
|
|
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/ShukeBta/MediaStationGo/internal/service"
|
|
)
|
|
|
|
// organizeReq carries optional per-request overrides. 留空则沿用系统设置。
|
|
type organizeReq struct {
|
|
TargetPath string `json:"target_path"`
|
|
TransferMode string `json:"transfer_mode"`
|
|
}
|
|
|
|
// bindOrganizeOptions parses the optional JSON body into OrganizeOptions.
|
|
// A missing/empty body is fine — it means "use the configured defaults".
|
|
func bindOrganizeOptions(c *gin.Context) service.OrganizeOptions {
|
|
var req organizeReq
|
|
_ = c.ShouldBindJSON(&req)
|
|
opts := service.OrganizeOptions{TargetPath: strings.TrimSpace(req.TargetPath)}
|
|
if m := strings.TrimSpace(req.TransferMode); m != "" {
|
|
opts.TransferMode = service.TransferMode(m)
|
|
}
|
|
return opts
|
|
}
|
|
|
|
func organizeMediaHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
opts := bindOrganizeOptions(c)
|
|
dst, err := svc.Organizer.OrganizeMediaWithOptions(c.Request.Context(), c.Param("id"), opts)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"path": dst})
|
|
}
|
|
}
|
|
|
|
func organizeLibraryHandler(svc *service.Container) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
opts := bindOrganizeOptions(c)
|
|
res, err := svc.Organizer.OrganizeLibraryWithOptions(c.Request.Context(), c.Param("id"), opts)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, res)
|
|
}
|
|
}
|