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) {
|
if (payload.sortBy) {
|
||||||
var orderByNumber = payload.sortBy === 'book.volumeNumber'
|
var orderByNumber = payload.sortBy === 'book.volumeNumber'
|
||||||
var direction = payload.sortDesc ? 'desc' : 'asc'
|
var direction = payload.sortDesc ? 'desc' : 'asc'
|
||||||
|
// if (req.query.sort === 'size') {
|
||||||
|
// console.warn('1SORTING BY SIZE', audiobooks[0])
|
||||||
|
// }
|
||||||
audiobooks = sort(audiobooks)[direction]((ab) => {
|
audiobooks = sort(audiobooks)[direction]((ab) => {
|
||||||
// Supports dot notation strings i.e. "book.title"
|
// Supports dot notation strings i.e. "book.title"
|
||||||
var value = payload.sortBy.split('.').reduce((a, b) => a[b], ab)
|
var value = payload.sortBy.split('.').reduce((a, b) => a[b], ab)
|
||||||
if (orderByNumber && !isNaN(value)) return Number(value)
|
if (orderByNumber && !isNaN(value)) return Number(value)
|
||||||
return value
|
return value
|
||||||
})
|
})
|
||||||
|
// if (req.query.sort === 'size') {
|
||||||
|
// console.warn('2SORTING BY SIZE', audiobooks[0])
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payload.limit) {
|
if (payload.limit) {
|
||||||
|
@ -100,24 +100,24 @@ class Audiobook {
|
|||||||
return this.book ? this.book.genres || [] : []
|
return this.book ? this.book.genres || [] : []
|
||||||
}
|
}
|
||||||
|
|
||||||
get totalDuration() {
|
get duration() {
|
||||||
var total = 0
|
var total = 0
|
||||||
this.tracks.forEach((track) => total += track.duration)
|
this.tracks.forEach((track) => total += track.duration)
|
||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
|
||||||
get totalSize() {
|
get size() {
|
||||||
var total = 0
|
var total = 0
|
||||||
this.tracks.forEach((track) => total += track.size)
|
this.tracks.forEach((track) => total += track.size)
|
||||||
return total
|
return total
|
||||||
}
|
}
|
||||||
|
|
||||||
get sizePretty() {
|
get sizePretty() {
|
||||||
return bytesPretty(this.totalSize)
|
return bytesPretty(this.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
get durationPretty() {
|
get durationPretty() {
|
||||||
return elapsedPretty(this.totalDuration)
|
return elapsedPretty(this.duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
get invalidParts() {
|
get invalidParts() {
|
||||||
@ -206,8 +206,8 @@ class Audiobook {
|
|||||||
fullPath: this.fullPath,
|
fullPath: this.fullPath,
|
||||||
addedAt: this.addedAt,
|
addedAt: this.addedAt,
|
||||||
lastUpdate: this.lastUpdate,
|
lastUpdate: this.lastUpdate,
|
||||||
duration: this.totalDuration,
|
duration: this.duration,
|
||||||
size: this.totalSize,
|
size: this.size,
|
||||||
ebooks: this.ebooks.map(ebook => ebook.toJSON()),
|
ebooks: this.ebooks.map(ebook => ebook.toJSON()),
|
||||||
numEbooks: this.ebooks.length,
|
numEbooks: this.ebooks.length,
|
||||||
numTracks: this.tracks.length,
|
numTracks: this.tracks.length,
|
||||||
@ -229,9 +229,9 @@ class Audiobook {
|
|||||||
fullPath: this.fullPath,
|
fullPath: this.fullPath,
|
||||||
addedAt: this.addedAt,
|
addedAt: this.addedAt,
|
||||||
lastUpdate: this.lastUpdate,
|
lastUpdate: this.lastUpdate,
|
||||||
duration: this.totalDuration,
|
duration: this.duration,
|
||||||
durationPretty: this.durationPretty,
|
durationPretty: this.durationPretty,
|
||||||
size: this.totalSize,
|
size: this.size,
|
||||||
sizePretty: this.sizePretty,
|
sizePretty: this.sizePretty,
|
||||||
missingParts: this.missingParts,
|
missingParts: this.missingParts,
|
||||||
invalidParts: this.invalidParts,
|
invalidParts: this.invalidParts,
|
||||||
|
@ -55,7 +55,7 @@ class Stream extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get totalDuration() {
|
get totalDuration() {
|
||||||
return this.audiobook.totalDuration
|
return this.audiobook.duration
|
||||||
}
|
}
|
||||||
|
|
||||||
get tracksAudioFileType() {
|
get tracksAudioFileType() {
|
||||||
|
@ -166,7 +166,7 @@ module.exports = {
|
|||||||
getAudiobooksTotalDuration(audiobooks) {
|
getAudiobooksTotalDuration(audiobooks) {
|
||||||
var totalDuration = 0
|
var totalDuration = 0
|
||||||
audiobooks.forEach((ab) => {
|
audiobooks.forEach((ab) => {
|
||||||
totalDuration += ab.totalDuration
|
totalDuration += ab.duration
|
||||||
})
|
})
|
||||||
return totalDuration
|
return totalDuration
|
||||||
},
|
},
|
||||||
@ -174,7 +174,7 @@ module.exports = {
|
|||||||
getAudiobooksTotalSize(audiobooks) {
|
getAudiobooksTotalSize(audiobooks) {
|
||||||
var totalSize = 0
|
var totalSize = 0
|
||||||
audiobooks.forEach((ab) => {
|
audiobooks.forEach((ab) => {
|
||||||
totalSize += ab.totalSize
|
totalSize += ab.size
|
||||||
})
|
})
|
||||||
return totalSize
|
return totalSize
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user