add delete and and page
This commit is contained in:
parent
684c186224
commit
429bb85632
2 changed files with 37 additions and 8 deletions
|
|
@ -1325,6 +1325,7 @@ const createPost = async (tags, title, content) => {
|
|||
date: Date.now(),
|
||||
status: 'publish',
|
||||
tags: tags.join('-'),
|
||||
page: pageIdx,
|
||||
title
|
||||
},
|
||||
ack => {
|
||||
|
|
@ -1435,11 +1436,25 @@ const createPost = async (tags, title, content) => {
|
|||
|
||||
/**
|
||||
* @param {string} postId
|
||||
* @param {string} page
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const deletePost = async postId => {
|
||||
await new Promise(res => {
|
||||
res(postId)
|
||||
const deletePost = async (postId, page) => {
|
||||
await new Promise((res, rej) => {
|
||||
require('../Mediator')
|
||||
.getUser()
|
||||
.get(Key.WALL)
|
||||
.get(Key.PAGES)
|
||||
.get(page)
|
||||
.get(Key.POSTS)
|
||||
.get(postId)
|
||||
.put(null, ack => {
|
||||
if (ack.err && typeof ack.err !== 'number') {
|
||||
rej(new Error(ack.err))
|
||||
} else {
|
||||
res()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2289,11 +2289,25 @@ module.exports = async (
|
|||
}
|
||||
})
|
||||
|
||||
app.delete(`/api/gun/wall/:postID`, (_, res) =>
|
||||
res.status(200).json({
|
||||
ok: 'true'
|
||||
})
|
||||
)
|
||||
app.delete(`/api/gun/wall/:postInfo`, async (req, res) => {
|
||||
try {
|
||||
const { postInfo } = req.params
|
||||
const parts = postInfo.split('&')
|
||||
const [page, postId] = parts
|
||||
if (!page || !postId) {
|
||||
throw new Error(`please provide a "postId" and a "page"`)
|
||||
}
|
||||
await GunActions.deletePost(postId, page)
|
||||
return res.status(200).json({
|
||||
ok: 'true'
|
||||
})
|
||||
} catch (e) {
|
||||
return res.status(500).json({
|
||||
errorMessage:
|
||||
(typeof e === 'string' ? e : e.message) || 'Unknown error.'
|
||||
})
|
||||
}
|
||||
})
|
||||
/////////////////////////////////
|
||||
/**
|
||||
* @template P
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue