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

  • NodeBB

    Can you post the code that causes the crash?

  • Community Rep

    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);
        }
    });
    
  • Community Rep

    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.


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

  • Community Rep

    @Chris Not yet, soon! 🙂

  • Community Rep

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

  • Community Rep

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

  • GNU/Linux Admin

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


  • Isn't this possible with markdown anyway?

  • Plugin & Theme Dev

    @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

  • Community Rep

    Right, and the advantage that the markdown has is that the link doesn't need to have a specific format of matching the pattern of http*jpg|gif|png etc. I could change it to parse looking for img tags, and downloading those URLs


  • @BDHarrington7 said:

    @Chris Not yet, soon! 🙂

    Has there been any further updates on this? 😁

  • Admin

    Oh this is cool, I never realized that you actually fetch the image and save a copy to your server. So potentially you could do something like GitHub does (ie. host all images on your own CDN), so you don't have to worry about serving non-secure images from random sites when you're on SSL 👍

  • Community Rep

    @psychobunny said:

    ...so you don't have to worry about serving non-secure images from random sites when you're on SSL 👍

    Yep, exactly. Well that and I didn't like that an image takedown would make my forum look crappy.

    @Albus are you referring to the upload capability or the imgurl capability?


  • @BDHarrington7 Is the imgur upload still something you are looking at, or are you done with the plugin for now?


  • @Albus are you referring to the upload capability or the imgurl capability?

    Sorry for late reply - life happens and I'm just getting another chance to do some testing with NodeBB.
    I'm referring to the auto-imgur upload which @Punkbob has just referenced.

  • Community Rep

    I hadn't had the chance to look into any sort of integration with imgur, so sorry about that! If anyone wants to take a stab at that for now I would be paying attention to any pull requests


  • Webm support Plox.


  • any update on integration with imgur upload through api function?


  • I found a bug, but when I headed over to GitHub the files are totally different so I'll tell you here...

    Valid URL: http://oyster.ignimgs.com/wordpress/stg.ign.com/2014/09/TWDS5_2Sht_FM3_2.jpg?q=fhye

    the above should work, but it doesn't due to the dots in stg.ign.com and the query string, I've changed the library.js file to be more liberal:

    regexStr = '<a href="(https?://.+\.(' + extensions.join('|') + ')).*">[^<]*<\/a>';

    Should anyone else have this problem, then that'll work for you!

Suggested Topics

| |