2024-01-24 22:39:47 +00:00
|
|
|
import { cache, http } from '@/services'
|
2024-01-18 11:13:05 +00:00
|
|
|
|
|
|
|
export const playlistCollaborationService = {
|
|
|
|
async createInviteLink (playlist: Playlist) {
|
|
|
|
if (playlist.is_smart) {
|
|
|
|
throw Error('Smart playlists are not collaborative.')
|
|
|
|
}
|
|
|
|
|
|
|
|
const token = (await http.post<{ token: string }>(`playlists/${playlist.id}/collaborators/invite`)).token
|
|
|
|
return `${window.location.origin}/#/playlist/collaborate/${token}`
|
|
|
|
},
|
|
|
|
|
|
|
|
async acceptInvite (token: string) {
|
|
|
|
return http.post<Playlist>(`playlists/collaborators/accept`, { token })
|
2024-01-24 22:39:47 +00:00
|
|
|
},
|
|
|
|
|
2024-01-26 14:24:46 +00:00
|
|
|
async fetchCollaborators (playlist: Playlist) {
|
2024-01-24 22:39:47 +00:00
|
|
|
return http.get<PlaylistCollaborator[]>(`playlists/${playlist.id}/collaborators`)
|
|
|
|
},
|
|
|
|
|
|
|
|
async removeCollaborator (playlist: Playlist, collaborator: PlaylistCollaborator) {
|
|
|
|
await http.delete(`playlists/${playlist.id}/collaborators`, { collaborator: collaborator.id })
|
|
|
|
// invalidate the playlist cache
|
|
|
|
cache.remove(['playlist.songs', playlist.id])
|
2024-01-18 11:13:05 +00:00
|
|
|
}
|
|
|
|
}
|