Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from Rewrite0/issue-10
Browse files Browse the repository at this point in the history
fixes #10
  • Loading branch information
Rewrite0 committed May 12, 2023
2 parents 6172afe + 9bc6494 commit 96c1f38
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 51 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public-hoist-pattern[]=@vue/runtime-core
13 changes: 4 additions & 9 deletions src/api/bangumi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import type { BangumiItem } from '#/bangumi';

/**
* 添加番剧订阅
Expand All @@ -17,14 +18,8 @@ function addBangumi(type: string, rss_link: string) {
}

/**
* 获取AB存储的数据
* 获取订阅番剧数据
*/
const getABData = () => axios.get('api/v1/data');
const getABData = () => axios.get<BangumiItem[]>('api/v1/bangumi/getAll');

/**
* 删除番剧规则
* @param {string} name 番名 (title_raw)
*/
const removeRule = (name: string) => axios.get(`api/v1/removeRule/${name}`);

export { addBangumi, getABData, removeRule };
export { addBangumi, getABData };
7 changes: 5 additions & 2 deletions src/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import axios from 'axios';
import type { Config } from '#/config';

export async function setConfig(newConfig: Config) {
const { data } = await axios.post('api/v1/updateConfig', newConfig);
return data;
const { data } = await axios.post<{
message: 'Success' | 'Failed to update config';
}>('api/v1/updateConfig', newConfig);

return data.message === 'Success';
}

export async function getConfig() {
Expand Down
11 changes: 8 additions & 3 deletions src/api/program.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import axios from 'axios';

/** 重启 */
export const appRestart = () => axios.get('api/v1/restart');
export async function appRestart() {
const { data } = await axios.get<{ status: 'ok' }>('api/v1/restart');
return data.status === 'ok';
}

/** 启动 */
export const appStart = () => axios.get('api/v1/start');
Expand All @@ -11,6 +14,8 @@ export const appStop = () => axios.get('api/v1/stop');

/** 状态 */
export async function appStatus() {
const { data } = await axios.get<boolean>('api/v1/status');
return data;
const { data } = await axios.get<{ status: 'stop' | 'running' }>(
'api/v1/status'
);
return data.status !== 'stop';
}
2 changes: 1 addition & 1 deletion src/pages/YLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { status } = storeToRefs(programStore());
运行状态:
<div
class="i-carbon:dot-mark"
:class="{ 'text-red': !status, 'text-green': status }"
:class="[status ? 'text-green' : 'text-red']"
></div>
</div>
</el-header>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/bangumi/components/BangumiData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ onActivated(() => {
<b>不会</b> 出现在此处</span
>
<el-table
:data="store.data.bangumi_info"
:data="store.data"
stripe
border
style="width: 100%"
Expand All @@ -31,7 +31,7 @@ onActivated(() => {
<el-table-column prop="season" label="季度" width="60" />
<el-table-column prop="dpi" label="分辨率" />
<el-table-column prop="subtitle" label="字幕" />
<el-table-column prop="group" label="字幕组" />
<el-table-column prop="group_name" label="字幕组" />
</el-table>
</el-collapse-item>
</el-collapse>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/bangumi/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import BangumiData from './components/BangumiData.vue';
<!-- E 番剧列表 -->
</el-row>

<el-row :gutter="20">
<el-row :gutter="20" style="display: none">
<!-- S 添加新番 -->
<el-col :xs="24" :sm="24" :md="12" :lg="8">
<el-col :xs="24" :sm="24" :md="12" :lg="8" mb-20px>
<AddBangumi type="new" />
</el-col>
<!-- E 添加新番 -->

<!-- S 添加旧番 -->
<el-col :xs="24" :sm="24" :md="12" :lg="8">
<el-col :xs="24" :sm="24" :md="12" :lg="8" mb-20px>
<AddBangumi type="old" />
</el-col>
<!-- E 添加旧番 -->
Expand Down
4 changes: 2 additions & 2 deletions src/pages/config/components/ProgramItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const program = computed(() => form.program);
<template>
<ConfigFormRow title="主程序">
<ConfigFormCol label="RSS 检查间隔">
<el-input v-model.number="program.sleep_time" type="number" />
<el-input v-model.number="program.rss_time" type="number" />
</ConfigFormCol>

<ConfigFormCol label="重命名频率">
<el-input v-model.number="program.rename_times" type="number" />
<el-input v-model.number="program.rename_time" type="number" />
</ConfigFormCol>

<ConfigFormCol label="WebUI 端口" prop="program.webui_port">
Expand Down
2 changes: 1 addition & 1 deletion src/pages/config/components/ProxyItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const proxy = computed(() => form.proxy);
</el-select>
</ConfigFormCol>

<ConfigFormCol label="ip" prop="proxy.host">
<ConfigFormCol label="host" prop="proxy.host">
<el-input v-model="proxy.host"></el-input>
</ConfigFormCol>

Expand Down
19 changes: 12 additions & 7 deletions src/pages/config/components/RssParserItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<script lang="ts" setup>
import { form, rssParserLang, rssParserType, tfOptions } from '../form-data';
import {
form,
rssParserLang,
rssParserMethodType,
rssParserType,
tfOptions,
} from '../form-data';
const rssParser = computed(() => form.rss_parser);
Expand Down Expand Up @@ -51,13 +57,12 @@ watch(filter, (nv) => {
<el-input v-model="rssParser.custom_url"></el-input>
</ConfigFormCol>

<ConfigFormCol label="TMDB 解析">
<el-select v-model="rssParser.enable_tmdb" flex-1>
<ConfigFormCol label="解析类型">
<el-select v-model="rssParser.parser_type" flex-1>
<el-option
v-for="(opt, index) in tfOptions"
:key="index"
:label="opt.label"
:value="opt.value"
v-for="opt in rssParserMethodType"
:key="opt"
:value="opt"
></el-option>
</el-select>
</ConfigFormCol>
Expand Down
19 changes: 14 additions & 5 deletions src/pages/config/form-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import type {
ProxyType,
RenameMethod,
RssParserLang,
RssParserMethodType,
RssParserType,
} from '#/config';

export const form = reactive<Config>({
data_version: 4,
program: {
sleep_time: 0,
rename_times: 0,
rss_time: 0,
rename_time: 0,
webui_port: 0,
},
downloader: {
Expand All @@ -28,9 +28,9 @@ export const form = reactive<Config>({
type: 'mikan',
token: '',
custom_url: '',
enable_tmdb: false,
filter: [],
language: 'zh',
parser_type: 'parser',
},
bangumi_manage: {
enable: true,
Expand Down Expand Up @@ -60,10 +60,19 @@ export const form = reactive<Config>({

export const downloaderType: DownloaderType = ['qbittorrent'];
export const rssParserType: RssParserType = ['mikan'];
export const rssParserMethodType: RssParserMethodType = [
'tmdb',
'mikan',
'parser',
];
export const rssParserLang: RssParserLang = ['zh', 'en', 'jp'];
export const renameMethod: RenameMethod = ['normal', 'pn', 'advance', 'none'];
export const proxyType: ProxyType = ['http', 'https', 'socks5'];
export const notificationType: NotificationType = ['telegram', 'server-chan', 'bark'];
export const notificationType: NotificationType = [
'telegram',
'server-chan',
'bark',
];
export const tfOptions = [
{ label: '是', value: true },
{ label: '否', value: false },
Expand Down
14 changes: 7 additions & 7 deletions src/pages/debug/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ function restart() {
ElMessageBox.confirm('该操作将重启程序!', {
type: 'warning',
})
.then(async () => {
.then(() => {
appRestart()
.then(({ data }) => {
if (data.status === 'success') {
.then((res) => {
if (res) {
ElMessage({
message: '正在重启, 请稍后刷新页面...',
message: '重启中...',
type: 'success',
});
}
})
.catch((error) => {
console.error('🚀 ~ file: index.vue:41 ~ .then ~ error:', error);
ElMessage({
message: '操作失败, 请重试!',
message: '操作失败, 请手动重启容器!',
type: 'error',
});
});
Expand All @@ -51,7 +51,7 @@ function restart() {
<section class="debug">
<el-row :gutter="20">
<!-- S 重置数据 -->
<el-col :xs="24" :sm="12" :lg="8">
<el-col :xs="24" :sm="12" :lg="8" mb-20px>
<el-card shadow="hover">
<template #header>
<div class="card-header">
Expand All @@ -69,7 +69,7 @@ function restart() {
<!-- E 重置数据 -->

<!-- S 重启程序 -->
<el-col :xs="24" :sm="12" :lg="8" style="display: none">
<el-col :xs="24" :sm="12" :lg="8" mb-20px>
<el-card shadow="hover">
<template #header>
<div class="card-header">
Expand Down
3 changes: 2 additions & 1 deletion src/store/bangumi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getABData } from '../api/bangumi';
import type { BangumiItem } from '#/bangumi';

export const bangumiStore = defineStore('bangumi', () => {
const data = ref({ rss_link: '', data_version: 4, bangumi_info: [] });
const data = ref<BangumiItem[]>();

const get = async () => {
const res = await getABData();
Expand Down
39 changes: 35 additions & 4 deletions src/store/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ElMessage } from 'element-plus';
import { ElMessage, ElMessageBox } from 'element-plus';
import { getConfig, setConfig } from '@/api/config';
import { appRestart } from '@/api/program';
import type { Config } from '#/config';

const { status } = storeToRefs(programStore());

export const configStore = defineStore('config', () => {
const config = ref<Config>();

Expand All @@ -13,13 +16,41 @@ export const configStore = defineStore('config', () => {
let finalConfig: Config;
if (config.value !== undefined) {
finalConfig = Object.assign(config.value, newConfig);
const { message } = await setConfig(finalConfig);
const res = await setConfig(finalConfig);

if (message === 'Success') {
if (res) {
ElMessage({
message: '保存成功, 请重启容器以应用新的配置!',
message: '保存成功!',
type: 'success',
});

if (!status.value) {
ElMessageBox.confirm('当前程序没有运行,是否重启?', {
type: 'warning',
})
.then(() => {
appRestart()
.then((res) => {
if (res) {
ElMessage({
message: '重启中...',
type: 'success',
});
}
})
.catch((error) => {
console.error(
'🚀 ~ file: index.vue:41 ~ .then ~ error:',
error
);
ElMessage({
message: '操作失败, 请手动重启容器!',
type: 'error',
});
});
})
.catch(() => {});
}
} else {
ElMessage({
message: '保存失败, 请重试!',
Expand Down
18 changes: 18 additions & 0 deletions types/bangumi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface BangumiItem {
id: number;
official_title: string;
year: string | null;
title_raw: string;
season: number;
season_raw: string;
group_name: string;
dpi: string;
source: string;
subtitle: string;
eps_collect: boolean;
offset: number;
filter: string[];
rss_link: string[];
poster_link: string;
added: boolean;
}
9 changes: 5 additions & 4 deletions types/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { UnionToTuple } from '#/utils';

export interface Config {
data_version: 4;
program: {
sleep_time: number;
rename_times: number;
rss_time: number;
rename_time: number;
webui_port: number;
};
downloader: {
Expand All @@ -20,9 +19,9 @@ export interface Config {
type: 'mikan';
token: string;
custom_url: string;
enable_tmdb: boolean;
filter: Array<string>;
language: 'zh' | 'en' | 'jp';
parser_type: 'tmdb' | 'mikan' | 'parser';
};
bangumi_manage: {
enable: boolean;
Expand Down Expand Up @@ -64,6 +63,8 @@ export type Notification = getItem<'notification'>;
export type DownloaderType = UnionToTuple<Downloader['type']>;
/** rss parser 源 */
export type RssParserType = UnionToTuple<RssParser['type']>;
/** rss parser 方法 */
export type RssParserMethodType = UnionToTuple<RssParser['parser_type']>;
/** rss parser 语言 */
export type RssParserLang = UnionToTuple<RssParser['language']>;
/** 重命名方式 */
Expand Down

0 comments on commit 96c1f38

Please sign in to comment.