mirror of
https://github.com/KevinMidboe/seasoned.git
synced 2026-03-10 19:39:10 +00:00
Do a separate api call to check if an item is requested already
This commit is contained in:
24
src/api.js
24
src/api.js
@@ -137,6 +137,28 @@ const request = (id, type, authorization_token=undefined) => {
|
|||||||
.catch(error => { console.error(`api error requesting: ${id}, type: ${type}`); throw error })
|
.catch(error => { console.error(`api error requesting: ${id}, type: ${type}`); throw error })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check request status by tmdb id and type
|
||||||
|
* @param {number} tmdb id
|
||||||
|
* @param {string} type
|
||||||
|
* @returns {object} Success/Failure response
|
||||||
|
*/
|
||||||
|
const getRequestStatus = (id, type, authorization_token=undefined) => {
|
||||||
|
const url = new URL('v2/request', SEASONED_URL)
|
||||||
|
url.pathname = path.join(url.pathname, id.toString())
|
||||||
|
url.searchParams.append('type', type)
|
||||||
|
|
||||||
|
return fetch(url.href)
|
||||||
|
.then(resp => {
|
||||||
|
const status = resp.status;
|
||||||
|
if (status === 200) { return true }
|
||||||
|
else if (status === 404) { return false }
|
||||||
|
else {
|
||||||
|
console.error(`api error getting request status for id ${id} and type ${type}`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => Promise.reject(err))
|
||||||
|
}
|
||||||
|
|
||||||
// - - - Authenticate with plex - - -
|
// - - - Authenticate with plex - - -
|
||||||
|
|
||||||
@@ -210,4 +232,4 @@ const elasticSearchMoviesAndShows = (query) => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
export { getMovie, getShow, getTmdbListByPath, searchTmdb, searchTorrents, addMagnet, request, plexAuthenticate, getEmoji, elasticSearchMoviesAndShows }
|
export { getMovie, getShow, getTmdbListByPath, searchTmdb, searchTorrents, addMagnet, request, getRequestStatus, plexAuthenticate, getEmoji, elasticSearchMoviesAndShows }
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ import Person from './Person.vue'
|
|||||||
|
|
||||||
import LoadingPlaceholder from './ui/LoadingPlaceholder.vue'
|
import LoadingPlaceholder from './ui/LoadingPlaceholder.vue'
|
||||||
|
|
||||||
import { getMovie, getShow, request } from '@/api.js'
|
import { getMovie, getShow, request, getRequestStatus } from '@/api.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['id', 'type'],
|
props: ['id', 'type'],
|
||||||
@@ -157,13 +157,15 @@ export default {
|
|||||||
this.title = movie.title
|
this.title = movie.title
|
||||||
this.poster = movie.poster
|
this.poster = movie.poster
|
||||||
this.backdrop = movie.backdrop
|
this.backdrop = movie.backdrop
|
||||||
this.matched = movie.existsInPlex;
|
this.matched = movie.existsInPlex
|
||||||
// TODO should get a request response, used /plex/:id before
|
this.checkIfRequested(movie)
|
||||||
// this.requested = movie.requested;
|
.then(status => this.requested = status )
|
||||||
this.requested = true
|
|
||||||
|
|
||||||
document.title = movie.title + storage.pageTitlePostfix;
|
document.title = movie.title + storage.pageTitlePostfix;
|
||||||
},
|
},
|
||||||
|
async checkIfRequested(movie) {
|
||||||
|
return await getRequestStatus(movie.id, movie.type)
|
||||||
|
},
|
||||||
nestedDataToString(data) {
|
nestedDataToString(data) {
|
||||||
let nestedArray = []
|
let nestedArray = []
|
||||||
data.forEach(item => nestedArray.push(item));
|
data.forEach(item => nestedArray.push(item));
|
||||||
|
|||||||
Reference in New Issue
Block a user