Skip to content

Commit

Permalink
Fix queue, now is possible add blacklist and only administrator can d…
Browse files Browse the repository at this point in the history
…elete or re-download anime
  • Loading branch information
cesxhin committed Oct 15, 2023
1 parent 3aaaf99 commit 8f26c51
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 23 deletions.
30 changes: 18 additions & 12 deletions src/components/card/details/detailsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,29 @@
</template>
<template v-else>
<ButtonRequestDownload
:name="item.name"
:url="item.urlPageDownload"
:nameCfg="store.getSchemasBySelectSearch.nameCfg"
:type="item.type"
/>
</template>
</template>
<template v-else>
<ButtonLoading
:action="reDownload"
color="warning"
icon="$redownload"
class="mr-1"
/>
<ButtonLoading
:action="remove"
color="error"
icon="$trash"
/>

<template v-if="useGet(store.getUser, 'role', 0) === 100">
<ButtonLoading
:action="reDownload"
color="warning"
icon="$redownload"
class="mr-1"
/>

<ButtonLoading
:action="remove"
color="error"
icon="$trash"
/>
</template>
<template v-if="!isNil(store.getUser) || !isNil(item.watchList)">
<ButtonLoading
:action="() => setWatchList(item.watchList)"
Expand Down Expand Up @@ -182,7 +187,8 @@ async function remove(){
await apiAsync(
removeContent({
name: item.value.name_id,
nameCfg: item.value.nameCfg
nameCfg: item.value.nameCfg,
username: store.getUser?.username
}, null, item.value.type),
() => {
clearTimeout(tokenStatus.value);
Expand Down
5 changes: 4 additions & 1 deletion src/components/card/details/getStarted.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ async function setProgress(){
(err) => {
if(err.response.status === 404)
foundProgress.value = false;
}
},
null,
null,
true
)
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/components/elements/buttonRequestDownload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

<script setup>
const props = defineProps({
name:{
type: String
},
url:{
type: String
},
Expand All @@ -19,7 +22,7 @@ const props = defineProps({
type: String
})
const { url, nameCfg, type } = toRefs(props);
const { name, url, nameCfg, type } = toRefs(props);
const btnDisabled = ref(false);
const loading = ref(true);
Expand All @@ -30,6 +33,7 @@ async function checkQueue(){
loading.value = true;
await apiAsync(
findQueue({
name: name.value,
url: url.value,
nameCfg: nameCfg.value
}, type.value),
Expand All @@ -45,10 +49,16 @@ async function checkQueue(){
async function sendRequestQueue(){
await apiAsync(
requestDownloadContent(null, {
name: name.value,
url: url.value,
nameCfg: nameCfg.value
}, type.value),
() => btnDisabled.value = true
() => btnDisabled.value = true,
null,
null,
{
200: 'The request has been sent! Please wait a few moments, thanks'
}
)
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/room/bookManga.vue
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,11 @@ async function load() {
getStatus({
name: route.query.name
}, 'book'),
(data) => chapters.value = data
(data) => chapters.value = data,
null,
null,
null,
true
);
if(!isNil(progress.value))
Expand Down
6 changes: 5 additions & 1 deletion src/components/room/videoAnime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,11 @@ async function getVideoEpisode() {
getStatus({
name: route.query.name
}, 'video'),
(data) => episodes.value = data
(data) => episodes.value = data,
null,
null,
null,
true
)
}
Expand Down
8 changes: 8 additions & 0 deletions src/composables/useApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ export default function useApi() {
return await axios.put(`/api/manga/request-queue`, data, { params, timeout: TIMEOUT });
}

async function blackList(params, data, type) {
if (type === 'video')
return await axios.put(`/api/anime/blacklist`, data, { params, timeout: TIMEOUT });
else
return await axios.put(`/api/manga/blacklist`, data, { params, timeout: TIMEOUT });
}

async function downloadContent(params, data, type) {
if (type === 'video')
return await axios.post(`/api/anime/download`, data, { params, timeout: TIMEOUT });
Expand Down Expand Up @@ -186,6 +193,7 @@ export default function useApi() {
downloadContent,
findQueue,
requestDownloadContent,
blackList,
getAllQueue,
removeQueue,
reDownloadContent,
Expand Down
32 changes: 26 additions & 6 deletions src/pages/queue/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
>
<thead>
<tr>
<th class="text-left">
Name
</th>
<th class="text-left">
Url
</th>
Expand All @@ -23,6 +26,7 @@
v-for="item in listQueueAnime"
:key="item.name"
>
<td>{{ item.name }}</td>
<td>{{ item.url }}</td>
<td>{{ item.nameCfg }}</td>
<td class="text-center">
Expand All @@ -34,14 +38,14 @@
/>
<ButtonLoading
color="error"
:action="() => reject(item.url, item.nameCfg, 'video')"
:action="() => reject(item.name, item.url, item.nameCfg, 'video')"
icon="$x"
class="mr-1"
/>
<ButtonLoading
color="black"
icon="$blacklist"
:action="() => null"
:action="() => addToBlackList(item.name, item.url, item.nameCfg, 'video')"
/>
</td>
</tr>
Expand All @@ -55,6 +59,9 @@
>
<thead>
<tr>
<th class="text-left">
Name
</th>
<th class="text-left">
Url
</th>
Expand All @@ -71,6 +78,7 @@
v-for="item in listQueueManga"
:key="item.name"
>
<td>{{ item.name }}</td>
<td>{{ item.url }}</td>
<td>{{ item.nameCfg }}</td>
<td class="text-center">
Expand All @@ -82,14 +90,14 @@
/>
<ButtonLoading
color="error"
:action="() => reject(item.url, item.nameCfg, 'book')"
:action="() => reject(item.name, item.url, item.nameCfg, 'book')"
icon="$x"
class="mr-1"
/>
<ButtonLoading
color="black"
icon="$blacklist"
:action="() => null"
:action="() => addToBlackList(item.name, item.url, item.nameCfg, 'book')"
/>
</td>
</tr>
Expand All @@ -103,7 +111,7 @@
import { isNil } from 'lodash';
const store = useStore();
const {apiAsync, getAllQueue, downloadContent, removeQueue} = useApi();
const {apiAsync, getAllQueue, downloadContent, removeQueue, blackList} = useApi();
const listQueueAnime = ref([]);
const listQueueManga = ref([]);
Expand Down Expand Up @@ -154,9 +162,21 @@ async function accept(url, nameCfg, type){
)
}
async function reject(url, nameCfg, type){
async function reject(name, url, nameCfg, type){
await apiAsync(
removeQueue(null, {
name,
nameCfg,
url
}, type),
() => time.value = Date.now()
)
}
async function addToBlackList(name, url, nameCfg, type){
await apiAsync(
blackList(null, {
name,
nameCfg,
url
}, type),
Expand Down
11 changes: 11 additions & 0 deletions src/server/api/anime/[...].js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ router.put('/request-queue', defineEventHandler(async (event) => {
}
}))

router.put('/blacklist', defineEventHandler(async (event) => {
const params = getQuery(event);
const data = await readBody(event);

try{
return (await axios.put(`${API_BASE}/episode/blacklist`, data, {params})).data;
}catch(err){
throw createError({ statusCode: err.response.status, statusMessage: err.response.statusText })
}
}))

router.get('/queue', defineEventHandler(async (event) => {
const params = getQuery(event);

Expand Down
10 changes: 10 additions & 0 deletions src/server/api/manga/[...].js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ router.delete('/queue', defineEventHandler(async (event) => {
}
}))

router.put('/blacklist', defineEventHandler(async (event) => {
const params = getQuery(event);
const data = await readBody(event);

try{
return (await axios.put(`${API_BASE}/chapter/blacklist`, data, {params})).data;
}catch(err){
throw createError({ statusCode: err.response.status, statusMessage: err.response.statusText })
}
}))

router.get('/register', defineEventHandler(async (event) => {
const {id, ...params} = getQuery(event);
Expand Down

0 comments on commit 8f26c51

Please sign in to comment.