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

80 lines
2.7 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2024-04-04 22:20:42 +00:00
<section class="text-k-text-secondary">
<h3 class="text-2xl mb-2">
<span class="mr-2 text-[var(--lastfm-color)]">
<Icon :icon="faLastfm" />
</span>
Last.fm Integration
2024-04-03 14:48:52 +00:00
</h3>
2022-04-15 14:24:30 +00:00
2022-04-21 22:51:48 +00:00
<div v-if="useLastfm" data-testid="lastfm-integrated">
<p>Last.fm integration is enabled. Koel will attempt to retrieve album and artist information from Last.fm.</p>
<p v-if="connected">
It appears that you have connected your Last.fm account as well Perfect!
2022-04-15 14:24:30 +00:00
</p>
<p v-else>You can also connect your Last.fm account here.</p>
2022-04-15 14:24:30 +00:00
<p>
Connecting Koel and your Last.fm account enables such exciting features as
2024-04-04 22:20:42 +00:00
<a href="https://www.last.fm/about/trackmymusic" rel="noopener" target="_blank">scrobbling</a>.
2022-04-15 14:24:30 +00:00
</p>
2024-04-04 22:20:42 +00:00
<div class="buttons mt-4 space-x-2">
<Btn class="!bg-[var(--lastfm-color)]" @click.prevent="connect">{{ connected ? 'Reconnect' : 'Connect' }}</Btn>
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>
2024-03-17 17:55:47 +00:00
Last.fm integration is not enabled.
<span v-if="isAdmin" data-testid="lastfm-admin-instruction">
2024-03-17 17:55:47 +00:00
Check
2024-04-23 21:01:27 +00:00
<a class="text-k-highlight" href="https://docs.koel.dev/service-integrations#last-fm" target="_blank">
2024-03-17 17:55:47 +00:00
Documentation
</a>
for instructions.
2022-04-15 14:24:30 +00:00
</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-07-15 07:23:55 +00:00
import { faLastfm } from '@fortawesome/free-brands-svg-icons'
import { computed, defineAsyncComponent } from 'vue'
import { authService, http } from '@/services'
2022-04-15 14:24:30 +00:00
import { forceReloadWindow } from '@/utils'
import { useAuthorization, useThirdPartyServices } from '@/composables'
2022-04-15 14:24:30 +00:00
2024-04-04 22:20:42 +00:00
const Btn = defineAsyncComponent(() => import('@/components/ui/form/Btn.vue'))
2022-04-15 14:24:30 +00:00
const { currentUser, isAdmin } = useAuthorization()
const { useLastfm } = useThirdPartyServices()
2022-04-15 14:24:30 +00:00
2022-06-10 10:47:46 +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-11-16 17:57:38 +00:00
`${window.BASE_URL}lastfm/connect?api_token=${authService.getApiToken()}`,
2022-04-15 17:00:08 +00:00
'_blank',
'toolbar=no,titlebar=no,location=no,width=1024,height=640',
2022-04-15 17:00:08 +00:00
)
2022-04-15 14:24:30 +00:00
2022-04-21 22:51:48 +00:00
const disconnect = async () => {
await http.delete('lastfm/disconnect')
2022-04-21 22:51:48 +00:00
forceReloadWindow()
}
2022-04-15 14:24:30 +00:00
</script>
2024-04-04 20:13:35 +00:00
<style lang="postcss" scoped>
2024-04-04 22:20:42 +00:00
section {
--lastfm-color: #d31f27;
2022-04-15 14:24:30 +00:00
}
</style>