mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-23 18:11:37 +08:00
fix: request error bugs.
webui: move func to store reduce code in component.
This commit is contained in:
@@ -89,9 +89,8 @@ class TorrentManager(Database):
|
||||
)
|
||||
|
||||
def enable_rule(self, _id: str | int):
|
||||
# TODO: to fix search_id
|
||||
data = self.bangumi.search(int(_id))
|
||||
if isinstance(data, Bangumi):
|
||||
data = self.bangumi.search_id(int(_id))
|
||||
if data:
|
||||
data.deleted = False
|
||||
self.bangumi.update(data)
|
||||
logger.info(f"[Manager] Enable rule for {data.official_title}")
|
||||
|
||||
@@ -37,11 +37,17 @@ class RequestContent(RequestURL):
|
||||
return []
|
||||
|
||||
def get_xml(self, _url, retry: int = 3) -> xml.etree.ElementTree.Element:
|
||||
return xml.etree.ElementTree.fromstring(self.get_url(_url, retry).text)
|
||||
try:
|
||||
return xml.etree.ElementTree.fromstring(self.get_url(_url, retry).text)
|
||||
except ConnectionError:
|
||||
logger.warning(f"[Network] Failed to get XML: {_url}")
|
||||
|
||||
# API JSON
|
||||
def get_json(self, _url) -> dict:
|
||||
return self.get_url(_url).json()
|
||||
try:
|
||||
return self.get_url(_url).json()
|
||||
except ConnectionError:
|
||||
logger.warning(f"[Network] Failed to get JSON: {_url}")
|
||||
|
||||
def post_json(self, _url, data: dict) -> dict:
|
||||
return self.post_url(_url, data).json()
|
||||
@@ -63,4 +69,4 @@ class RequestContent(RequestURL):
|
||||
soup = self.get_xml(_url)
|
||||
return soup.find("./channel/title").text
|
||||
except ConnectionError:
|
||||
logger.warning(f"Failed to get RSS title: {_url}")
|
||||
logger.warning(f"[Network] Failed to get RSS title: {_url}")
|
||||
|
||||
@@ -96,6 +96,16 @@ defineEmits(['click']);
|
||||
:title="bangumi.group_name"
|
||||
type="primary"
|
||||
/>
|
||||
<ab-tag
|
||||
v-if="bangumi.dpi"
|
||||
:title="bangumi.dpi"
|
||||
type="primary"
|
||||
/>
|
||||
<ab-tag
|
||||
v-if="bangumi.subtitle"
|
||||
:title="bangumi.subtitle"
|
||||
type="primary"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,35 +1,18 @@
|
||||
<script lang="ts" setup>
|
||||
import {Down, Search} from '@icon-park/vue-next';
|
||||
import {ref} from 'vue';
|
||||
|
||||
const {
|
||||
onSelect,
|
||||
onInput,
|
||||
onSearch,
|
||||
inputValue,
|
||||
selectingProvider,
|
||||
provider,
|
||||
providers,
|
||||
getProviders,
|
||||
bangumiList
|
||||
} = useSearchStore();
|
||||
|
||||
const inputValue = ref<string>('');
|
||||
const selectingProvider = ref<boolean>(false);
|
||||
|
||||
const {input$, provider, providers, getProviders, bangumiList} = useSearchStore();
|
||||
|
||||
/**
|
||||
* - 输入中 debounce 600ms 后触发搜索
|
||||
* - 按回车或点击搜索 icon 按钮后触发搜索
|
||||
* - 切换 provider 源站时触发搜索
|
||||
*/
|
||||
|
||||
|
||||
function onInput(e: Event) {
|
||||
const value = (e.target as HTMLInputElement).value;
|
||||
input$.next(value);
|
||||
inputValue.value = value;
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
input$.next(inputValue.value);
|
||||
}
|
||||
|
||||
function onSelect(site: string) {
|
||||
provider.value = site;
|
||||
selectingProvider.value = !selectingProvider.value
|
||||
onSearch();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getProviders();
|
||||
@@ -48,7 +31,6 @@ onMounted(() => {
|
||||
space-x-12px
|
||||
w-400px
|
||||
overflow-hidden
|
||||
transition-width
|
||||
shadow-inner
|
||||
>
|
||||
<Search
|
||||
@@ -62,7 +44,7 @@ onMounted(() => {
|
||||
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Input to search"
|
||||
:placeholder="$t('topbar.search.placeholder')"
|
||||
input-reset
|
||||
:value="inputValue"
|
||||
@keyup.enter="onSearch"
|
||||
@@ -113,7 +95,7 @@ onMounted(() => {
|
||||
:key="index"
|
||||
:bangumi="item"
|
||||
type="search"
|
||||
transition-all
|
||||
transition-opacity
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -124,8 +106,8 @@ onMounted(() => {
|
||||
background: #4E2A94;
|
||||
}
|
||||
|
||||
.fade-enter-active, .fade-leave-active {
|
||||
transition: opacity .3s;
|
||||
.list-enter-active, .list-leave-active {
|
||||
transition: opacity 0.5s ease;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
@@ -20,7 +20,7 @@ const InnerStyle = computed(() => {
|
||||
|
||||
<template>
|
||||
<div p-1px rounded-16px inline-flex :class="type">
|
||||
<div bg-white rounded-12px px-8px text-10px :class="InnerStyle">
|
||||
<div bg-white rounded-12px px-8px text-10px truncate max-w-72px :class="InnerStyle">
|
||||
{{ title }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
const {t, changeLocale} = useMyI18n();
|
||||
const {running, onUpdate, offUpdate} = useAppInfo();
|
||||
|
||||
const search = ref('');
|
||||
const show = ref(false);
|
||||
const showAdd = ref(false);
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
"restart": "Restart",
|
||||
"shutdown": "Shutdown",
|
||||
"reset_rule": "Reset Rule",
|
||||
"search": {
|
||||
"placeholder": "Type to search"
|
||||
},
|
||||
"profile": {
|
||||
"title": "Profile",
|
||||
"pop_title": "Change Account",
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
"restart": "重启",
|
||||
"shutdown": "关闭",
|
||||
"reset_rule": "重置规则",
|
||||
"search": {
|
||||
"placeholder": "输入关键字搜索"
|
||||
},
|
||||
"profile": {
|
||||
"title": "账户设置",
|
||||
"pop_title": "修改账户",
|
||||
@@ -68,7 +71,7 @@
|
||||
"status": "状态",
|
||||
"delete": "删除",
|
||||
"disable": "禁用",
|
||||
"enable": "启用",
|
||||
"enable": "启用"
|
||||
},
|
||||
"player": {
|
||||
"hit": "请设置媒体播放器地址"
|
||||
|
||||
@@ -4,13 +4,15 @@ import {
|
||||
debounceTime,
|
||||
filter,
|
||||
switchMap,
|
||||
tap,
|
||||
takeUntil, tap,
|
||||
} from "rxjs";
|
||||
import type {BangumiRule} from "#/bangumi";
|
||||
|
||||
|
||||
export function useSearchStore () {
|
||||
export function useSearchStore() {
|
||||
const bangumiList = ref<BangumiRule[]>([]);
|
||||
const inputValue = ref<string>('');
|
||||
const selectingProvider = ref<boolean>(false);
|
||||
|
||||
const providers = ref<string[]>(['mikan', 'dmhy', 'nyaa']);
|
||||
const provider = ref<string>('mikan');
|
||||
@@ -25,22 +27,51 @@ export function useSearchStore () {
|
||||
providers.value = res;
|
||||
});
|
||||
|
||||
/**
|
||||
* - 输入中 debounce 600ms 后触发搜索
|
||||
* - 按回车或点击搜索 icon 按钮后触发搜索
|
||||
* - 切换 provider 源站时触发搜索
|
||||
*/
|
||||
|
||||
|
||||
|
||||
const bangumiInfo$ = input$.pipe(
|
||||
debounceTime(600),
|
||||
tap(() => {
|
||||
bangumiList.value = [];
|
||||
}),
|
||||
filter(Boolean),
|
||||
switchMap((input: string) => apiSearch.get(input, provider.value)),
|
||||
switchMap((input: string) => apiSearch.get(input, provider.value).pipe(takeUntil(input$))),
|
||||
tap((bangumi: BangumiRule) => {
|
||||
bangumiList.value.push(bangumi);
|
||||
}),
|
||||
)
|
||||
.subscribe()
|
||||
.subscribe()
|
||||
|
||||
function onInput(e: Event) {
|
||||
const value = (e.target as HTMLInputElement).value;
|
||||
input$.next(value);
|
||||
inputValue.value = value;
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
input$.next(inputValue.value);
|
||||
}
|
||||
|
||||
function onSelect(site: string) {
|
||||
provider.value = site;
|
||||
selectingProvider.value = !selectingProvider.value
|
||||
onSearch();
|
||||
}
|
||||
|
||||
return {
|
||||
input$,
|
||||
bangumiInfo$,
|
||||
inputValue,
|
||||
selectingProvider,
|
||||
onSelect,
|
||||
onInput,
|
||||
onSearch,
|
||||
provider,
|
||||
getProviders,
|
||||
providers,
|
||||
|
||||
Reference in New Issue
Block a user