Skip to content

Commit

Permalink
webui: add rss manage function.
Browse files Browse the repository at this point in the history
  • Loading branch information
EstrellaXD committed Sep 4, 2023
1 parent 20c3c42 commit fdd6769
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 107 deletions.
30 changes: 20 additions & 10 deletions backend/src/module/api/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ async def add_rss(rss: RSSItem, current_user=Depends(get_current_user)):
return u_response(result)


@router.post(path="/enable/many", response_model=APIResponse)
async def enable_many_rss(rss_ids: list[int], current_user=Depends(get_current_user)):
if not current_user:
raise UNAUTHORIZED
with RSSEngine() as engine:
result = engine.enable_list(rss_ids)
return u_response(result)


@router.delete(path="/delete/{rss_id}", response_model=APIResponse)
async def delete_rss(rss_id: int, current_user=Depends(get_current_user)):
if not current_user:
Expand All @@ -47,6 +56,15 @@ async def delete_rss(rss_id: int, current_user=Depends(get_current_user)):
)


@router.post(path="/delete/many", response_model=APIResponse)
async def delete_many_rss(rss_ids: list[int], current_user=Depends(get_current_user)):
if not current_user:
raise UNAUTHORIZED
with RSSEngine() as engine:
result = engine.delete_list(rss_ids)
return u_response(result)


@router.patch(path="/disable/{rss_id}", response_model=APIResponse)
async def disable_rss(rss_id: int, current_user=Depends(get_current_user)):
if not current_user:
Expand All @@ -69,16 +87,8 @@ async def disable_many_rss(rss_ids: list[int], current_user=Depends(get_current_
if not current_user:
raise UNAUTHORIZED
with RSSEngine() as engine:
if engine.disable_list(rss_ids):
return JSONResponse(
status_code=200,
content={"msg_en": "Disable RSS successfully.", "msg_zh": "禁用 RSS 成功。"},
)
else:
return JSONResponse(
status_code=406,
content={"msg_en": "Disable RSS failed.", "msg_zh": "禁用 RSS 失败。"},
)
result = engine.disable_list(rss_ids)
return u_response(result)


@router.patch(path="/update/{rss_id}", response_model=APIResponse)
Expand Down
11 changes: 11 additions & 0 deletions backend/src/module/database/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def update(self, _id: int, data: RSSUpdate):
self.session.refresh(db_data)
return True

def enable(self, _id: int):
statement = select(RSSItem).where(RSSItem.id == _id)
db_data = self.session.exec(statement).first()
if not db_data:
return False
db_data.enabled = True
self.session.add(db_data)
self.session.commit()
self.session.refresh(db_data)
return True

def disable(self, _id: int):
statement = select(RSSItem).where(RSSItem.id == _id)
db_data = self.session.exec(statement).first()
Expand Down
26 changes: 26 additions & 0 deletions backend/src/module/rss/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ def add_rss(self, rss_link: str, name: str | None = None, aggregate: bool = True
def disable_list(self, rss_id_list: list[int]):
for rss_id in rss_id_list:
self.rss.disable(rss_id)
return ResponseModel(
status=True,
status_code=200,
msg_en="Disable RSS successfully.",
msg_zh="禁用 RSS 成功。",
)

def enable_list(self, rss_id_list: list[int]):
for rss_id in rss_id_list:
self.rss.enable(rss_id)
return ResponseModel(
status=True,
status_code=200,
msg_en="Enable RSS successfully.",
msg_zh="启用 RSS 成功。",
)

def delete_list(self, rss_id_list: list[int]):
for rss_id in rss_id_list:
self.rss.delete(rss_id)
return ResponseModel(
status=True,
status_code=200,
msg_en="Delete RSS successfully.",
msg_zh="删除 RSS 成功。",
)

def pull_rss(self, rss_item: RSSItem) -> list[Torrent]:
torrents = self._get_torrents(rss_item)
Expand Down
5 changes: 5 additions & 0 deletions webui/src/api/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export const apiRSS = {
return data!;
},

async enableMany(rss_list: number[]) {
const { data } = await axios.post<ApiSuccess>(`api/v1/rss/enable/many`, rss_list);
return data!;
},

async refreshAll() {
const { data } = await axios.get<ApiSuccess>('api/v1/rss/refresh/all');
return data!;
Expand Down
4 changes: 3 additions & 1 deletion webui/src/components/ab-bangumi-card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ defineEmits(['click']);
<div text-h3 truncate>{{ name }}</div>
<ab-tag
:title="`Season ${season}`"
type="primary"
/>
</div>
</div>
Expand All @@ -90,6 +91,7 @@ defineEmits(['click']);
<div flex space-x-8px>
<ab-tag
:title="`Season ${season}`"
type="primary"
/>
<ab-tag
v-if="group !== ''"
Expand All @@ -99,7 +101,7 @@ defineEmits(['click']);
</div>
</div>
</div>
<ab-add round="true" type="medium" @click="()=> $emit('click')"/>
<ab-add :round="true" type="medium" @click="()=> $emit('click')"/>
</div>
</div>
</template>
Expand Down
11 changes: 7 additions & 4 deletions webui/src/components/ab-rss-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ withDefaults(
parser: string;
}>(),
{
enable: false,
aggregate: false,
}
);
const select = ref(false);
defineEmits(['on-select']);
const checked = ref(false);
</script>

<template>
<div class="rss-group">
<div class="left-side" flex space-x-40px>
<ab-checkbox
small
:model-value="select"
@update:model-value="select = $event"
:model-value="checked"
@update:model-value="checked = $event"
@click="() => $emit('on-select')"
/>
<div w-200px text-h3 truncate>{{ name }}</div>
<div w-300px text-h3 truncate>{{ url }}</div>
Expand Down
28 changes: 15 additions & 13 deletions webui/src/components/basic/ab-search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const props = withDefaults(
);
const emit = defineEmits(['update:value', 'click-search']);
const { site, providers, bangumiInfo$} = storeToRefs(useSearchStore());
const { getProviders, onInput } = useSearchStore();
const {site, providers } = storeToRefs(useSearchStore());
const {getProviders} = useSearchStore();
onMounted(() => {
getProviders();
Expand Down Expand Up @@ -60,8 +60,7 @@ function onSearch() {
:value="value"
:placeholder="placeholder"
input-reset
@keyup.enter="onInput"
@input="onInput"
@keyup.enter="onSearch"
/>
<div
h-full
Expand Down Expand Up @@ -104,15 +103,18 @@ function onSearch() {
</div>
</div>
</div>
<div abs top-84px left-200px z-98>
<ab-bangumi-card
name="name"
season=1
poster=""
group="Lilith-Raws"
type="search"
/>
</div>
<!-- <div -->
<!-- v-if="bangumiInfo$" -->
<!-- abs top-84px left-200px z-98> -->
<!-- <ab-bangumi-card-->
<!-- v-for="i in bangumiInfo$" -->
<!-- :key="i.id"-->
<!-- :poster="i.poster_link ?? ''" -->
<!-- :name="i.official_title" -->
<!-- :season="i.season" -->
<!-- :group="i.group_name" -->
<!-- /> -->
<!-- </div> -->
</template>

<style lang="scss" scoped>
Expand Down
1 change: 0 additions & 1 deletion webui/src/components/basic/ab-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const props = withDefaults(
items: Array<SelectItem | string>;
}>(),
{
items: ['test1', 'test2'],
}
);
Expand Down
8 changes: 5 additions & 3 deletions webui/src/components/layout/ab-topbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const items = [
},
];
const onSearchFocus = ref(false);
onBeforeMount(() => {
onUpdate();
});
Expand All @@ -68,14 +70,14 @@ onUnmounted(() => {
</script>

<template>
<div h-60px bg-theme-row text-white rounded-12px fx-cer px-24px>
<div h-60px bg-theme-row text-white rounded-16px fx-cer px-24px>
<div flex space-x-16px>
<div fx-cer space-x-16px>
<img src="/images/logo-light.svg" alt="favicon" wh-24px/>
<img src="/images/AutoBangumi.svg" alt="AutoBangumi" h-24px rel top-2px/>
<img v-show="onSearchFocus === false" src="/images/AutoBangumi.svg" alt="AutoBangumi" h-24px rel top-2px/>
</div>

<ab-search v-model:value="search"/>
<ab-search/>
</div>

<div ml-auto>
Expand Down
3 changes: 2 additions & 1 deletion webui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"url": "Url",
"status": "Status",
"delete": "Delete",
"disable": "Disable"
"disable": "Disable",
"enable": "Enable",
},
"player": {
"hit": "Please set up the media player"
Expand Down
1 change: 1 addition & 0 deletions webui/src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"status": "状态",
"delete": "删除",
"disable": "禁用",
"enable": "启用",
},
"player": {
"hit": "请设置媒体播放器地址"
Expand Down
1 change: 1 addition & 0 deletions webui/src/pages/index/bangumi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ definePage({
:poster="i.poster_link ?? ''"
:name="i.official_title"
:season="i.season"
type="primary"
@click="() => openEditPopup(i)"
></ab-bangumi-card>

Expand Down
20 changes: 11 additions & 9 deletions webui/src/pages/index/rss.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
const {rss, selectedRSS} = storeToRefs(useRSSStore());
const {getAll, deleteSelected, disableSelected, appendSelected} = useRSSStore();
const {getAll, deleteSelected, disableSelected, enableSelected, handleCheckboxClicked} = useRSSStore();
onActivated(() => {
getAll();
Expand Down Expand Up @@ -36,16 +36,18 @@ definePage({
:url="i.url"
:enable="i.enabled"
:parser="i.parser"
:aggregate="i.aggregate">
:aggregate="i.aggregate"
@on-select="handleCheckboxClicked(i.id)"
>
</ab-rss-item>
</div>
<div line my-12px></div>
<div text-h2>
{{ selectedRSS }}
</div>
<div flex="~ justify-end" space-x-10px>
<ab-button @click="disableSelected">{{ $t('rss.disable') }}</ab-button>
<ab-button class="type-warn" @click="deleteSelected">{{ $t('rss.delete') }}</ab-button>
<div v-if="selectedRSS.length > 0">
<div line my-12px></div>
<div flex="~ justify-end" space-x-10px>
<ab-button @click="enableSelected">{{ $t('rss.enable') }}</ab-button>
<ab-button @click="disableSelected">{{ $t('rss.disable') }}</ab-button>
<ab-button class="type-warn" @click="deleteSelected">{{ $t('rss.delete') }}</ab-button>
</div>
</div>
</ab-container>
</div>
Expand Down
37 changes: 26 additions & 11 deletions webui/src/store/rss.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import type { RSS } from '#/rss';
import type { ApiSuccess } from '#/api';
import type {RSS} from '#/rss';
import type {ApiSuccess} from '#/api';

export const useRSSStore = defineStore('rss', () => {
const message = useMessage();
const rss = ref<RSS[]>();
const selectedRSS= ref<number[]>([]);
const selectedRSS = ref<number[]>([]);

const { execute: getAll, onResult: onRSSResult } = useApi(
const {execute: getAll, onResult: onRSSResult} = useApi(
apiRSS.get
);
const { execute: updateRSS, onResult: onUpdateRSSResult } = useApi(
const {execute: updateRSS, onResult: onUpdateRSSResult} = useApi(
apiRSS.update
);
const { execute: disableRSS, onResult: onDisableRSSResult} = useApi(
const {execute: disableRSS, onResult: onDisableRSSResult} = useApi(
apiRSS.disableMany
);
const { execute: deleteRSS, onResult: onDeleteRSSResult } = useApi(
const {execute: deleteRSS, onResult: onDeleteRSSResult} = useApi(
apiRSS.deleteMany
);

const {execute: enableRSS, onResult: onEnableRSSResult} = useApi(
apiRSS.enableMany
);


onRSSResult((res) => {
function sort(arr: RSS[]) {
Expand All @@ -43,18 +47,28 @@ export const useRSSStore = defineStore('rss', () => {
deleteRSS(selectedRSS.value);
}

function enableSelected() {
enableRSS(selectedRSS.value);
}

function actionSuccess(apiRes: ApiSuccess) {
message.success(apiRes.msg_en);
refresh();
}

function appendSelected(id: number) {
selectedRSS.value.push(id);
function handleCheckboxClicked(id: number) {
if (selectedRSS.value.includes(id)) {
// delete id in list
selectedRSS.value = selectedRSS.value.filter((e) => e !== id);
} else {
selectedRSS.value.push(id)
}
}

onUpdateRSSResult(actionSuccess);
onDeleteRSSResult(actionSuccess);
onDisableRSSResult(actionSuccess)
onDisableRSSResult(actionSuccess);
onEnableRSSResult(actionSuccess);

return {
rss,
Expand All @@ -63,6 +77,7 @@ export const useRSSStore = defineStore('rss', () => {
selectedRSS,
disableSelected,
deleteSelected,
appendSelected,
enableSelected,
handleCheckboxClicked,
};
});
Loading

0 comments on commit fdd6769

Please sign in to comment.