From 489bf41f6aab5dd6f223c4d7062f79c9122349a2 Mon Sep 17 00:00:00 2001 From: Daniel Shleifman Date: Mon, 23 Aug 2021 15:14:39 +0300 Subject: [PATCH 1/7] DebugMode toggle added --- .../DetailedView/index.jsx | 25 +++++++++++++++++-- .../TorrentCache/index.jsx | 11 ++++---- web/src/locales/en/translation.json | 1 + web/src/locales/ru/translation.json | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx b/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx index 4222d7d..5dc8e2b 100644 --- a/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx +++ b/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx @@ -1,4 +1,6 @@ import { useTranslation } from 'react-i18next' +import { Checkbox, FormControlLabel } from '@material-ui/core' +import { useState } from 'react' import { SectionTitle, WidgetWrapper } from '../style' import { DetailedViewCacheSection, DetailedViewWidgetSection } from './style' @@ -24,6 +26,9 @@ export default function DetailedView({ cache, }) { const { t } = useTranslation() + const [isSnakeDebugMode, setIsSnakeDebugMode] = useState( + JSON.parse(localStorage.getItem('isSnakeDebugMode')) || false, + ) return ( <> @@ -43,9 +48,25 @@ export default function DetailedView({ - {t('Cache')} +
+ {t('Cache')} + + { + setIsSnakeDebugMode(checked) + localStorage.setItem('isSnakeDebugMode', checked) + }} + /> + } + label={t('DebugMode')} + /> +
- + +
) diff --git a/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx b/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx index 99af7c9..ba21254 100644 --- a/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx +++ b/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx @@ -10,7 +10,7 @@ import getShortCacheMap from './getShortCacheMap' import { SnakeWrapper, ScrollNotification } from './style' import { createGradient, snakeSettings } from './snakeSettings' -const TorrentCache = ({ cache, isMini }) => { +const TorrentCache = ({ cache, isMini, isSnakeDebugMode }) => { const { t } = useTranslation() const [dimensions, setDimensions] = useState({ width: 0, height: 0 }) const { width } = dimensions @@ -91,16 +91,16 @@ const TorrentCache = ({ cache, isMini }) => { ctx.strokeRect(0, 0, pieceSize, pieceSize) ctx.setTransform(1, 0, 0, 1, 0, 0) - if (priority > 0) { + if (!isMini && isSnakeDebugMode && priority > 0) { let info = '' if (priority === 1) info = '*' else if (priority === 2) info = 'H' else if (priority === 3) info = 'R' else if (priority === 4) info = 'N' else if (priority === 5) info = 'A' - ctx.font = isMini ? '12px monospace' : '10px monospace' - const xpad = isMini ? pieceSize * 0.34 : pieceSize * 0.28 - const ypad = isMini ? pieceSize * 0.69 : pieceSize * 0.78 + ctx.font = '10px monospace' + const xpad = pieceSize * 0.28 + const ypad = pieceSize * 0.78 ctx.fillStyle = 'black' ctx.fillText(info, x + xpad, y + ypad) } @@ -123,6 +123,7 @@ const TorrentCache = ({ cache, isMini }) => { rangeColor, isMini, theme, + isSnakeDebugMode, ]) return ( diff --git a/web/src/locales/en/translation.json b/web/src/locales/en/translation.json index 2913290..b2eb3c9 100644 --- a/web/src/locales/en/translation.json +++ b/web/src/locales/en/translation.json @@ -33,6 +33,7 @@ "CopyHash": "Copy Hash", "CopyLink": "Copy link", "Data": "Data", + "DebugMode": "Debug mode", "Delete": "Delete", "DeleteTorrent?": "Delete Torrent?", "DeleteTorrents?": "Delete All Torrents?", diff --git a/web/src/locales/ru/translation.json b/web/src/locales/ru/translation.json index a344d3f..6208c40 100644 --- a/web/src/locales/ru/translation.json +++ b/web/src/locales/ru/translation.json @@ -33,6 +33,7 @@ "CopyHash": "Скопировать хеш", "CopyLink": "Копировать", "Data": "Данные", + "DebugMode": "Режим отладки", "Delete": "Удалить", "DeleteTorrent?": "Удалить торрент?", "DeleteTorrents?": "Удалить все торренты?", From fabd9e05f614a831f887c8f69afad19538baffaa Mon Sep 17 00:00:00 2001 From: Daniel Shleifman Date: Mon, 23 Aug 2021 16:13:51 +0300 Subject: [PATCH 2/7] hover effect added to poster in torrent card --- web/src/components/TorrentCard/style.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/src/components/TorrentCard/style.js b/web/src/components/TorrentCard/style.js index 5c14d06..142d05b 100644 --- a/web/src/components/TorrentCard/style.js +++ b/web/src/components/TorrentCard/style.js @@ -38,6 +38,12 @@ export const TorrentCardPoster = styled.div` overflow: hidden; text-align: center; cursor: pointer; + transition: 0.2s; + position: relative; + + :hover { + filter: brightness(0.7); + } ${({ isPoster, From 6775ded8ae9847da08874ff400f630df7aa32d1a Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Mon, 23 Aug 2021 20:27:17 +0300 Subject: [PATCH 3/7] update log --- server/cmd/main.go | 2 +- server/cmd/preconfig_pos.go | 7 +++++-- server/log/log.go | 2 +- server/torr/apihelper.go | 10 ++++++++-- server/torr/stream.go | 20 ++++++++++++-------- server/web/server.go | 2 +- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/server/cmd/main.go b/server/cmd/main.go index 43cf2e4..a7d9c67 100644 --- a/server/cmd/main.go +++ b/server/cmd/main.go @@ -55,7 +55,7 @@ func main() { settings.HttpAuth = params.HttpAuth log.Init(params.LogPath, params.WebLogPath) fmt.Println("=========== START ===========") - fmt.Println("Build Go version:", runtime.Version()) + fmt.Println("TorrServer", version.Version+",", runtime.Version()) if params.HttpAuth { log.TLogln("Use HTTP Auth file", settings.Path+"/accs.db") } diff --git a/server/cmd/preconfig_pos.go b/server/cmd/preconfig_pos.go index e3aa953..44b8e8b 100644 --- a/server/cmd/preconfig_pos.go +++ b/server/cmd/preconfig_pos.go @@ -8,6 +8,7 @@ import ( "syscall" "server/log" + "server/settings" ) func Preconfig(dkill bool) { @@ -22,8 +23,10 @@ func Preconfig(dkill bool) { go func() { for s := range sigc { if dkill { - log.TLogln("Signal catched:", s) - log.TLogln("To stop server, close it from web / api") + if (settings.BTsets.EnableDebug || s != syscall.SIGPIPE) { + log.TLogln("Signal catched:", s) + log.TLogln("To stop server, close it from web / api") + } } } }() diff --git a/server/log/log.go b/server/log/log.go index 9030bf5..6720534 100644 --- a/server/log/log.go +++ b/server/log/log.go @@ -50,7 +50,7 @@ func Init(path, webpath string) { //https://stackoverflow.com/a/36140590 //fmt.Print(time.Now().UTC().Format("2006-01-02T15:04:05.999Z") + " TLOG " + string(bytes)) log.SetFlags(log.Ldate|log.Ltime|log.LUTC|log.Lmsgprefix) - log.SetPrefix("0000 TLOG ") + log.SetPrefix("UTC0 TLOG ") log.SetOutput(ff) } } diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index 7752654..1eb3782 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -214,7 +214,7 @@ func SetSettings(set *sets.BTSets) { } lockApi.Lock() defer lockApi.Unlock() - log.TLogln("drop all") + log.TLogln("drop all torrents") dropAllTorrent() time.Sleep(time.Second * 2) log.TLogln("disconect") @@ -222,6 +222,7 @@ func SetSettings(set *sets.BTSets) { sets.SetBTSets(set) log.TLogln("connect") bts.Connect() + time.Sleep(time.Second * 2) log.TLogln("end set settings") } @@ -231,11 +232,16 @@ func SetDefSettings() { } lockApi.Lock() defer lockApi.Unlock() + log.TLogln("drop all torrents") dropAllTorrent() + time.Sleep(time.Second * 2) + log.TLogln("disconect") bts.Disconnect() sets.SetDefault() + log.TLogln("connect") bts.Connect() - time.Sleep(time.Second * 5) + time.Sleep(time.Second * 2) + log.TLogln("end set default settings") } func dropAllTorrent() { diff --git a/server/torr/stream.go b/server/torr/stream.go index 2072811..aba5a66 100644 --- a/server/torr/stream.go +++ b/server/torr/stream.go @@ -48,10 +48,12 @@ func (t *Torrent) Stream(fileID int, req *http.Request, resp http.ResponseWriter reader := t.NewReader(file) host, port, err := net.SplitHostPort(req.RemoteAddr) - if err != nil { - log.Println("Connect client") - } else { - log.Println("Connect client", host, port) + if sets.BTsets.EnableDebug { + if err != nil { + log.Println("Connect client") + } else { + log.Println("Connect client", host, port) + } } sets.SetViewed(&sets.Viewed{t.Hash().HexString(), fileID}) @@ -62,10 +64,12 @@ func (t *Torrent) Stream(fileID int, req *http.Request, resp http.ResponseWriter http.ServeContent(resp, req, file.Path(), time.Unix(t.Timestamp, 0), reader) t.CloseReader(reader) - if err != nil { - log.Println("Disconnect client") - } else { - log.Println("Disconnect client", host, port) + if sets.BTsets.EnableDebug { + if err != nil { + log.Println("Disconnect client") + } else { + log.Println("Disconnect client", host, port) + } } return nil } diff --git a/server/web/server.go b/server/web/server.go index 71f142e..2e655c4 100644 --- a/server/web/server.go +++ b/server/web/server.go @@ -22,7 +22,7 @@ var ( ) func Start(port string) { - log.TLogln("Start TorrServer", version.Version) + log.TLogln("Start TorrServer") ips := getLocalIps() if len(ips) > 0 { log.TLogln("IP:", ips) From 3e79bfb4bb06092bad33ea587488304c8b521a3b Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Mon, 23 Aug 2021 20:27:58 +0300 Subject: [PATCH 4/7] update web translations --- web/src/locales/en/translation.json | 2 +- web/src/locales/ru/translation.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/locales/en/translation.json b/web/src/locales/en/translation.json index b2eb3c9..bcac4b2 100644 --- a/web/src/locales/en/translation.json +++ b/web/src/locales/en/translation.json @@ -33,7 +33,7 @@ "CopyHash": "Copy Hash", "CopyLink": "Copy link", "Data": "Data", - "DebugMode": "Debug mode", + "DebugMode": "Show download priorities", "Delete": "Delete", "DeleteTorrent?": "Delete Torrent?", "DeleteTorrents?": "Delete All Torrents?", diff --git a/web/src/locales/ru/translation.json b/web/src/locales/ru/translation.json index 6208c40..03bfc4a 100644 --- a/web/src/locales/ru/translation.json +++ b/web/src/locales/ru/translation.json @@ -33,7 +33,7 @@ "CopyHash": "Скопировать хеш", "CopyLink": "Копировать", "Data": "Данные", - "DebugMode": "Режим отладки", + "DebugMode": "Метки приоритетов загрузки", "Delete": "Удалить", "DeleteTorrent?": "Удалить торрент?", "DeleteTorrents?": "Удалить все торренты?", From e61a86da0d9f905c56a7133264c0deaacca26c39 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Tue, 24 Aug 2021 00:35:27 +0300 Subject: [PATCH 5/7] fix checkbox on dark theme and respect mini too --- .../DialogTorrentDetailsContent/DetailedView/index.jsx | 3 +++ .../DialogTorrentDetailsContent/TorrentCache/index.jsx | 8 ++++---- web/src/components/DialogTorrentDetailsContent/index.jsx | 3 ++- web/src/locales/ru/translation.json | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx b/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx index 5dc8e2b..a9d31f4 100644 --- a/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx +++ b/web/src/components/DialogTorrentDetailsContent/DetailedView/index.jsx @@ -54,7 +54,9 @@ export default function DetailedView({ { setIsSnakeDebugMode(checked) localStorage.setItem('isSnakeDebugMode', checked) @@ -62,6 +64,7 @@ export default function DetailedView({ /> } label={t('DebugMode')} + labelPlacement='start' /> diff --git a/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx b/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx index ba21254..847cb70 100644 --- a/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx +++ b/web/src/components/DialogTorrentDetailsContent/TorrentCache/index.jsx @@ -91,16 +91,16 @@ const TorrentCache = ({ cache, isMini, isSnakeDebugMode }) => { ctx.strokeRect(0, 0, pieceSize, pieceSize) ctx.setTransform(1, 0, 0, 1, 0, 0) - if (!isMini && isSnakeDebugMode && priority > 0) { + if (isSnakeDebugMode && priority > 0) { let info = '' if (priority === 1) info = '*' else if (priority === 2) info = 'H' else if (priority === 3) info = 'R' else if (priority === 4) info = 'N' else if (priority === 5) info = 'A' - ctx.font = '10px monospace' - const xpad = pieceSize * 0.28 - const ypad = pieceSize * 0.78 + ctx.font = isMini ? '13px monospace' : '10px monospace' + const xpad = isMini ? pieceSize * 0.35 : pieceSize * 0.29 + const ypad = isMini ? pieceSize * 0.69 : pieceSize * 0.78 ctx.fillStyle = 'black' ctx.fillText(info, x + xpad, y + ypad) } diff --git a/web/src/components/DialogTorrentDetailsContent/index.jsx b/web/src/components/DialogTorrentDetailsContent/index.jsx index c4696f2..c761ba5 100644 --- a/web/src/components/DialogTorrentDetailsContent/index.jsx +++ b/web/src/components/DialogTorrentDetailsContent/index.jsx @@ -45,6 +45,7 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) { const [playableFileList, setPlayableFileList] = useState() const [seasonAmount, setSeasonAmount] = useState(null) const [selectedSeason, setSelectedSeason] = useState() + const [isSnakeDebugMode] = useState(JSON.parse(localStorage.getItem('isSnakeDebugMode')) || false) const { poster, @@ -210,7 +211,7 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) { /> - +