'Improved' getLatest() function to always have 18 results. It's a bit slower though..

This commit is contained in:
Kylart 2016-12-09 23:12:05 +09:00
parent eddebdd57d
commit bd1d72b223
3 changed files with 30 additions and 8 deletions

View File

@ -55,7 +55,7 @@
<div class="elem"> <div class="elem">
<h6>{{ release.title }}</h6> <h6>{{ release.title }}</h6>
<div class="picture"> <div class="picture">
<img v-bind:src="release.picture" height="180"> <img v-bind:src="release.picture" height="180" width="105%">
</div> </div>
<div class="text-container"> <div class="text-container">
<div class="synopsis"> <div class="synopsis">
@ -133,7 +133,7 @@
<h5>Characters</h5> <h5>Characters</h5>
<div class="mdl-grid"> <div class="mdl-grid">
<div v-for="character in infos.characters" <div v-for="character in infos.characters"
class="character mdl-cell mdl-cell--3-col mdl-cell--3-col-phone"> class="character mdl-cell mdl-cell--3-col mdl-cell--6-col-phone">
<h6 class="character-name">{{ character.name }}</h6> <h6 class="character-name">{{ character.name }}</h6>
<h6 class="seiyuu-name" >by {{ character.actor }}</h6> <h6 class="seiyuu-name" >by {{ character.actor }}</h6>
</div> </div>

View File

@ -21,6 +21,7 @@
"dependencies": { "dependencies": {
"find-remove": "^1.0.0", "find-remove": "^1.0.0",
"is-online": "^5.2.0", "is-online": "^5.2.0",
"mal-scraper": "^1.0.6",
"malapi": "0.0.3", "malapi": "0.0.3",
"node-nyaa-api": "latest", "node-nyaa-api": "latest",
"progressbar.js": "^1.0.1" "progressbar.js": "^1.0.1"

View File

@ -54,9 +54,18 @@ function getNameForResearch(name) {
return tmp.join(' ') return tmp.join(' ')
} }
function 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))
}
}
// Make the research for the latest animes // Make the research for the latest animes
function getLatest () { function getLatest () {
Nyaa.get_latest( function (err, animes) { Nyaa.search('[HorribleSubs]', function (err, animes) {
// Initialize // Initialize
releases.releases = [] releases.releases = []
releases.show = false releases.show = false
@ -79,15 +88,27 @@ function getLatest () {
title: getNameOnly(animes[anime].title), title: getNameOnly(animes[anime].title),
link: animes[anime].link, link: animes[anime].link,
synopsis: reduceString(result.synopsis), synopsis: reduceString(result.synopsis),
picture: result.image picture: result.image,
published: animes[anime].published
}) })
}).then( () => {
if (releases.releases.length === 35)
{
releases.releases.sort(byProperty('published'))
releases.releases.reverse()
// 35 elements is too much, reducing to 18
for (let i = 0; i < 17; ++i)
releases.releases.pop()
}
}).then( () => {
setTimeout( () => {
loader.show = false
releases.show = true
}, 1200)
}) })
} }
} }
setTimeout( () => {
loader.show = false
releases.show = true
}, 3000)
}) })
} }