[www] Document update
This commit is contained in:
1 parent
f36c2617f6
commit
aab113314d
3 files changed
+15
-28
No files matched your search
@@ -21,7 +21,8 @@ class Document {
|
|||||||
constructor(data) {
|
constructor(data) {
|
||||||
this.id = data.id
|
this.id = data.id
|
||||||
this.hash = data.hash
|
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.type = data.type
|
||||||
this.title = data.title
|
this.title = data.title
|
||||||
this.category = data.category
|
this.category = data.category
|
||||||
|
|||||||
+2
-20
@@ -9,6 +9,7 @@ const getPathWithNoTrailingSlash = require('../lib/url').getPathWithNoTrailingSl
|
|||||||
const {get} = require('koa-route')
|
const {get} = require('koa-route')
|
||||||
const {splitBy} = require('../lib/array')
|
const {splitBy} = require('../lib/array')
|
||||||
const {unique} = require('../utils/common')
|
const {unique} = require('../utils/common')
|
||||||
|
const {bakeDocument} = require('./documents')
|
||||||
|
|
||||||
const sizes = [
|
const sizes = [
|
||||||
ImageArtifactType.MEDIUM,
|
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() {
|
function getDocument() {
|
||||||
return get('/document/:id', async (ctx, id) => {
|
return get('/document/:id', async (ctx, id) => {
|
||||||
const path = getPathWithNoTrailingSlash(ctx.path)
|
const path = getPathWithNoTrailingSlash(ctx.path)
|
||||||
@@ -60,7 +42,7 @@ function getDocument() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
ctx.type = 'text/html'
|
ctx.type = 'text/html'
|
||||||
ctx.body = await render(path, Component, getMeta(document))
|
ctx.body = await render(path, Component, getMeta(document), {menuPadding: true})
|
||||||
} else {
|
} else {
|
||||||
ctx.status = 404
|
ctx.status = 404
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-7
@@ -31,18 +31,23 @@ function getMeta(teacher) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function bakeDocument(document) {
|
async function bakeDocument(document) {
|
||||||
//const preview = await document.preview.unpack()
|
|
||||||
const preview = document.preview
|
const preview = document.preview
|
||||||
if (!preview) return null
|
if (!preview) return null
|
||||||
|
|
||||||
const image = preview.findArtifact(sizes)
|
const image = preview.findArtifact(sizes)
|
||||||
if (!image) return null
|
if (!image) return null
|
||||||
|
|
||||||
|
const category = (document.category || '')
|
||||||
|
.replace('Documents/', '')
|
||||||
|
.replace('Pages/', '')
|
||||||
|
.replace('Albums/', '')
|
||||||
|
.replace('Articles /', '')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
category: document.category,
|
category,
|
||||||
title: document.title,
|
title: document.title,
|
||||||
fileName: document.file.name,
|
fileName: document.fileInfo.name,
|
||||||
fileSize: document.file.size,
|
fileSize: document.fileInfo.size,
|
||||||
fileUrl: document.url,
|
fileUrl: document.url,
|
||||||
imageUrl: image.url,
|
imageUrl: image.url,
|
||||||
url: document.viewUrl,
|
url: document.viewUrl,
|
||||||
@@ -50,16 +55,14 @@ async function bakeDocument(document) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getDocuments() {
|
function getDocuments() {
|
||||||
return get('/documents', async (ctx) => {
|
return get('/documents', async ctx => {
|
||||||
const path = getPathWithNoTrailingSlash(ctx.path)
|
const path = getPathWithNoTrailingSlash(ctx.path)
|
||||||
let documents = await Document.find({})
|
let documents = await Document.find({})
|
||||||
|
|
||||||
if (documents) {
|
if (documents) {
|
||||||
//documents = teachersSorted(documents)
|
|
||||||
documents = await Promise.all(documents.map(bakeDocument))
|
documents = await Promise.all(documents.map(bakeDocument))
|
||||||
documents = documents.filter(Boolean)
|
documents = documents.filter(Boolean)
|
||||||
|
|
||||||
//const collections = splitBy(d => d.category)(documents)
|
|
||||||
const collections = getSorted(documents)
|
const collections = getSorted(documents)
|
||||||
|
|
||||||
const Component = (
|
const Component = (
|
||||||
@@ -152,4 +155,5 @@ function getSorted(documents) {
|
|||||||
}], [])
|
}], [])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.bakeDocument = bakeDocument
|
||||||
exports.getDocuments = getDocuments
|
exports.getDocuments = getDocuments
|
||||||
Reference in new issue
Block a user