mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-29 06:37:16 +02:00
Add:Sync local media progress button on local media page
This commit is contained in:
@@ -766,9 +766,11 @@ export default {
|
|||||||
screenOrientationChange() {
|
screenOrientationChange() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.updateScreenSize()
|
this.updateScreenSize()
|
||||||
this.trackWidth = this.$refs.track.clientWidth
|
if (this.$refs.track) {
|
||||||
this.updateTrack()
|
this.trackWidth = this.$refs.track.clientWidth
|
||||||
this.updateReadyTrack()
|
this.updateTrack()
|
||||||
|
this.updateReadyTrack()
|
||||||
|
}
|
||||||
}, 50)
|
}, 50)
|
||||||
},
|
},
|
||||||
updateScreenSize() {
|
updateScreenSize() {
|
||||||
|
|||||||
+1
-1
@@ -175,7 +175,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('[default] Calling syncLocalMediaProgress')
|
console.log('[default] Calling syncLocalMediaProgress')
|
||||||
var response = await this.$db.syncLocalMediaProgressWithServer()
|
const response = await this.$db.syncLocalMediaProgressWithServer()
|
||||||
if (!response) {
|
if (!response) {
|
||||||
if (this.$platform != 'web') this.$toast.error('Failed to sync local media with server')
|
if (this.$platform != 'web') this.$toast.error('Failed to sync local media with server')
|
||||||
this.$store.commit('setLastLocalMediaSyncResults', null)
|
this.$store.commit('setLastLocalMediaSyncResults', null)
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="w-full h-full py-6">
|
<div class="w-full h-full py-6">
|
||||||
|
<div v-if="localLibraryItemsOnCurrentServer.length" class="flex items-center justify-between mb-4 pb-2 px-2 border-b border-white border-opacity-10">
|
||||||
|
<p class="text-sm text-gray-100">{{ localLibraryItemsOnCurrentServer.length }} local items on this server</p>
|
||||||
|
<ui-btn small :loading="syncing" @click="syncLocalMedia">Sync</ui-btn>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="lastLocalMediaSyncResults" class="px-2 mb-4">
|
<div v-if="lastLocalMediaSyncResults" class="px-2 mb-4">
|
||||||
<div class="w-full pl-2 pr-2 py-2 bg-black bg-opacity-25 rounded-lg relative">
|
<div class="w-full pl-2 pr-2 py-2 bg-black bg-opacity-25 rounded-lg relative">
|
||||||
<div class="flex items-center mb-1">
|
<div class="flex items-center mb-1">
|
||||||
@@ -23,9 +28,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h1 class="text-base font-semibold px-3 mb-2">Local Folders</h1>
|
<h1 class="text-base font-semibold px-2 mb-2">Local Folders</h1>
|
||||||
|
|
||||||
<div v-if="!isIos" class="w-full max-w-full px-3 py-2">
|
<div v-if="!isIos" class="w-full max-w-full px-2 py-2">
|
||||||
<template v-for="folder in localFolders">
|
<template v-for="folder in localFolders">
|
||||||
<nuxt-link :to="`/localMedia/folders/${folder.id}`" :key="folder.id" class="flex items-center px-2 py-4 bg-primary rounded-md border-bg mb-1">
|
<nuxt-link :to="`/localMedia/folders/${folder.id}`" :key="folder.id" class="flex items-center px-2 py-4 bg-primary rounded-md border-bg mb-1">
|
||||||
<span class="material-icons text-xl text-yellow-400">folder</span>
|
<span class="material-icons text-xl text-yellow-400">folder</span>
|
||||||
@@ -55,6 +60,7 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
localFolders: [],
|
localFolders: [],
|
||||||
|
localLibraryItems: [],
|
||||||
newFolderMediaType: null,
|
newFolderMediaType: null,
|
||||||
mediaTypeItems: [
|
mediaTypeItems: [
|
||||||
{
|
{
|
||||||
@@ -65,7 +71,8 @@ export default {
|
|||||||
value: 'podcast',
|
value: 'podcast',
|
||||||
text: 'Podcasts'
|
text: 'Podcasts'
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
syncing: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -75,6 +82,14 @@ export default {
|
|||||||
lastLocalMediaSyncResults() {
|
lastLocalMediaSyncResults() {
|
||||||
return this.$store.state.lastLocalMediaSyncResults
|
return this.$store.state.lastLocalMediaSyncResults
|
||||||
},
|
},
|
||||||
|
serverConnectionConfigId() {
|
||||||
|
return this.$store.getters['user/getServerConnectionConfigId']
|
||||||
|
},
|
||||||
|
localLibraryItemsOnCurrentServer() {
|
||||||
|
return this.localLibraryItems.filter((lli) => {
|
||||||
|
return lli.serverConnectionConfigId === this.serverConnectionConfigId
|
||||||
|
})
|
||||||
|
},
|
||||||
numLocalMediaSynced() {
|
numLocalMediaSynced() {
|
||||||
if (!this.lastLocalMediaSyncResults) return 0
|
if (!this.lastLocalMediaSyncResults) return 0
|
||||||
return this.lastLocalMediaSyncResults.numLocalMediaProgressForServer || 0
|
return this.lastLocalMediaSyncResults.numLocalMediaProgressForServer || 0
|
||||||
@@ -97,6 +112,33 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async syncLocalMedia() {
|
||||||
|
console.log('[localMedia] Calling syncLocalMediaProgress')
|
||||||
|
this.syncing = true
|
||||||
|
const response = await this.$db.syncLocalMediaProgressWithServer()
|
||||||
|
if (!response) {
|
||||||
|
if (this.$platform != 'web') this.$toast.error('Failed to sync local media with server')
|
||||||
|
this.$store.commit('setLastLocalMediaSyncResults', null)
|
||||||
|
this.syncing = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const { numLocalMediaProgressForServer, numServerProgressUpdates, numLocalProgressUpdates } = response
|
||||||
|
if (numLocalMediaProgressForServer > 0) {
|
||||||
|
response.syncedAt = Date.now()
|
||||||
|
response.serverConfigName = this.$store.getters['user/getServerConfigName']
|
||||||
|
this.$store.commit('setLastLocalMediaSyncResults', response)
|
||||||
|
|
||||||
|
if (numServerProgressUpdates > 0 || numLocalProgressUpdates > 0) {
|
||||||
|
console.log(`[localMedia] ${numServerProgressUpdates} Server progress updates | ${numLocalProgressUpdates} Local progress updates`)
|
||||||
|
} else {
|
||||||
|
console.log('[localMedia] syncLocalMediaProgress No updates were necessary')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('[localMedia] syncLocalMediaProgress No local media progress to sync')
|
||||||
|
this.$store.commit('setLastLocalMediaSyncResults', null)
|
||||||
|
}
|
||||||
|
this.syncing = false
|
||||||
|
},
|
||||||
async selectFolder() {
|
async selectFolder() {
|
||||||
if (!this.newFolderMediaType) {
|
if (!this.newFolderMediaType) {
|
||||||
return this.$toast.error('Must select a media type')
|
return this.$toast.error('Must select a media type')
|
||||||
@@ -107,14 +149,14 @@ export default {
|
|||||||
return this.$toast.error(`Error: ${folderObj.error || 'Unknown Error'}`)
|
return this.$toast.error(`Error: ${folderObj.error || 'Unknown Error'}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
var indexOfExisting = this.localFolders.findIndex((lf) => lf.id == folderObj.id)
|
const indexOfExisting = this.localFolders.findIndex((lf) => lf.id == folderObj.id)
|
||||||
if (indexOfExisting >= 0) {
|
if (indexOfExisting >= 0) {
|
||||||
this.localFolders.splice(indexOfExisting, 1, folderObj)
|
this.localFolders.splice(indexOfExisting, 1, folderObj)
|
||||||
} else {
|
} else {
|
||||||
this.localFolders.push(folderObj)
|
this.localFolders.push(folderObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
var permissionsGood = await AbsFileSystem.checkFolderPermissions({ folderUrl: folderObj.contentUrl })
|
const permissionsGood = await AbsFileSystem.checkFolderPermissions({ folderUrl: folderObj.contentUrl })
|
||||||
|
|
||||||
if (!permissionsGood) {
|
if (!permissionsGood) {
|
||||||
this.$toast.error('Folder permissions failed')
|
this.$toast.error('Folder permissions failed')
|
||||||
@@ -127,6 +169,7 @@ export default {
|
|||||||
},
|
},
|
||||||
async init() {
|
async init() {
|
||||||
this.localFolders = (await this.$db.getLocalFolders()) || []
|
this.localFolders = (await this.$db.getLocalFolders()) || []
|
||||||
|
this.localLibraryItems = await this.$db.getLocalLibraryItems()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ export const getters = {
|
|||||||
getToken: (state) => {
|
getToken: (state) => {
|
||||||
return state.user ? state.user.token : null
|
return state.user ? state.user.token : null
|
||||||
},
|
},
|
||||||
|
getServerConnectionConfigId: (state) => {
|
||||||
|
return state.serverConnectionConfig ? state.serverConnectionConfig.id : null
|
||||||
|
},
|
||||||
getServerAddress: (state) => {
|
getServerAddress: (state) => {
|
||||||
return state.serverConnectionConfig ? state.serverConnectionConfig.address : null
|
return state.serverConnectionConfig ? state.serverConnectionConfig.address : null
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user