mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-01 00:18:14 +01:00
Fix:Size and duration sort
This commit is contained in:
parent
95ab2ab4b5
commit
9423727f89
@ -135,12 +135,18 @@ class LibraryController {
|
||||
if (payload.sortBy) {
|
||||
var orderByNumber = payload.sortBy === 'book.volumeNumber'
|
||||
var direction = payload.sortDesc ? 'desc' : 'asc'
|
||||
// if (req.query.sort === 'size') {
|
||||
// console.warn('1SORTING BY SIZE', audiobooks[0])
|
||||
// }
|
||||
audiobooks = sort(audiobooks)[direction]((ab) => {
|
||||
// Supports dot notation strings i.e. "book.title"
|
||||
var value = payload.sortBy.split('.').reduce((a, b) => a[b], ab)
|
||||
if (orderByNumber && !isNaN(value)) return Number(value)
|
||||
return value
|
||||
})
|
||||
// if (req.query.sort === 'size') {
|
||||
// console.warn('2SORTING BY SIZE', audiobooks[0])
|
||||
// }
|
||||
}
|
||||
|
||||
if (payload.limit) {
|
||||
|
@ -100,24 +100,24 @@ class Audiobook {
|
||||
return this.book ? this.book.genres || [] : []
|
||||
}
|
||||
|
||||
get totalDuration() {
|
||||
get duration() {
|
||||
var total = 0
|
||||
this.tracks.forEach((track) => total += track.duration)
|
||||
return total
|
||||
}
|
||||
|
||||
get totalSize() {
|
||||
get size() {
|
||||
var total = 0
|
||||
this.tracks.forEach((track) => total += track.size)
|
||||
return total
|
||||
}
|
||||
|
||||
get sizePretty() {
|
||||
return bytesPretty(this.totalSize)
|
||||
return bytesPretty(this.size)
|
||||
}
|
||||
|
||||
get durationPretty() {
|
||||
return elapsedPretty(this.totalDuration)
|
||||
return elapsedPretty(this.duration)
|
||||
}
|
||||
|
||||
get invalidParts() {
|
||||
@ -206,8 +206,8 @@ class Audiobook {
|
||||
fullPath: this.fullPath,
|
||||
addedAt: this.addedAt,
|
||||
lastUpdate: this.lastUpdate,
|
||||
duration: this.totalDuration,
|
||||
size: this.totalSize,
|
||||
duration: this.duration,
|
||||
size: this.size,
|
||||
ebooks: this.ebooks.map(ebook => ebook.toJSON()),
|
||||
numEbooks: this.ebooks.length,
|
||||
numTracks: this.tracks.length,
|
||||
@ -229,9 +229,9 @@ class Audiobook {
|
||||
fullPath: this.fullPath,
|
||||
addedAt: this.addedAt,
|
||||
lastUpdate: this.lastUpdate,
|
||||
duration: this.totalDuration,
|
||||
duration: this.duration,
|
||||
durationPretty: this.durationPretty,
|
||||
size: this.totalSize,
|
||||
size: this.size,
|
||||
sizePretty: this.sizePretty,
|
||||
missingParts: this.missingParts,
|
||||
invalidParts: this.invalidParts,
|
||||
|
@ -55,7 +55,7 @@ class Stream extends EventEmitter {
|
||||
}
|
||||
|
||||
get totalDuration() {
|
||||
return this.audiobook.totalDuration
|
||||
return this.audiobook.duration
|
||||
}
|
||||
|
||||
get tracksAudioFileType() {
|
||||
|
@ -166,7 +166,7 @@ module.exports = {
|
||||
getAudiobooksTotalDuration(audiobooks) {
|
||||
var totalDuration = 0
|
||||
audiobooks.forEach((ab) => {
|
||||
totalDuration += ab.totalDuration
|
||||
totalDuration += ab.duration
|
||||
})
|
||||
return totalDuration
|
||||
},
|
||||
@ -174,7 +174,7 @@ module.exports = {
|
||||
getAudiobooksTotalSize(audiobooks) {
|
||||
var totalSize = 0
|
||||
audiobooks.forEach((ab) => {
|
||||
totalSize += ab.totalSize
|
||||
totalSize += ab.size
|
||||
})
|
||||
return totalSize
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user