A question regarding my next plugin



  • @julian Apparently, you can change

    http://api.discogs.com/image/R-90-5920911-1406378530-1731.jpeg

    to http://s.pixogs.com/image/R-90-5920911-1406378530-1731.jpeg

    And you get the correct image, but I'm not sure how that would be changed, as the API gives you the full URL.


  • GNU/Linux Admin

    var imageUrl = whatever;
    imageUrl.replace('api.discogs', 's.pixogs');
    


  • @julian Yes that would work. 😆



  • @julian said:

    var imageUrl = whatever;
    imageUrl.replace('api.discogs', 's.pixogs');
    

    Object #<Object> has no method 'replace' 😞

    I didn't actually use whatever, but it was either a not defined error, or this one. I also tried using things like

    $('img[src="http://api.discogs.com"]').attr('src','http://s.pixogs.com');

    But nothing changed.


  • GNU/Linux Admin

    Sounds like the image url isn't actually a string... try typeof imageUrl to find out what it is.



  • @julian What do I do with that? 😆 We can't all be as smart as you Julian. 😛


  • GNU/Linux Admin

    Ah yes... compliments can only get you so far 😆

    var imageUrl = whatever;
    // imageUrl.replace('api.discogs', 's.pixogs');
    console.log('@@@@@ omgomgomg, the image is of type: ', typeof imageUrl);
    

    😛

    It should be a string. It seems it isn't. Maybe it's an Array?



  • @julian Can I just clarify where the best place to put this is? Also, whatever; is undefined. 🙂

    Ok, so I did

    var imageUrl = [];
    // imageUrl.replace('api.discogs', 's.pixogs');
    console.log('@@@@@ omgomgomg, the image is of type: ', typeof imageUrl);
    

    and it comes back as object.

    Same if I do {}

    Everything else comes back as undefined. I even tried worknowplskthx


  • GNU/Linux Admin

    Mmm.. this is what I get back from discogs (it's in the albumData variable now):

    { style: [ 'Drum n Bass' ],
      thumb: 'http://api.discogs.com/image/R-90-3514574-1343107301-6843.jpeg',
      format: [ 'Vinyl', 'LP' ],
      country: 'UK, Europe & US',
      ...
    

    So, you can get the image url: var imageUrl = albumData.thumb

    ... and replace it with the new CDN url: imageUrl = imageUrl.replace('api.discogs', 's.pixogs');

    ... or all-in-one: var imageUrl = albumData.thumb.replace('api.discogs', 's.pixogs'); 😄



  • @julian And where's the best place to add this? I'm getting albumData is undefined. 😞


  • GNU/Linux Admin



  • Okay, I got it.

    I did this instead:

    callback(null, {
                    uri: albumData.uri,
                    thumbnail: albumData.thumb.replace('api.discogs.com/image/R-90-', 's.pixogs.com/image/R-'),
                    catno: albumData.catno,
                    title: albumData.title,
                    style: Array.isArray(albumData.style) ? albumData.style[0] : albumData.style,
                    label: Array.isArray(albumData.label) ? albumData.label[0] : albumData.label,
                    year: albumData.year
                });


  • OK, works great, one teeny tiny issue.

    How do I stop it crashing while people type the discog number in?

    TypeError: Cannot read property 'uri' of undefined
    at Request._callback (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:30:35)
    at Request.self.callback (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:123:22)
    at Request.emit (events.js:98:17)
    at Request.<anonymous> (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:1047:14)
    at Request.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:998:12)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:929:16
    at process._tickDomainCallback (node.js:463:13)
    

    Should add that's the first callback action.

    As the api responds with 200, even if there's no data. Is there was way of backing out if uri is undefined. Rather than crashing. 😆


  • Admin

    Maybe

      var albumData = JSON.parse(body).results[0];
    
      if (!albumData) {
        return callback(null, {});
      }
    
      callback(null, {
        uri: albumData.uri,

  • GNU/Linux Admin

    If all discog numbers follow a pattern, you can also tailor the regular expression to only evaluate to true if a certain condition is met (character length, etc)



  • @julian Unfortunately they weren't, but @psychobunny's suggestion worked a treat.


Log in to reply
 

Suggested Topics

  • 2
  • 16
  • 2
  • 5
  • 10
| |