Added a method in localPage to sort animes by name and by episode number (ascending or not will be chosen via config file later).

This commit is contained in:
Kylart 2017-03-07 00:33:38 +01:00
parent cf5d5ecaec
commit 1aa9b765f6
1 changed files with 10 additions and 11 deletions

View File

@ -10,6 +10,7 @@ const self = this
// This will later be set with the config file
const downloadRep = 'Downloads'
const ascending = false
const fs = require('fs')
const path = require('path')
@ -35,16 +36,6 @@ exports.filterFiles = (files, filters) => {
return filteredFiles
}
exports.byProperty = (prop) => {
return function (a, b) {
if (typeof a[prop] == "number")
{
return (a[prop] - b[prop])
}
return ((a[prop] < b[prop]) ? -1 : ((a[prop] > b[prop]) ? 1 : 0))
}
}
// This function works only if the file is named this way:
// [FANSUB] <NAME> <-> <EP_NUMBER> <EXTENSION_NAME>
exports.searchAnime = (filename, object) => {
@ -74,7 +65,15 @@ exports.searchAnime = (filename, object) => {
result.mark = anime.statistics.score.value
object.files.push(result)
object.files.sort(self.byProperty('title'))
if (ascending)
object.files.sort((a, b) => a.title === b.title ?
- b.episode.toString().localeCompare(a.episode) :
a.title.toString().localeCompare(b.title))
else
object.files.sort((a, b) => a.title === b.title ?
b.episode.toString().localeCompare(a.episode) :
a.title.toString().localeCompare(b.title))
})
}