diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index b0fa8070..18b59f21 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -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} */ -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() + } + }) }) } diff --git a/src/routes.js b/src/routes.js index 8ed44da5..57211dc1 100644 --- a/src/routes.js +++ b/src/routes.js @@ -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