Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
5ba36ee4
Unverified
Commit
5ba36ee4
authored
Oct 14, 2020
by
Jafar Akhondali
Committed by
GitHub
Oct 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: server code (#2545)
+ Remove duplicated await + Replace some legacy codes with ES6 + Fix some of eslint problems
parent
0a1f0ac9
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
26 additions
and
38 deletions
+26
-38
db.js
server/core/db.js
+1
-2
asset.js
server/graph/resolvers/asset.js
+1
-1
master.js
server/master.js
+3
-3
assetFolders.js
server/models/assetFolders.js
+1
-2
pages.js
server/models/pages.js
+4
-4
renderer.js
server/modules/rendering/html-image-prefetch/renderer.js
+1
-1
underline.js
server/modules/rendering/markdown-core/underline.js
+5
-5
renderer.js
server/modules/rendering/markdown-kroki/renderer.js
+2
-7
renderer.js
server/modules/rendering/markdown-plantuml/renderer.js
+3
-8
engine.js
server/modules/search/elasticsearch/engine.js
+1
-1
setup.js
server/setup.js
+1
-1
page.test.js
server/test/helpers/page.test.js
+3
-3
No files found.
server/core/db.js
View file @
5ba36ee4
...
@@ -43,8 +43,7 @@ module.exports = {
...
@@ -43,8 +43,7 @@ module.exports = {
let
sslOptions
=
null
let
sslOptions
=
null
if
(
dbUseSSL
&&
_
.
isPlainObject
(
dbConfig
)
&&
_
.
get
(
WIKI
.
config
.
db
,
'sslOptions.auto'
,
null
)
===
false
)
{
if
(
dbUseSSL
&&
_
.
isPlainObject
(
dbConfig
)
&&
_
.
get
(
WIKI
.
config
.
db
,
'sslOptions.auto'
,
null
)
===
false
)
{
sslOptions
=
WIKI
.
config
.
db
.
sslOptions
sslOptions
=
WIKI
.
config
.
db
.
sslOptions
// eslint-disable-next-line no-unneeded-ternary
sslOptions
.
rejectUnauthorized
=
sslOptions
.
rejectUnauthorized
!==
false
sslOptions
.
rejectUnauthorized
=
sslOptions
.
rejectUnauthorized
===
false
?
false
:
true
if
(
sslOptions
.
ca
&&
sslOptions
.
ca
.
indexOf
(
'-----'
)
!==
0
)
{
if
(
sslOptions
.
ca
&&
sslOptions
.
ca
.
indexOf
(
'-----'
)
!==
0
)
{
sslOptions
.
ca
=
fs
.
readFileSync
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
sslOptions
.
ca
))
sslOptions
.
ca
=
fs
.
readFileSync
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
sslOptions
.
ca
))
}
}
...
...
server/graph/resolvers/asset.js
View file @
5ba36ee4
...
@@ -39,7 +39,7 @@ module.exports = {
...
@@ -39,7 +39,7 @@ module.exports = {
const
parentPath
=
parentHierarchy
.
map
(
h
=>
h
.
slug
).
join
(
'/'
)
const
parentPath
=
parentHierarchy
.
map
(
h
=>
h
.
slug
).
join
(
'/'
)
return
_
.
filter
(
results
,
r
=>
{
return
_
.
filter
(
results
,
r
=>
{
const
path
=
parentPath
?
`
${
parentPath
}
/
${
r
.
slug
}
`
:
r
.
slug
const
path
=
parentPath
?
`
${
parentPath
}
/
${
r
.
slug
}
`
:
r
.
slug
return
WIKI
.
auth
.
checkAccess
(
context
.
req
.
user
,
[
'read:assets'
],
{
path
})
;
return
WIKI
.
auth
.
checkAccess
(
context
.
req
.
user
,
[
'read:assets'
],
{
path
})
})
})
}
}
},
},
...
...
server/master.js
View file @
5ba36ee4
...
@@ -26,8 +26,8 @@ module.exports = async () => {
...
@@ -26,8 +26,8 @@ module.exports = async () => {
// Load middlewares
// Load middlewares
// ----------------------------------------
// ----------------------------------------
var
mw
=
autoload
(
path
.
join
(
WIKI
.
SERVERPATH
,
'/middlewares'
))
const
mw
=
autoload
(
path
.
join
(
WIKI
.
SERVERPATH
,
'/middlewares'
))
var
ctrl
=
autoload
(
path
.
join
(
WIKI
.
SERVERPATH
,
'/controllers'
))
const
ctrl
=
autoload
(
path
.
join
(
WIKI
.
SERVERPATH
,
'/controllers'
))
// ----------------------------------------
// ----------------------------------------
// Define Express App
// Define Express App
...
@@ -169,7 +169,7 @@ module.exports = async () => {
...
@@ -169,7 +169,7 @@ module.exports = async () => {
// ----------------------------------------
// ----------------------------------------
app
.
use
((
req
,
res
,
next
)
=>
{
app
.
use
((
req
,
res
,
next
)
=>
{
var
err
=
new
Error
(
'Not Found'
)
const
err
=
new
Error
(
'Not Found'
)
err
.
status
=
404
err
.
status
=
404
next
(
err
)
next
(
err
)
})
})
...
...
server/models/assetFolders.js
View file @
5ba36ee4
...
@@ -47,8 +47,7 @@ module.exports = class AssetFolder extends Model {
...
@@ -47,8 +47,7 @@ module.exports = class AssetFolder extends Model {
sqb
.
select
(
'a.id'
,
'a.name'
,
'a.slug'
,
'a.parentId'
).
from
(
'assetFolders AS a'
).
join
(
'ancestors'
,
'ancestors.parentId'
,
'a.id'
)
sqb
.
select
(
'a.id'
,
'a.name'
,
'a.slug'
,
'a.parentId'
).
from
(
'assetFolders AS a'
).
join
(
'ancestors'
,
'ancestors.parentId'
,
'a.id'
)
})
})
}).
select
(
'*'
).
from
(
'ancestors'
)
}).
select
(
'*'
).
from
(
'ancestors'
)
}
}
else
{
else
{
hier
=
await
WIKI
.
models
.
knex
.
withRecursive
(
'ancestors'
,
qb
=>
{
hier
=
await
WIKI
.
models
.
knex
.
withRecursive
(
'ancestors'
,
qb
=>
{
qb
.
select
(
'id'
,
'name'
,
'slug'
,
'parentId'
).
from
(
'assetFolders'
).
where
(
'id'
,
folderId
).
union
(
sqb
=>
{
qb
.
select
(
'id'
,
'name'
,
'slug'
,
'parentId'
).
from
(
'assetFolders'
).
where
(
'id'
,
folderId
).
union
(
sqb
=>
{
sqb
.
select
(
'a.id'
,
'a.name'
,
'a.slug'
,
'a.parentId'
).
from
(
'assetFolders AS a'
).
join
(
'ancestors'
,
'ancestors.parentId'
,
'a.id'
)
sqb
.
select
(
'a.id'
,
'a.name'
,
'a.slug'
,
'a.parentId'
).
from
(
'assetFolders AS a'
).
join
(
'ancestors'
,
'ancestors.parentId'
,
'a.id'
)
...
...
server/models/pages.js
View file @
5ba36ee4
...
@@ -231,7 +231,7 @@ module.exports = class Page extends Model {
...
@@ -231,7 +231,7 @@ module.exports = class Page extends Model {
*/
*/
static
async
createPage
(
opts
)
{
static
async
createPage
(
opts
)
{
// -> Validate path
// -> Validate path
if
(
opts
.
path
.
in
dexOf
(
'.'
)
>=
0
||
opts
.
path
.
indexOf
(
' '
)
>=
0
||
opts
.
path
.
indexOf
(
'
\
\'
) >= 0 || opts.path.indexOf('
//') >= 0
) {
if
(
opts
.
path
.
in
cludes
(
'.'
)
||
opts
.
path
.
includes
(
' '
)
||
opts
.
path
.
includes
(
'
\
\'
) || opts.path.includes('
//')
) {
throw
new
WIKI
.
Error
.
PageIllegalPath
()
throw
new
WIKI
.
Error
.
PageIllegalPath
()
}
}
...
@@ -484,7 +484,7 @@ module.exports = class Page extends Model {
...
@@ -484,7 +484,7 @@ module.exports = class Page extends Model {
}
}
// -> Validate path
// -> Validate path
if
(
opts
.
destinationPath
.
in
dexOf
(
'.'
)
>=
0
||
opts
.
destinationPath
.
indexOf
(
' '
)
>=
0
||
opts
.
destinationPath
.
indexOf
(
'
\
\'
) >= 0 || opts.destinationPath.indexOf('
//') >= 0
) {
if
(
opts
.
destinationPath
.
in
cludes
(
'.'
)
||
opts
.
destinationPath
.
includes
(
' '
)
||
opts
.
destinationPath
.
includes
(
'
\
\'
) || opts.destinationPath.includes('
//')
) {
throw
new
WIKI
.
Error
.
PageIllegalPath
()
throw
new
WIKI
.
Error
.
PageIllegalPath
()
}
}
...
@@ -514,7 +514,7 @@ module.exports = class Page extends Model {
...
@@ -514,7 +514,7 @@ module.exports = class Page extends Model {
}
}
// -> Check for existing page at destination path
// -> Check for existing page at destination path
const
destPage
=
await
await
WIKI
.
models
.
pages
.
query
().
findOne
({
const
destPage
=
await
WIKI
.
models
.
pages
.
query
().
findOne
({
path
:
opts
.
destinationPath
,
path
:
opts
.
destinationPath
,
localeCode
:
opts
.
destinationLocale
localeCode
:
opts
.
destinationLocale
})
})
...
@@ -595,7 +595,7 @@ module.exports = class Page extends Model {
...
@@ -595,7 +595,7 @@ module.exports = class Page extends Model {
if
(
_
.
has
(
opts
,
'id'
))
{
if
(
_
.
has
(
opts
,
'id'
))
{
page
=
await
WIKI
.
models
.
pages
.
query
().
findById
(
opts
.
id
)
page
=
await
WIKI
.
models
.
pages
.
query
().
findById
(
opts
.
id
)
}
else
{
}
else
{
page
=
await
await
WIKI
.
models
.
pages
.
query
().
findOne
({
page
=
await
WIKI
.
models
.
pages
.
query
().
findOne
({
path
:
opts
.
path
,
path
:
opts
.
path
,
localeCode
:
opts
.
locale
localeCode
:
opts
.
locale
})
})
...
...
server/modules/rendering/html-image-prefetch/renderer.js
View file @
5ba36ee4
...
@@ -17,7 +17,7 @@ const prefetch = async (element) => {
...
@@ -17,7 +17,7 @@ const prefetch = async (element) => {
const
contentType
=
response
.
headers
[
`content-type`
]
const
contentType
=
response
.
headers
[
`content-type`
]
const
image
=
Buffer
.
from
(
response
.
body
).
toString
(
'base64'
)
const
image
=
Buffer
.
from
(
response
.
body
).
toString
(
'base64'
)
element
.
attr
(
'src'
,
`data:
${
contentType
}
;base64,
${
image
}
`
)
element
.
attr
(
'src'
,
`data:
${
contentType
}
;base64,
${
image
}
`
)
element
.
removeClass
(
'prefetch-candidate'
)
;
element
.
removeClass
(
'prefetch-candidate'
)
}
}
module
.
exports
=
{
module
.
exports
=
{
...
...
server/modules/rendering/markdown-core/underline.js
View file @
5ba36ee4
const
renderEm
=
(
tokens
,
idx
,
opts
,
env
,
slf
)
=>
{
const
renderEm
=
(
tokens
,
idx
,
opts
,
env
,
slf
)
=>
{
const
token
=
tokens
[
idx
]
;
const
token
=
tokens
[
idx
]
if
(
token
.
markup
===
'_'
)
{
if
(
token
.
markup
===
'_'
)
{
token
.
tag
=
'u'
;
token
.
tag
=
'u'
}
}
return
slf
.
renderToken
(
tokens
,
idx
,
opts
)
;
return
slf
.
renderToken
(
tokens
,
idx
,
opts
)
}
}
module
.
exports
=
(
md
)
=>
{
module
.
exports
=
(
md
)
=>
{
md
.
renderer
.
rules
.
em_open
=
renderEm
;
md
.
renderer
.
rules
.
em_open
=
renderEm
md
.
renderer
.
rules
.
em_close
=
renderEm
;
md
.
renderer
.
rules
.
em_close
=
renderEm
}
}
server/modules/rendering/markdown-kroki/renderer.js
View file @
5ba36ee4
...
@@ -73,13 +73,8 @@ module.exports = {
...
@@ -73,13 +73,8 @@ module.exports = {
continue
continue
}
}
var
closeMarkerMatched
=
true
const
i
=
closeMarker
.
findIndex
(
item
=>
item
!==
state
.
src
[
start
+
i
])
for
(
i
=
0
;
i
<
closeMarker
.
length
;
++
i
)
{
const
closeMarkerMatched
=
i
!==
-
1
if
(
closeMarker
[
i
]
!==
state
.
src
[
start
+
i
])
{
closeMarkerMatched
=
false
break
}
}
if
(
!
closeMarkerMatched
)
{
if
(
!
closeMarkerMatched
)
{
continue
continue
...
...
server/modules/rendering/markdown-plantuml/renderer.js
View file @
5ba36ee4
...
@@ -74,13 +74,8 @@ module.exports = {
...
@@ -74,13 +74,8 @@ module.exports = {
continue
continue
}
}
var
closeMarkerMatched
=
true
const
i
=
closeMarker
.
findIndex
(
item
=>
item
!==
state
.
src
[
start
+
i
])
for
(
i
=
0
;
i
<
closeMarker
.
length
;
++
i
)
{
const
closeMarkerMatched
=
i
!==
-
1
if
(
closeMarker
[
i
]
!==
state
.
src
[
start
+
i
])
{
closeMarkerMatched
=
false
break
}
}
if
(
!
closeMarkerMatched
)
{
if
(
!
closeMarkerMatched
)
{
continue
continue
...
@@ -112,7 +107,7 @@ module.exports = {
...
@@ -112,7 +107,7 @@ module.exports = {
altToken
altToken
)
)
var
zippedCode
=
encode64
(
zlib
.
deflateRawSync
(
'@startuml
\
n'
+
contents
+
'
\
n@enduml'
).
toString
(
'binary'
))
const
zippedCode
=
encode64
(
zlib
.
deflateRawSync
(
'@startuml
\
n'
+
contents
+
'
\
n@enduml'
).
toString
(
'binary'
))
token
=
state
.
push
(
'uml_diagram'
,
'img'
,
0
)
token
=
state
.
push
(
'uml_diagram'
,
'img'
,
0
)
// alt is constructed from children. No point in populating it here.
// alt is constructed from children. No point in populating it here.
...
...
server/modules/search/elasticsearch/engine.js
View file @
5ba36ee4
...
@@ -104,7 +104,7 @@ module.exports = {
...
@@ -104,7 +104,7 @@ module.exports = {
},
},
{
{
query_string
:
{
query_string
:
{
query
:
"*"
+
q
+
"*"
query
:
`*
${
q
}
*`
}
}
}
}
],
],
...
...
server/setup.js
View file @
5ba36ee4
...
@@ -378,7 +378,7 @@ module.exports = () => {
...
@@ -378,7 +378,7 @@ module.exports = () => {
// ----------------------------------------
// ----------------------------------------
app
.
use
(
function
(
req
,
res
,
next
)
{
app
.
use
(
function
(
req
,
res
,
next
)
{
var
err
=
new
Error
(
'Not Found'
)
const
err
=
new
Error
(
'Not Found'
)
err
.
status
=
404
err
.
status
=
404
next
(
err
)
next
(
err
)
})
})
...
...
server/test/helpers/page.test.js
View file @
5ba36ee4
...
@@ -7,7 +7,7 @@ describe('helpers/page/injectPageMetadata', () => {
...
@@ -7,7 +7,7 @@ describe('helpers/page/injectPageMetadata', () => {
isPublished
:
true
,
isPublished
:
true
,
updatedAt
:
new
Date
(),
updatedAt
:
new
Date
(),
content
:
'TEST CONTENT'
,
content
:
'TEST CONTENT'
,
createdAt
:
new
Date
(
'2019-01-01'
)
,
createdAt
:
new
Date
(
'2019-01-01'
)
}
}
it
(
'returns the page content by default when content type is unknown'
,
()
=>
{
it
(
'returns the page content by default when content type is unknown'
,
()
=>
{
...
@@ -20,7 +20,7 @@ describe('helpers/page/injectPageMetadata', () => {
...
@@ -20,7 +20,7 @@ describe('helpers/page/injectPageMetadata', () => {
const
markdownPage
=
{
const
markdownPage
=
{
...
page
,
...
page
,
contentType
:
'markdown'
,
contentType
:
'markdown'
,
editorKey
:
'markdown'
,
editorKey
:
'markdown'
}
}
const
expected
=
`---
const
expected
=
`---
...
@@ -42,7 +42,7 @@ TEST CONTENT`
...
@@ -42,7 +42,7 @@ TEST CONTENT`
const
htmlPage
=
{
const
htmlPage
=
{
...
page
,
...
page
,
contentType
:
'html'
,
contentType
:
'html'
,
editorKey
:
'html'
,
editorKey
:
'html'
}
}
const
expected
=
`<!--
const
expected
=
`<!--
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment