feat: page locale migration + deps update
This commit is contained in:
@@ -58,6 +58,13 @@ router.get(['/e', '/e/*'], async (req, res, next) => {
|
||||
userId: req.user.id,
|
||||
isPrivate: false
|
||||
})
|
||||
|
||||
const injectCode = {
|
||||
css: WIKI.config.theming.injectCSS,
|
||||
head: WIKI.config.theming.injectHead,
|
||||
body: WIKI.config.theming.injectBody
|
||||
}
|
||||
|
||||
if (page) {
|
||||
if (!WIKI.auth.checkAccess(req.user, ['manage:pages'], pageArgs)) {
|
||||
_.set(res.locals, 'pageMeta.title', 'Unauthorized')
|
||||
@@ -84,7 +91,7 @@ router.get(['/e', '/e/*'], async (req, res, next) => {
|
||||
content: null
|
||||
}
|
||||
}
|
||||
res.render('editor', { page })
|
||||
res.render('editor', { page, injectCode })
|
||||
})
|
||||
|
||||
/**
|
||||
|
@@ -98,9 +98,10 @@ module.exports = {
|
||||
},
|
||||
async migrateToLocale(obj, args, context) {
|
||||
try {
|
||||
|
||||
const count = await WIKI.models.pages.migrateToLocale(args)
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Migrated all content to target locale successfully.')
|
||||
responseResult: graphHelper.generateSuccess('Migrated content to target locale successfully.'),
|
||||
count
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
|
@@ -77,7 +77,7 @@ type PageMutation {
|
||||
migrateToLocale(
|
||||
sourceLocale: String!
|
||||
targetLocale: String!
|
||||
): DefaultResponse @auth(requires: ["manage:system"])
|
||||
): PageMigrationResponse @auth(requires: ["manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
@@ -89,6 +89,11 @@ type PageResponse {
|
||||
page: Page
|
||||
}
|
||||
|
||||
type PageMigrationResponse {
|
||||
responseResult: ResponseStatus!
|
||||
count: Int
|
||||
}
|
||||
|
||||
type Page {
|
||||
id: Int!
|
||||
path: String!
|
||||
|
@@ -421,6 +421,19 @@ module.exports = class Page extends Model {
|
||||
return fs.emptyDir(path.join(process.cwd(), `data/cache`))
|
||||
}
|
||||
|
||||
static async migrateToLocale({ sourceLocale, targetLocale }) {
|
||||
return WIKI.models.pages.query()
|
||||
.patch({
|
||||
localeCode: targetLocale
|
||||
})
|
||||
.where({
|
||||
localeCode: sourceLocale
|
||||
})
|
||||
.whereNotExists(function() {
|
||||
this.select('id').from('pages AS pagesm').where('pagesm.localeCode', targetLocale).andWhereRaw('pagesm.path = pages.path')
|
||||
})
|
||||
}
|
||||
|
||||
static cleanHTML(rawHTML = '') {
|
||||
return striptags(rawHTML || '')
|
||||
.replace(emojiRegex(), '')
|
||||
|
@@ -1,5 +1,9 @@
|
||||
extends master.pug
|
||||
|
||||
block head
|
||||
if injectCode.css
|
||||
style(type='text/css')!= injectCode.css
|
||||
|
||||
block body
|
||||
#root
|
||||
editor(
|
||||
|
Reference in New Issue
Block a user