Rebuild second__lengthText if needed
This commit is contained in:
parent
d5d02bcef9
commit
5c3a4df209
|
@ -3,6 +3,7 @@ const {render} = require("pinski/plugins")
|
||||||
const db = require("../utils/db")
|
const db = require("../utils/db")
|
||||||
const {getToken, getUser} = require("../utils/getuser")
|
const {getToken, getUser} = require("../utils/getuser")
|
||||||
const pug = require("pug")
|
const pug = require("pug")
|
||||||
|
const converters = require("../utils/converters")
|
||||||
|
|
||||||
class InstanceError extends Error {
|
class InstanceError extends Error {
|
||||||
constructor(error, identifier) {
|
constructor(error, identifier) {
|
||||||
|
@ -50,6 +51,11 @@ module.exports = [
|
||||||
if (!format.second__height && format.resolution) format.second__height = +format.resolution.slice(0, -1)
|
if (!format.second__height && format.resolution) format.second__height = +format.resolution.slice(0, -1)
|
||||||
if (!format.second__order) format.second__order = formatOrder(format)
|
if (!format.second__order) format.second__order = formatOrder(format)
|
||||||
}
|
}
|
||||||
|
for (const rec of video.recommendedVideos) {
|
||||||
|
if (!rec.second__lengthText && rec.lengthSeconds > 0) {
|
||||||
|
rec.second__lengthText = converters.lengthSecondsToLengthText(rec.lengthSeconds)
|
||||||
|
}
|
||||||
|
}
|
||||||
const subscribed = user.isSubscribed(video.authorId)
|
const subscribed = user.isSubscribed(video.authorId)
|
||||||
return render(200, "pug/video.pug", {video, subscribed})
|
return render(200, "pug/video.pug", {video, subscribed})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -18,4 +18,14 @@ function timeToPastText(timestamp) {
|
||||||
}, null) || "just now"
|
}, null) || "just now"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function lengthSecondsToLengthText(seconds) {
|
||||||
|
return [Math.floor(seconds/3600), Math.floor(seconds/60)%60, seconds%60]
|
||||||
|
.reduce((a, c, i, t) => (
|
||||||
|
a ? a : c || i == 1 ? t.slice(i) : false
|
||||||
|
), false)
|
||||||
|
.map((x, i) => i === 0 ? x : (x+"").padStart(2, "0"))
|
||||||
|
.join(":")
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.timeToPastText = timeToPastText
|
module.exports.timeToPastText = timeToPastText
|
||||||
|
module.exports.lengthSecondsToLengthText = lengthSecondsToLengthText
|
||||||
|
|
Loading…
Reference in New Issue