koel/resources/assets/js/components/profile-preferences/LastfmIntegration.vue

93 lines
2.7 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
<section class="text-secondary">
<h1>Last.fm Integration</h1>
2022-04-21 22:51:48 +00:00
<div v-if="useLastfm" data-testid="lastfm-integrated">
2022-04-15 14:24:30 +00:00
<p>
This installation of Koel integrates with Last.fm.
2022-04-21 22:51:48 +00:00
<span v-if="connected">
2022-04-15 14:24:30 +00:00
It appears that you have connected your Last.fm account as well Perfect!
</span>
<span v-else>It appears that you havent connected to your Last.fm account though.</span>
</p>
<p>
Connecting Koel and your Last.fm account enables such exciting features as
<a
class="text-orange"
href="https://www.last.fm/about/trackmymusic"
rel="noopener"
2022-04-21 22:51:48 +00:00
target="_blank"
2022-04-15 14:24:30 +00:00
>
scrobbling
</a>.
</p>
<div class="buttons">
2022-04-21 22:51:48 +00:00
<Btn class="connect" @click.prevent="connect">
2022-04-15 14:24:30 +00:00
<i class="fa fa-lastfm"></i>
2022-04-21 22:51:48 +00:00
{{ connected ? 'Reconnect' : 'Connect' }}
2022-04-15 17:00:08 +00:00
</Btn>
2022-04-15 14:24:30 +00:00
2022-04-21 22:51:48 +00:00
<Btn v-if="connected" class="disconnect" gray @click.prevent="disconnect">Disconnect</Btn>
2022-04-15 14:24:30 +00:00
</div>
</div>
<div v-else data-testid="lastfm-not-integrated">
<p>
This installation of Koel has no Last.fm integration.
2022-04-21 22:51:48 +00:00
<span v-if="currentUser.is_admin" data-testid="lastfm-admin-instruction">
2022-04-15 14:24:30 +00:00
Visit
<a href="https://docs.koel.dev/3rd-party.html#last-fm" class="text-orange" target="_blank">Koels Wiki</a>
for a quick how-to.
</span>
<span v-else data-testid="lastfm-user-instruction">
Try politely asking an administrator to enable it.
</span>
</p>
</div>
</section>
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2022-04-21 22:51:48 +00:00
import { computed, defineAsyncComponent, toRef } from 'vue'
2022-04-24 08:50:45 +00:00
import { commonStore, userStore } from '@/stores'
import { authService, httpService } from '@/services'
2022-04-15 14:24:30 +00:00
import { forceReloadWindow } from '@/utils'
2022-04-21 18:39:18 +00:00
const Btn = defineAsyncComponent(() => import('@/components/ui/Btn.vue'))
2022-04-15 14:24:30 +00:00
2022-04-21 22:51:48 +00:00
const currentUser = toRef(userStore.state, 'current')
2022-04-24 08:50:45 +00:00
const useLastfm = toRef(commonStore.state, 'useLastfm')
2022-04-15 14:24:30 +00:00
2022-04-21 22:51:48 +00:00
const connected = computed(() => Boolean(currentUser.value.preferences.lastfm_session_key))
2022-04-15 14:24:30 +00:00
2022-04-15 17:00:08 +00:00
/**
* Connect the current user to Last.fm.
* This method opens a new window.
* Koel will reload once the connection is successful.
*/
const connect = () => window.open(
2022-04-24 08:50:45 +00:00
`${window.BASE_URL}lastfm/connect?api_token=${authService.getToken()}`,
2022-04-15 17:00:08 +00:00
'_blank',
'toolbar=no,titlebar=no,location=no,width=1024,height=640'
)
2022-04-15 14:24:30 +00:00
2022-04-21 22:51:48 +00:00
const disconnect = async () => {
2022-04-24 08:50:45 +00:00
await httpService.delete('lastfm/disconnect')
2022-04-21 22:51:48 +00:00
forceReloadWindow()
}
2022-04-15 14:24:30 +00:00
</script>
<style lang="scss" scoped>
.buttons {
margin-top: 1.25rem;
2022-04-30 11:59:37 +00:00
> * + * {
margin-left: 0.5rem;
}
2022-04-15 14:24:30 +00:00
.connect {
background: #d31f27; // Last.fm color yo!
}
}
</style>