Skip to content
Snippets Groups Projects
Commit 3733c20d authored by Konrad Mohrfeldt's avatar Konrad Mohrfeldt :koala:
Browse files

feat: add read-only playlists store

refs #127
parent de26eb39
No related branches found
No related tags found
No related merge requests found
......@@ -156,3 +156,15 @@ export const steeringAuthInit: { getRequestDefaults: () => RequestInit } = {
}
},
}
export const tankAuthInit: { getRequestDefaults: () => RequestInit } = {
getRequestDefaults() {
const authStore = useAuthStore()
return {
headers: {
Authorization: `Bearer ${authStore.currentUser?.tankSessionToken}`,
},
}
},
}
import { defineStore } from 'pinia'
import { tankAuthInit } from '@/stores/auth'
import { APIListPaginated, APIRetrieve, createExtendableAPI, createTankURL } from '@/api'
import { Playlist } from '@/types'
/**
* Calculates the duration of a playlist.
* May return null if the playlist contains entries with an invalid duration.
* @param playlist
*/
export function calculatePlaylistDurationInSeconds(playlist: Playlist) {
let duration = 0
for (const entry of playlist.entries) {
// entry.duration may be null/NaN if the entry references
// a stream or other resources without an inherent duration
if (typeof entry.duration !== 'number' || isNaN(entry.duration)) {
return null
}
// entry.duration is in nanoseconds
duration += entry.duration / 1_000_000_000
}
return duration
}
export const usePlaylistStore = defineStore('playlists', () => {
const endpoint = createTankURL.prefix('playlists')
const { base, ...api } = createExtendableAPI<Playlist>(endpoint, tankAuthInit)
const { list } = APIListPaginated(api)
return {
...base,
list,
...APIRetrieve(api),
}
})
import { components as steeringComponents } from '@/steering-types'
import { components as tankComponents } from '@/tank-types'
export type Module = {
icon: string
......@@ -17,3 +18,4 @@ export type PaginationData = {
export type TimeSlot = Required<steeringComponents['schemas']['TimeSlot']>
export type Show = Required<steeringComponents['schemas']['Show']>
export type Playlist = Required<tankComponents['schemas']['store.Playlist']>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment