mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-28 13:58:23 +02:00
Fix unnecessary download thread, fix load audiobooks having different uri
This commit is contained in:
parent
5a025b3a03
commit
cd3277a5f9
6 changed files with 37 additions and 19 deletions
14
Server.js
14
Server.js
|
@ -28,8 +28,13 @@ class Server extends EventEmitter {
|
||||||
|
|
||||||
getServerUrl(url) {
|
getServerUrl(url) {
|
||||||
if (!url) return null
|
if (!url) return null
|
||||||
var urlObject = new URL(url)
|
try {
|
||||||
return `${urlObject.protocol}//${urlObject.hostname}:${urlObject.port}`
|
var urlObject = new URL(url)
|
||||||
|
return `${urlObject.protocol}//${urlObject.hostname}:${urlObject.port}`
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Invalid URL', error)
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setUser(user) {
|
setUser(user) {
|
||||||
|
@ -82,6 +87,9 @@ class Server extends EventEmitter {
|
||||||
|
|
||||||
async check(url) {
|
async check(url) {
|
||||||
var serverUrl = this.getServerUrl(url)
|
var serverUrl = this.getServerUrl(url)
|
||||||
|
if (!serverUrl) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
var res = await this.ping(serverUrl)
|
var res = await this.ping(serverUrl)
|
||||||
if (!res || !res.success) {
|
if (!res || !res.success) {
|
||||||
return false
|
return false
|
||||||
|
@ -134,7 +142,7 @@ class Server extends EventEmitter {
|
||||||
ping(url) {
|
ping(url) {
|
||||||
var pingUrl = url + '/ping'
|
var pingUrl = url + '/ping'
|
||||||
console.log('[Server] Check server', pingUrl)
|
console.log('[Server] Check server', pingUrl)
|
||||||
return axios.get(pingUrl).then((res) => {
|
return axios.get(pingUrl, { timeout: 1000 }).then((res) => {
|
||||||
return res.data
|
return res.data
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('Server check failed', error)
|
console.error('Server check failed', error)
|
||||||
|
|
|
@ -13,8 +13,8 @@ android {
|
||||||
applicationId "com.audiobookshelf.app"
|
applicationId "com.audiobookshelf.app"
|
||||||
minSdkVersion rootProject.ext.minSdkVersion
|
minSdkVersion rootProject.ext.minSdkVersion
|
||||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||||
versionCode 23
|
versionCode 24
|
||||||
versionName "0.9.7-beta"
|
versionName "0.9.8-beta"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
aaptOptions {
|
aaptOptions {
|
||||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||||
|
|
|
@ -25,8 +25,6 @@ import com.getcapacitor.PluginMethod
|
||||||
import com.getcapacitor.annotation.CapacitorPlugin
|
import com.getcapacitor.annotation.CapacitorPlugin
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.concurrent.ExecutorService
|
|
||||||
import java.util.concurrent.Executors
|
|
||||||
|
|
||||||
|
|
||||||
@CapacitorPlugin(name = "AudioDownloader")
|
@CapacitorPlugin(name = "AudioDownloader")
|
||||||
|
@ -222,17 +220,28 @@ class AudioDownloader : Plugin() {
|
||||||
if (audiobookFile == null) {
|
if (audiobookFile == null) {
|
||||||
Log.e(tag, "Audiobook was not found $audiobookUrl")
|
Log.e(tag, "Audiobook was not found $audiobookUrl")
|
||||||
} else {
|
} else {
|
||||||
|
Log.d(tag, "Audiobook File Found StorageId:${audiobookFile.getStorageId(context)} | AbsolutePath:${audiobookFile.getAbsolutePath(context)} | BasePath:${audiobookFile.getBasePath(context)}")
|
||||||
|
|
||||||
var _name = audiobookFile.name
|
var _name = audiobookFile.name
|
||||||
if (_name == null) _name = ""
|
if (_name == null) _name = ""
|
||||||
var _coverUrl = ""
|
|
||||||
if (coverFile != null) _coverUrl = coverFile.uri.toString()
|
|
||||||
|
|
||||||
var size = audiobookFile.length()
|
var size = audiobookFile.length()
|
||||||
var abItem = AudiobookItem(audiobookFile.uri, _name, size, _coverUrl)
|
|
||||||
|
if (audiobookFile.uri.toString() !== audiobookUrl) {
|
||||||
|
Log.d(tag, "Audiobook URI ${audiobookFile.uri} is different from $audiobookUrl => using the latter")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use existing URI's - bug happening where new uri is different from initial
|
||||||
|
var abItem = AudiobookItem(Uri.parse(audiobookUrl), _name, size, coverUrl)
|
||||||
|
|
||||||
|
Log.d(tag, "Setting AB ITEM ${abItem.name} | ${abItem.size} | ${abItem.uri} | ${abItem.coverUrl}")
|
||||||
|
|
||||||
audiobookItems.add(abItem)
|
audiobookItems.add(abItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.d(tag, "Load Finished ${audiobookItems.size} found")
|
||||||
|
|
||||||
var audiobookObjs:List<JSObject> = audiobookItems.map{ it.toJSObject() }
|
var audiobookObjs:List<JSObject> = audiobookItems.map{ it.toJSObject() }
|
||||||
var mediaItemNoticePayload = JSObject()
|
var mediaItemNoticePayload = JSObject()
|
||||||
mediaItemNoticePayload.put("items", audiobookObjs)
|
mediaItemNoticePayload.put("items", audiobookObjs)
|
||||||
|
@ -341,7 +350,7 @@ class AudioDownloader : Plugin() {
|
||||||
var simplePath = resultDocFile.getSimplePath(context)
|
var simplePath = resultDocFile.getSimplePath(context)
|
||||||
var storageId = resultDocFile.getStorageId(context)
|
var storageId = resultDocFile.getStorageId(context)
|
||||||
var size = resultDocFile.length()
|
var size = resultDocFile.length()
|
||||||
Log.d(tag, "Finished Moving File, NAME: ${resultDocFile.name} | $storageId | SimplePath: $simplePath")
|
Log.d(tag, "Finished Moving File, NAME: ${resultDocFile.name} | URI:${resultDocFile.uri} | AbsolutePath:${resultDocFile.getAbsolutePath(context)} | $storageId | SimplePath: $simplePath")
|
||||||
|
|
||||||
var abFolder = folder.findFolder(title)
|
var abFolder = folder.findFolder(title)
|
||||||
var jsobj = JSObject()
|
var jsobj = JSObject()
|
||||||
|
@ -370,14 +379,11 @@ class AudioDownloader : Plugin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// After file is downloaded, move the files into an audiobook directory inside the user selected folder
|
// After file is downloaded, move the files into an audiobook directory inside the user selected folder
|
||||||
val executorService: ExecutorService = Executors.newFixedThreadPool(4)
|
|
||||||
executorService.execute {
|
|
||||||
if (id == coverDownloadId) {
|
if (id == coverDownloadId) {
|
||||||
docfile?.moveFileTo(context, folder, FileDescription(coverFilename, title, MimeType.IMAGE), callback)
|
docfile?.moveFileTo(context, folder, FileDescription(coverFilename, title, MimeType.IMAGE), callback)
|
||||||
} else if (id == audiobookDownloadId) {
|
} else if (id == audiobookDownloadId) {
|
||||||
docfile?.moveFileTo(context, folder, FileDescription(filename, title, MimeType.AUDIO), callback)
|
docfile?.moveFileTo(context, folder, FileDescription(filename, title, MimeType.AUDIO), callback)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var progressUpdater = DownloadProgressUpdater(downloadManager, audiobookDownloadId, progressReceiver, doneReceiver)
|
var progressUpdater = DownloadProgressUpdater(downloadManager, audiobookDownloadId, progressReceiver, doneReceiver)
|
||||||
|
|
|
@ -173,7 +173,7 @@ export default {
|
||||||
var size = data.size || 0
|
var size = data.size || 0
|
||||||
var isCover = !!data.isCover
|
var isCover = !!data.isCover
|
||||||
|
|
||||||
console.log('Download complete', filename, downloadId, contentUrl, 'AudiobookId:', audiobookId, 'Is Cover:', isCover)
|
console.log(`Download complete "${contentUrl}" | ${filename} | DlId: ${downloadId} | Is Cover? ${isCover}`)
|
||||||
var downloadObj = this.$store.getters['downloads/getDownload'](audiobookId)
|
var downloadObj = this.$store.getters['downloads/getDownload'](audiobookId)
|
||||||
if (!downloadObj) {
|
if (!downloadObj) {
|
||||||
console.error('Failed to find download for audiobook', audiobookId)
|
console.error('Failed to find download for audiobook', audiobookId)
|
||||||
|
@ -231,9 +231,9 @@ export default {
|
||||||
coverUrl: item.coverUrl || null
|
coverUrl: item.coverUrl || null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log('onMediaLoaded Items', JSON.stringify(jsitems))
|
|
||||||
|
|
||||||
var downloads = await this.$sqlStore.getAllDownloads()
|
var downloads = await this.$sqlStore.getAllDownloads()
|
||||||
|
|
||||||
for (let i = 0; i < downloads.length; i++) {
|
for (let i = 0; i < downloads.length; i++) {
|
||||||
var download = downloads[i]
|
var download = downloads[i]
|
||||||
var jsitem = jsitems.find((item) => item.contentUrl === download.contentUrl)
|
var jsitem = jsitems.find((item) => item.contentUrl === download.contentUrl)
|
||||||
|
@ -298,7 +298,6 @@ export default {
|
||||||
},
|
},
|
||||||
async initMediaStore() {
|
async initMediaStore() {
|
||||||
// Request and setup listeners for media files on native
|
// Request and setup listeners for media files on native
|
||||||
console.log('Permissino SET LISTENER')
|
|
||||||
AudioDownloader.addListener('permission', (data) => {
|
AudioDownloader.addListener('permission', (data) => {
|
||||||
this.onPermissionUpdate(data)
|
this.onPermissionUpdate(data)
|
||||||
})
|
})
|
||||||
|
@ -349,7 +348,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkPermission = await AudioDownloader.checkStoragePermission()
|
var checkPermission = await AudioDownloader.checkStoragePermission()
|
||||||
console.log('Storage Permission is', checkPermission.value)
|
console.log('Storage Permission is' + checkPermission.value)
|
||||||
if (!checkPermission.value) {
|
if (!checkPermission.value) {
|
||||||
console.log('Will require permissions')
|
console.log('Will require permissions')
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "audiobookshelf-app",
|
"name": "audiobookshelf-app",
|
||||||
"version": "v0.9.7-beta",
|
"version": "v0.9.8-beta",
|
||||||
"author": "advplyr",
|
"author": "advplyr",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nuxt --hostname localhost --port 1337",
|
"dev": "nuxt --hostname localhost --port 1337",
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
<ui-btn v-if="isUpdateAvailable" class="w-full my-4" color="success" @click="clickUpdate">Update is available</ui-btn>
|
<ui-btn v-if="isUpdateAvailable" class="w-full my-4" color="success" @click="clickUpdate">Update is available</ui-btn>
|
||||||
|
|
||||||
<ui-btn v-if="!isUpdateAvailable || immediateUpdateAllowed" class="w-full my-4" color="primary" @click="openAppStore">Open app store</ui-btn>
|
<ui-btn v-if="!isUpdateAvailable || immediateUpdateAllowed" class="w-full my-4" color="primary" @click="openAppStore">Open app store</ui-btn>
|
||||||
|
|
||||||
|
<p>UA: {{ updateAvailability }} | Avail: {{ availableVersion }} | Curr: {{ currentVersion }} | ImmedAllowed: {{ immediateUpdateAllowed }}</p>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -51,6 +53,9 @@ export default {
|
||||||
availableVersion() {
|
availableVersion() {
|
||||||
return this.appUpdateInfo ? this.appUpdateInfo.availableVersion : null
|
return this.appUpdateInfo ? this.appUpdateInfo.availableVersion : null
|
||||||
},
|
},
|
||||||
|
currentVersion() {
|
||||||
|
return this.appUpdateInfo ? this.appUpdateInfo.currentVersion : null
|
||||||
|
},
|
||||||
immediateUpdateAllowed() {
|
immediateUpdateAllowed() {
|
||||||
return this.appUpdateInfo ? !!this.appUpdateInfo.immediateUpdateAllowed : false
|
return this.appUpdateInfo ? !!this.appUpdateInfo.immediateUpdateAllowed : false
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue