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
27adad8d
Commit
27adad8d
authored
Nov 18, 2018
by
Nicolas Giard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: localization master callback + various fixes
parent
3abc2546
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
69 additions
and
18 deletions
+69
-18
kernel.js
server/core/kernel.js
+3
-0
localization.js
server/core/localization.js
+9
-0
queue.js
server/core/queue.js
+5
-0
redis.js
server/core/redis.js
+14
-0
index.js
server/graph/index.js
+20
-16
fetch-graph-locale.js
server/jobs/fetch-graph-locale.js
+2
-0
render-page.js
server/jobs/render-page.js
+10
-1
sync-graph-locales.js
server/jobs/sync-graph-locales.js
+2
-0
setup.js
server/setup.js
+1
-1
wiki.js
wiki.js
+3
-0
No files found.
server/core/kernel.js
View file @
27adad8d
const
_
=
require
(
'lodash'
)
const
EventEmitter
=
require
(
'events'
)
/* global WIKI */
...
...
@@ -23,6 +24,8 @@ module.exports = {
await
WIKI
.
models
.
onReady
await
WIKI
.
configSvc
.
loadFromDb
()
await
WIKI
.
queue
.
clean
()
WIKI
.
events
=
new
EventEmitter
()
WIKI
.
redisSub
=
require
(
'./redis'
).
subscribe
()
}
catch
(
err
)
{
WIKI
.
logger
.
error
(
err
)
process
.
exit
(
1
)
...
...
server/core/localization.js
View file @
27adad8d
...
...
@@ -33,6 +33,15 @@ module.exports = {
// Load current language + namespaces
this
.
refreshNamespaces
(
true
)
// Listen for localization events
WIKI
.
events
.
on
(
'localization'
,
(
action
)
=>
{
switch
(
action
)
{
case
'reload'
:
this
.
refreshNamespaces
()
break
}
})
return
this
},
attachMiddleware
(
app
)
{
...
...
server/core/queue.js
View file @
27adad8d
...
...
@@ -36,6 +36,11 @@ module.exports = {
}
})
},
async
quit
()
{
for
(
const
queueName
in
this
.
job
)
{
await
this
.
job
[
queueName
].
close
()
}
},
async
clean
()
{
return
Promise
.
each
(
_
.
keys
(
WIKI
.
data
.
jobs
),
queueName
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
server/core/redis.js
View file @
27adad8d
...
...
@@ -19,5 +19,19 @@ module.exports = {
WIKI
.
logger
.
error
(
'Invalid Redis configuration!'
)
process
.
exit
(
1
)
}
},
subscribe
()
{
let
red
=
this
.
init
()
red
.
on
(
'message'
,
(
channel
,
msg
)
=>
{
WIKI
.
events
.
emit
(
channel
,
msg
)
})
red
.
subscribe
(
'localization'
,
(
err
,
count
)
=>
{
if
(
err
)
{
WIKI
.
logger
.
error
(
err
)
process
.
exit
(
1
)
}
WIKI
.
logger
.
info
(
'Redis Subscriber connection: [ OK ]'
)
})
return
red
}
}
server/graph/index.js
View file @
27adad8d
...
...
@@ -4,8 +4,8 @@ const fs = require('fs')
const
path
=
require
(
'path'
)
const
autoload
=
require
(
'auto-load'
)
const
PubSub
=
require
(
'graphql-subscriptions'
).
PubSub
const
util
=
require
(
'util
'
)
const
winston
=
require
(
'winston
'
)
const
{
LEVEL
,
MESSAGE
}
=
require
(
'triple-beam
'
)
const
Transport
=
require
(
'winston-transport
'
)
/* global WIKI */
...
...
@@ -37,20 +37,24 @@ let schemaDirectives = autoload(path.join(WIKI.SERVERPATH, 'graph/directives'))
// Live Trail Logger (admin)
let
LiveTrailLogger
=
winston
.
transports
.
LiveTrailLogger
=
function
(
options
)
{
this
.
name
=
'livetrailLogger'
this
.
level
=
'debug'
}
util
.
inherits
(
LiveTrailLogger
,
winston
.
Transport
)
LiveTrailLogger
.
prototype
.
log
=
function
(
level
,
msg
,
meta
,
callback
)
{
WIKI
.
GQLEmitter
.
publish
(
'livetrail'
,
{
loggingLiveTrail
:
{
timestamp
:
new
Date
(),
level
,
output
:
msg
}
})
callback
(
null
,
true
)
class
LiveTrailLogger
extends
Transport
{
constructor
(
opts
)
{
super
(
opts
)
this
.
name
=
'liveTrailLogger'
this
.
level
=
'debug'
}
log
(
info
,
callback
=
()
=>
{})
{
WIKI
.
GQLEmitter
.
publish
(
'livetrail'
,
{
loggingLiveTrail
:
{
timestamp
:
new
Date
(),
level
:
info
[
LEVEL
],
output
:
info
[
MESSAGE
]
}
})
callback
(
null
,
true
)
}
}
WIKI
.
logger
.
add
(
new
LiveTrailLogger
({}))
...
...
server/jobs/fetch-graph-locale.js
View file @
27adad8d
...
...
@@ -51,6 +51,8 @@ module.exports = async (job) => {
throw
new
Error
(
'Failed to fetch cached locales list! Restart server to resolve this issue.'
)
}
await
WIKI
.
redis
.
publish
(
'localization'
,
'reload'
)
WIKI
.
logger
.
info
(
`Fetching locale
${
job
.
data
.
locale
}
from Graph endpoint: [ COMPLETED ]`
)
}
catch
(
err
)
{
WIKI
.
logger
.
error
(
`Fetching locale
${
job
.
data
.
locale
}
from Graph endpoint: [ FAILED ]`
)
...
...
server/jobs/render-page.js
View file @
27adad8d
...
...
@@ -29,16 +29,25 @@ module.exports = async (job) => {
$
(
'h1,h2,h3,h4,h5,h6'
).
each
((
idx
,
el
)
=>
{
const
depth
=
_
.
toSafeInteger
(
el
.
name
.
substring
(
1
))
-
(
isStrict
?
1
:
2
)
let
leafPathError
=
false
const
leafPath
=
_
.
reduce
(
_
.
times
(
depth
),
(
curPath
,
curIdx
)
=>
{
if
(
_
.
has
(
toc
,
curPath
))
{
const
lastLeafIdx
=
_
.
get
(
toc
,
curPath
).
length
-
1
curPath
=
`
${
curPath
}
[
${
lastLeafIdx
}
].children`
if
(
lastLeafIdx
>=
0
)
{
curPath
=
`
${
curPath
}
[
${
lastLeafIdx
}
].children`
}
else
{
leafPathError
=
true
}
}
return
curPath
},
'root'
)
if
(
leafPathError
)
{
return
}
const
leafSlug
=
$
(
'.toc-anchor'
,
el
).
first
().
attr
(
'href'
)
$
(
'.toc-anchor'
,
el
).
remove
()
_
.
get
(
toc
,
leafPath
).
push
({
title
:
_
.
trim
(
$
(
el
).
text
()),
anchor
:
leafSlug
,
...
...
server/jobs/sync-graph-locales.js
View file @
27adad8d
...
...
@@ -68,6 +68,8 @@ module.exports = async (job) => {
}).
where
(
'code'
,
WIKI
.
config
.
lang
.
code
)
}
await
WIKI
.
redis
.
publish
(
'localization'
,
'reload'
)
WIKI
.
logger
.
info
(
'Syncing locales with Graph endpoint: [ COMPLETED ]'
)
}
catch
(
err
)
{
WIKI
.
logger
.
error
(
'Syncing locales with Graph endpoint: [ FAILED ]'
)
...
...
server/setup.js
View file @
27adad8d
...
...
@@ -133,7 +133,7 @@ module.exports = () => {
nativeName
:
'English'
})
// Create default
locale
// Create default
groups
WIKI
.
logger
.
info
(
'Creating default groups...'
)
const
adminGroup
=
await
WIKI
.
models
.
groups
.
query
().
insert
({
...
...
wiki.js
View file @
27adad8d
...
...
@@ -121,6 +121,9 @@ const init = {
await
global
.
WIKI
.
models
.
knex
.
destroy
()
console
.
warn
(
chalk
.
yellow
(
'--- Closing Redis connections...'
))
await
global
.
WIKI
.
redis
.
quit
()
await
global
.
WIKI
.
redisSub
.
quit
()
console
.
warn
(
chalk
.
yellow
(
'--- Closing Queue connections...'
))
await
global
.
WIKI
.
queue
.
quit
()
console
.
warn
(
chalk
.
yellow
(
'--- Closing Server connections...'
))
global
.
WIKI
.
server
.
destroy
(()
=>
{
global
.
WIKI
=
{}
...
...
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