[www] Document update

This commit is contained in:
Roman Timashev committed 2017-10-23 02:05:31 +03:00
1 parent f36c2617f6
commit aab113314d
3 files changed
+15 -28

No files matched your search

+2 -1
View File
@@ -21,7 +21,8 @@ class Document {
constructor(data) {
this.id = data.id
this.hash = data.hash
this.file = new DocumentFile(data.file)
this.file = data.file
this.fileInfo = new DocumentFile(data.fileInfo)
this.type = data.type
this.title = data.title
this.category = data.category
+2 -20
View File
@@ -9,6 +9,7 @@ const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSl
const {get} = require('koa-route')
const {splitBy} = require('../lib/array')
const {unique} = require('../utils/common')
const {bakeDocument} = require('./documents')
const sizes = [
ImageArtifactType.MEDIUM,
@@ -23,25 +24,6 @@ function getMeta(document) {
}
}
async function bakeDocument(document) {
//const preview = await document.preview.unpack()
const preview = document.preview
if (!preview) return null
const image = preview.findArtifact(sizes)
if (!image) return null
return {
category: document.category,
title: document.title,
fileName: document.file.name,
fileSize: document.file.size,
fileUrl: document.url,
imageUrl: image.url,
url: document.viewUrl,
}
}
function getDocument() {
return get('/document/:id', async (ctx, id) => {
const path = getPathWithNoTrailingSlash(ctx.path)
@@ -60,7 +42,7 @@ function getDocument() {
)
ctx.type = 'text/html'
ctx.body = await render(path, Component, getMeta(document))
ctx.body = await render(path, Component, getMeta(document), {menuPadding: true})
} else {
ctx.status = 404
}
+11 -7
View File
@@ -31,18 +31,23 @@ function getMeta(teacher) {
}
async function bakeDocument(document) {
//const preview = await document.preview.unpack()
const preview = document.preview
if (!preview) return null
const image = preview.findArtifact(sizes)
if (!image) return null
const category = (document.category || '')
.replace('Documents/', '')
.replace('Pages/', '')
.replace('Albums/', '')
.replace('Articles /', '')
return {
category: document.category,
category,
title: document.title,
fileName: document.file.name,
fileSize: document.file.size,
fileName: document.fileInfo.name,
fileSize: document.fileInfo.size,
fileUrl: document.url,
imageUrl: image.url,
url: document.viewUrl,
@@ -50,16 +55,14 @@ async function bakeDocument(document) {
}
function getDocuments() {
return get('/documents', async (ctx) => {
return get('/documents', async ctx => {
const path = getPathWithNoTrailingSlash(ctx.path)
let documents = await Document.find({})
if (documents) {
//documents = teachersSorted(documents)
documents = await Promise.all(documents.map(bakeDocument))
documents = documents.filter(Boolean)
//const collections = splitBy(d => d.category)(documents)
const collections = getSorted(documents)
const Component = (
@@ -152,4 +155,5 @@ function getSorted(documents) {
}], [])
}
exports.bakeDocument = bakeDocument
exports.getDocuments = getDocuments