Hey guys? im newbie on node so i want to make a custom file uploader button to upload for example ".pdf" extensions at the main page not into replies/topics. you guys know if there are any guide o plugin than i take as guide?, second question is if i able to do this just with the nodebb core or its not possible and i need to use dependencies? Thanks in advance 🙂
Use method from library.js in main.js ( static js file )
-
Hi,
I have a problem while using Quickstart Plugin for NodeBB
In library JS I wan to add:plugin.testMethod = function () { console.log('test method'); };
or:
const User = module.parent.require('./user'); plugin.getUserData = User.getUserData;
how I can make use of it in main.js ?
In$(document).ready(function () {
thanks
-
I don't believe you can do that since what you're asking for is using server side code on the client. To do that, the entire stack would need to be available on the client and everything it does. Basically running NodeBB on the client.
What you could do is set up your own socket and return the desired data that way.
In your library.js file:
const pluginSockets = require.main.require('./src/socket.io/plugins'); // This will add to the sockets object used by NodeBB core pluginSockets.customFunc = ((socket, dataDoToFetch, done) => { const response = 'This response is only a string but it can be whatever you want'; done(null, response); });
Then client side:
socket.emit('plugins.customFunc', dataDoToFetch, (err, data) => { if (err) console.log('My socket customFunc', err, data); else console.log('Do stuff with this', data); });
I cannot guarantee that this will work out of the box since my setup involves a bit more complexity, but this is the basic idea. Give it a shot!
Suggested Topics
Copyright © 2022 NodeBB | Contributors