Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/settings/btsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type BTSets struct {
UseDisk bool
TorrentsSavePath string
RemoveCacheOnDrop bool
OneCacheForAll bool

// Torrent
ForceEncrypt bool
Expand Down
12 changes: 10 additions & 2 deletions server/torr/storage/torrstor/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (c *Cache) GetState() *state.CacheState {
return cState
}

func (c *Cache) cleanPieces() {
func (c *Cache) doCleanPieces() {
if c.isRemove || c.isClosed {
return
}
Expand All @@ -197,8 +197,8 @@ func (c *Cache) cleanPieces() {
defer func() { c.isRemove = false }()
c.muRemove.Unlock()

remPieces := c.getRemPieces()
if c.filled > c.capacity {
remPieces := c.getRemPieces()
rems := (c.filled-c.capacity)/c.pieceLength + 1
for _, p := range remPieces {
c.removePiece(p)
Expand All @@ -211,6 +211,14 @@ func (c *Cache) cleanPieces() {
}
}

func (c *Cache) cleanPieces() {
if settings.BTsets.OneCacheForAll {
c.storage.cleanPieces()
} else {
c.doCleanPieces()
}
}

func (c *Cache) getRemPieces() []*Piece {
piecesRemove := make([]*Piece, 0)
fill := int64(0)
Expand Down
54 changes: 53 additions & 1 deletion server/torr/storage/torrstor/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package torrstor

import (
"sync"

"slices"
"os"
"path/filepath"
"server/torr/storage"
"server/settings"

"github.com/anacrolix/torrent/metainfo"
ts "github.com/anacrolix/torrent/storage"
Expand Down Expand Up @@ -70,3 +73,52 @@ func (s *Storage) GetCache(hash metainfo.Hash) *Cache {
}
return nil
}

func (s *Storage) cleanPieces() {
s.mu.Lock()
defer s.mu.Unlock()
var filled int64 = 0
for _, ch := range s.caches {
filled += ch.filled
}
overfill := filled - s.capacity
if overfill < 0 {
return
}
sortCachesByModifiedDate := func(a, b *Cache) int {
aname := filepath.Join(settings.BTsets.TorrentsSavePath, a.hash.HexString())
bname := filepath.Join(settings.BTsets.TorrentsSavePath, b.hash.HexString())
ainfo, err := os.Stat(aname)
if err != nil {
return -1
}
binfo, err := os.Stat(bname)
if err != nil {
return 1
}
return ainfo.ModTime().Compare(binfo.ModTime())
}
nonempty := slices.Values(slices.Collect(func(yield func(*Cache) bool) {
for _, c := range s.caches {
if c.filled > 0 {
if !yield(c) {
return
}
}
}
}))
// fill sortedcaches with refs to non-empty caches sorted by respective
// folder modified date in descending order (older first)
sortedcaches := slices.SortedFunc(nonempty, sortCachesByModifiedDate)
for _, c := range sortedcaches {
_cap := c.capacity
c.capacity = max(c.filled - overfill, 0)
overfill -= c.filled
c.doCleanPieces()
overfill += c.filled
c.capacity = _cap
if overfill <= 0 {
return
}
}
}
20 changes: 10 additions & 10 deletions server/web/pages/template/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ var Mstile150x150png []byte
//go:embed pages/site.webmanifest
var Sitewebmanifest []byte

//go:embed pages/static/js/2.17225dbd.chunk.js
var Staticjs217225dbdchunkjs []byte
//go:embed pages/static/js/2.f2fe60bf.chunk.js
var Staticjs2f2fe60bfchunkjs []byte

//go:embed pages/static/js/2.17225dbd.chunk.js.LICENSE.txt
var Staticjs217225dbdchunkjsLICENSEtxt []byte
//go:embed pages/static/js/2.f2fe60bf.chunk.js.LICENSE.txt
var Staticjs2f2fe60bfchunkjsLICENSEtxt []byte

//go:embed pages/static/js/2.17225dbd.chunk.js.map
var Staticjs217225dbdchunkjsmap []byte
//go:embed pages/static/js/2.f2fe60bf.chunk.js.map
var Staticjs2f2fe60bfchunkjsmap []byte

//go:embed pages/static/js/main.c7b9a3c5.chunk.js
var Staticjsmainc7b9a3c5chunkjs []byte
//go:embed pages/static/js/main.95752178.chunk.js
var Staticjsmain95752178chunkjs []byte

//go:embed pages/static/js/main.c7b9a3c5.chunk.js.map
var Staticjsmainc7b9a3c5chunkjsmap []byte
//go:embed pages/static/js/main.95752178.chunk.js.map
var Staticjsmain95752178chunkjsmap []byte

//go:embed pages/static/js/runtime-main.5ed86a79.js
var Staticjsruntimemain5ed86a79js []byte
Expand Down
16 changes: 8 additions & 8 deletions server/web/pages/template/pages/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"files": {
"main.js": "./static/js/main.c7b9a3c5.chunk.js",
"main.js.map": "./static/js/main.c7b9a3c5.chunk.js.map",
"main.js": "./static/js/main.95752178.chunk.js",
"main.js.map": "./static/js/main.95752178.chunk.js.map",
"runtime-main.js": "./static/js/runtime-main.5ed86a79.js",
"runtime-main.js.map": "./static/js/runtime-main.5ed86a79.js.map",
"static/js/2.17225dbd.chunk.js": "./static/js/2.17225dbd.chunk.js",
"static/js/2.17225dbd.chunk.js.map": "./static/js/2.17225dbd.chunk.js.map",
"static/js/2.f2fe60bf.chunk.js": "./static/js/2.f2fe60bf.chunk.js",
"static/js/2.f2fe60bf.chunk.js.map": "./static/js/2.f2fe60bf.chunk.js.map",
"index.html": "./index.html",
"static/js/2.17225dbd.chunk.js.LICENSE.txt": "./static/js/2.17225dbd.chunk.js.LICENSE.txt"
"static/js/2.f2fe60bf.chunk.js.LICENSE.txt": "./static/js/2.f2fe60bf.chunk.js.LICENSE.txt"
},
"entrypoints": [
"static/js/runtime-main.5ed86a79.js",
"static/js/2.17225dbd.chunk.js",
"static/js/main.c7b9a3c5.chunk.js"
"static/js/2.f2fe60bf.chunk.js",
"static/js/main.95752178.chunk.js"
]
}
}
3 changes: 2 additions & 1 deletion server/web/pages/template/pages/index.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions server/web/pages/template/pages/static/js/2.f2fe60bf.chunk.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions server/web/pages/template/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,39 +301,39 @@ func RouteWebPages(route gin.IRouter) {
c.Data(200, "application/manifest+json", Sitewebmanifest)
})

route.GET("/static/js/2.17225dbd.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs217225dbdchunkjs))
route.GET("/static/js/2.f2fe60bf.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2f2fe60bfchunkjs))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/javascript; charset=utf-8", Staticjs217225dbdchunkjs)
c.Data(200, "text/javascript; charset=utf-8", Staticjs2f2fe60bfchunkjs)
})

route.GET("/static/js/2.17225dbd.chunk.js.LICENSE.txt", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs217225dbdchunkjsLICENSEtxt))
route.GET("/static/js/2.f2fe60bf.chunk.js.LICENSE.txt", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2f2fe60bfchunkjsLICENSEtxt))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "text/plain; charset=utf-8", Staticjs217225dbdchunkjsLICENSEtxt)
c.Data(200, "text/plain; charset=utf-8", Staticjs2f2fe60bfchunkjsLICENSEtxt)
})

route.GET("/static/js/2.17225dbd.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs217225dbdchunkjsmap))
route.GET("/static/js/2.f2fe60bf.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2f2fe60bfchunkjsmap))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/json", Staticjs217225dbdchunkjsmap)
c.Data(200, "application/json", Staticjs2f2fe60bfchunkjsmap)
})

route.GET("/static/js/main.c7b9a3c5.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmainc7b9a3c5chunkjs))
route.GET("/static/js/main.95752178.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmain95752178chunkjs))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/javascript; charset=utf-8", Staticjsmainc7b9a3c5chunkjs)
c.Data(200, "text/javascript; charset=utf-8", Staticjsmain95752178chunkjs)
})

route.GET("/static/js/main.c7b9a3c5.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmainc7b9a3c5chunkjsmap))
route.GET("/static/js/main.95752178.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmain95752178chunkjsmap))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/json", Staticjsmainc7b9a3c5chunkjsmap)
c.Data(200, "application/json", Staticjsmain95752178chunkjsmap)
})

route.GET("/static/js/runtime-main.5ed86a79.js", func(c *gin.Context) {
Expand Down
13 changes: 12 additions & 1 deletion web/src/components/Settings/PrimarySettingsComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function PrimarySettingsComponent({
updateSettings,
}) {
const { t } = useTranslation()
const { UseDisk, TorrentsSavePath, RemoveCacheOnDrop } = settings || {}
const { UseDisk, TorrentsSavePath, RemoveCacheOnDrop, OneCacheForAll } = settings || {}
const preloadCacheSize = Math.round((cacheSize / 100) * preloadCachePercentage)

return (
Expand Down Expand Up @@ -140,6 +140,17 @@ export default function PrimarySettingsComponent({
<small>{t('SettingsDialog.RemoveCacheOnDropDesc')}</small>
</div>
<br />
<FormControlLabel
control={
<Switch checked={OneCacheForAll} onChange={inputForm} id='OneCacheForAll' color='secondary' />
}
label={t('SettingsDialog.OneCacheForAll')}
labelPlacement='start'
/>
<div>
<small>{t('SettingsDialog.OneCacheForAllDesc')}</small>
</div>
<br />
<TextField
onChange={inputForm}
margin='normal'
Expand Down
1 change: 1 addition & 0 deletions web/src/components/Settings/defaultSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
UseDisk: false,
TorrentsSavePath: '',
RemoveCacheOnDrop: false,
OneCacheForAll: false,
ForceEncrypt: false,
RetrackersMode: 1,
TorrentDisconnectTimeout: 30,
Expand Down
4 changes: 3 additions & 1 deletion web/src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@
"FriendlyName": "DLNA Server Name",
"FriendlyNameHint": "Leave blank to use default",
"JsonFile": "JSON File",
"MobileAppSettings": "Players",
"MobileAppSettings": "Mobile app settings",
"OneCacheForAll": "Apply Cache Size for All Torrents' Caches",
"OneCacheForAllDesc": "If disabled Cache Size applies to individual torrents' caches",
"PeersListenPort": "Peers Listen Port",
"PeersListenPortHint": "1024 - 65535, 0 - random",
"PreloadCache": "Preload Cache Before Play",
Expand Down
4 changes: 3 additions & 1 deletion web/src/locales/ru/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@
"FriendlyName": "Имя сервера DLNA",
"FriendlyNameHint": "Оставьте пустым, чтобы использовать значение по умолчанию.",
"JsonFile": "JSON-файл",
"MobileAppSettings": "Плееры",
"MobileAppSettings": "Настройки приложения",
"OneCacheForAll": "Ограничивать общий рамер всех кешей всех торрентов",
"OneCacheForAllDesc": "Если отключено, ограничение размера кеша применяется к каждому торренту в отдельности",
"PeersListenPort": "Порт для входящих подключений",
"PeersListenPortHint": "1024 - 65535, 0 - авто",
"PreloadCache": "Буфер предзагрузки",
Expand Down