commit
2e1d75c288
4 changed files with 60 additions and 63 deletions
|
|
@ -49,7 +49,7 @@
|
|||
"request-promise": "^4.2.2",
|
||||
"response-time": "^2.3.2",
|
||||
"shelljs": "^0.8.2",
|
||||
"shock-common": "^13.0.1",
|
||||
"shock-common": "^14.2.0",
|
||||
"socket.io": "2.1.1",
|
||||
"text-encoding": "^0.7.0",
|
||||
"tingodb": "^0.6.1",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ const uuidv1 = require('uuid/v1')
|
|||
const logger = require('winston')
|
||||
const Common = require('shock-common')
|
||||
const { Constants, Schema } = Common
|
||||
const Gun = require('gun')
|
||||
|
||||
const { ErrorCode } = Constants
|
||||
|
||||
|
|
@ -1229,6 +1230,49 @@ const setLastSeenApp = () =>
|
|||
})
|
||||
)
|
||||
|
||||
/**
|
||||
* @param {string[]} tags
|
||||
* @param {string} title
|
||||
* @param {Common.Schema.ContentItem[]} content
|
||||
* @returns {Promise<[string, Common.Schema.RawPost]>}
|
||||
*/
|
||||
const createPostNew = async (tags, title, content) => {
|
||||
/** @type {Common.Schema.RawPost} */
|
||||
const newPost = {
|
||||
date: Date.now(),
|
||||
status: 'publish',
|
||||
tags: tags.join('-'),
|
||||
title,
|
||||
contentItems: {}
|
||||
}
|
||||
|
||||
content.forEach(c => {
|
||||
// @ts-expect-error
|
||||
const uuid = Gun.text.random()
|
||||
newPost.contentItems[uuid] = c
|
||||
})
|
||||
|
||||
/** @type {string} */
|
||||
const postID = await Common.makePromise((res, rej) => {
|
||||
const _n = require('../Mediator')
|
||||
.getUser()
|
||||
.get(Key.POSTS_NEW)
|
||||
.set(
|
||||
// @ts-expect-error
|
||||
newPost,
|
||||
ack => {
|
||||
if (ack.err && typeof ack.err !== 'number') {
|
||||
rej(new Error(ack.err))
|
||||
} else {
|
||||
res(_n._.get)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return [postID, newPost]
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string[]} tags
|
||||
* @param {string} title
|
||||
|
|
@ -1312,27 +1356,24 @@ const createPost = async (tags, title, content) => {
|
|||
)
|
||||
})
|
||||
|
||||
/** @type {string} */
|
||||
const postID = await new Promise((res, rej) => {
|
||||
const _n = require('../Mediator')
|
||||
const [postID, newPost] = await createPostNew(tags, title, content)
|
||||
|
||||
await Common.makePromise((res, rej) => {
|
||||
require('../Mediator')
|
||||
.getUser()
|
||||
.get(Key.WALL)
|
||||
.get(Key.PAGES)
|
||||
.get(pageIdx)
|
||||
.get(Key.POSTS)
|
||||
.set(
|
||||
{
|
||||
date: Date.now(),
|
||||
status: 'publish',
|
||||
tags: tags.join('-'),
|
||||
page: pageIdx,
|
||||
title
|
||||
},
|
||||
.get(postID)
|
||||
.put(
|
||||
// @ts-expect-error
|
||||
newPost,
|
||||
ack => {
|
||||
if (ack.err && typeof ack.err !== 'number') {
|
||||
rej(new Error(ack.err))
|
||||
} else {
|
||||
res(_n._.get)
|
||||
res()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
@ -1354,52 +1395,6 @@ const createPost = async (tags, title, content) => {
|
|||
})
|
||||
}
|
||||
|
||||
const contentItems = require('../Mediator')
|
||||
.getUser()
|
||||
.get(Key.WALL)
|
||||
.get(Key.PAGES)
|
||||
.get(pageIdx)
|
||||
.get(Key.POSTS)
|
||||
.get(postID)
|
||||
.get(Key.CONTENT_ITEMS)
|
||||
|
||||
try {
|
||||
await Promise.all(
|
||||
content.map(
|
||||
ci =>
|
||||
new Promise(res => {
|
||||
// @ts-ignore
|
||||
contentItems.set(ci, ack => {
|
||||
if (ack.err && typeof ack.err !== 'number') {
|
||||
throw new Error(ack.err)
|
||||
}
|
||||
|
||||
res()
|
||||
})
|
||||
})
|
||||
)
|
||||
)
|
||||
} catch (e) {
|
||||
await new Promise(res => {
|
||||
require('../Mediator')
|
||||
.getUser()
|
||||
.get(Key.WALL)
|
||||
.get(Key.PAGES)
|
||||
.get(pageIdx)
|
||||
.get(Key.POSTS)
|
||||
.get(postID)
|
||||
.put(null, ack => {
|
||||
if (ack.err && typeof ack.err !== 'number') {
|
||||
throw new Error(ack.err)
|
||||
}
|
||||
|
||||
res()
|
||||
})
|
||||
})
|
||||
|
||||
throw e
|
||||
}
|
||||
|
||||
const loadedPost = await new Promise(res => {
|
||||
require('../Mediator')
|
||||
.getUser()
|
||||
|
|
|
|||
|
|
@ -62,3 +62,5 @@ exports.TOTAL_TIPS = 'totalTips'
|
|||
exports.TIPS_PAYMENT_STATUS = 'tipsPaymentStatus'
|
||||
|
||||
exports.PROFILE_BINARY = 'profileBinary'
|
||||
|
||||
exports.POSTS_NEW = 'posts'
|
||||
|
|
|
|||
|
|
@ -6021,10 +6021,10 @@ shellwords@^0.1.1:
|
|||
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
|
||||
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==
|
||||
|
||||
shock-common@^13.0.1:
|
||||
version "13.0.1"
|
||||
resolved "https://registry.yarnpkg.com/shock-common/-/shock-common-13.0.1.tgz#f0916e51e63311b90509e5831896abc7c9febbcf"
|
||||
integrity sha512-lXyS1PFrQzE3yPvnPxACkQKTLuuu52s4gqw4hZ9vmmlJX3fh8cV+jZ9E1/zblyxPayZhjQPvEX13NZD2xDDwiQ==
|
||||
shock-common@^14.2.0:
|
||||
version "14.2.0"
|
||||
resolved "https://registry.yarnpkg.com/shock-common/-/shock-common-14.2.0.tgz#b9d78d7235d84c9aaffb3d42a5db2583dec43763"
|
||||
integrity sha512-kLPAgpJNQekHAfiwPj+xVR7ReIPsi37mACpmk6YF7YIx7/jTQZYWxN+YQgQnrIlw8ELPj6igj+f6w310fmxOgA==
|
||||
dependencies:
|
||||
immer "^6.0.6"
|
||||
lodash "^4.17.19"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue