Solved deleting posts of an account


  • Hi @baris , is there any code you can give us so that we can delete the posts by an account? (let's say user id:54321)

    Additionally, on the profile options, when I click "delete content", it actually purges the content, not deletes it. On a thread, when I "delete" a post, it just makes the post invisible but the post stays there. I think it would make more sense to say "purge content"...


  • additionally, do spiders read the content of a deleted post? do they show up on google search results?

  • NodeBB Admin

    Spiders wouldn't see deleted post content unless the spider group is given the view deleted privilege.

  • NodeBB Admin

    For deleting posts of a user something like this should work.

    /* globals require, console, process */
    
    'use strict';
    
    const nconf = require('nconf');
    
    nconf.file({
    	file: 'config.json',
    });
    
    nconf.defaults({
    	base_dir: __dirname,
    	views_dir: './build/public/templates',
    	upload_path: 'public/uploads',
    });
    
    const db = require('./src/database');
    
    const uid = '123';
    
    db.init(async (err) => {
    	const meta = require('./src/meta');
    	await meta.configs.init();
    	if (err) {
    		console.log(`NodeBB could not connect to your database. Error: ${err.message}`);
    		process.exit();
    	}
    
    	await deletePosts();
    	console.log('done');
    	process.exit();
    });
    
    async function deletePosts() {
    	const pids = await db.getSortedSetRange(`uid:${uid}:posts`, 0, -1);
    	const posts = require('./src/posts');
    	for (const pid of pids) {
    		await posts.delete(pid, 1);
    	}
    }
    

    Replace the value of uid with the target user.


  • @baris 👍 good, I checked the moderation privileges... spiders are not given "view deleted posts" privilege...

    so, technically, from the search engine results perspective, purging the post is the same as deleting post...


  • @baris thanks for the code 👍

  • Topic has been marked as solved   crazycellsC   crazycells 

Suggested Topics

  • 2
  • 2
  • 2
  • 7
  • 5
| | | |