mirror of
https://github.com/nexus-stc/hyperboria
synced 2024-12-05 01:12:55 +01:00
d51e5ab65d
- fix: Translation fixes - fix: Various fixes - feat: PB translations, configuration changes - fix: Bugfixes GitOrigin-RevId: 55f8b148c42a296162fc707c36a5146ca0073b4b
71 lines
1.6 KiB
JavaScript
71 lines
1.6 KiB
JavaScript
import dateFormat from 'dateformat'
|
|
|
|
export function getFirstAuthors (authors, etAl = true, firstNAuthors = 1) {
|
|
let etAlSuffix = ''
|
|
if (etAl) {
|
|
etAlSuffix = ' et al'
|
|
}
|
|
if (authors) {
|
|
if (authors.length > firstNAuthors) {
|
|
return authors.slice(0, firstNAuthors).join(';') + etAlSuffix
|
|
} else if (authors.length === 1) {
|
|
if (authors[0].split(';').length - 1 >= 1) {
|
|
const commaAuthors = authors[0].split(';').map(function (el) {
|
|
return el.trim()
|
|
})
|
|
if (commaAuthors.length > firstNAuthors) {
|
|
return (commaAuthors.slice(0, firstNAuthors)).join('; ') + etAlSuffix
|
|
} else {
|
|
return commaAuthors.join('; ')
|
|
}
|
|
}
|
|
return authors[0]
|
|
} else {
|
|
return authors.join('; ')
|
|
}
|
|
} else {
|
|
return ''
|
|
}
|
|
}
|
|
|
|
export function getMegabytes (bytes) {
|
|
try {
|
|
if (bytes) {
|
|
return (bytes / (1024 * 1024)).toFixed(2) + ' Mb'
|
|
}
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function getIssuedDate (unixtime) {
|
|
if (!unixtime) return null
|
|
try {
|
|
return dateFormat(new Date(unixtime * 1000), 'yyyy')
|
|
} catch (e) {
|
|
console.error(e)
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function getCoverUrl (cu, fictionId, libgenId, cuSuf, md5) {
|
|
if (cu) return cu
|
|
let r = ''
|
|
if (libgenId || fictionId) {
|
|
if (libgenId) {
|
|
const bulkId = (libgenId - (libgenId % 1000))
|
|
r = `covers/${bulkId}/${md5}`
|
|
} else if (fictionId) {
|
|
const bulkId = (fictionId - (fictionId % 1000))
|
|
r = `fictioncovers/${bulkId}/${md5}`
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
if (cuSuf) {
|
|
r = r + `-${cuSuf}`
|
|
return `http://gen.lib.rus.ec/${r}.jpg`
|
|
}
|
|
return null
|
|
}
|