Project
This commit is contained in:
@@ -10,6 +10,20 @@ const characterCounter = (totalCharacterCount, chunk) => {
|
|||||||
return totalCharacterCount + chunk.length
|
return totalCharacterCount + chunk.length
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const saveFile = async (file, userId, chapterIndex, artifactVersion) => {
|
||||||
|
const fileText = file.data.toString()
|
||||||
|
// if (Object.hasOwnProperty.call(file, index)) {
|
||||||
|
// const file = request.files[index]
|
||||||
|
// }
|
||||||
|
return await saveChapter(
|
||||||
|
userId,
|
||||||
|
file.name,
|
||||||
|
fileText,
|
||||||
|
chapterIndex,
|
||||||
|
artifactVersion
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const saveChapter = async (userId, chapterName, text, chapterIndex, artifactVersion) => {
|
const saveChapter = async (userId, chapterName, text, chapterIndex, artifactVersion) => {
|
||||||
const chunks = md.parse(
|
const chunks = md.parse(
|
||||||
text
|
text
|
||||||
@@ -360,20 +374,31 @@ module.exports = function (options) {
|
|||||||
if (artifactVersion && request.files) {
|
if (artifactVersion && request.files) {
|
||||||
// TODO: Parse files and store their texts...
|
// TODO: Parse files and store their texts...
|
||||||
const chapterIndex = artifactVersion.chapters.length + 1
|
const chapterIndex = artifactVersion.chapters.length + 1
|
||||||
for (const index in request.files.chapters) {
|
if (request.files.chapters.length > 0) {
|
||||||
const file = request.files.chapters[index]
|
for (const index in request.files.chapters) {
|
||||||
const fileText = file.data.toString()
|
const file = request.files.chapters[index] ?? request.files.chapters
|
||||||
// if (Object.hasOwnProperty.call(file, index)) {
|
const fileText = file.data.toString()
|
||||||
// const file = request.files[index]
|
// if (Object.hasOwnProperty.call(file, index)) {
|
||||||
// }
|
// const file = request.files[index]
|
||||||
const chapter = await saveChapter(
|
// }
|
||||||
|
const chapter = await saveFile(
|
||||||
|
file,
|
||||||
|
request.user.id,
|
||||||
|
chapterIndex+index,
|
||||||
|
artifactVersion
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const file = request.files.chapters
|
||||||
|
|
||||||
|
const chapter = await saveFile(
|
||||||
|
file,
|
||||||
request.user.id,
|
request.user.id,
|
||||||
file.name,
|
chapterIndex,
|
||||||
fileText,
|
|
||||||
chapterIndex+index,
|
|
||||||
artifactVersion
|
artifactVersion
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
response.redirect(`/v/${artifactVersion.id}`)
|
response.redirect(`/v/${artifactVersion.id}`)
|
||||||
} else {
|
} else {
|
||||||
next()
|
next()
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ block content
|
|||||||
|
|
||||||
if isOwnedByUser
|
if isOwnedByUser
|
||||||
.divider
|
.divider
|
||||||
|
.row
|
||||||
|
.col.s12
|
||||||
|
p.flow-text
|
||||||
|
-
|
||||||
|
const wordCount = artifactVersion.chapters.reduce((totalWordCount, chapter) => totalWordCount+chapter.wordCount, 0)
|
||||||
|
span.chip #{wordCount.toLocaleString()} words
|
||||||
.row
|
.row
|
||||||
.col.s12
|
.col.s12
|
||||||
a.btn.black(href=`/v/${artifactVersion.id}/chapters/add`) add chapter
|
a.btn.black(href=`/v/${artifactVersion.id}/chapters/add`) add chapter
|
||||||
|
|||||||
Reference in New Issue
Block a user