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
8000ebec
Commit
8000ebec
authored
Oct 26, 2019
by
Justin Kromlinger
Committed by
Nicolas Giard
Oct 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: use dataPath variable as given in file config (#1118)
* Actually use path variables as given in default config * Drop paths.content, avoid populating the global WIKI object
parent
5b36988d
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
30 additions
and
26 deletions
+30
-26
config.sample.yml
config.sample.yml
+7
-0
data.yml
server/app/data.yml
+1
-3
upload.js
server/controllers/upload.js
+1
-1
sideloader.js
server/core/sideloader.js
+4
-4
system.js
server/core/system.js
+1
-1
purge-uploads.js
server/jobs/purge-uploads.js
+1
-1
assets.js
server/models/assets.js
+6
-6
pages.js
server/models/pages.js
+4
-4
storage.js
server/modules/storage/git/storage.js
+2
-2
setup.js
server/setup.js
+3
-4
No files found.
config.sample.yml
View file @
8000ebec
...
...
@@ -105,3 +105,9 @@ uploads:
# download the offline files for sideloading.
offline
:
false
# ---------------------------------------------------------------------
# Data Path
# ---------------------------------------------------------------------
# Writeable data path for Wiki.js, mainly for cache and user uploads.
dataPath
:
./data
\ No newline at end of file
server/app/data.yml
View file @
8000ebec
...
...
@@ -57,9 +57,7 @@ defaults:
# System defaults
channel
:
BETA
setup
:
false
paths
:
content
:
./content
data
:
./data
dataPath
:
./data
cors
:
credentials
:
true
maxAge
:
600
...
...
server/controllers/upload.js
View file @
8000ebec
...
...
@@ -11,7 +11,7 @@ const sanitize = require('sanitize-filename')
* Upload files
*/
router
.
post
(
'/u'
,
multer
({
dest
:
path
.
join
(
WIKI
.
ROOTPATH
,
'data/
uploads'
),
dest
:
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'
uploads'
),
limits
:
{
fileSize
:
WIKI
.
config
.
uploads
.
maxFileSize
,
files
:
WIKI
.
config
.
uploads
.
maxFiles
...
...
server/core/sideloader.js
View file @
8000ebec
...
...
@@ -10,7 +10,7 @@ module.exports = {
return
}
const
sideloadExists
=
await
fs
.
pathExists
(
path
.
join
(
WIKI
.
ROOTPATH
,
'data/
sideload'
))
const
sideloadExists
=
await
fs
.
pathExists
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'
sideload'
))
if
(
!
sideloadExists
)
{
return
...
...
@@ -25,16 +25,16 @@ module.exports = {
}
},
async
importLocales
()
{
const
localeExists
=
await
fs
.
pathExists
(
path
.
join
(
WIKI
.
ROOTPATH
,
'data/
sideload/locales.json'
))
const
localeExists
=
await
fs
.
pathExists
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'
sideload/locales.json'
))
if
(
localeExists
)
{
WIKI
.
logger
.
info
(
'Found locales master file. Importing locale packages...'
)
let
importedLocales
=
0
const
locales
=
await
fs
.
readJson
(
path
.
join
(
WIKI
.
ROOTPATH
,
'data/
sideload/locales.json'
))
const
locales
=
await
fs
.
readJson
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'
sideload/locales.json'
))
if
(
locales
&&
_
.
has
(
locales
,
'data.localization.locales'
))
{
for
(
const
locale
of
locales
.
data
.
localization
.
locales
)
{
try
{
const
localeData
=
await
fs
.
readJson
(
path
.
join
(
WIKI
.
ROOTPATH
,
`data/
sideload/
${
locale
.
code
}
.json`
))
const
localeData
=
await
fs
.
readJson
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
sideload/
${
locale
.
code
}
.json`
))
if
(
localeData
)
{
WIKI
.
logger
.
info
(
`Importing
${
locale
.
name
}
locale package...`
)
...
...
server/core/system.js
View file @
8000ebec
...
...
@@ -16,7 +16,7 @@ module.exports = {
},
init
()
{
// Clear content cache
fs
.
emptyDir
(
path
.
join
(
WIKI
.
ROOTPATH
,
'data/
cache'
))
fs
.
emptyDir
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'
cache'
))
return
this
},
...
...
server/jobs/purge-uploads.js
View file @
8000ebec
...
...
@@ -9,7 +9,7 @@ module.exports = async () => {
WIKI
.
logger
.
info
(
'Purging orphaned upload files...'
)
try
{
const
uplTempPath
=
path
.
resolve
(
process
.
cwd
(),
WIKI
.
config
.
paths
.
data
,
'uploads'
)
const
uplTempPath
=
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'uploads'
)
await
fs
.
ensureDir
(
uplTempPath
)
const
ls
=
await
fs
.
readdir
(
uplTempPath
)
const
fifteenAgo
=
moment
().
subtract
(
15
,
'minutes'
)
...
...
server/models/assets.js
View file @
8000ebec
...
...
@@ -74,7 +74,7 @@ module.exports = class Asset extends Model {
}
async
deleteAssetCache
()
{
await
fs
.
remove
(
path
.
join
(
process
.
cwd
(),
`data/
cache/
${
this
.
hash
}
.dat`
))
await
fs
.
remove
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
cache/
${
this
.
hash
}
.dat`
))
}
static
async
upload
(
opts
)
{
...
...
@@ -125,9 +125,9 @@ module.exports = class Asset extends Model {
// Move temp upload to cache
if
(
opts
.
mode
===
'upload'
)
{
await
fs
.
move
(
opts
.
path
,
path
.
join
(
process
.
cwd
(),
`data/
cache/
${
fileHash
}
.dat`
),
{
overwrite
:
true
})
await
fs
.
move
(
opts
.
path
,
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
cache/
${
fileHash
}
.dat`
),
{
overwrite
:
true
})
}
else
{
await
fs
.
copy
(
opts
.
path
,
path
.
join
(
process
.
cwd
(),
`data/
cache/
${
fileHash
}
.dat`
),
{
overwrite
:
true
})
await
fs
.
copy
(
opts
.
path
,
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
cache/
${
fileHash
}
.dat`
),
{
overwrite
:
true
})
}
// Add to Storage
...
...
@@ -158,7 +158,7 @@ module.exports = class Asset extends Model {
static
async
getAssetFromCache
(
assetPath
,
res
)
{
const
fileHash
=
assetHelper
.
generateHash
(
assetPath
)
const
cachePath
=
path
.
join
(
process
.
cwd
(),
`data/
cache/
${
fileHash
}
.dat`
)
const
cachePath
=
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
cache/
${
fileHash
}
.dat`
)
return
new
Promise
((
resolve
,
reject
)
=>
{
res
.
type
(
path
.
extname
(
assetPath
))
...
...
@@ -174,7 +174,7 @@ module.exports = class Asset extends Model {
static
async
getAssetFromDb
(
assetPath
,
res
)
{
const
fileHash
=
assetHelper
.
generateHash
(
assetPath
)
const
cachePath
=
path
.
join
(
process
.
cwd
(),
`data/
cache/
${
fileHash
}
.dat`
)
const
cachePath
=
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
cache/
${
fileHash
}
.dat`
)
const
asset
=
await
WIKI
.
models
.
assets
.
query
().
where
(
'hash'
,
fileHash
).
first
()
if
(
asset
)
{
...
...
@@ -188,6 +188,6 @@ module.exports = class Asset extends Model {
}
static
async
flushTempUploads
()
{
return
fs
.
emptyDir
(
path
.
join
(
process
.
cwd
(),
`data/
uploads`
))
return
fs
.
emptyDir
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
uploads`
))
}
}
server/models/pages.js
View file @
8000ebec
...
...
@@ -728,7 +728,7 @@ module.exports = class Page extends Model {
* @returns {Promise} Promise with no value
*/
static
async
savePageToCache
(
page
)
{
const
cachePath
=
path
.
join
(
process
.
cwd
(),
`data/
cache/
${
page
.
hash
}
.bin`
)
const
cachePath
=
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
cache/
${
page
.
hash
}
.bin`
)
await
fs
.
outputFile
(
cachePath
,
WIKI
.
models
.
pages
.
cacheSchema
.
encode
({
id
:
page
.
id
,
authorId
:
page
.
authorId
,
...
...
@@ -757,7 +757,7 @@ module.exports = class Page extends Model {
*/
static
async
getPageFromCache
(
opts
)
{
const
pageHash
=
pageHelper
.
generateHash
({
path
:
opts
.
path
,
locale
:
opts
.
locale
,
privateNS
:
opts
.
isPrivate
?
'TODO'
:
''
})
const
cachePath
=
path
.
join
(
process
.
cwd
(),
`data/
cache/
${
pageHash
}
.bin`
)
const
cachePath
=
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
cache/
${
pageHash
}
.bin`
)
try
{
const
pageBuffer
=
await
fs
.
readFile
(
cachePath
)
...
...
@@ -785,14 +785,14 @@ module.exports = class Page extends Model {
* @returns {Promise} Promise with no value
*/
static
async
deletePageFromCache
(
page
)
{
return
fs
.
remove
(
path
.
join
(
process
.
cwd
(),
`data/
cache/
${
page
.
hash
}
.bin`
))
return
fs
.
remove
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
cache/
${
page
.
hash
}
.bin`
))
}
/**
* Flush the contents of the Cache
*/
static
async
flushCache
()
{
return
fs
.
emptyDir
(
path
.
join
(
process
.
cwd
(),
`data/
cache`
))
return
fs
.
emptyDir
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
`
cache`
))
}
/**
...
...
server/modules/storage/git/storage.js
View file @
8000ebec
...
...
@@ -15,7 +15,7 @@ const commonDisk = require('../disk/common')
module
.
exports
=
{
git
:
null
,
repoPath
:
path
.
join
(
process
.
cwd
(),
'data/
repo'
),
repoPath
:
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'
repo'
),
async
activated
()
{
// not used
},
...
...
@@ -66,7 +66,7 @@ module.exports = {
WIKI
.
logger
.
info
(
'(STORAGE/GIT) Setting SSH Command config...'
)
if
(
this
.
config
.
sshPrivateKeyMode
===
'contents'
)
{
try
{
this
.
config
.
sshPrivateKeyPath
=
path
.
join
(
WIKI
.
ROOTPATH
,
'data/
secure/git-ssh.pem'
)
this
.
config
.
sshPrivateKeyPath
=
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'
secure/git-ssh.pem'
)
await
fs
.
outputFile
(
this
.
config
.
sshPrivateKeyPath
,
this
.
config
.
sshPrivateKeyContent
,
{
encoding
:
'utf8'
,
mode
:
0o600
...
...
server/setup.js
View file @
8000ebec
...
...
@@ -144,10 +144,9 @@ module.exports = () => {
// Create directory structure
WIKI
.
logger
.
info
(
'Creating data directories...'
)
const
dataPath
=
path
.
join
(
process
.
cwd
(),
'data'
)
await
fs
.
ensureDir
(
dataPath
)
await
fs
.
emptyDir
(
path
.
join
(
dataPath
,
'cache'
))
await
fs
.
ensureDir
(
path
.
join
(
dataPath
,
'uploads'
))
await
fs
.
ensureDir
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
))
await
fs
.
emptyDir
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'cache'
))
await
fs
.
ensureDir
(
path
.
resolve
(
WIKI
.
ROOTPATH
,
WIKI
.
config
.
dataPath
,
'uploads'
))
// Generate certificates
WIKI
.
logger
.
info
(
'Generating certificates...'
)
...
...
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