feat: core improvements + local fs provider + UI fixes
This commit is contained in:
@@ -17,7 +17,7 @@ module.exports = {
|
||||
})
|
||||
|
||||
passport.deserializeUser(function (id, done) {
|
||||
WIKI.db.users.query().findById(id).then((user) => {
|
||||
WIKI.models.users.query().findById(id).then((user) => {
|
||||
if (user) {
|
||||
done(null, user)
|
||||
} else {
|
||||
@@ -40,7 +40,7 @@ module.exports = {
|
||||
_.forEach(currentStrategies, stg => { passport.unuse(stg) })
|
||||
|
||||
// Load enabled strategies
|
||||
const enabledStrategies = await WIKI.db.authentication.getStrategies()
|
||||
const enabledStrategies = await WIKI.models.authentication.getStrategies()
|
||||
for (let idx in enabledStrategies) {
|
||||
const stg = enabledStrategies[idx]
|
||||
if (!stg.isEnabled) { continue }
|
||||
|
@@ -52,7 +52,7 @@ module.exports = {
|
||||
* Load config from DB
|
||||
*/
|
||||
async loadFromDb() {
|
||||
let conf = await WIKI.db.settings.getConfig()
|
||||
let conf = await WIKI.models.settings.getConfig()
|
||||
if (conf) {
|
||||
WIKI.config = _.defaultsDeep(conf, WIKI.config)
|
||||
} else {
|
||||
@@ -73,9 +73,9 @@ module.exports = {
|
||||
if (!_.isPlainObject(value)) {
|
||||
value = { v: value }
|
||||
}
|
||||
let affectedRows = await WIKI.db.settings.query().patch({ value }).where('key', key)
|
||||
let affectedRows = await WIKI.models.settings.query().patch({ value }).where('key', key)
|
||||
if (affectedRows === 0 && value) {
|
||||
await WIKI.db.settings.query().insert({ key, value })
|
||||
await WIKI.models.settings.query().insert({ key, value })
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
@@ -74,7 +74,7 @@ module.exports = {
|
||||
|
||||
// Load DB Models
|
||||
|
||||
const models = autoload(path.join(WIKI.SERVERPATH, 'db/models'))
|
||||
const models = autoload(path.join(WIKI.SERVERPATH, 'models'))
|
||||
|
||||
// Set init tasks
|
||||
|
||||
|
@@ -6,7 +6,7 @@ module.exports = {
|
||||
WIKI.logger.info('= Wiki.js =============================')
|
||||
WIKI.logger.info('=======================================')
|
||||
|
||||
WIKI.db = require('./db').init()
|
||||
WIKI.models = require('./db').init()
|
||||
WIKI.redis = require('./redis').init()
|
||||
WIKI.queue = require('./queue').init()
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports = {
|
||||
*/
|
||||
async preBootMaster() {
|
||||
try {
|
||||
await WIKI.db.onReady
|
||||
await WIKI.models.onReady
|
||||
await WIKI.configSvc.loadFromDb()
|
||||
await WIKI.queue.clean()
|
||||
} catch (err) {
|
||||
@@ -48,6 +48,7 @@ module.exports = {
|
||||
*/
|
||||
async postBootMaster() {
|
||||
await WIKI.auth.activateStrategies()
|
||||
await WIKI.models.storage.refreshTargetsFromDisk()
|
||||
await WIKI.queue.start()
|
||||
}
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
async loadLocale(locale, opts = { silent: false }) {
|
||||
const res = await WIKI.db.locales.query().findOne('code', locale)
|
||||
const res = await WIKI.models.locales.query().findOne('code', locale)
|
||||
if (res) {
|
||||
if (_.isPlainObject(res.strings)) {
|
||||
_.forOwn(res.strings, (data, ns) => {
|
||||
|
@@ -45,7 +45,7 @@ module.exports = {
|
||||
$not: 'guest'
|
||||
}
|
||||
}).toArray()
|
||||
await WIKI.db.User.bulkCreate(_.map(userData, usr => {
|
||||
await WIKI.models.User.bulkCreate(_.map(userData, usr => {
|
||||
return {
|
||||
email: usr.email,
|
||||
name: usr.name || 'Imported User',
|
||||
|
@@ -79,6 +79,7 @@ exports.up = knex => {
|
||||
table.string('publishStartDate')
|
||||
table.string('publishEndDate')
|
||||
table.text('content')
|
||||
table.string('contentType').notNullable()
|
||||
table.string('createdAt').notNullable()
|
||||
})
|
||||
// PAGES -------------------------------
|
||||
@@ -92,6 +93,7 @@ exports.up = knex => {
|
||||
table.string('publishStartDate')
|
||||
table.string('publishEndDate')
|
||||
table.text('content')
|
||||
table.string('contentType').notNullable()
|
||||
table.string('createdAt').notNullable()
|
||||
table.string('updatedAt').notNullable()
|
||||
})
|
||||
|
@@ -16,7 +16,7 @@ module.exports = {
|
||||
},
|
||||
AuthenticationQuery: {
|
||||
async strategies(obj, args, context, info) {
|
||||
let strategies = await WIKI.db.authentication.getStrategies()
|
||||
let strategies = await WIKI.models.authentication.getStrategies()
|
||||
strategies = strategies.map(stg => ({
|
||||
...stg,
|
||||
config: _.sortBy(_.transform(stg.config, (res, value, key) => {
|
||||
@@ -31,7 +31,7 @@ module.exports = {
|
||||
AuthenticationMutation: {
|
||||
async login(obj, args, context) {
|
||||
try {
|
||||
let authResult = await WIKI.db.users.login(args, context)
|
||||
let authResult = await WIKI.models.users.login(args, context)
|
||||
return {
|
||||
...authResult,
|
||||
responseResult: graphHelper.generateSuccess('Login success')
|
||||
@@ -42,7 +42,7 @@ module.exports = {
|
||||
},
|
||||
async loginTFA(obj, args, context) {
|
||||
try {
|
||||
let authResult = await WIKI.db.users.loginTFA(args, context)
|
||||
let authResult = await WIKI.models.users.loginTFA(args, context)
|
||||
return {
|
||||
...authResult,
|
||||
responseResult: graphHelper.generateSuccess('TFA success')
|
||||
@@ -54,7 +54,7 @@ module.exports = {
|
||||
async updateStrategies(obj, args, context) {
|
||||
try {
|
||||
for (let str of args.strategies) {
|
||||
await WIKI.db.authentication.query().patch({
|
||||
await WIKI.models.authentication.query().patch({
|
||||
isEnabled: str.isEnabled,
|
||||
config: _.reduce(str.config, (result, value, key) => {
|
||||
_.set(result, `${value.key}.value`, value.value)
|
||||
|
@@ -4,19 +4,19 @@
|
||||
module.exports = {
|
||||
Query: {
|
||||
comments(obj, args, context, info) {
|
||||
return WIKI.db.Comment.findAll({ where: args })
|
||||
return WIKI.models.Comment.findAll({ where: args })
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
createComment(obj, args) {
|
||||
return WIKI.db.Comment.create({
|
||||
return WIKI.models.Comment.create({
|
||||
content: args.content,
|
||||
author: args.userId,
|
||||
document: args.documentId
|
||||
})
|
||||
},
|
||||
deleteComment(obj, args) {
|
||||
return WIKI.db.Comment.destroy({
|
||||
return WIKI.models.Comment.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
},
|
||||
@@ -24,7 +24,7 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
modifyComment(obj, args) {
|
||||
return WIKI.db.Comment.update({
|
||||
return WIKI.models.Comment.update({
|
||||
content: args.content
|
||||
}, {
|
||||
where: { id: args.id }
|
||||
|
@@ -4,15 +4,15 @@
|
||||
module.exports = {
|
||||
Query: {
|
||||
documents(obj, args, context, info) {
|
||||
return WIKI.db.Document.findAll({ where: args })
|
||||
return WIKI.models.Document.findAll({ where: args })
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
createDocument(obj, args) {
|
||||
return WIKI.db.Document.create(args)
|
||||
return WIKI.models.Document.create(args)
|
||||
},
|
||||
deleteDocument(obj, args) {
|
||||
return WIKI.db.Document.destroy({
|
||||
return WIKI.models.Document.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
},
|
||||
@@ -20,7 +20,7 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
modifyDocument(obj, args) {
|
||||
return WIKI.db.Document.update({
|
||||
return WIKI.models.Document.update({
|
||||
title: args.title,
|
||||
subtitle: args.subtitle
|
||||
}, {
|
||||
@@ -28,7 +28,7 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
moveDocument(obj, args) {
|
||||
return WIKI.db.Document.update({
|
||||
return WIKI.models.Document.update({
|
||||
path: args.path
|
||||
}, {
|
||||
where: { id: args.id }
|
||||
|
@@ -6,16 +6,16 @@ const gql = require('graphql')
|
||||
module.exports = {
|
||||
Query: {
|
||||
files(obj, args, context, info) {
|
||||
return WIKI.db.File.findAll({ where: args })
|
||||
return WIKI.models.File.findAll({ where: args })
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
uploadFile(obj, args) {
|
||||
// todo
|
||||
return WIKI.db.File.create(args)
|
||||
return WIKI.models.File.create(args)
|
||||
},
|
||||
deleteFile(obj, args) {
|
||||
return WIKI.db.File.destroy({
|
||||
return WIKI.models.File.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
},
|
||||
@@ -23,18 +23,18 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
renameFile(obj, args) {
|
||||
return WIKI.db.File.update({
|
||||
return WIKI.models.File.update({
|
||||
filename: args.filename
|
||||
}, {
|
||||
where: { id: args.id }
|
||||
})
|
||||
},
|
||||
moveFile(obj, args) {
|
||||
return WIKI.db.File.findById(args.fileId).then(fl => {
|
||||
return WIKI.models.File.findById(args.fileId).then(fl => {
|
||||
if (!fl) {
|
||||
throw new gql.GraphQLError('Invalid File ID')
|
||||
}
|
||||
return WIKI.db.Folder.findById(args.folderId).then(fld => {
|
||||
return WIKI.models.Folder.findById(args.folderId).then(fld => {
|
||||
if (!fld) {
|
||||
throw new gql.GraphQLError('Invalid Folder ID')
|
||||
}
|
||||
|
@@ -4,15 +4,15 @@
|
||||
module.exports = {
|
||||
Query: {
|
||||
folders(obj, args, context, info) {
|
||||
return WIKI.db.Folder.findAll({ where: args })
|
||||
return WIKI.models.Folder.findAll({ where: args })
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
createFolder(obj, args) {
|
||||
return WIKI.db.Folder.create(args)
|
||||
return WIKI.models.Folder.create(args)
|
||||
},
|
||||
deleteFolder(obj, args) {
|
||||
return WIKI.db.Folder.destroy({
|
||||
return WIKI.models.Folder.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
},
|
||||
@@ -20,7 +20,7 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
renameFolder(obj, args) {
|
||||
return WIKI.db.Folder.update({
|
||||
return WIKI.models.Folder.update({
|
||||
name: args.name
|
||||
}, {
|
||||
where: { id: args.id }
|
||||
|
@@ -13,22 +13,22 @@ module.exports = {
|
||||
},
|
||||
GroupQuery: {
|
||||
async list(obj, args, context, info) {
|
||||
return WIKI.db.groups.query().select(
|
||||
return WIKI.models.groups.query().select(
|
||||
'groups.*',
|
||||
WIKI.db.groups.relatedQuery('users').count().as('userCount')
|
||||
WIKI.models.groups.relatedQuery('users').count().as('userCount')
|
||||
)
|
||||
},
|
||||
async single(obj, args, context, info) {
|
||||
return WIKI.db.groups.query().findById(args.id)
|
||||
return WIKI.models.groups.query().findById(args.id)
|
||||
}
|
||||
},
|
||||
GroupMutation: {
|
||||
async assignUser(obj, args) {
|
||||
const grp = await WIKI.db.groups.query().findById(args.groupId)
|
||||
const grp = await WIKI.models.groups.query().findById(args.groupId)
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
const usr = await WIKI.db.users.query().findById(args.userId)
|
||||
const usr = await WIKI.models.users.query().findById(args.userId)
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
@@ -38,7 +38,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
async create(obj, args) {
|
||||
const group = await WIKI.db.groups.query().insertAndFetch({
|
||||
const group = await WIKI.models.groups.query().insertAndFetch({
|
||||
name: args.name
|
||||
})
|
||||
return {
|
||||
@@ -47,17 +47,17 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
async delete(obj, args) {
|
||||
await WIKI.db.groups.query().deleteById(args.id)
|
||||
await WIKI.models.groups.query().deleteById(args.id)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group has been deleted.')
|
||||
}
|
||||
},
|
||||
async unassignUser(obj, args) {
|
||||
const grp = await WIKI.db.groups.query().findById(args.groupId)
|
||||
const grp = await WIKI.models.groups.query().findById(args.groupId)
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
const usr = await WIKI.db.users.query().findById(args.userId)
|
||||
const usr = await WIKI.models.users.query().findById(args.userId)
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
@@ -67,7 +67,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
async update(obj, args) {
|
||||
await WIKI.db.groups.query().patch({ name: args.name }).where('id', args.id)
|
||||
await WIKI.models.groups.query().patch({ name: args.name }).where('id', args.id)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Group has been updated.')
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ module.exports = {
|
||||
LocalizationQuery: {
|
||||
async locales(obj, args, context, info) {
|
||||
let remoteLocales = await WIKI.redis.get('locales')
|
||||
let localLocales = await WIKI.db.locales.query().select('id', 'code', 'isRTL', 'name', 'nativeName', 'createdAt', 'updatedAt')
|
||||
let localLocales = await WIKI.models.locales.query().select('id', 'code', 'isRTL', 'name', 'nativeName', 'createdAt', 'updatedAt')
|
||||
remoteLocales = (remoteLocales) ? JSON.parse(remoteLocales) : localLocales
|
||||
return _.map(remoteLocales, rl => {
|
||||
let isInstalled = _.some(localLocales, ['code', rl.code])
|
||||
|
@@ -11,18 +11,18 @@ module.exports = {
|
||||
},
|
||||
PageQuery: {
|
||||
async list(obj, args, context, info) {
|
||||
return WIKI.db.pages.query().select(
|
||||
return WIKI.models.pages.query().select(
|
||||
'pages.*',
|
||||
WIKI.db.pages.relatedQuery('users').count().as('userCount')
|
||||
WIKI.models.pages.relatedQuery('users').count().as('userCount')
|
||||
)
|
||||
},
|
||||
async single(obj, args, context, info) {
|
||||
return WIKI.db.pages.query().findById(args.id)
|
||||
return WIKI.models.pages.query().findById(args.id)
|
||||
}
|
||||
},
|
||||
PageMutation: {
|
||||
async create(obj, args, context) {
|
||||
const page = await WIKI.db.pages.createPage({
|
||||
const page = await WIKI.models.pages.createPage({
|
||||
...args,
|
||||
authorId: context.req.user.id
|
||||
})
|
||||
@@ -32,13 +32,13 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
async delete(obj, args) {
|
||||
await WIKI.db.groups.query().deleteById(args.id)
|
||||
await WIKI.models.groups.query().deleteById(args.id)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Page has been deleted.')
|
||||
}
|
||||
},
|
||||
async update(obj, args, context) {
|
||||
const page = await WIKI.db.pages.updatePage({
|
||||
const page = await WIKI.models.pages.updatePage({
|
||||
...args,
|
||||
authorId: context.req.user.id
|
||||
})
|
||||
|
@@ -6,16 +6,16 @@ const gql = require('graphql')
|
||||
module.exports = {
|
||||
Query: {
|
||||
rights(obj, args, context, info) {
|
||||
return WIKI.db.Right.findAll({ where: args })
|
||||
return WIKI.models.Right.findAll({ where: args })
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
addRightToGroup(obj, args) {
|
||||
return WIKI.db.Group.findById(args.groupId).then(grp => {
|
||||
return WIKI.models.Group.findById(args.groupId).then(grp => {
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
return WIKI.db.Right.create({
|
||||
return WIKI.models.Right.create({
|
||||
path: args.path,
|
||||
role: args.role,
|
||||
exact: args.exact,
|
||||
@@ -25,7 +25,7 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
removeRightFromGroup(obj, args) {
|
||||
return WIKI.db.Right.destroy({
|
||||
return WIKI.models.Right.destroy({
|
||||
where: {
|
||||
id: args.rightId
|
||||
},
|
||||
@@ -33,7 +33,7 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
modifyRight(obj, args) {
|
||||
return WIKI.db.Right.update({
|
||||
return WIKI.models.Right.update({
|
||||
path: args.path,
|
||||
role: args.role,
|
||||
exact: args.exact,
|
||||
|
@@ -6,7 +6,7 @@ const _ = require('lodash')
|
||||
module.exports = {
|
||||
Query: {
|
||||
settings(obj, args, context, info) {
|
||||
return WIKI.db.Setting.findAll({ where: args, raw: true }).then(entries => {
|
||||
return WIKI.models.Setting.findAll({ where: args, raw: true }).then(entries => {
|
||||
return _.map(entries, entry => {
|
||||
entry.config = JSON.stringify(entry.config)
|
||||
return entry
|
||||
@@ -16,7 +16,7 @@ module.exports = {
|
||||
},
|
||||
Mutation: {
|
||||
setConfigEntry(obj, args) {
|
||||
return WIKI.db.Setting.update({
|
||||
return WIKI.models.Setting.update({
|
||||
value: args.value
|
||||
}, { where: { key: args.key } })
|
||||
}
|
||||
|
@@ -12,13 +12,24 @@ module.exports = {
|
||||
},
|
||||
StorageQuery: {
|
||||
async targets(obj, args, context, info) {
|
||||
let targets = await WIKI.db.storage.getTargets()
|
||||
targets = targets.map(tgt => ({
|
||||
...tgt,
|
||||
config: _.sortBy(_.transform(tgt.config, (res, value, key) => {
|
||||
res.push({ key, value: JSON.stringify(value) })
|
||||
}, []), 'key')
|
||||
}))
|
||||
let targets = await WIKI.models.storage.getTargets()
|
||||
targets = targets.map(tgt => {
|
||||
const targetInfo = _.find(WIKI.data.storage, ['key', tgt.key]) || {}
|
||||
console.info(targetInfo)
|
||||
return {
|
||||
...tgt,
|
||||
config: _.sortBy(_.transform(tgt.config, (res, value, key) => {
|
||||
const configData = _.get(targetInfo.props, key, {})
|
||||
res.push({
|
||||
key,
|
||||
value: JSON.stringify({
|
||||
...configData,
|
||||
value
|
||||
})
|
||||
})
|
||||
}, []), 'key')
|
||||
}
|
||||
})
|
||||
if (args.filter) { targets = graphHelper.filter(targets, args.filter) }
|
||||
if (args.orderBy) { targets = graphHelper.orderBy(targets, args.orderBy) }
|
||||
return targets
|
||||
@@ -28,11 +39,11 @@ module.exports = {
|
||||
async updateTargets(obj, args, context) {
|
||||
try {
|
||||
for (let tgt of args.targets) {
|
||||
await WIKI.db.storage.query().patch({
|
||||
await WIKI.models.storage.query().patch({
|
||||
isEnabled: tgt.isEnabled,
|
||||
mode: tgt.mode,
|
||||
config: _.reduce(tgt.config, (result, value, key) => {
|
||||
_.set(result, `${value.key}.value`, value.value)
|
||||
_.set(result, `${value.key}`, value.value)
|
||||
return result
|
||||
}, {})
|
||||
}).where('key', tgt.key)
|
||||
|
@@ -33,7 +33,7 @@ module.exports = {
|
||||
configFile: path.join(process.cwd(), 'config.yml'),
|
||||
currentVersion: WIKI.version,
|
||||
dbType: _.get(dbTypes, WIKI.config.db.type, 'Unknown DB'),
|
||||
dbVersion: _.get(WIKI.db, 'knex.client.version', 'Unknown version'),
|
||||
dbVersion: _.get(WIKI.models, 'knex.client.version', 'Unknown version'),
|
||||
dbHost: WIKI.config.db.host,
|
||||
latestVersion: WIKI.version, // TODO
|
||||
latestVersionReleaseDate: new Date(), // TODO
|
||||
|
@@ -6,16 +6,16 @@ const gql = require('graphql')
|
||||
module.exports = {
|
||||
Query: {
|
||||
tags(obj, args, context, info) {
|
||||
return WIKI.db.Tag.findAll({ where: args })
|
||||
return WIKI.models.Tag.findAll({ where: args })
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
assignTagToDocument(obj, args) {
|
||||
return WIKI.db.Tag.findById(args.tagId).then(tag => {
|
||||
return WIKI.models.Tag.findById(args.tagId).then(tag => {
|
||||
if (!tag) {
|
||||
throw new gql.GraphQLError('Invalid Tag ID')
|
||||
}
|
||||
return WIKI.db.Document.findById(args.documentId).then(doc => {
|
||||
return WIKI.models.Document.findById(args.documentId).then(doc => {
|
||||
if (!doc) {
|
||||
throw new gql.GraphQLError('Invalid Document ID')
|
||||
}
|
||||
@@ -24,10 +24,10 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
createTag(obj, args) {
|
||||
return WIKI.db.Tag.create(args)
|
||||
return WIKI.models.Tag.create(args)
|
||||
},
|
||||
deleteTag(obj, args) {
|
||||
return WIKI.db.Tag.destroy({
|
||||
return WIKI.models.Tag.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
},
|
||||
@@ -35,11 +35,11 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
removeTagFromDocument(obj, args) {
|
||||
return WIKI.db.Tag.findById(args.tagId).then(tag => {
|
||||
return WIKI.models.Tag.findById(args.tagId).then(tag => {
|
||||
if (!tag) {
|
||||
throw new gql.GraphQLError('Invalid Tag ID')
|
||||
}
|
||||
return WIKI.db.Document.findById(args.documentId).then(doc => {
|
||||
return WIKI.models.Document.findById(args.documentId).then(doc => {
|
||||
if (!doc) {
|
||||
throw new gql.GraphQLError('Invalid Document ID')
|
||||
}
|
||||
@@ -48,7 +48,7 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
renameTag(obj, args) {
|
||||
return WIKI.db.Group.update({
|
||||
return WIKI.models.Group.update({
|
||||
key: args.key
|
||||
}, {
|
||||
where: { id: args.id }
|
||||
|
@@ -10,18 +10,18 @@ module.exports = {
|
||||
},
|
||||
UserQuery: {
|
||||
async list(obj, args, context, info) {
|
||||
return WIKI.db.users.query()
|
||||
return WIKI.models.users.query()
|
||||
.select('id', 'email', 'name', 'provider', 'role', 'createdAt', 'updatedAt')
|
||||
},
|
||||
async search(obj, args, context, info) {
|
||||
return WIKI.db.users.query()
|
||||
return WIKI.models.users.query()
|
||||
.where('email', 'like', `%${args.query}%`)
|
||||
.orWhere('name', 'like', `%${args.query}%`)
|
||||
.limit(10)
|
||||
.select('id', 'email', 'name', 'provider', 'role', 'createdAt', 'updatedAt')
|
||||
},
|
||||
async single(obj, args, context, info) {
|
||||
let usr = await WIKI.db.users.query().findById(args.id)
|
||||
let usr = await WIKI.models.users.query().findById(args.id)
|
||||
usr.password = ''
|
||||
usr.tfaSecret = ''
|
||||
return usr
|
||||
@@ -29,13 +29,13 @@ module.exports = {
|
||||
},
|
||||
UserMutation: {
|
||||
create(obj, args) {
|
||||
return WIKI.db.users.query().insertAndFetch(args)
|
||||
return WIKI.models.users.query().insertAndFetch(args)
|
||||
},
|
||||
delete(obj, args) {
|
||||
return WIKI.db.users.query().deleteById(args.id)
|
||||
return WIKI.models.users.query().deleteById(args.id)
|
||||
},
|
||||
update(obj, args) {
|
||||
return WIKI.db.users.query().patch({
|
||||
return WIKI.models.users.query().patch({
|
||||
email: args.email,
|
||||
name: args.name,
|
||||
provider: args.provider,
|
||||
|
@@ -5,7 +5,7 @@ const { createApolloFetch } = require('apollo-fetch')
|
||||
/* global WIKI */
|
||||
|
||||
WIKI.redis = require('../core/redis').init()
|
||||
WIKI.db = require('../core/db').init()
|
||||
WIKI.models = require('../core/db').init()
|
||||
|
||||
module.exports = async (job) => {
|
||||
WIKI.logger.info(`Fetching locale ${job.data.locale} from Graph endpoint...`)
|
||||
@@ -39,8 +39,8 @@ module.exports = async (job) => {
|
||||
const locales = await WIKI.redis.get('locales')
|
||||
if (locales) {
|
||||
const currentLocale = _.find(JSON.parse(locales), ['code', job.data.locale]) || {}
|
||||
await WIKI.db.locales.query().delete().where('code', job.data.locale)
|
||||
await WIKI.db.locales.query().insert({
|
||||
await WIKI.models.locales.query().delete().where('code', job.data.locale)
|
||||
await WIKI.models.locales.query().insert({
|
||||
code: job.data.locale,
|
||||
strings: lcObj,
|
||||
isRTL: currentLocale.isRTL,
|
||||
|
@@ -5,7 +5,7 @@ const { createApolloFetch } = require('apollo-fetch')
|
||||
/* global WIKI */
|
||||
|
||||
WIKI.redis = require('../core/redis').init()
|
||||
WIKI.db = require('../core/db').init()
|
||||
WIKI.models = require('../core/db').init()
|
||||
|
||||
module.exports = async (job) => {
|
||||
WIKI.logger.info('Syncing locales with Graph endpoint...')
|
||||
@@ -59,7 +59,7 @@ module.exports = async (job) => {
|
||||
_.set(lcObj, row.key.replace(':', '.'), row.value)
|
||||
})
|
||||
|
||||
await WIKI.db.locales.query().update({
|
||||
await WIKI.models.locales.query().update({
|
||||
code: WIKI.config.lang.code,
|
||||
strings: lcObj,
|
||||
isRTL: currentLocale.isRTL,
|
||||
|
@@ -3,7 +3,7 @@ const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
const _ = require('lodash')
|
||||
const yaml = require('js-yaml')
|
||||
const commonHelper = require('../../helpers/common')
|
||||
const commonHelper = require('../helpers/common')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
@@ -33,7 +33,7 @@ module.exports = class Authentication extends Model {
|
||||
}
|
||||
|
||||
static async getStrategies() {
|
||||
const strategies = await WIKI.db.authentication.query()
|
||||
const strategies = await WIKI.models.authentication.query()
|
||||
return strategies.map(str => ({
|
||||
...str,
|
||||
domainWhitelist: _.get(str.domainWhitelist, 'v', []),
|
||||
@@ -43,7 +43,7 @@ module.exports = class Authentication extends Model {
|
||||
|
||||
static async refreshStrategiesFromDisk() {
|
||||
try {
|
||||
const dbStrategies = await WIKI.db.authentication.query()
|
||||
const dbStrategies = await WIKI.models.authentication.query()
|
||||
|
||||
// -> Fetch definitions from disk
|
||||
const authDirs = await fs.readdir(path.join(WIKI.SERVERPATH, 'modules/authentication'))
|
||||
@@ -86,7 +86,7 @@ module.exports = class Authentication extends Model {
|
||||
}
|
||||
})
|
||||
if (newStrategies.length > 0) {
|
||||
await WIKI.db.authentication.query().insert(newStrategies)
|
||||
await WIKI.models.authentication.query().insert(newStrategies)
|
||||
WIKI.logger.info(`Loaded ${newStrategies.length} new authentication strategies: [ OK ]`)
|
||||
} else {
|
||||
WIKI.logger.info(`No new authentication strategies found: [ SKIPPED ]`)
|
@@ -27,12 +27,12 @@ module.exports = class Editor extends Model {
|
||||
}
|
||||
|
||||
static async getEnabledEditors() {
|
||||
return WIKI.db.editors.query().where({ isEnabled: true })
|
||||
return WIKI.models.editors.query().where({ isEnabled: true })
|
||||
}
|
||||
|
||||
static async refreshEditorsFromDisk() {
|
||||
try {
|
||||
const dbEditors = await WIKI.db.editors.query()
|
||||
const dbEditors = await WIKI.models.editors.query()
|
||||
const diskEditors = autoload(path.join(WIKI.SERVERPATH, 'modules/editor'))
|
||||
let newEditors = []
|
||||
_.forOwn(diskEditors, (strategy, strategyKey) => {
|
||||
@@ -49,7 +49,7 @@ module.exports = class Editor extends Model {
|
||||
}
|
||||
})
|
||||
if (newEditors.length > 0) {
|
||||
await WIKI.db.editors.query().insert(newEditors)
|
||||
await WIKI.models.editors.query().insert(newEditors)
|
||||
WIKI.logger.info(`Loaded ${newEditors.length} new editors: [ OK ]`)
|
||||
} else {
|
||||
WIKI.logger.info(`No new editors found: [ SKIPPED ]`)
|
@@ -82,7 +82,7 @@ module.exports = class PageHistory extends Model {
|
||||
}
|
||||
|
||||
static async addVersion(opts) {
|
||||
await WIKI.db.pageHistory.query().insert({
|
||||
await WIKI.models.pageHistory.query().insert({
|
||||
pageId: opts.id,
|
||||
authorId: opts.authorId,
|
||||
content: opts.content,
|
@@ -22,6 +22,7 @@ module.exports = class Page extends Model {
|
||||
publishStartDate: {type: 'string'},
|
||||
publishEndDate: {type: 'string'},
|
||||
content: {type: 'string'},
|
||||
contentType: {type: 'string'},
|
||||
|
||||
createdAt: {type: 'string'},
|
||||
updatedAt: {type: 'string'}
|
||||
@@ -87,7 +88,7 @@ module.exports = class Page extends Model {
|
||||
}
|
||||
|
||||
static async createPage(opts) {
|
||||
const page = await WIKI.db.pages.query().insertAndFetch({
|
||||
const page = await WIKI.models.pages.query().insertAndFetch({
|
||||
authorId: opts.authorId,
|
||||
content: opts.content,
|
||||
creatorId: opts.authorId,
|
||||
@@ -101,7 +102,7 @@ module.exports = class Page extends Model {
|
||||
publishStartDate: opts.publishStartDate,
|
||||
title: opts.title
|
||||
})
|
||||
await WIKI.db.storage.pageEvent({
|
||||
await WIKI.models.storage.pageEvent({
|
||||
event: 'created',
|
||||
page
|
||||
})
|
||||
@@ -109,15 +110,21 @@ module.exports = class Page extends Model {
|
||||
}
|
||||
|
||||
static async updatePage(opts) {
|
||||
const ogPage = await WIKI.db.pages.query().findById(opts.id)
|
||||
const ogPage = await WIKI.models.pages.query().findById(opts.id)
|
||||
if (!ogPage) {
|
||||
throw new Error('Invalid Page Id')
|
||||
}
|
||||
await WIKI.db.pageHistory.addVersion(ogPage)
|
||||
const page = await WIKI.db.pages.query().patchAndFetch({
|
||||
await WIKI.models.pageHistory.addVersion(ogPage)
|
||||
const page = await WIKI.models.pages.query().patchAndFetchById(ogPage.id, {
|
||||
authorId: opts.authorId,
|
||||
content: opts.content,
|
||||
description: opts.description,
|
||||
isPublished: opts.isPublished,
|
||||
publishEndDate: opts.publishEndDate,
|
||||
publishStartDate: opts.publishStartDate,
|
||||
title: opts.title
|
||||
}).where('id', opts.id)
|
||||
await WIKI.db.storage.pageEvent({
|
||||
})
|
||||
await WIKI.models.storage.pageEvent({
|
||||
event: 'updated',
|
||||
page
|
||||
})
|
@@ -32,7 +32,7 @@ module.exports = class Setting extends Model {
|
||||
}
|
||||
|
||||
static async getConfig() {
|
||||
const settings = await WIKI.db.settings.query()
|
||||
const settings = await WIKI.models.settings.query()
|
||||
if (settings.length > 0) {
|
||||
return _.reduce(settings, (res, val, key) => {
|
||||
_.set(res, val.key, (val.value.v) ? val.value.v : val.value)
|
@@ -3,7 +3,7 @@ const path = require('path')
|
||||
const fs = require('fs-extra')
|
||||
const _ = require('lodash')
|
||||
const yaml = require('js-yaml')
|
||||
const commonHelper = require('../../helpers/common')
|
||||
const commonHelper = require('../helpers/common')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
@@ -30,12 +30,12 @@ module.exports = class Storage extends Model {
|
||||
}
|
||||
|
||||
static async getTargets() {
|
||||
return WIKI.db.storage.query()
|
||||
return WIKI.models.storage.query()
|
||||
}
|
||||
|
||||
static async refreshTargetsFromDisk() {
|
||||
try {
|
||||
const dbTargets = await WIKI.db.storage.query()
|
||||
const dbTargets = await WIKI.models.storage.query()
|
||||
|
||||
// -> Fetch definitions from disk
|
||||
const storageDirs = await fs.readdir(path.join(WIKI.SERVERPATH, 'modules/storage'))
|
||||
@@ -44,10 +44,29 @@ module.exports = class Storage extends Model {
|
||||
const def = await fs.readFile(path.join(WIKI.SERVERPATH, 'modules/storage', dir, 'definition.yml'), 'utf8')
|
||||
diskTargets.push(yaml.safeLoad(def))
|
||||
}
|
||||
WIKI.data.storage = diskTargets.map(target => ({
|
||||
...target,
|
||||
props: _.transform(target.props, (result, value, key) => {
|
||||
let defaultValue = ''
|
||||
if (_.isPlainObject(value)) {
|
||||
defaultValue = !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value.type)
|
||||
} else {
|
||||
defaultValue = commonHelper.getTypeDefaultValue(value)
|
||||
}
|
||||
_.set(result, key, {
|
||||
default: defaultValue,
|
||||
type: (value.type || value).toLowerCase(),
|
||||
title: value.title || _.startCase(key),
|
||||
hint: value.hint || false,
|
||||
enum: value.enum || false
|
||||
})
|
||||
return result
|
||||
}, {})
|
||||
}))
|
||||
|
||||
// -> Insert new targets
|
||||
let newTargets = []
|
||||
_.forEach(diskTargets, target => {
|
||||
for (let target of WIKI.data.storage) {
|
||||
if (!_.some(dbTargets, ['key', target.key])) {
|
||||
newTargets.push({
|
||||
key: target.key,
|
||||
@@ -55,28 +74,25 @@ module.exports = class Storage extends Model {
|
||||
isEnabled: false,
|
||||
mode: 'push',
|
||||
config: _.transform(target.props, (result, value, key) => {
|
||||
if (_.isPlainObject(value)) {
|
||||
let cfgValue = {
|
||||
type: value.type.toLowerCase(),
|
||||
value: !_.isNil(value.default) ? value.default : commonHelper.getTypeDefaultValue(value.type)
|
||||
}
|
||||
if (_.isArray(value.enum)) {
|
||||
cfgValue.enum = value.enum
|
||||
}
|
||||
_.set(result, key, cfgValue)
|
||||
} else {
|
||||
_.set(result, key, {
|
||||
type: value.toLowerCase(),
|
||||
value: commonHelper.getTypeDefaultValue(value)
|
||||
})
|
||||
}
|
||||
_.set(result, key, value.default)
|
||||
return result
|
||||
}, {})
|
||||
})
|
||||
} else {
|
||||
const targetConfig = _.get(_.find(dbTargets, ['key', target.key]), 'config', {})
|
||||
await WIKI.models.storage.query().patch({
|
||||
title: target.title,
|
||||
config: _.transform(target.props, (result, value, key) => {
|
||||
if (!_.has(result, key)) {
|
||||
_.set(result, key, value.default)
|
||||
}
|
||||
return result
|
||||
}, targetConfig)
|
||||
}).where('key', target.key)
|
||||
}
|
||||
})
|
||||
}
|
||||
if (newTargets.length > 0) {
|
||||
await WIKI.db.storage.query().insert(newTargets)
|
||||
await WIKI.models.storage.query().insert(newTargets)
|
||||
WIKI.logger.info(`Loaded ${newTargets.length} new storage targets: [ OK ]`)
|
||||
} else {
|
||||
WIKI.logger.info(`No new storage targets found: [ SKIPPED ]`)
|
||||
@@ -87,8 +103,8 @@ module.exports = class Storage extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
static async pageEvent(event, page) {
|
||||
const targets = await WIKI.db.storage.query().where('isEnabled', true)
|
||||
static async pageEvent({ event, page }) {
|
||||
const targets = await WIKI.models.storage.query().where('isEnabled', true)
|
||||
if (targets && targets.length > 0) {
|
||||
_.forEach(targets, target => {
|
||||
WIKI.queue.job.syncStorage.add({
|
@@ -3,7 +3,7 @@
|
||||
const bcrypt = require('bcryptjs-then')
|
||||
const _ = require('lodash')
|
||||
const tfa = require('node-2fa')
|
||||
const securityHelper = require('../../helpers/security')
|
||||
const securityHelper = require('../helpers/security')
|
||||
const Model = require('objection').Model
|
||||
|
||||
const bcryptRegexp = /^\$2[ayb]\$[0-9]{2}\$[A-Za-z0-9./]{53}$/
|
||||
@@ -151,7 +151,7 @@ module.exports = class User extends Model {
|
||||
profile.provider = _.lowerCase(profile.provider)
|
||||
primaryEmail = _.toLower(primaryEmail)
|
||||
|
||||
let user = await WIKI.db.users.query().findOne({
|
||||
let user = await WIKI.models.users.query().findOne({
|
||||
email: primaryEmail,
|
||||
provider: profile.provider
|
||||
})
|
||||
@@ -163,7 +163,7 @@ module.exports = class User extends Model {
|
||||
name: profile.displayName || _.split(primaryEmail, '@')[0]
|
||||
})
|
||||
} else {
|
||||
user = await WIKI.db.users.query().insertAndFetch({
|
||||
user = await WIKI.models.users.query().insertAndFetch({
|
||||
email: primaryEmail,
|
||||
provider: profile.provider,
|
||||
providerId: profile.id,
|
||||
@@ -186,7 +186,7 @@ module.exports = class User extends Model {
|
||||
// deny: false
|
||||
// }]
|
||||
// }
|
||||
// return WIKI.db.users.query().insert(nUsr)
|
||||
// return WIKI.models.users.query().insert(nUsr)
|
||||
// }
|
||||
|
||||
return user
|
||||
@@ -238,7 +238,7 @@ module.exports = class User extends Model {
|
||||
if (result) {
|
||||
let userId = _.toSafeInteger(result)
|
||||
if (userId && userId > 0) {
|
||||
let user = await WIKI.db.users.query().findById(userId)
|
||||
let user = await WIKI.models.users.query().findById(userId)
|
||||
if (user && user.verifyTFA(opts.securityCode)) {
|
||||
return Promise.fromCallback(clb => {
|
||||
context.req.logIn(user, clb)
|
@@ -15,7 +15,7 @@ module.exports = {
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, function (accessToken, refreshToken, profile, cb) {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -20,7 +20,7 @@ module.exports = {
|
||||
let waadProfile = jwt.decode(params.id_token)
|
||||
waadProfile.id = waadProfile.oid
|
||||
waadProfile.provider = 'azure'
|
||||
WIKI.db.users.processProfile(waadProfile).then((user) => {
|
||||
WIKI.models.users.processProfile(waadProfile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -13,7 +13,7 @@ module.exports = {
|
||||
ssoBaseURL: conf.ssoBaseURL,
|
||||
serverBaseURL: conf.serverBaseURL
|
||||
}, (profile, cb) => {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -15,7 +15,7 @@ module.exports = {
|
||||
callbackURL: conf.callbackURL,
|
||||
scope: 'identify email'
|
||||
}, function (accessToken, refreshToken, profile, cb) {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -15,7 +15,7 @@ module.exports = {
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -15,7 +15,7 @@ module.exports = {
|
||||
callbackURL: conf.callbackURL,
|
||||
profileFields: ['id', 'displayName', 'email']
|
||||
}, function (accessToken, refreshToken, profile, cb) {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -15,7 +15,7 @@ module.exports = {
|
||||
callbackURL: conf.callbackURL,
|
||||
scope: ['user:email']
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -14,7 +14,7 @@ module.exports = {
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -29,7 +29,7 @@ module.exports = {
|
||||
}, (profile, cb) => {
|
||||
profile.provider = 'ldap'
|
||||
profile.id = profile.dn
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -13,7 +13,7 @@ module.exports = {
|
||||
usernameField: 'email',
|
||||
passwordField: 'password'
|
||||
}, (uEmail, uPassword, done) => {
|
||||
WIKI.db.users.query().findOne({
|
||||
WIKI.models.users.query().findOne({
|
||||
email: uEmail,
|
||||
providerKey: 'local'
|
||||
}).then((user) => {
|
||||
|
@@ -14,7 +14,7 @@ module.exports = {
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, function (accessToken, refreshToken, profile, cb) {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -16,7 +16,7 @@ module.exports = {
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -14,7 +14,7 @@ module.exports = {
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
@@ -15,7 +15,7 @@ module.exports = {
|
||||
callbackURL: conf.callbackURL,
|
||||
scope: 'user_read'
|
||||
}, function (accessToken, refreshToken, profile, cb) {
|
||||
WIKI.db.users.processProfile(profile).then((user) => {
|
||||
WIKI.models.users.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
|
7
server/modules/storage/box/definition.yml
Normal file
7
server/modules/storage/box/definition.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
key: box
|
||||
title: Box
|
||||
author: requarks.io
|
||||
props:
|
||||
clientId: String
|
||||
clientSecret: String
|
||||
rootFolder: String
|
23
server/modules/storage/box/storage.js
Normal file
23
server/modules/storage/box/storage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
module.exports = {
|
||||
async activated() {
|
||||
|
||||
},
|
||||
async deactivated() {
|
||||
|
||||
},
|
||||
async init() {
|
||||
|
||||
},
|
||||
async created() {
|
||||
|
||||
},
|
||||
async updated() {
|
||||
|
||||
},
|
||||
async deleted() {
|
||||
|
||||
},
|
||||
async renamed() {
|
||||
|
||||
}
|
||||
}
|
@@ -1,5 +1,8 @@
|
||||
key: disk
|
||||
title: Local FS
|
||||
title: Local File System
|
||||
author: requarks.io
|
||||
props:
|
||||
path: String
|
||||
path:
|
||||
type: String
|
||||
title: Path
|
||||
hint: Absolute path without a trailing slash (e.g. /home/wiki/backup, C:\wiki\backup)
|
||||
|
@@ -1,23 +1,68 @@
|
||||
module.exports = {
|
||||
async activated() {
|
||||
|
||||
},
|
||||
async deactivated() {
|
||||
|
||||
},
|
||||
async init() {
|
||||
|
||||
},
|
||||
async created() {
|
||||
|
||||
},
|
||||
async updated() {
|
||||
|
||||
},
|
||||
async deleted() {
|
||||
|
||||
},
|
||||
async renamed() {
|
||||
const fs = require('fs-extra')
|
||||
const path = require('path')
|
||||
|
||||
/**
|
||||
* Get file extension based on content type
|
||||
*/
|
||||
const getFileExtension = (contentType) => {
|
||||
switch (contentType) {
|
||||
case 'markdown':
|
||||
return 'md'
|
||||
case 'html':
|
||||
return 'html'
|
||||
default:
|
||||
return 'txt'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject page metadata into contents
|
||||
*/
|
||||
const injectMetadata = (page) => {
|
||||
let meta = [
|
||||
['title', page.title],
|
||||
['description', page.description]
|
||||
]
|
||||
let metaFormatted = ''
|
||||
switch (page.contentType) {
|
||||
case 'markdown':
|
||||
metaFormatted = meta.map(mt => `[//]: # ${mt[0]}: ${mt[1]}`).join('\n')
|
||||
break
|
||||
case 'html':
|
||||
metaFormatted = meta.map(mt => `<!-- ${mt[0]}: ${mt[1]} -->`).join('\n')
|
||||
break
|
||||
default:
|
||||
metaFormatted = meta.map(mt => `#WIKI ${mt[0]}: ${mt[1]}`).join('\n')
|
||||
break
|
||||
}
|
||||
return `${metaFormatted}\n\n${page.content}`
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
async activated() {
|
||||
// not used
|
||||
},
|
||||
async deactivated() {
|
||||
// not used
|
||||
},
|
||||
async init() {
|
||||
await fs.ensureDir(this.config.path)
|
||||
},
|
||||
async created() {
|
||||
const filePath = path.join(this.config.path, `${this.page.path}.${getFileExtension(this.page.contentType)}`)
|
||||
await fs.outputFile(filePath, injectMetadata(this.page), 'utf8')
|
||||
},
|
||||
async updated() {
|
||||
const filePath = path.join(this.config.path, `${this.page.path}.${getFileExtension(this.page.contentType)}`)
|
||||
await fs.outputFile(filePath, injectMetadata(this.page), 'utf8')
|
||||
},
|
||||
async deleted() {
|
||||
const filePath = path.join(this.config.path, `${this.page.path}.${getFileExtension(this.page.contentType)}`)
|
||||
await fs.unlink(filePath)
|
||||
},
|
||||
async renamed() {
|
||||
const sourceFilePath = path.join(this.config.path, `${this.page.sourcePath}.${getFileExtension(this.page.contentType)}`)
|
||||
const destinationFilePath = path.join(this.config.path, `${this.page.destinationPath}.${getFileExtension(this.page.contentType)}`)
|
||||
await fs.move(sourceFilePath, destinationFilePath, { overwrite: true })
|
||||
}
|
||||
}
|
||||
|
@@ -5,16 +5,32 @@ props:
|
||||
authType:
|
||||
type: String
|
||||
default: 'ssh'
|
||||
title: Authentication Type
|
||||
hint: Use SSH for maximum security.
|
||||
enum:
|
||||
- 'basic'
|
||||
- 'ssh'
|
||||
repoUrl: String
|
||||
repoUrl:
|
||||
type: String
|
||||
title: Repository URI
|
||||
hint: Git-compliant URI (e.g. git@github.com:org/repo.git for ssh, https://github.com/org/repo.git for basic)
|
||||
branch:
|
||||
type: String
|
||||
default: 'master'
|
||||
verifySSL:
|
||||
type: Boolean
|
||||
default: true
|
||||
sshPrivateKeyPath: String
|
||||
basicUsername: String
|
||||
basicPassword: String
|
||||
title: Verify SSL Certificate
|
||||
hint: Some hosts requires SSL certificate checking to be disabled. Leave enabled for proper security.
|
||||
sshPrivateKeyPath:
|
||||
type: String
|
||||
title: SSH Private Key Path
|
||||
hint: SSH Authentication Only - Absolute path to the key. The key must NOT be passphrase-protected.
|
||||
basicUsername:
|
||||
type: String
|
||||
title: Username
|
||||
hint: Basic Authentication Only
|
||||
basicPassword:
|
||||
type: String
|
||||
title: Password / PAT
|
||||
hint: Basic Authentication Only
|
||||
|
@@ -303,7 +303,7 @@ module.exports = () => {
|
||||
|
||||
// Create default locale
|
||||
WIKI.logger.info('Installing default locale...')
|
||||
await WIKI.db.locales.query().insert({
|
||||
await WIKI.models.locales.query().insert({
|
||||
code: 'en',
|
||||
strings: require('./locales/default.json'),
|
||||
isRTL: false,
|
||||
@@ -312,23 +312,23 @@ module.exports = () => {
|
||||
})
|
||||
|
||||
// Load authentication strategies + enable local
|
||||
await WIKI.db.authentication.refreshStrategiesFromDisk()
|
||||
await WIKI.db.authentication.query().patch({ isEnabled: true }).where('key', 'local')
|
||||
await WIKI.models.authentication.refreshStrategiesFromDisk()
|
||||
await WIKI.models.authentication.query().patch({ isEnabled: true }).where('key', 'local')
|
||||
|
||||
// Load editors + enable default
|
||||
await WIKI.db.editors.refreshEditorsFromDisk()
|
||||
await WIKI.db.editors.query().patch({ isEnabled: true }).where('key', 'markdown')
|
||||
await WIKI.models.editors.refreshEditorsFromDisk()
|
||||
await WIKI.models.editors.query().patch({ isEnabled: true }).where('key', 'markdown')
|
||||
|
||||
// Load storage targets
|
||||
await WIKI.db.storage.refreshTargetsFromDisk()
|
||||
await WIKI.models.storage.refreshTargetsFromDisk()
|
||||
|
||||
// Create root administrator
|
||||
WIKI.logger.info('Creating root administrator...')
|
||||
await WIKI.db.users.query().delete().where({
|
||||
await WIKI.models.users.query().delete().where({
|
||||
providerKey: 'local',
|
||||
email: req.body.adminEmail
|
||||
})
|
||||
await WIKI.db.users.query().insert({
|
||||
await WIKI.models.users.query().insert({
|
||||
email: req.body.adminEmail,
|
||||
provider: 'local',
|
||||
password: req.body.adminPassword,
|
||||
@@ -341,12 +341,12 @@ module.exports = () => {
|
||||
|
||||
// Create Guest account
|
||||
WIKI.logger.info('Creating guest account...')
|
||||
const guestUsr = await WIKI.db.users.query().findOne({
|
||||
const guestUsr = await WIKI.models.users.query().findOne({
|
||||
providerKey: 'local',
|
||||
email: 'guest@example.com'
|
||||
})
|
||||
if (!guestUsr) {
|
||||
await WIKI.db.users.query().insert({
|
||||
await WIKI.models.users.query().insert({
|
||||
provider: 'local',
|
||||
email: 'guest@example.com',
|
||||
name: 'Guest',
|
||||
|
@@ -4,7 +4,9 @@ block body
|
||||
#app.is-fullscreen
|
||||
v-app
|
||||
.onboarding
|
||||
img(src='/svg/logo-wikijs.svg', alt='Wiki.js')
|
||||
h1= t('welcome.title')
|
||||
h2= t('welcome.subtitle')
|
||||
v-btn(color='primary', href='/e/home')= t('welcome.createhome')
|
||||
img.animated.zoomIn(src='/svg/logo-wikijs.svg', alt='Wiki.js')
|
||||
.headline= t('welcome.title')
|
||||
.subheading.mt-3= t('welcome.subtitle')
|
||||
v-btn.mt-5(color='primary', href='/e/home', large)
|
||||
v-icon(left) add
|
||||
span= t('welcome.createhome')
|
||||
|
Reference in New Issue
Block a user