• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

[nodebb-plugin-imgbed] Image Embedding with only a URL

Scheduled Pinned Locked Moved NodeBB Plugins
imgbedimageembedplugin
39 Posts 13 Posters 20.1k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by Bri
    #1

    Post (hotlink) an image into the forum by just pasting a URL, way easier than downloading an image only to upload it again.

    Current version on npm is 1.0.2!
    If you want uploading, take a look at @barisusakli 's imgur plugin.

    Git Repository

    ...or, run

    npm install nodebb-plugin-imgbed
    

    Updates:

    • I fixed the ACP page to look less terrible
    • You now have the option to choose other syntaxes to parse to (bbcode, html)
    • The preview window now renders correctly.
    1 Reply Last reply
    3
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    wrote on last edited by
    #2

    Nice plugin @BDHarrington7! 🙂

    1 Reply Last reply
    0
  • C Offline
    C Offline
    Chris
    wrote on last edited by
    #3

    Nice plugin. One suggestion I'd make is that if someone posts a hotlink to an image that it either downloads it to the forum first, then displays the image, or if an Imgur api key is active it sends it to imgur then links it from there.

    The only reason I suggest this is so often on so many forums old historical images that were hotlinked are deleted or no longer accessible. Would be nice to preserve information including images wherever possible.

    Nice work though.

    1 Reply Last reply
    0
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    wrote on last edited by
    #4

    Ah yeah, I agree! Github does the same. Our readme has imgur links, but when Github parses it, it autouploads it to their own CDN.

    1 Reply Last reply
    0
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by
    #5

    That was one of the future goals I had for this plugin, actually 🙂

    @Julian could you point me in the right direction for interfacing with the upload functionality of the forum?

    Also on another note, I noticed that the composition window has a message at the bottom saying to "Upload images by dragging and dropping them", but I don't see that in my version (0.2.1) of NodeBB, is that a plugin?

    1 Reply Last reply
    0
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    wrote on last edited by
    #6

    Ah, that functionality is available when you associate your imgur client ID with NodeBB. Otherwise the feature is disabled -- as should that message!

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #7

    That message only shows up when you enter a imgur client ID in the admin/settings section.

    1 Reply Last reply
    1
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by
    #8

    I know I have access to this __default variable within the plugin, but that only gives me access to the root directory of the plugin. Is there a way to get to the actual uploads directory from a plugin?

    1 Reply Last reply
    0
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    wrote on last edited by julian
    #9

    @bdharrington7, try this:

    var nconf = module.parent.require('nconf'),
        uploadPath = nconf.get('upload_path'),    // this
        absolutePath = path.join(nconf.get('base_dir'), nconf.get('upload_path');    // or alternatively, this
    
    1 Reply Last reply
    0
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by
    #10

    @julian Thanks!

    Now I'm seeing some weird behavior, I'm requiring the spawn child_process now, and calling curl, but when I load the forum (or when supervisor reloads it), it crashes 3-4 times before staying alive, and it's these kind of error messages:

    NodeBB/src/webserver.js:376
    		var footer = templates.footer.parse({
    		                              ^
    TypeError: Cannot call method 'parse' of undefined
    at module.exports.init.translator.translate.templates.logout (~/NodeBB/src/webserver.js:376:34)
    at Object.Plugins.fireHook (~/NodeBB/src/plugins.js:256:5)
    at module.exports.init (~/NodeBB/src/webserver.js:375:11)
    at Object.templates.ready (~/NodeBB/public/src/templates.js:47:5)
    at EventEmitter.nconf.file.file (~/NodeBB/app.js:124:18)
    at EventEmitter.g (events.js:185:14)
    at EventEmitter.emit (events.js:115:20)
    at Plugins.init (~/NodeBB/src/plugins.js:42:23)
    at Plugins.reload (~/NodeBB/src/plugins.js:89:5)
    at async.iterator.fn (~/NodeBB/node_modules/async/lib/async.js:579:34)
    

    DEBUG: Program node app exited with code 1

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #11

    Can you post the code that causes the crash?

    1 Reply Last reply
    0
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by Bri
    #12

    Sure, here's the code snippet, from my library.js:

    fs.exists(fullWgetPath, function(exist){ 
        if (!exist){
            console.log ("File not found for " + fullRelPath);   // seeing weird behavior here, crashes a few times and then loads??
            var file = fs.createWriteStream( fullWgetPath );
            var curl = spawn('curl', [rawUrl]);
            curl.stdout.on('data', function(data) { file.write(data); });
            curl.stdout.on('end', function(data) {
                file.end();
                console.log("File downloaded! " + rawUrl);
            });
            curl.on('exit', function(code) {
                if (code != 0) {
                    console.log('Failed: ' + code);
                }
            });
            // var wget = "wget " + rawUrl + " -O " + fullWgetPath;
            // var child = exec(wget, function (err, stdout, stderr){
            //     if (err){
            //         console.log(constants.name + ": Error wget-ing " + rawUrl);
            //         console.log(err);
            //     }
            //     else {
            //         console.log(constants.name + ": Successfully downloaded " + rawUrl + stdout);
            //     }
            // });
        }
        else {
            console.log("file exists: " + fullWgetPath);
        }
    });
    
    1 Reply Last reply
    0
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by Bri
    #13

    I've made a few improvements to the plugin, including allowing custom extensions to be specified, and uploading to the server when an image is linked. I had some issues when in the downloading case: The post would be parsed, and the local url would be returned, but it was before the file was actually downloaded, so the image would show up as broken when you post an image. The way I resolved it was using the websockets, and signaling the client when the file was finished downloading.

    I welcome any comments or concerns about the code, especially before I publish it to npm. I do still have a few more ideas for this plugin (progress bar, maybe making an option where the conversion to a local url can be made permanent, imgur uploading)... I remember that @psychobunny mentioned incorporating a CDN but that sounds like something for a separate plugin, to handle all other types of uploads.

    1 Reply Last reply
    0
  • C Offline
    C Offline
    Chris
    wrote on last edited by
    #14

    @BDHarrington7 excited for the downloading linked images. If an imgur api is specified does it move it over to imgur?

    1 Reply Last reply
    0
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by
    #15

    @Chris Not yet, soon! 🙂

    ? 1 Reply Last reply
    0
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by
    #16

    @baris I did find the problem, it was stupid. I was staying up too late when I introduced the bug that caused the crash.

    1 Reply Last reply
    0
  • BriB Offline
    BriB Offline
    Bri Community Rep
    wrote on last edited by
    #17

    Also, is there a global debug flag that you can reference on the server side?

    1 Reply Last reply
    0
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    wrote on last edited by
    #18

    @BDHarrington7 -- start nodebb using ./nodebb dev. This will set the NODE_ENV environment variable to "development"

    1 Reply Last reply
    1
  • S Offline
    S Offline
    Scuzz
    wrote on last edited by
    #19

    Isn't this possible with markdown anyway?

    1 Reply Last reply
    0
  • SchamperS Offline
    SchamperS Offline
    Schamper Plugin & Theme Dev
    wrote on last edited by Schamper
    #20

    @Scuzz said:

    Isn't this possible with markdown anyway?

    Ye, you should be able to embed an image using ![alt](link)
    Like so:
    Much stylish

    1 Reply Last reply
    1

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development