mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
add viewed
This commit is contained in:
@@ -5,7 +5,7 @@ import CachedIcon from '@material-ui/icons/Cached'
|
|||||||
import LinearProgress from '@material-ui/core/LinearProgress';
|
import LinearProgress from '@material-ui/core/LinearProgress';
|
||||||
|
|
||||||
import { getPeerString, humanizeSize } from '../utils/Utils'
|
import { getPeerString, humanizeSize } from '../utils/Utils'
|
||||||
import { playlistTorrHost, streamHost } from '../utils/Hosts'
|
import { playlistTorrHost, streamHost, viewedHost } from '../utils/Hosts'
|
||||||
import DialogTitle from '@material-ui/core/DialogTitle'
|
import DialogTitle from '@material-ui/core/DialogTitle'
|
||||||
import DialogContent from '@material-ui/core/DialogContent'
|
import DialogContent from '@material-ui/core/DialogContent'
|
||||||
|
|
||||||
@@ -25,12 +25,20 @@ const style = {
|
|||||||
|
|
||||||
export default function DialogTorrentInfo(props) {
|
export default function DialogTorrentInfo(props) {
|
||||||
const [torrent, setTorrent] = React.useState(props.torrent)
|
const [torrent, setTorrent] = React.useState(props.torrent)
|
||||||
|
const [viewed, setViewed] = React.useState(null)
|
||||||
const [progress, setProgress] = React.useState(-1)
|
const [progress, setProgress] = React.useState(-1)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTorrent(props.torrent)
|
setTorrent(props.torrent)
|
||||||
if(torrent.stat==2)
|
if(torrent.stat==2)
|
||||||
setProgress(torrent.preloaded_bytes * 100 / torrent.preload_size)
|
setProgress(torrent.preloaded_bytes * 100 / torrent.preload_size)
|
||||||
|
getViewed(props.torrent.hash,(list) => {
|
||||||
|
if (list) {
|
||||||
|
let lst = list.map((itm) => itm.file_index)
|
||||||
|
setViewed(lst)
|
||||||
|
}else
|
||||||
|
setViewed(null)
|
||||||
|
})
|
||||||
}, [props.torrent, props.open])
|
}, [props.torrent, props.open])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -74,7 +82,7 @@ export default function DialogTorrentInfo(props) {
|
|||||||
href={streamHost() + '/' + encodeURIComponent(file.path.split('\\').pop().split('/').pop()) + '?link=' + torrent.hash + '&index=' + file.id + '&play'}
|
href={streamHost() + '/' + encodeURIComponent(file.path.split('\\').pop().split('/').pop()) + '?link=' + torrent.hash + '&index=' + file.id + '&play'}
|
||||||
>
|
>
|
||||||
<Typography>
|
<Typography>
|
||||||
{file.path.split('\\').pop().split('/').pop()} | {humanizeSize(file.length)}
|
{file.path.split('\\').pop().split('/').pop()} | {humanizeSize(file.length)} {viewed && viewed.indexOf(file.id)!=-1 && "| ✓"}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={() => fetch(streamHost() + '?link=' + torrent.hash + '&index=' + file.id + '&preload')}>
|
<Button onClick={() => fetch(streamHost() + '?link=' + torrent.hash + '&index=' + file.id + '&preload')}>
|
||||||
@@ -89,6 +97,30 @@ export default function DialogTorrentInfo(props) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getViewed(hash, callback) {
|
||||||
|
try {
|
||||||
|
fetch(viewedHost(), {
|
||||||
|
method: 'post',
|
||||||
|
body: JSON.stringify({ action: 'list', hash: hash }),
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json, text/plain, */*',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => res.json())
|
||||||
|
.then(
|
||||||
|
(json) => {
|
||||||
|
callback(json)
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
callback(null)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getPlayableFile(torrent){
|
function getPlayableFile(torrent){
|
||||||
if (!torrent || !torrent.file_stats)
|
if (!torrent || !torrent.file_stats)
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export var torrserverHost = ''
|
|||||||
// export var torrserverHost = 'http://127.0.0.1:8090'
|
// export var torrserverHost = 'http://127.0.0.1:8090'
|
||||||
|
|
||||||
export const torrentsHost = () => torrserverHost + '/torrents'
|
export const torrentsHost = () => torrserverHost + '/torrents'
|
||||||
|
export const viewedHost = () => torrserverHost + '/viewed'
|
||||||
export const cacheHost = () => torrserverHost + '/cache'
|
export const cacheHost = () => torrserverHost + '/cache'
|
||||||
export const torrentUploadHost = () => torrserverHost + '/torrent/upload'
|
export const torrentUploadHost = () => torrserverHost + '/torrent/upload'
|
||||||
export const settingsHost = () => torrserverHost + '/settings'
|
export const settingsHost = () => torrserverHost + '/settings'
|
||||||
|
|||||||
Reference in New Issue
Block a user