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
8f944494
Unverified
Commit
8f944494
authored
Apr 09, 2023
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: convert to esm (wip)
parent
e9e93eff
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
70 additions
and
59 deletions
+70
-59
auth.mjs
server/core/auth.mjs
+1
-1
scheduler.mjs
server/core/scheduler.mjs
+1
-1
common.mjs
server/helpers/common.mjs
+2
-2
page.mjs
server/helpers/page.mjs
+3
-3
navigation.mjs
server/models/navigation.mjs
+2
-2
pages.mjs
server/models/pages.mjs
+5
-5
storage.mjs
server/models/storage.mjs
+4
-4
tags.mjs
server/models/tags.mjs
+1
-1
users.mjs
server/models/users.mjs
+1
-1
authentication.mjs
server/modules/authentication/local/authentication.mjs
+4
-4
ext.mjs
server/modules/extensions/git/ext.mjs
+2
-2
ext.mjs
server/modules/extensions/pandoc/ext.mjs
+3
-3
ext.mjs
server/modules/extensions/puppeteer/ext.mjs
+9
-7
ext.mjs
server/modules/extensions/sharp/ext.mjs
+14
-12
renderer.mjs
server/modules/rendering/html-core/renderer.mjs
+2
-2
storage.mjs
server/modules/storage/db/storage.mjs
+2
-2
render-page.mjs
server/tasks/workers/render-page.mjs
+2
-2
worker.mjs
server/worker.mjs
+12
-5
No files found.
server/core/auth.mjs
View file @
8f944494
...
...
@@ -78,7 +78,7 @@ export default {
const
enabledStrategies
=
await
WIKI
.
db
.
authentication
.
getStrategies
({
enabledOnly
:
true
})
for
(
const
stg
of
enabledStrategies
)
{
try
{
const
strategy
=
require
(
`../modules/authentication/
${
stg
.
module
}
/authentication.js`
)
const
strategy
=
(
await
import
(
`../modules/authentication/
${
stg
.
module
}
/authentication.mjs`
)).
default
stg
.
config
.
callbackURL
=
`
${
WIKI
.
config
.
host
}
/login/
${
stg
.
id
}
/callback`
stg
.
config
.
key
=
stg
.
id
...
...
server/core/scheduler.mjs
View file @
8f944494
...
...
@@ -20,7 +20,7 @@ export default {
this
.
maxWorkers
=
WIKI
.
config
.
scheduler
.
workers
===
'auto'
?
(
os
.
cpus
().
length
-
1
)
:
WIKI
.
config
.
scheduler
.
workers
if
(
this
.
maxWorkers
<
1
)
{
this
.
maxWorkers
=
1
}
WIKI
.
logger
.
info
(
`Initializing Worker Pool (Limit:
${
this
.
maxWorkers
}
)...`
)
this
.
workerPool
=
new
DynamicThreadPool
(
1
,
this
.
maxWorkers
,
path
.
join
(
WIKI
.
SERVERPATH
,
'worker.js'
),
{
this
.
workerPool
=
new
DynamicThreadPool
(
1
,
this
.
maxWorkers
,
path
.
join
(
WIKI
.
SERVERPATH
,
'worker.
m
js'
),
{
errorHandler
:
(
err
)
=>
WIKI
.
logger
.
warn
(
err
),
exitHandler
:
()
=>
WIKI
.
logger
.
debug
(
'A worker has gone offline.'
),
onlineHandler
:
()
=>
WIKI
.
logger
.
debug
(
'New worker is online.'
)
...
...
server/helpers/common.mjs
View file @
8f944494
...
...
@@ -81,9 +81,9 @@ export function parseModuleProps (props) {
return
transform
(
props
,
(
result
,
value
,
key
)
=>
{
let
defaultValue
=
''
if
(
isPlainObject
(
value
))
{
defaultValue
=
!
isNil
(
value
.
default
)
?
value
.
default
:
this
.
getTypeDefaultValue
(
value
.
type
)
defaultValue
=
!
isNil
(
value
.
default
)
?
value
.
default
:
getTypeDefaultValue
(
value
.
type
)
}
else
{
defaultValue
=
this
.
getTypeDefaultValue
(
value
)
defaultValue
=
getTypeDefaultValue
(
value
)
}
set
(
result
,
key
,
{
default
:
defaultValue
,
...
...
server/helpers/page.mjs
View file @
8f944494
import
qs
from
'querystring'
import
{
fromPairs
,
get
,
initial
,
invert
,
isEmpty
,
last
}
from
'lodash-es'
import
{
fromPairs
,
get
,
head
,
initial
,
invert
,
isEmpty
,
last
}
from
'lodash-es'
import
crypto
from
'node:crypto'
import
path
from
'node:path'
...
...
@@ -59,7 +59,7 @@ export function parsePath (rawPath, opts = {}) {
}
}
pathObj
.
path
=
_
.
join
(
pathParts
,
'/'
)
pathObj
.
path
=
pathParts
.
join
(
'/'
)
return
pathObj
}
...
...
@@ -102,7 +102,7 @@ export function injectPageMetadata(page) {
* Check if path is a reserved path
*/
export
function
isReservedPath
(
rawPath
)
{
const
firstSection
=
_
.
head
(
rawPath
.
split
(
'/'
))
const
firstSection
=
head
(
rawPath
.
split
(
'/'
))
if
(
firstSection
.
length
<
1
)
{
return
true
}
else
if
(
localeSegmentRegex
.
test
(
firstSection
))
{
...
...
server/models/navigation.mjs
View file @
8f944494
import
{
Model
}
from
'objection'
import
{
has
}
from
'lodash-es'
import
{
has
,
intersection
}
from
'lodash-es'
/**
* Navigation model
...
...
@@ -59,7 +59,7 @@ export class Navigation extends Model {
static
getAuthorizedItems
(
tree
=
[],
groups
=
[])
{
return
tree
.
filter
(
leaf
=>
{
return
leaf
.
visibilityMode
===
'all'
||
_
.
intersection
(
leaf
.
visibilityGroups
,
groups
).
length
>
0
return
leaf
.
visibilityMode
===
'all'
||
intersection
(
leaf
.
visibilityGroups
,
groups
).
length
>
0
})
}
}
server/models/pages.mjs
View file @
8f944494
import
{
Model
}
from
'objection'
import
{
find
,
get
,
has
,
i
sEmpty
,
isString
,
pick
}
from
'lodash-es'
import
{
find
,
get
,
has
,
i
nitial
,
isEmpty
,
isString
,
last
,
pick
}
from
'lodash-es'
import
{
Type
as
JSBinType
}
from
'js-binary'
import
{
generateHash
,
getFileExtension
,
injectPageMetadata
}
from
'../helpers/page.mjs'
import
path
from
'node:path'
...
...
@@ -272,7 +272,7 @@ export class Page extends Model {
}
// -> Check for empty content
if
(
!
opts
.
content
||
_
.
trim
(
opts
.
content
).
length
<
1
)
{
if
(
!
opts
.
content
||
opts
.
content
.
trim
(
).
length
<
1
)
{
throw
new
WIKI
.
Error
.
PageEmptyContent
()
}
...
...
@@ -282,7 +282,7 @@ export class Page extends Model {
locale
:
opts
.
locale
,
path
:
opts
.
path
}))
{
if
(
!
_
.
isEmpty
(
opts
.
scriptCss
))
{
if
(
!
isEmpty
(
opts
.
scriptCss
))
{
scriptCss
=
new
CleanCSS
({
inline
:
false
}).
minify
(
opts
.
scriptCss
).
styles
}
else
{
scriptCss
=
''
...
...
@@ -350,8 +350,8 @@ export class Page extends Model {
const
pathParts
=
page
.
path
.
split
(
'/'
)
await
WIKI
.
db
.
tree
.
addPage
({
id
:
page
.
id
,
parentPath
:
_
.
initial
(
pathParts
).
join
(
'/'
),
fileName
:
_
.
last
(
pathParts
),
parentPath
:
initial
(
pathParts
).
join
(
'/'
),
fileName
:
last
(
pathParts
),
locale
:
page
.
localeCode
,
title
:
page
.
title
,
meta
:
{
...
...
server/models/storage.mjs
View file @
8f944494
import
{
Model
}
from
'objection'
import
path
from
'node:path'
import
fs
from
'node:fs/promises'
import
{
capitalize
,
find
,
has
,
hasIn
,
uniq
}
from
'lodash-es'
import
{
capitalize
,
find
,
has
,
hasIn
,
remove
,
uniq
}
from
'lodash-es'
import
yaml
from
'js-yaml'
/**
...
...
@@ -68,7 +68,7 @@ export class Storage extends Model {
static
async
ensureModule
(
moduleName
)
{
if
(
!
has
(
WIKI
.
storage
.
modules
,
moduleName
))
{
try
{
WIKI
.
storage
.
modules
[
moduleName
]
=
require
(
`../modules/storage/
${
moduleName
}
/storage`
)
WIKI
.
storage
.
modules
[
moduleName
]
=
(
await
import
(
`../modules/storage/
${
moduleName
}
/storage.mjs`
)).
default
WIKI
.
logger
.
debug
(
`Activated storage module
${
moduleName
}
: [ OK ]`
)
return
true
}
catch
(
err
)
{
...
...
@@ -89,7 +89,7 @@ export class Storage extends Model {
const
activeModules
=
uniq
(
dbTargets
.
map
(
t
=>
t
.
module
))
try
{
// -> Stop and delete existing jobs
// const prevjobs =
_.
remove(WIKI.scheduler.jobs, job => job.name === 'sync-storage')
// const prevjobs = remove(WIKI.scheduler.jobs, job => job.name === 'sync-storage')
// if (prevjobs.length > 0) {
// prevjobs.forEach(job => job.stop())
// }
...
...
@@ -101,7 +101,7 @@ export class Storage extends Model {
// -> Initialize targets
// for (const target of this.targets) {
// const targetDef =
_.
find(WIKI.data.storage, ['key', target.key])
// const targetDef = find(WIKI.data.storage, ['key', target.key])
// target.fn = require(`../modules/storage/${target.key}/storage`)
// target.fn.config = target.config
// target.fn.mode = target.mode
...
...
server/models/tags.mjs
View file @
8f944494
...
...
@@ -73,7 +73,7 @@ export class Tag extends Model {
// Fetch current page tags
const
targetTags
=
existingTags
.
filter
(
t
=>
_
.
includes
(
tags
,
t
.
tag
))
const
targetTags
=
existingTags
.
filter
(
t
=>
tags
.
includes
(
t
.
tag
))
const
currentTags
=
await
page
.
$relatedQuery
(
'tags'
)
// Tags to relate
...
...
server/models/users.mjs
View file @
8f944494
/* global WIKI */
import
{
difference
,
find
,
first
,
flatten
,
flattenDeep
,
get
,
has
,
isArray
,
isEmpty
,
isNil
,
last
,
set
,
toString
,
truncate
,
uniq
}
from
'lodash-es'
import
{
difference
,
find
,
first
,
flatten
,
flattenDeep
,
get
,
has
,
isArray
,
isEmpty
,
isNil
,
isString
,
last
,
set
,
toString
,
truncate
,
uniq
}
from
'lodash-es'
import
tfa
from
'node-2fa'
import
jwt
from
'jsonwebtoken'
import
{
Model
}
from
'objection'
...
...
server/modules/authentication/local/authentication.js
→
server/modules/authentication/local/authentication.
m
js
View file @
8f944494
/* global WIKI */
const
bcrypt
=
require
(
'bcryptjs-then'
)
import
bcrypt
from
'bcryptjs-then'
// ------------------------------------
// Local Account
// ------------------------------------
const
LocalStrategy
=
require
(
'passport-local'
).
Strategy
import
{
Strategy
}
from
'passport-local'
module
.
exports
=
{
export
default
{
init
(
passport
,
conf
)
{
passport
.
use
(
conf
.
key
,
new
Local
Strategy
({
new
Strategy
({
usernameField
:
'email'
,
passwordField
:
'password'
},
async
(
uEmail
,
uPassword
,
done
)
=>
{
...
...
server/modules/extensions/git/ext.js
→
server/modules/extensions/git/ext.
m
js
View file @
8f944494
const
cmdExists
=
require
(
'command-exists'
)
import
cmdExists
from
'command-exists'
module
.
exports
=
{
export
default
{
key
:
'git'
,
title
:
'Git'
,
description
:
'Distributed version control system. Required for the Git storage module.'
,
...
...
server/modules/extensions/pandoc/ext.js
→
server/modules/extensions/pandoc/ext.
m
js
View file @
8f944494
const
cmdExists
=
require
(
'command-exists'
)
const
os
=
require
(
'os'
)
import
cmdExists
from
'command-exists'
import
os
from
'node:os'
module
.
exports
=
{
export
default
{
key
:
'pandoc'
,
title
:
'Pandoc'
,
description
:
'Convert between markup formats. Required for converting from other formats such as MediaWiki, AsciiDoc, Textile and other wikis.'
,
...
...
server/modules/extensions/puppeteer/ext.js
→
server/modules/extensions/puppeteer/ext.
m
js
View file @
8f944494
const
os
=
require
(
'os'
)
const
path
=
require
(
'path'
)
const
util
=
require
(
'util'
)
const
exec
=
util
.
promisify
(
require
(
'child_process'
).
exec
)
const
fs
=
require
(
'fs-extra'
)
import
os
from
'node:os'
import
path
from
'node:path'
import
util
from
'node:util'
import
{
exec
as
execSync
}
from
'node:child_process'
import
fse
from
'fs-extra'
module
.
exports
=
{
const
exec
=
util
.
promisify
(
execSync
)
export
default
{
key
:
'puppeteer'
,
title
:
'Puppeteer'
,
description
:
'Headless chromium browser for server-side rendering. Required for generating PDF versions of pages and render content elements on the server (e.g. Mermaid diagrams)'
,
...
...
@@ -15,7 +17,7 @@ module.exports = {
isInstallable
:
true
,
async
check
()
{
try
{
this
.
isInstalled
=
await
fs
.
pathExists
(
path
.
join
(
WIKI
.
SERVERPATH
,
'node_modules/puppeteer-core/.local-chromium'
))
this
.
isInstalled
=
await
fs
e
.
pathExists
(
path
.
join
(
WIKI
.
SERVERPATH
,
'node_modules/puppeteer-core/.local-chromium'
))
}
catch
(
err
)
{
this
.
isInstalled
=
false
}
...
...
server/modules/extensions/sharp/ext.js
→
server/modules/extensions/sharp/ext.
m
js
View file @
8f944494
const
fs
=
require
(
'fs-extra'
)
const
os
=
require
(
'os'
)
const
path
=
require
(
'path'
)
const
util
=
require
(
'util'
)
const
exec
=
util
.
promisify
(
require
(
'child_process'
).
exec
)
const
{
pipeline
}
=
require
(
'stream/promises'
)
import
fse
from
'fs-extra'
import
os
from
'node:os'
import
path
from
'node:path'
import
util
from
'node:util'
import
{
exec
as
execSync
}
from
'node:child_process'
import
{
pipeline
}
from
'node:stream/promises'
module
.
exports
=
{
const
exec
=
util
.
promisify
(
execSync
)
export
default
{
key
:
'sharp'
,
title
:
'Sharp'
,
description
:
'Process and transform images. Required to generate thumbnails of uploaded images and perform transformations.'
,
...
...
@@ -15,7 +17,7 @@ module.exports = {
isInstalled
:
false
,
isInstallable
:
true
,
async
check
()
{
this
.
isInstalled
=
await
fs
.
pathExists
(
path
.
join
(
WIKI
.
SERVERPATH
,
'node_modules/sharp/wiki_installed.txt'
))
this
.
isInstalled
=
await
fs
e
.
pathExists
(
path
.
join
(
WIKI
.
SERVERPATH
,
'node_modules/sharp/wiki_installed.txt'
))
return
this
.
isInstalled
},
async
install
()
{
...
...
@@ -25,7 +27,7 @@ module.exports = {
timeout
:
120000
,
windowsHide
:
true
})
await
fs
.
ensureFile
(
path
.
join
(
WIKI
.
SERVERPATH
,
'node_modules/sharp/wiki_installed.txt'
))
await
fs
e
.
ensureFile
(
path
.
join
(
WIKI
.
SERVERPATH
,
'node_modules/sharp/wiki_installed.txt'
))
this
.
isInstalled
=
true
WIKI
.
logger
.
info
(
stdout
)
WIKI
.
logger
.
warn
(
stderr
)
...
...
@@ -36,7 +38,7 @@ module.exports = {
sharp
:
null
,
async
load
()
{
if
(
!
this
.
sharp
)
{
this
.
sharp
=
require
(
'sharp'
)
this
.
sharp
=
(
await
import
(
'sharp'
)).
default
}
},
/**
...
...
@@ -57,13 +59,13 @@ module.exports = {
this
.
load
()
if
(
inputPath
)
{
inputStream
=
fs
.
createReadStream
(
inputPath
)
inputStream
=
fs
e
.
createReadStream
(
inputPath
)
}
if
(
!
inputStream
)
{
throw
new
Error
(
'Failed to open readable input stream for image resizing.'
)
}
if
(
outputPath
)
{
outputStream
=
fs
.
createWriteStream
(
outputPath
)
outputStream
=
fs
e
.
createWriteStream
(
outputPath
)
}
if
(
!
outputStream
)
{
throw
new
Error
(
'Failed to open writable output stream for image resizing.'
)
...
...
server/modules/rendering/html-core/renderer.js
→
server/modules/rendering/html-core/renderer.
m
js
View file @
8f944494
...
...
@@ -6,7 +6,7 @@ const URL = require('url').URL
const
mustacheRegExp
=
/
(\{
|{
?){2}(
.+
?)(\}
|}
?){2}
/i
module
.
exports
=
{
export
default
{
async
render
()
{
const
$
=
cheerio
.
load
(
this
.
input
,
{
decodeEntities
:
true
...
...
@@ -21,7 +21,7 @@ module.exports = {
// --------------------------------
for
(
let
child
of
_
.
reject
(
this
.
children
,
[
'step'
,
'post'
]))
{
const
renderer
=
require
(
`../
${
child
.
key
}
/renderer.js`
)
const
renderer
=
require
(
`../
${
child
.
key
}
/renderer.
m
js`
)
await
renderer
.
init
(
$
,
child
.
config
)
}
...
...
server/modules/storage/db/storage.js
→
server/modules/storage/db/storage.
m
js
View file @
8f944494
const
fs
=
require
(
'fs-extra'
)
import
fs
from
'node:fs/promises'
module
.
exports
=
{
export
default
{
async
activated
()
{
},
async
deactivated
()
{
},
async
init
()
{
},
...
...
server/tasks/workers/render-page.mjs
View file @
8f944494
...
...
@@ -24,8 +24,8 @@ export async function task ({ payload }) {
WIKI
.
logger
.
warn
(
`Failed to render page ID
${
payload
.
id
}
because content was empty: [ FAILED ]`
)
}
for
(
le
t
core
of
pipeline
)
{
const
renderer
=
require
(
`../../modules/rendering/
${
core
.
key
}
/renderer.js`
)
for
(
cons
t
core
of
pipeline
)
{
const
renderer
=
(
await
import
(
`../../modules/rendering/
${
core
.
key
}
/renderer.mjs`
)).
default
output
=
await
renderer
.
render
.
call
({
config
:
core
.
config
,
children
:
core
.
children
,
...
...
server/worker.js
→
server/worker.
m
js
View file @
8f944494
import
{
ThreadWorker
}
from
'poolifier'
import
{
kebabCase
}
from
'lodash-es'
import
path
from
'node:path'
import
configSvc
from
'./core/config.mjs'
import
logger
from
'./core/logger.mjs'
import
db
from
'./core/db.mjs'
// ----------------------------------------
// Init Minimal Core
...
...
@@ -11,12 +14,11 @@ const WIKI = {
ROOTPATH
:
process
.
cwd
(),
INSTANCE_ID
:
'worker'
,
SERVERPATH
:
path
.
join
(
process
.
cwd
(),
'server'
),
Error
:
require
(
'./helpers/error'
),
configSvc
:
require
(
'./core/config'
),
configSvc
,
ensureDb
:
async
()
=>
{
if
(
WIKI
.
db
)
{
return
true
}
WIKI
.
db
=
require
(
'./core/db'
)
.
init
(
true
)
WIKI
.
db
=
await
db
.
init
(
true
)
try
{
await
WIKI
.
configSvc
.
loadFromDb
()
...
...
@@ -32,8 +34,13 @@ const WIKI = {
}
global
.
WIKI
=
WIKI
WIKI
.
configSvc
.
init
(
true
)
WIKI
.
logger
=
require
(
'./core/logger'
).
init
()
await
WIKI
.
configSvc
.
init
(
true
)
// ----------------------------------------
// Init Logger
// ----------------------------------------
WIKI
.
logger
=
logger
.
init
()
// ----------------------------------------
// Execute Task
...
...
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