remove for offline content

- added translateion for logout
- destroy offline strorage with player
This commit is contained in:
Shiny Nematoda 2023-10-08 06:50:38 +00:00
parent ae016a731e
commit 98fb69e7d5
6 changed files with 42 additions and 24 deletions

View file

@ -1,3 +1,3 @@
{ {
"date": "2023-09-22" "date": "2023-10-08"
} }

View file

@ -87,7 +87,6 @@ const setProxy = async () => {
OpenOffline = async () => { OpenOffline = async () => {
if (window.offline) { if (window.offline) {
const songs = await window.offline.list(); const songs = await window.offline.list();
console.log();
results.resetItems(); results.resetItems();
results.setItem('songs', { results.setItem('songs', {
title: 'Hyp • ' + t('title.offline'), title: 'Hyp • ' + t('title.offline'),
@ -439,7 +438,7 @@ onMounted(async () => {
<AlbumItem <AlbumItem
:name="t('title.offline')" :name="t('title.offline')"
:grad="useRand()" :grad="useRand()"
@open-album="OpenOffline()" /> @open-album="OpenOffline" />
<AlbumItem <AlbumItem
v-for="i in list" v-for="i in list"
:key="i.name" :key="i.name"
@ -489,7 +488,7 @@ onMounted(async () => {
</p> </p>
</form> </form>
<button v-if="auth" @click="Logout" class="logout textbox">Logout</button> <button v-if="auth" @click="Logout" class="logout textbox">{{ t('title.logout') }}</button>
</div> </div>
</template> </template>

View file

@ -124,6 +124,10 @@ function destroy() {
window.audioPlayer.destroy(); window.audioPlayer.destroy();
window.audioPlayer = undefined; window.audioPlayer = undefined;
} }
if (window.offline) {
window.offline.destroy();
window.offline = undefined;
}
} }
const titleState = ['Playing', 'Paused']; const titleState = ['Playing', 'Paused'];

View file

@ -1,5 +1,12 @@
<script setup> <script setup>
import { ref, watch, onActivated, onUpdated, onDeactivated } from 'vue'; import {
ref,
watch,
computed,
onActivated,
onUpdated,
onDeactivated,
} from 'vue';
import Btn from './Btn.vue'; import Btn from './Btn.vue';
import SongItem from './SongItem.vue'; import SongItem from './SongItem.vue';
@ -29,6 +36,10 @@ const emit = defineEmits(['play-urls']),
isSearch = ref(/search/.test(location.pathname)), isSearch = ref(/search/.test(location.pathname)),
albumMenu = ref(false); albumMenu = ref(false);
const plId = computed(
(x = results.items?.songs?.items?.[0]) => x?.playlistId || !!x?.offlineUri,
);
const shuffleAdd = () => { const shuffleAdd = () => {
const songs = results.items.songs.items.map(i => ({ const songs = results.items.songs.items.map(i => ({
url: i.url, url: i.url,
@ -114,22 +125,25 @@ const shuffleAdd = () => {
}); });
} }
}, },
removePlaylist = async id => { removePlaylist = async () => {
const consent = confirm('Confirm?'); const consent = confirm('Confirm?');
console.log(id, consent); if (!plId.value || !consent) return;
if (!id || !consent) return; if (plId.value === true)
window.offline &&
console.log(id, consent); Promise.all(
(await window.offline.list()).map(i =>
if (useVerifyAuth(id)) { window.offline.remove(i.offlineUri),
const { message } = await useAuthRemovePlaylist(id); ),
);
else if (useVerifyAuth(plId.value)) {
const { message } = await useAuthRemovePlaylist(plId.value);
if (message != 'ok') { if (message != 'ok') {
alert(message); alert(message);
return; return;
} }
} else useRemovePlaylist(id); } else useRemovePlaylist(plId.value);
useRoute('/library'); useRoute('/library');
nav.state.page = 'library'; nav.state.page = 'library';
@ -286,11 +300,9 @@ onDeactivated(() => {
@click="shuffleAdd"></button> @click="shuffleAdd"></button>
<button <button
v-if="results.items?.songs?.items?.[0]?.playlistId" v-if="plId"
class="bi bi-trash3 clickable" class="bi bi-trash3 clickable"
@click=" @click="removePlaylist"></button>
removePlaylist(results.items?.songs?.items?.[0]?.playlistId)
"></button>
</div> </div>
</Transition> </Transition>
</template> </template>
@ -323,6 +335,7 @@ onDeactivated(() => {
:key="song.url || song.id" :key="song.url || song.id"
:index="index" :index="index"
:playlistId="song.playlistId" :playlistId="song.playlistId"
:offlineUri="song.offlineUri"
:author="song.uploaderName || song.artist || song.subtitle" :author="song.uploaderName || song.artist || song.subtitle"
:title="song.title || song.name" :title="song.title || song.name"
:channel=" :channel="

View file

@ -27,6 +27,7 @@ const props = defineProps({
play: String, play: String,
art: String, art: String,
playlistId: String, playlistId: String,
offlineUri: String,
}), }),
emit = defineEmits(['open-song', 'nxt-song', 'remove']); emit = defineEmits(['open-song', 'nxt-song', 'remove']);
@ -60,6 +61,7 @@ const openSong = el => {
thumbnails: [{ url: props.art }], thumbnails: [{ url: props.art }],
}); });
}, },
rm = () => emit('remove', props.index),
Remove = () => { Remove = () => {
const auth = useStore().getItem('auth'), const auth = useStore().getItem('auth'),
isRemote = results.items?.songs?.title?.startsWith('Playlist - '); isRemote = results.items?.songs?.title?.startsWith('Playlist - ');
@ -80,13 +82,12 @@ const openSong = el => {
console.log(json); console.log(json);
if (!json.error) { if (!json.error) {
if (json.message == 'ok') emit('remove', props.index); if (json.message == 'ok') rm();
} else alert(json.error); } else alert(json.error);
}); });
} else } else if (props.offlineUri)
useUpdatePlaylist(props.playlistId, props.index, () => window.offline && window.offline.remove(props.offlineUri).then(rm);
emit('remove', props.index), else useUpdatePlaylist(props.playlistId, props.index, () => rm());
);
}, },
Share = () => { Share = () => {
const data = { const data = {
@ -132,7 +133,7 @@ onMounted(() => {
<Transition name="fade"> <Transition name="fade">
<div v-if="show" class="popup ign"> <div v-if="show" class="popup ign">
<span <span
v-if="playlistId" v-if="playlistId || offlineUri"
class="bi bi-dash-lg clickable ign" class="bi bi-dash-lg clickable ign"
@click="Remove"></span> @click="Remove"></span>
<span <span

View file

@ -12,6 +12,7 @@
"spotlight": "Spotlight", "spotlight": "Spotlight",
"community": "Community", "community": "Community",
"login": "Login", "login": "Login",
"logout": "Logout",
"local": "Local", "local": "Local",
"remote": "Remote", "remote": "Remote",
"search": "Search", "search": "Search",