Skip to content

Commit 076e923

Browse files
committed
feat: save page + create event for storage targets
1 parent cb84df7 commit 076e923

File tree

22 files changed

+158
-89
lines changed

22 files changed

+158
-89
lines changed

client/components/admin/admin-contribute.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
v-divider.mt-3
1313
v-subheader {{ $t('admin:contribute.fundOurWork') }}
1414
.body-1.pl-3 {{ $t('admin:contribute.openCollective') }}
15-
v-card-actions.mt-3.ml-2
15+
v-card-actions.ml-2
1616
v-btn(depressed, color='primary', href='https://opencollective.com/wikijs')
1717
v-icon(left) local_atm
1818
span {{ $t('admin:contribute.makeADonation') }}
19+
.body-1.mt-3.pl-3 {{ $t('admin:contribute.tshirts') }}
20+
v-card-actions.ml-2
21+
v-btn(depressed, color='primary', href='https://wikijs.threadless.com')
22+
v-icon(left) shopping_cart
23+
span {{ $t('admin:contribute.shop') }}
1924
v-divider.mt-3
2025
v-subheader {{ $t('admin:contribute.contribute') }}
2126
.body-1.pl-3

client/components/editor.vue

+2
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ export default {
9494
const resp = await this.$apollo.mutate({
9595
mutation: createPageMutation,
9696
variables: {
97+
content: this.$store.get('editor/content'),
9798
description: this.$store.get('editor/description'),
9899
editor: 'markdown',
99100
locale: this.$store.get('editor/locale'),
101+
isPrivate: false,
100102
isPublished: this.$store.get('editor/isPublished'),
101103
path: this.$store.get('editor/path'),
102104
publishEndDate: this.$store.get('editor/publishEndDate'),

client/components/editor/editor-code.vue

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export default {
220220
},
221221
onCmInput: _.debounce(function (newContent) {
222222
linesMap = []
223+
this.$store.set('editor/content', newContent)
223224
this.previewHTML = md.render(newContent)
224225
this.$nextTick(() => {
225226
Prism.highlightAllUnder(this.$refs.editorPreview)

client/graph/editor/create.gql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
mutation ($description: String, $editor: String, $isPublished: Boolean!, $locale: String!, $path: String!, $publishEndDate: Date, $publishStartDate: Date, $tags: [String], $title: String!) {
1+
mutation ($content: String!, $description: String!, $editor: String!, $isPrivate: Boolean!, $isPublished: Boolean!, $locale: String!, $path: String!, $publishEndDate: Date, $publishStartDate: Date, $tags: [String]!, $title: String!) {
22
pages {
3-
create(description: $description, editor: $editor, isPublished: $isPublished, locale: $locale, path: $path, publishEndDate: $publishEndDate, publishStartDate: $publishStartDate, tags: $tags, title: $title) {
3+
create(content: $content, description: $description, editor: $editor, isPrivate: $isPrivate, isPublished: $isPublished, locale: $locale, path: $path, publishEndDate: $publishEndDate, publishStartDate: $publishStartDate, tags: $tags, title: $title) {
44
responseResult {
55
succeeded
66
errorCode

client/store/editor.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { make } from 'vuex-pathify'
22

33
const state = {
4-
title: '',
4+
content: '',
55
description: '',
6-
tags: [],
7-
path: '',
86
isPublished: true,
9-
publishStartDate: '',
10-
publishEndDate: '',
117
locale: 'en',
12-
mode: 'create'
8+
mode: 'create',
9+
path: '',
10+
publishEndDate: '',
11+
publishStartDate: '',
12+
tags: [],
13+
title: ''
1314
}
1415

1516
export default {

server/app/data.yml

+7
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,19 @@ jobs:
6161
fetchGraphLocale:
6262
onInit: false
6363
cron: false
64+
concurrency: 0
6465
purgeUploads:
6566
onInit: true
6667
cron: '*/15 * * * *'
68+
concurrency: 0
6769
syncGraphLocales:
6870
onInit: true
6971
cron: '0 0 * * *'
72+
concurrency: 0
73+
syncStorage:
74+
onInit: false
75+
cron: false
76+
concurrency: 1
7077
telemetry:
7178
BUGSNAG_ID: 'bb4b324d0675bcbba10025617fd2cec8'
7279
BUGSNAG_REMOTE: 'https://notify.bugsnag.com'

server/core/queue.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ module.exports = {
1010
init() {
1111
_.forOwn(WIKI.data.jobs, (queueParams, queueName) => {
1212
this.job[queueName] = new Bull(queueName, {
13-
prefix: `q-${WIKI.config.ha.uid}`,
13+
prefix: `queue`,
1414
redis: WIKI.config.redis
1515
})
16-
this.job[queueName].process(path.join(WIKI.SERVERPATH, `jobs/${_.kebabCase(queueName)}.js`))
16+
if (queueParams.concurrency > 0) {
17+
this.job[queueName].process(queueParams.concurrency, path.join(WIKI.SERVERPATH, `jobs/${_.kebabCase(queueName)}.js`))
18+
} else {
19+
this.job[queueName].process(path.join(WIKI.SERVERPATH, `jobs/${_.kebabCase(queueName)}.js`))
20+
}
1721
})
1822
return this
1923
},
@@ -36,7 +40,7 @@ module.exports = {
3640
return Promise.each(_.keys(WIKI.data.jobs), queueName => {
3741
return new Promise((resolve, reject) => {
3842
let keyStream = WIKI.redis.scanStream({
39-
match: `q-${WIKI.config.ha.uid}:${queueName}:*`
43+
match: `queue:${queueName}:*`
4044
})
4145
keyStream.on('data', resultKeys => {
4246
if (resultKeys.length > 0) {

server/db/models/pages.js

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const Model = require('objection').Model
22

3+
/* global WIKI */
4+
35
/**
46
* Pages model
57
*/
@@ -75,4 +77,22 @@ module.exports = class Page extends Model {
7577
this.createdAt = new Date().toISOString()
7678
this.updatedAt = new Date().toISOString()
7779
}
80+
81+
static async createPage(opts) {
82+
const page = await WIKI.db.pages.query().insertAndFetch({
83+
authorId: opts.authorId,
84+
content: opts.content,
85+
description: opts.description,
86+
editorKey: opts.editor,
87+
isPrivate: opts.isPrivate,
88+
isPublished: opts.isPublished,
89+
localeCode: opts.locale,
90+
path: opts.path,
91+
publishEndDate: opts.publishEndDate,
92+
publishStartDate: opts.publishStartDate,
93+
title: opts.title
94+
})
95+
await WIKI.db.storage.createPage(page)
96+
return page
97+
}
7898
}

server/db/models/storage.js

+15
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,19 @@ module.exports = class Storage extends Model {
8686
WIKI.logger.error(err)
8787
}
8888
}
89+
90+
static async createPage(page) {
91+
const targets = await WIKI.db.storage.query().where('isEnabled', true)
92+
if (targets && targets.length > 0) {
93+
_.forEach(targets, target => {
94+
WIKI.queue.job.syncStorage.add({
95+
event: 'created',
96+
target,
97+
page
98+
}, {
99+
removeOnComplete: true
100+
})
101+
})
102+
}
103+
}
89104
}

server/db/models/users.js

-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ module.exports = class User extends Model {
193193
}
194194

195195
static async login (opts, context) {
196-
console.info(context)
197196
if (_.has(WIKI.auth.strategies, opts.strategy)) {
198197
_.set(context.req, 'body.email', opts.username)
199198
_.set(context.req, 'body.password', opts.password)

server/graph/resolvers/page.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,9 @@ module.exports = {
2222
},
2323
PageMutation: {
2424
async create(obj, args, context) {
25-
const page = await WIKI.db.pages.query().insertAndFetch({
26-
path: args.path,
27-
title: args.title,
28-
description: args.description,
25+
const page = await WIKI.db.pages.createPage({
26+
...args,
2927
isPrivate: false,
30-
isPublished: args.isPublished,
31-
publishStartDate: args.publishStartDate,
32-
publishEndDate: args.publishEndDate,
33-
localeCode: args.locale,
34-
editorKey: args.editor,
3528
authorId: context.req.user.id
3629
})
3730
return {

server/graph/schemas/page.graphql

+6-4
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@ type PageQuery {
3434

3535
type PageMutation {
3636
create(
37-
description: String
38-
editor: String
37+
content: String!
38+
description: String!
39+
editor: String!
3940
isPublished: Boolean!
40-
isPrivate: Boolean
41+
isPrivate: Boolean!
4142
locale: String!
4243
path: String!
4344
publishEndDate: Date
4445
publishStartDate: Date
45-
tags: [String]
46+
tags: [String]!
4647
title: String!
4748
): PageResponse
4849

4950
update(
5051
id: Int!
52+
content: String
5153
description: String
5254
editor: String
5355
isPublished: Boolean

server/jobs/sync-storage.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require('../core/worker')
2+
3+
/* global WIKI */
4+
5+
module.exports = async (job) => {
6+
WIKI.logger.info(`Syncing with storage provider ${job.data.target.title}...`)
7+
8+
try {
9+
const target = require(`../modules/storage/${job.data.target.key}/storage.js`)
10+
target[job.data.event].call({
11+
config: job.data.target.config,
12+
mode: job.data.target.mode,
13+
page: job.data.page
14+
})
15+
WIKI.logger.info(`Syncing with storage provider ${job.data.target.title}: [ COMPLETED ]`)
16+
} catch (err) {
17+
WIKI.logger.error(`Syncing with storage provider ${job.data.target.title}: [ FAILED ]`)
18+
WIKI.logger.error(err.message)
19+
}
20+
}
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module.exports = {
2-
async activated(opts) {
2+
async activated() {
33

44
},
5-
async deactivated(opts) {
5+
async deactivated() {
66

77
},
8-
async init(opts) {
8+
async init() {
99

1010
},
11-
async created(opts) {
11+
async created() {
1212

1313
},
14-
async updated(opts) {
14+
async updated() {
1515

1616
},
17-
async deleted(opts) {
17+
async deleted() {
1818

1919
},
20-
async renamed(opts) {
20+
async renamed() {
2121

2222
}
2323
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module.exports = {
2-
async activated(opts) {
2+
async activated() {
33

44
},
5-
async deactivated(opts) {
5+
async deactivated() {
66

77
},
8-
async init(opts) {
8+
async init() {
99

1010
},
11-
async created(opts) {
11+
async created() {
1212

1313
},
14-
async updated(opts) {
14+
async updated() {
1515

1616
},
17-
async deleted(opts) {
17+
async deleted() {
1818

1919
},
20-
async renamed(opts) {
20+
async renamed() {
2121

2222
}
2323
}
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module.exports = {
2-
async activated(opts) {
2+
async activated() {
33

44
},
5-
async deactivated(opts) {
5+
async deactivated() {
66

77
},
8-
async init(opts) {
8+
async init() {
99

1010
},
11-
async created(opts) {
11+
async created() {
1212

1313
},
14-
async updated(opts) {
14+
async updated() {
1515

1616
},
17-
async deleted(opts) {
17+
async deleted() {
1818

1919
},
20-
async renamed(opts) {
20+
async renamed() {
2121

2222
}
2323
}
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module.exports = {
2-
async activated(opts) {
2+
async activated() {
33

44
},
5-
async deactivated(opts) {
5+
async deactivated() {
66

77
},
8-
async init(opts) {
8+
async init() {
99

1010
},
11-
async created(opts) {
11+
async created() {
1212

1313
},
14-
async updated(opts) {
14+
async updated() {
1515

1616
},
17-
async deleted(opts) {
17+
async deleted() {
1818

1919
},
20-
async renamed(opts) {
20+
async renamed() {
2121

2222
}
2323
}
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module.exports = {
2-
async activated(opts) {
2+
async activated() {
33

44
},
5-
async deactivated(opts) {
5+
async deactivated() {
66

77
},
8-
async init(opts) {
8+
async init() {
99

1010
},
11-
async created(opts) {
11+
async created() {
1212

1313
},
14-
async updated(opts) {
14+
async updated() {
1515

1616
},
17-
async deleted(opts) {
17+
async deleted() {
1818

1919
},
20-
async renamed(opts) {
20+
async renamed() {
2121

2222
}
2323
}

0 commit comments

Comments
 (0)