mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-07 08:46:40 +08:00
Refactor SiteTorrentTable.vue and AddDownloadDialog.vue components
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { PropType } from 'vue'
|
import type { PropType } from 'vue'
|
||||||
import { useToast } from 'vue-toast-notification'
|
|
||||||
import { useConfirm } from 'vuetify-use-dialog'
|
|
||||||
import { formatFileSize } from '@/@core/utils/formatters'
|
import { formatFileSize } from '@/@core/utils/formatters'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { doneNProgress, startNProgress } from '@/api/nprogress'
|
import type { Context } from '@/api/types'
|
||||||
import type { Context, MediaInfo, TorrentInfo } from '@/api/types'
|
import AddDownloadDialog from '../dialog/AddDownloadDialog.vue'
|
||||||
|
|
||||||
// 输入参数
|
// 输入参数
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -15,12 +13,6 @@ const props = defineProps({
|
|||||||
height: String,
|
height: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 提示框
|
|
||||||
const $toast = useToast()
|
|
||||||
|
|
||||||
// 确认框
|
|
||||||
const createConfirm = useConfirm()
|
|
||||||
|
|
||||||
// 更多来源界面
|
// 更多来源界面
|
||||||
const showMoreTorrents = ref(false)
|
const showMoreTorrents = ref(false)
|
||||||
|
|
||||||
@@ -37,7 +29,22 @@ const meta = ref(props.torrent?.meta_info)
|
|||||||
const siteIcon = ref('')
|
const siteIcon = ref('')
|
||||||
|
|
||||||
// 存储是否已经下载过的记录
|
// 存储是否已经下载过的记录
|
||||||
const downloaded = ref<String[]>([])
|
const downloaded = ref<string[]>([])
|
||||||
|
|
||||||
|
// 添加下载对话框
|
||||||
|
const addDownloadDialog = ref(false)
|
||||||
|
|
||||||
|
// 添加下载成功
|
||||||
|
function addDownloadSuccess(url: string) {
|
||||||
|
addDownloadDialog.value = false
|
||||||
|
// 添加下载成功
|
||||||
|
downloaded.value.push(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加下载失败
|
||||||
|
function addDownloadError(error: string) {
|
||||||
|
addDownloadDialog.value = false
|
||||||
|
}
|
||||||
|
|
||||||
// 查询站点图标
|
// 查询站点图标
|
||||||
async function getSiteIcon() {
|
async function getSiteIcon() {
|
||||||
@@ -49,50 +56,9 @@ async function getSiteIcon() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 询问并添加下载
|
// 询问并添加下载
|
||||||
async function handleAddDownload(_site: any = undefined, _media: any = undefined, _torrent: any = undefined) {
|
async function handleAddDownload() {
|
||||||
if (!_media || !_torrent || !_site) {
|
// 打开下载对话框
|
||||||
_site = torrent.value?.site_name
|
addDownloadDialog.value = true
|
||||||
_media = media.value
|
|
||||||
_torrent = torrent.value
|
|
||||||
}
|
|
||||||
|
|
||||||
const isConfirmed = await createConfirm({
|
|
||||||
title: '确认',
|
|
||||||
content: `是否确认下载【${_site}】${_torrent?.title} ?`,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!isConfirmed) return
|
|
||||||
|
|
||||||
addDownload(_media, _torrent)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加下载
|
|
||||||
async function addDownload(_media: MediaInfo, _torrent: TorrentInfo) {
|
|
||||||
startNProgress()
|
|
||||||
try {
|
|
||||||
let result: { [key: string]: any }
|
|
||||||
|
|
||||||
if (_media) {
|
|
||||||
result = await api.post('download/', {
|
|
||||||
media_in: _media,
|
|
||||||
torrent_in: _torrent,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
result = await api.post('download/add', _torrent)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result && result.success) {
|
|
||||||
// 添加下载成功
|
|
||||||
$toast.success(`${_torrent?.site_name} ${_torrent?.title} 下载成功!`)
|
|
||||||
downloaded.value.push(_torrent?.enclosure || '')
|
|
||||||
} else {
|
|
||||||
// 添加下载失败
|
|
||||||
$toast.error(`${_torrent?.site_name} ${_torrent?.title} 下载失败:${result?.message}!`)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
doneNProgress()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开种子详情页面
|
// 打开种子详情页面
|
||||||
@@ -120,127 +86,138 @@ onMounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VCard
|
<div>
|
||||||
:width="props.width"
|
<VCard
|
||||||
:height="props.height"
|
:width="props.width"
|
||||||
:variant="downloaded.includes(torrent?.enclosure || '') ? 'outlined' : 'elevated'"
|
:height="props.height"
|
||||||
@click="handleAddDownload"
|
:variant="downloaded.includes(torrent?.enclosure || '') ? 'outlined' : 'elevated'"
|
||||||
>
|
@click="handleAddDownload"
|
||||||
<template v-if="!showMoreTorrents" #image>
|
>
|
||||||
<VAvatar class="absolute right-2 bottom-2 rounded" variant="flat" rounded="0">
|
<template v-if="!showMoreTorrents" #image>
|
||||||
<VImg :src="siteIcon" />
|
<VAvatar class="absolute right-2 bottom-2 rounded" variant="flat" rounded="0">
|
||||||
</VAvatar>
|
<VImg :src="siteIcon" />
|
||||||
</template>
|
</VAvatar>
|
||||||
<VCardItem class="py-1">
|
|
||||||
<VCardTitle class="break-words overflow-visible whitespace-break-spaces">
|
|
||||||
{{ media?.title ?? meta?.name }} {{ meta?.season_episode }}
|
|
||||||
<span class="text-green-700 ms-2 text-sm">↑{{ torrent?.seeders }}</span>
|
|
||||||
<span class="text-orange-700 ms-2 text-sm">↓{{ torrent?.peers }}</span>
|
|
||||||
</VCardTitle>
|
|
||||||
<template #append>
|
|
||||||
<div class="me-n3">
|
|
||||||
<IconBtn>
|
|
||||||
<VIcon icon="mdi-dots-vertical" />
|
|
||||||
<VMenu activator="parent" close-on-content-click>
|
|
||||||
<VList>
|
|
||||||
<VListItem variant="plain" @click="openTorrentDetail()">
|
|
||||||
<template #prepend>
|
|
||||||
<VIcon icon="mdi-information" />
|
|
||||||
</template>
|
|
||||||
<VListItemTitle>查看详情</VListItemTitle>
|
|
||||||
</VListItem>
|
|
||||||
<VListItem
|
|
||||||
v-if="props.torrent?.torrent_info?.enclosure?.startsWith('http')"
|
|
||||||
variant="plain"
|
|
||||||
@click="downloadTorrentFile()"
|
|
||||||
>
|
|
||||||
<template #prepend>
|
|
||||||
<VIcon icon="mdi-download" />
|
|
||||||
</template>
|
|
||||||
<VListItemTitle>下载种子文件</VListItemTitle>
|
|
||||||
</VListItem>
|
|
||||||
</VList>
|
|
||||||
</VMenu>
|
|
||||||
</IconBtn>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
</VCardItem>
|
<VCardItem class="py-1">
|
||||||
<VCardText class="text-subtitle-2">
|
<VCardTitle class="break-words overflow-visible whitespace-break-spaces">
|
||||||
{{ torrent?.title }}
|
{{ media?.title ?? meta?.name }} {{ meta?.season_episode }}
|
||||||
</VCardText>
|
<span class="text-green-700 ms-2 text-sm">↑{{ torrent?.seeders }}</span>
|
||||||
<VCardText>{{ torrent?.description }}</VCardText>
|
<span class="text-orange-700 ms-2 text-sm">↓{{ torrent?.peers }}</span>
|
||||||
<VCardItem v-if="torrent?.labels" class="pb-3 pt-0 pe-12">
|
</VCardTitle>
|
||||||
<VChip v-if="torrent?.hit_and_run" variant="elevated" size="small" class="me-1 mb-1 text-white bg-black">
|
|
||||||
H&R
|
|
||||||
</VChip>
|
|
||||||
<VChip v-if="torrent?.freedate_diff" variant="elevated" color="secondary" size="small" class="me-1 mb-1">
|
|
||||||
{{ torrent?.freedate_diff }}
|
|
||||||
</VChip>
|
|
||||||
<VChip
|
|
||||||
v-for="(label, index) in torrent?.labels"
|
|
||||||
:key="index"
|
|
||||||
variant="elevated"
|
|
||||||
size="small"
|
|
||||||
color="primary"
|
|
||||||
class="me-1 mb-1"
|
|
||||||
>
|
|
||||||
{{ label }}
|
|
||||||
</VChip>
|
|
||||||
<VChip v-if="meta?.edition" variant="elevated" size="small" class="me-1 mb-1 text-white bg-red-500">
|
|
||||||
{{ meta?.edition }}
|
|
||||||
</VChip>
|
|
||||||
<VChip v-if="meta?.resource_pix" variant="elevated" size="small" class="me-1 mb-1 text-white bg-red-500">
|
|
||||||
{{ meta?.resource_pix }}
|
|
||||||
</VChip>
|
|
||||||
<VChip v-if="meta?.video_encode" variant="elevated" size="small" class="me-1 mb-1 text-white bg-orange-500">
|
|
||||||
{{ meta?.video_encode }}
|
|
||||||
</VChip>
|
|
||||||
<VChip v-if="torrent?.size" variant="elevated" size="small" class="me-1 mb-1 text-white bg-yellow-500">
|
|
||||||
{{ formatFileSize(torrent?.size) }}
|
|
||||||
</VChip>
|
|
||||||
<VChip v-if="meta?.resource_team" variant="elevated" size="small" class="me-1 mb-1 text-white bg-cyan-500">
|
|
||||||
{{ meta?.resource_team }}
|
|
||||||
</VChip>
|
|
||||||
<VChip
|
|
||||||
v-if="torrent?.downloadvolumefactor !== 1 || torrent?.uploadvolumefactor !== 1"
|
|
||||||
:class="getVolumeFactorClass(torrent?.downloadvolumefactor, torrent?.uploadvolumefactor)"
|
|
||||||
variant="elevated"
|
|
||||||
size="small"
|
|
||||||
class="me-1 mb-1"
|
|
||||||
>
|
|
||||||
{{ torrent?.volume_factor }}
|
|
||||||
</VChip>
|
|
||||||
</VCardItem>
|
|
||||||
<VCardActions>
|
|
||||||
<VBtn v-if="props.more && props.more.length > 0" @click.stop="showMoreTorrents = !showMoreTorrents">
|
|
||||||
<template #append>
|
<template #append>
|
||||||
<VIcon :icon="showMoreTorrents ? 'mdi-chevron-up' : 'mdi-chevron-down'" />
|
<div class="me-n3">
|
||||||
|
<IconBtn>
|
||||||
|
<VIcon icon="mdi-dots-vertical" />
|
||||||
|
<VMenu activator="parent" close-on-content-click>
|
||||||
|
<VList>
|
||||||
|
<VListItem variant="plain" @click="openTorrentDetail()">
|
||||||
|
<template #prepend>
|
||||||
|
<VIcon icon="mdi-information" />
|
||||||
|
</template>
|
||||||
|
<VListItemTitle>查看详情</VListItemTitle>
|
||||||
|
</VListItem>
|
||||||
|
<VListItem
|
||||||
|
v-if="props.torrent?.torrent_info?.enclosure?.startsWith('http')"
|
||||||
|
variant="plain"
|
||||||
|
@click="downloadTorrentFile()"
|
||||||
|
>
|
||||||
|
<template #prepend>
|
||||||
|
<VIcon icon="mdi-download" />
|
||||||
|
</template>
|
||||||
|
<VListItemTitle>下载种子文件</VListItemTitle>
|
||||||
|
</VListItem>
|
||||||
|
</VList>
|
||||||
|
</VMenu>
|
||||||
|
</IconBtn>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
更多来源
|
</VCardItem>
|
||||||
</VBtn>
|
<VCardText class="text-subtitle-2">
|
||||||
</VCardActions>
|
{{ torrent?.title }}
|
||||||
<VExpandTransition>
|
</VCardText>
|
||||||
<div v-show="showMoreTorrents">
|
<VCardText>{{ torrent?.description }}</VCardText>
|
||||||
<VDivider />
|
<VCardItem v-if="torrent?.labels" class="pb-3 pt-0 pe-12">
|
||||||
<VChipGroup class="p-3" column>
|
<VChip v-if="torrent?.hit_and_run" variant="elevated" size="small" class="me-1 mb-1 text-white bg-black">
|
||||||
<VChip
|
H&R
|
||||||
v-for="(item, index) in props.more"
|
</VChip>
|
||||||
:key="index"
|
<VChip v-if="torrent?.freedate_diff" variant="elevated" color="secondary" size="small" class="me-1 mb-1">
|
||||||
@click.stop="handleAddDownload(item.torrent_info?.site_name, item.media_info, item.torrent_info)"
|
{{ torrent?.freedate_diff }}
|
||||||
>
|
</VChip>
|
||||||
<template #append>
|
<VChip
|
||||||
<VBadge color="primary" :content="`↑${item.torrent_info?.seeders}`" inline size="small" />
|
v-for="(label, index) in torrent?.labels"
|
||||||
<VBadge
|
:key="index"
|
||||||
v-if="item.torrent_info?.downloadvolumefactor !== 1 || item.torrent_info?.uploadvolumefactor !== 1"
|
variant="elevated"
|
||||||
:content="item.torrent_info?.volume_factor"
|
size="small"
|
||||||
inline
|
color="primary"
|
||||||
size="small"
|
class="me-1 mb-1"
|
||||||
/>
|
>
|
||||||
</template>
|
{{ label }}
|
||||||
{{ item.torrent_info.site_name }}
|
</VChip>
|
||||||
</VChip>
|
<VChip v-if="meta?.edition" variant="elevated" size="small" class="me-1 mb-1 text-white bg-red-500">
|
||||||
</VChipGroup>
|
{{ meta?.edition }}
|
||||||
</div>
|
</VChip>
|
||||||
</VExpandTransition>
|
<VChip v-if="meta?.resource_pix" variant="elevated" size="small" class="me-1 mb-1 text-white bg-red-500">
|
||||||
</VCard>
|
{{ meta?.resource_pix }}
|
||||||
|
</VChip>
|
||||||
|
<VChip v-if="meta?.video_encode" variant="elevated" size="small" class="me-1 mb-1 text-white bg-orange-500">
|
||||||
|
{{ meta?.video_encode }}
|
||||||
|
</VChip>
|
||||||
|
<VChip v-if="torrent?.size" variant="elevated" size="small" class="me-1 mb-1 text-white bg-yellow-500">
|
||||||
|
{{ formatFileSize(torrent?.size) }}
|
||||||
|
</VChip>
|
||||||
|
<VChip v-if="meta?.resource_team" variant="elevated" size="small" class="me-1 mb-1 text-white bg-cyan-500">
|
||||||
|
{{ meta?.resource_team }}
|
||||||
|
</VChip>
|
||||||
|
<VChip
|
||||||
|
v-if="torrent?.downloadvolumefactor !== 1 || torrent?.uploadvolumefactor !== 1"
|
||||||
|
:class="getVolumeFactorClass(torrent?.downloadvolumefactor, torrent?.uploadvolumefactor)"
|
||||||
|
variant="elevated"
|
||||||
|
size="small"
|
||||||
|
class="me-1 mb-1"
|
||||||
|
>
|
||||||
|
{{ torrent?.volume_factor }}
|
||||||
|
</VChip>
|
||||||
|
</VCardItem>
|
||||||
|
<VCardActions>
|
||||||
|
<VBtn v-if="props.more && props.more.length > 0" @click.stop="showMoreTorrents = !showMoreTorrents">
|
||||||
|
<template #append>
|
||||||
|
<VIcon :icon="showMoreTorrents ? 'mdi-chevron-up' : 'mdi-chevron-down'" />
|
||||||
|
</template>
|
||||||
|
更多来源
|
||||||
|
</VBtn>
|
||||||
|
</VCardActions>
|
||||||
|
<VExpandTransition>
|
||||||
|
<div v-show="showMoreTorrents">
|
||||||
|
<VDivider />
|
||||||
|
<VChipGroup class="p-3" column>
|
||||||
|
<VChip
|
||||||
|
v-for="(item, index) in props.more"
|
||||||
|
:key="index"
|
||||||
|
@click.stop="handleAddDownload(item.torrent_info?.site_name, item.media_info, item.torrent_info)"
|
||||||
|
>
|
||||||
|
<template #append>
|
||||||
|
<VBadge color="primary" :content="`↑${item.torrent_info?.seeders}`" inline size="small" />
|
||||||
|
<VBadge
|
||||||
|
v-if="item.torrent_info?.downloadvolumefactor !== 1 || item.torrent_info?.uploadvolumefactor !== 1"
|
||||||
|
:content="item.torrent_info?.volume_factor"
|
||||||
|
inline
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
{{ item.torrent_info.site_name }}
|
||||||
|
</VChip>
|
||||||
|
</VChipGroup>
|
||||||
|
</div>
|
||||||
|
</VExpandTransition>
|
||||||
|
</VCard>
|
||||||
|
<AddDownloadDialog
|
||||||
|
v-if="addDownloadDialog"
|
||||||
|
v-model="addDownloadDialog"
|
||||||
|
:media="props.torrent?.media_info"
|
||||||
|
:torrent="props.torrent?.torrent_info"
|
||||||
|
@done="addDownloadSuccess"
|
||||||
|
@error="addDownloadError"
|
||||||
|
@close="addDownloadDialog = false"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,32 +1,21 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { PropType } from 'vue'
|
import type { PropType } from 'vue'
|
||||||
import { useToast } from 'vue-toast-notification'
|
|
||||||
import { useConfirm } from 'vuetify-use-dialog'
|
|
||||||
import { formatFileSize } from '@/@core/utils/formatters'
|
import { formatFileSize } from '@/@core/utils/formatters'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { doneNProgress, startNProgress } from '@/api/nprogress'
|
import type { Context } from '@/api/types'
|
||||||
import type { Context, MediaInfo, TorrentInfo } from '@/api/types'
|
import AddDownloadDialog from '../dialog/AddDownloadDialog.vue'
|
||||||
|
|
||||||
// 输入参数
|
// 输入参数
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
torrent: Object as PropType<Context>,
|
torrent: Object as PropType<Context>,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 提示框
|
|
||||||
const $toast = useToast()
|
|
||||||
|
|
||||||
// 确认框
|
|
||||||
const createConfirm = useConfirm()
|
|
||||||
|
|
||||||
// 更多来源界面
|
// 更多来源界面
|
||||||
const showMoreTorrents = ref(false)
|
const showMoreTorrents = ref(false)
|
||||||
|
|
||||||
// 种子信息
|
// 种子信息
|
||||||
const torrent = ref(props.torrent?.torrent_info)
|
const torrent = ref(props.torrent?.torrent_info)
|
||||||
|
|
||||||
// 媒体信息
|
|
||||||
const media = ref(props.torrent?.media_info)
|
|
||||||
|
|
||||||
// 识别元数据
|
// 识别元数据
|
||||||
const meta = ref(props.torrent?.meta_info)
|
const meta = ref(props.torrent?.meta_info)
|
||||||
|
|
||||||
@@ -34,7 +23,10 @@ const meta = ref(props.torrent?.meta_info)
|
|||||||
const siteIcon = ref('')
|
const siteIcon = ref('')
|
||||||
|
|
||||||
// 存储是否已经下载过的记录
|
// 存储是否已经下载过的记录
|
||||||
const downloaded = ref<String[]>([])
|
const downloaded = ref<string[]>([])
|
||||||
|
|
||||||
|
// 添加下载对话框
|
||||||
|
const addDownloadDialog = ref(false)
|
||||||
|
|
||||||
// 查询站点图标
|
// 查询站点图标
|
||||||
async function getSiteIcon() {
|
async function getSiteIcon() {
|
||||||
@@ -46,50 +38,21 @@ async function getSiteIcon() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 询问并添加下载
|
// 询问并添加下载
|
||||||
async function handleAddDownload(_site: any = undefined, _media: any = undefined, _torrent: any = undefined) {
|
async function handleAddDownload() {
|
||||||
if (!_media || !_torrent || !_site) {
|
// 打开下载对话框
|
||||||
_site = torrent.value?.site_name
|
addDownloadDialog.value = true
|
||||||
_media = media.value
|
|
||||||
_torrent = torrent.value
|
|
||||||
}
|
|
||||||
|
|
||||||
const isConfirmed = await createConfirm({
|
|
||||||
title: '确认',
|
|
||||||
content: `是否确认下载【${_site}】${_torrent?.title} ?`,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!isConfirmed) return
|
|
||||||
|
|
||||||
addDownload(_media, _torrent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加下载
|
// 添加下载成功
|
||||||
async function addDownload(_media: MediaInfo, _torrent: TorrentInfo) {
|
function addDownloadSuccess(url: string) {
|
||||||
startNProgress()
|
addDownloadDialog.value = false
|
||||||
try {
|
// 添加下载成功
|
||||||
let result: { [key: string]: any }
|
downloaded.value.push(url)
|
||||||
|
}
|
||||||
|
|
||||||
if (_media) {
|
// 添加下载失败
|
||||||
result = await api.post('download/', {
|
function addDownloadError(error: string) {
|
||||||
media_in: _media,
|
addDownloadDialog.value = false
|
||||||
torrent_in: _torrent,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
result = await api.post('download/add', _torrent)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result && result.success) {
|
|
||||||
// 添加下载成功
|
|
||||||
$toast.success(`${_torrent?.site_name} ${_torrent?.title} 下载成功!`)
|
|
||||||
downloaded.value.push(_torrent?.enclosure || '')
|
|
||||||
} else {
|
|
||||||
// 添加下载失败
|
|
||||||
$toast.error(`${_torrent?.site_name} ${_torrent?.title} 下载失败:${result?.message}!`)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
doneNProgress()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开种子详情页面
|
// 打开种子详情页面
|
||||||
@@ -117,88 +80,102 @@ onMounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VListItem @click="handleAddDownload" :variant="downloaded.includes(torrent?.enclosure || '') ? 'outlined' : 'flat'">
|
<div>
|
||||||
<template v-if="!showMoreTorrents" #prepend>
|
<VListItem
|
||||||
<VAvatar class="rounded" variant="flat" @click.stop="openTorrentDetail">
|
@click="handleAddDownload"
|
||||||
<VImg :src="siteIcon" />
|
:variant="downloaded.includes(torrent?.enclosure || '') ? 'outlined' : 'flat'"
|
||||||
</VAvatar>
|
>
|
||||||
</template>
|
<template v-if="!showMoreTorrents" #prepend>
|
||||||
<VListItemTitle class="break-words overflow-visible whitespace-break-spaces">
|
<VAvatar class="rounded" variant="flat" @click.stop="openTorrentDetail">
|
||||||
{{ torrent?.title }}
|
<VImg :src="siteIcon" />
|
||||||
<span class="text-green-700 ms-2 text-sm">↑{{ torrent?.seeders }}</span>
|
</VAvatar>
|
||||||
<span class="text-orange-700 ms-2 text-sm">↓{{ torrent?.peers }}</span>
|
</template>
|
||||||
</VListItemTitle>
|
<VListItemTitle class="break-words overflow-visible whitespace-break-spaces">
|
||||||
<VListItemSubtitle>
|
{{ torrent?.title }}
|
||||||
{{ torrent?.description }}
|
<span class="text-green-700 ms-2 text-sm">↑{{ torrent?.seeders }}</span>
|
||||||
</VListItemSubtitle>
|
<span class="text-orange-700 ms-2 text-sm">↓{{ torrent?.peers }}</span>
|
||||||
<div v-if="torrent?.labels" class="pt-2">
|
</VListItemTitle>
|
||||||
<VChip v-if="torrent?.hit_and_run" variant="elevated" size="small" class="me-1 mb-1 text-white bg-black">
|
<VListItemSubtitle>
|
||||||
H&R
|
{{ torrent?.description }}
|
||||||
</VChip>
|
</VListItemSubtitle>
|
||||||
<VChip v-if="torrent?.freedate_diff" variant="elevated" color="secondary" size="small" class="me-1 mb-1">
|
<div v-if="torrent?.labels" class="pt-2">
|
||||||
{{ torrent?.freedate_diff }}
|
<VChip v-if="torrent?.hit_and_run" variant="elevated" size="small" class="me-1 mb-1 text-white bg-black">
|
||||||
</VChip>
|
H&R
|
||||||
<VChip
|
</VChip>
|
||||||
v-for="(label, index) in torrent?.labels"
|
<VChip v-if="torrent?.freedate_diff" variant="elevated" color="secondary" size="small" class="me-1 mb-1">
|
||||||
:key="index"
|
{{ torrent?.freedate_diff }}
|
||||||
variant="elevated"
|
</VChip>
|
||||||
size="small"
|
<VChip
|
||||||
color="primary"
|
v-for="(label, index) in torrent?.labels"
|
||||||
class="me-1 mb-1"
|
:key="index"
|
||||||
>
|
variant="elevated"
|
||||||
{{ label }}
|
size="small"
|
||||||
</VChip>
|
color="primary"
|
||||||
<VChip v-if="meta?.edition" variant="elevated" size="small" class="me-1 mb-1 text-white bg-red-500">
|
class="me-1 mb-1"
|
||||||
{{ meta?.edition }}
|
>
|
||||||
</VChip>
|
{{ label }}
|
||||||
<VChip v-if="meta?.resource_pix" variant="elevated" size="small" class="me-1 mb-1 text-white bg-red-500">
|
</VChip>
|
||||||
{{ meta?.resource_pix }}
|
<VChip v-if="meta?.edition" variant="elevated" size="small" class="me-1 mb-1 text-white bg-red-500">
|
||||||
</VChip>
|
{{ meta?.edition }}
|
||||||
<VChip v-if="meta?.video_encode" variant="elevated" size="small" class="me-1 mb-1 text-white bg-orange-500">
|
</VChip>
|
||||||
{{ meta?.video_encode }}
|
<VChip v-if="meta?.resource_pix" variant="elevated" size="small" class="me-1 mb-1 text-white bg-red-500">
|
||||||
</VChip>
|
{{ meta?.resource_pix }}
|
||||||
<VChip v-if="torrent?.size" variant="elevated" size="small" class="me-1 mb-1 text-white bg-yellow-500">
|
</VChip>
|
||||||
{{ formatFileSize(torrent?.size) }}
|
<VChip v-if="meta?.video_encode" variant="elevated" size="small" class="me-1 mb-1 text-white bg-orange-500">
|
||||||
</VChip>
|
{{ meta?.video_encode }}
|
||||||
<VChip v-if="meta?.resource_team" variant="elevated" size="small" class="me-1 mb-1 text-white bg-cyan-500">
|
</VChip>
|
||||||
{{ meta?.resource_team }}
|
<VChip v-if="torrent?.size" variant="elevated" size="small" class="me-1 mb-1 text-white bg-yellow-500">
|
||||||
</VChip>
|
{{ formatFileSize(torrent?.size) }}
|
||||||
<VChip
|
</VChip>
|
||||||
v-if="torrent?.downloadvolumefactor !== 1 || torrent?.uploadvolumefactor !== 1"
|
<VChip v-if="meta?.resource_team" variant="elevated" size="small" class="me-1 mb-1 text-white bg-cyan-500">
|
||||||
:class="getVolumeFactorClass(torrent?.downloadvolumefactor, torrent?.uploadvolumefactor)"
|
{{ meta?.resource_team }}
|
||||||
variant="elevated"
|
</VChip>
|
||||||
size="small"
|
<VChip
|
||||||
class="me-1 mb-1"
|
v-if="torrent?.downloadvolumefactor !== 1 || torrent?.uploadvolumefactor !== 1"
|
||||||
>
|
:class="getVolumeFactorClass(torrent?.downloadvolumefactor, torrent?.uploadvolumefactor)"
|
||||||
{{ torrent?.volume_factor }}
|
variant="elevated"
|
||||||
</VChip>
|
size="small"
|
||||||
</div>
|
class="me-1 mb-1"
|
||||||
<template #append>
|
>
|
||||||
<div class="me-n3">
|
{{ torrent?.volume_factor }}
|
||||||
<IconBtn>
|
</VChip>
|
||||||
<VIcon icon="mdi-dots-vertical" />
|
|
||||||
<VMenu activator="parent" close-on-content-click>
|
|
||||||
<VList>
|
|
||||||
<VListItem variant="plain" @click="openTorrentDetail()">
|
|
||||||
<template #prepend>
|
|
||||||
<VIcon icon="mdi-information" />
|
|
||||||
</template>
|
|
||||||
<VListItemTitle>查看详情</VListItemTitle>
|
|
||||||
</VListItem>
|
|
||||||
<VListItem
|
|
||||||
v-if="props.torrent?.torrent_info?.enclosure?.startsWith('http')"
|
|
||||||
variant="plain"
|
|
||||||
@click="downloadTorrentFile()"
|
|
||||||
>
|
|
||||||
<template #prepend>
|
|
||||||
<VIcon icon="mdi-download" />
|
|
||||||
</template>
|
|
||||||
<VListItemTitle>下载种子文件</VListItemTitle>
|
|
||||||
</VListItem>
|
|
||||||
</VList>
|
|
||||||
</VMenu>
|
|
||||||
</IconBtn>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
<template #append>
|
||||||
</VListItem>
|
<div class="me-n3">
|
||||||
|
<IconBtn>
|
||||||
|
<VIcon icon="mdi-dots-vertical" />
|
||||||
|
<VMenu activator="parent" close-on-content-click>
|
||||||
|
<VList>
|
||||||
|
<VListItem variant="plain" @click="openTorrentDetail()">
|
||||||
|
<template #prepend>
|
||||||
|
<VIcon icon="mdi-information" />
|
||||||
|
</template>
|
||||||
|
<VListItemTitle>查看详情</VListItemTitle>
|
||||||
|
</VListItem>
|
||||||
|
<VListItem
|
||||||
|
v-if="props.torrent?.torrent_info?.enclosure?.startsWith('http')"
|
||||||
|
variant="plain"
|
||||||
|
@click="downloadTorrentFile()"
|
||||||
|
>
|
||||||
|
<template #prepend>
|
||||||
|
<VIcon icon="mdi-download" />
|
||||||
|
</template>
|
||||||
|
<VListItemTitle>下载种子文件</VListItemTitle>
|
||||||
|
</VListItem>
|
||||||
|
</VList>
|
||||||
|
</VMenu>
|
||||||
|
</IconBtn>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</VListItem>
|
||||||
|
<AddDownloadDialog
|
||||||
|
v-if="addDownloadDialog"
|
||||||
|
v-model="addDownloadDialog"
|
||||||
|
:media="props.torrent?.media_info"
|
||||||
|
:torrent="props.torrent?.torrent_info"
|
||||||
|
@done="addDownloadSuccess"
|
||||||
|
@error="addDownloadError"
|
||||||
|
@close="addDownloadDialog = false"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useToast } from 'vue-toast-notification'
|
||||||
|
import api from '@/api'
|
||||||
|
import { doneNProgress, startNProgress } from '@/api/nprogress'
|
||||||
|
import type { DownloaderConf, MediaInfo, TorrentInfo, TransferDirectoryConf } from '@/api/types'
|
||||||
|
import { formatFileSize } from '@/@core/utils/formatters'
|
||||||
|
|
||||||
|
// 输入参数
|
||||||
|
const props = defineProps({
|
||||||
|
media: Object as PropType<MediaInfo>,
|
||||||
|
torrent: Object as PropType<TorrentInfo>,
|
||||||
|
})
|
||||||
|
|
||||||
|
// 提示框
|
||||||
|
const $toast = useToast()
|
||||||
|
|
||||||
|
// 选择的下载器
|
||||||
|
const selectedDownloader = ref(null)
|
||||||
|
|
||||||
|
// 选择的保存目录
|
||||||
|
const selectedDirectory = ref(null)
|
||||||
|
|
||||||
|
// 定义成功和失败事件
|
||||||
|
const emit = defineEmits(['done', 'error', 'close'])
|
||||||
|
|
||||||
|
// 所有目录设置
|
||||||
|
const directories = ref<TransferDirectoryConf[]>([])
|
||||||
|
|
||||||
|
// 是否正在加载
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
// 计算按钮图标
|
||||||
|
const icon = computed(() => (loading.value ? 'mdi-progress-download' : 'mdi-download'))
|
||||||
|
|
||||||
|
// 计算按钮文字
|
||||||
|
const buttonText = computed(() => (loading.value ? '下载中...' : '开始下载'))
|
||||||
|
|
||||||
|
// 加载目录设置
|
||||||
|
async function loadDirectories() {
|
||||||
|
try {
|
||||||
|
const result: { [key: string]: any } = await api.get('system/setting/Directories')
|
||||||
|
directories.value = result.data?.value ?? []
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取保存目录
|
||||||
|
const targetDirectories = computed(() => {
|
||||||
|
const downloadDirectories = directories.value.map(item => item.download_path)
|
||||||
|
return [...new Set(downloadDirectories)]
|
||||||
|
})
|
||||||
|
|
||||||
|
// 下载器
|
||||||
|
const downloaders = ref<DownloaderConf[]>([])
|
||||||
|
|
||||||
|
// 调用API查询下载器设置
|
||||||
|
async function loadDownloaderSetting() {
|
||||||
|
try {
|
||||||
|
const result: { [key: string]: any } = await api.get('system/setting/Downloaders')
|
||||||
|
downloaders.value = result.data?.value ?? []
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下载器可选项
|
||||||
|
const downloaderOptions = computed(() => {
|
||||||
|
return downloaders.value.map(item => ({
|
||||||
|
title: item.name,
|
||||||
|
value: item.name,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
// 添加下载
|
||||||
|
async function addDownload() {
|
||||||
|
startNProgress()
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
let result: { [key: string]: any }
|
||||||
|
|
||||||
|
if (props.media) {
|
||||||
|
result = await api.post('download/', {
|
||||||
|
media_in: props.media,
|
||||||
|
torrent_in: props.torrent,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
result = await api.post('download/add', props.torrent)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result && result.success) {
|
||||||
|
// 添加下载成功
|
||||||
|
$toast.success(`${props.torrent?.site_name} ${props.torrent?.title} 下载成功!`)
|
||||||
|
// 下载成功,返回链接
|
||||||
|
emit('done', props.torrent?.enclosure)
|
||||||
|
} else {
|
||||||
|
// 添加下载失败
|
||||||
|
$toast.error(`${props.torrent?.site_name} ${props.torrent?.title} 下载失败:${result?.message}!`)
|
||||||
|
// 下载失败,返回错误原因
|
||||||
|
emit('error', result?.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
|
doneNProgress()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
loadDirectories()
|
||||||
|
loadDownloaderSetting()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<VDialog max-width="40rem" scrollable>
|
||||||
|
<VCard title="下载确认">
|
||||||
|
<DialogCloseBtn @click="emit('close')" />
|
||||||
|
<VDivider />
|
||||||
|
<VCardText>
|
||||||
|
<VRow>
|
||||||
|
<VCol cols="12" class="text-lg text-high-emphasis">
|
||||||
|
是否确认下载 {{ props.torrent?.site_name }} - {{ props.torrent?.title }},大小:
|
||||||
|
{{ formatFileSize(props.torrent?.size || 0) }} ?
|
||||||
|
</VCol>
|
||||||
|
</VRow>
|
||||||
|
<VRow>
|
||||||
|
<VCol cols="12" md="4">
|
||||||
|
<VSelect
|
||||||
|
v-model="selectedDownloader"
|
||||||
|
:items="downloaderOptions"
|
||||||
|
label="下载器"
|
||||||
|
density="compact"
|
||||||
|
variant="underlined"
|
||||||
|
placeholder="默认"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
<VCol cols="12" md="8">
|
||||||
|
<VCombobox
|
||||||
|
v-model="selectedDirectory"
|
||||||
|
:items="targetDirectories"
|
||||||
|
label="保存目录"
|
||||||
|
placeholder="自动"
|
||||||
|
density="compact"
|
||||||
|
variant="underlined"
|
||||||
|
/>
|
||||||
|
</VCol>
|
||||||
|
</VRow>
|
||||||
|
</VCardText>
|
||||||
|
<VCardText class="text-center mt-3">
|
||||||
|
<VBtn variant="elevated" :disabled="loading" @click="addDownload" :prepend-icon="icon" class="px-5">
|
||||||
|
{{ buttonText }}
|
||||||
|
</VBtn>
|
||||||
|
</VCardText>
|
||||||
|
</VCard>
|
||||||
|
</VDialog>
|
||||||
|
</template>
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useToast } from 'vue-toast-notification'
|
|
||||||
import { useConfirm } from 'vuetify-use-dialog'
|
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import type { TorrentInfo } from '@/api/types'
|
import type { MediaInfo, TorrentInfo } from '@/api/types'
|
||||||
import { doneNProgress, startNProgress } from '@/api/nprogress'
|
|
||||||
import { formatFileSize } from '@core/utils/formatters'
|
import { formatFileSize } from '@core/utils/formatters'
|
||||||
|
import AddDownloadDialog from '../dialog/AddDownloadDialog.vue'
|
||||||
|
|
||||||
// 输入参数
|
// 输入参数
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -13,12 +11,6 @@ const props = defineProps({
|
|||||||
height: String,
|
height: String,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 提示框
|
|
||||||
const $toast = useToast()
|
|
||||||
|
|
||||||
// 确认框
|
|
||||||
const createConfirm = useConfirm()
|
|
||||||
|
|
||||||
// 数据列表
|
// 数据列表
|
||||||
const resourceDataList = ref<TorrentInfo[]>([])
|
const resourceDataList = ref<TorrentInfo[]>([])
|
||||||
|
|
||||||
@@ -34,6 +26,9 @@ const resourceItemsPerPage = ref(25)
|
|||||||
// 加载状态
|
// 加载状态
|
||||||
const resourceLoading = ref(false)
|
const resourceLoading = ref(false)
|
||||||
|
|
||||||
|
// 识别元数据
|
||||||
|
const torrent = ref<TorrentInfo>()
|
||||||
|
|
||||||
// 资源浏览表头
|
// 资源浏览表头
|
||||||
const resourceHeaders = [
|
const resourceHeaders = [
|
||||||
{ title: '标题', key: 'title', sortable: false },
|
{ title: '标题', key: 'title', sortable: false },
|
||||||
@@ -75,28 +70,21 @@ function getVolumeFactorClass(downloadVolume: number, uploadVolume: number) {
|
|||||||
|
|
||||||
// 添加下载
|
// 添加下载
|
||||||
async function addDownload(_torrent: any) {
|
async function addDownload(_torrent: any) {
|
||||||
const isConfirmed = await createConfirm({
|
torrent.value = _torrent
|
||||||
title: '确认',
|
addDownloadDialog.value = true
|
||||||
content: `是否确认下载【${_torrent.site_name}】${_torrent?.title} ?`,
|
}
|
||||||
})
|
|
||||||
|
|
||||||
if (!isConfirmed) return
|
// 添加下载对话框
|
||||||
|
const addDownloadDialog = ref(false)
|
||||||
|
|
||||||
startNProgress()
|
// 添加下载成功
|
||||||
try {
|
function addDownloadSuccess(url: string) {
|
||||||
const result: { [key: string]: any } = await api.post('download/add', _torrent)
|
addDownloadDialog.value = false
|
||||||
|
}
|
||||||
|
|
||||||
if (result.success) {
|
// 添加下载失败
|
||||||
// 添加下载成功
|
function addDownloadError(error: string) {
|
||||||
$toast.success(`${_torrent?.site_name} ${_torrent?.title} 添加下载成功!`)
|
addDownloadDialog.value = false
|
||||||
} else {
|
|
||||||
// 添加下载失败
|
|
||||||
$toast.error(`${_torrent?.site_name} ${_torrent?.title} 添加下载失败:${result.message || '未知错误'}`)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
doneNProgress()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 装载时查询站点图标
|
// 装载时查询站点图标
|
||||||
@@ -203,4 +191,12 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
<template #no-data> 没有数据 </template>
|
<template #no-data> 没有数据 </template>
|
||||||
</VDataTable>
|
</VDataTable>
|
||||||
|
<AddDownloadDialog
|
||||||
|
v-if="addDownloadDialog"
|
||||||
|
v-model="addDownloadDialog"
|
||||||
|
:torrent="torrent"
|
||||||
|
@done="addDownloadSuccess"
|
||||||
|
@error="addDownloadError"
|
||||||
|
@close="addDownloadDialog = false"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user