A question regarding my next plugin



  • I'm making a plugin that links to the discogs api using most of @julian's xkcd plugin.

    I'm getting the following when I try to activate the plugin:

    error: TypeError: Cannot read property '_locals' of undefined
    at Object.app.render (/home/a_5mith/35hz/node_modules/express/lib/application.js:486:14)
    at Function.router.render (/home/a_5mith/35hz/src/routes/index.js:164:15)
    at /home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:52:23
    at /home/a_5mith/35hz/node_modules/async/lib/async.js:232:13
    at async.each (/home/a_5mith/35hz/node_modules/async/lib/async.js:107:20)
    at _asyncMap (/home/a_5mith/35hz/node_modules/async/lib/async.js:226:9)
    at Object.map (/home/a_5mith/35hz/node_modules/async/lib/async.js:204:23)
    at Object.Embed.parse (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:32:11)
    at /home/a_5mith/35hz/src/plugins.js:325:36
    at /home/a_5mith/35hz/node_modules/async/lib/async.js:249:13
    

    Which is where appModule.render loads the partials file for the actual content. (which exists).

    I probably should have checked first, but does your XKCD plugin work on latest? 😄

    Also the discogs api requires a User-Agent string that identifies itself – preferably something that follows RFC 1945. Not sure what to do with that information though. 😆


  • GNU/Linux Admin

    Try again after merging this PR. Keep in mind we might introduce a third type of hook, so filter:app.load might end up being static:app.load... but I'll PR again after.



  • Unfortunately, no different. 😕 Still getting the above error, even after the PR.


  • GNU/Linux Admin

    @baris says you're not up to date 😛 (with core)

    Edit Wooo, developer party

    Selection_011.png




  • Admin

    I installed your plugin, works perfectably (well it doesn't seem to do anything... but no crashes)



  • @baris said:

    I can't sleep 😪

    Join the party, it's 5:44am and it's hotter than the surface of the sun in the UK.

    @psychobunny The commit that @baris linked to got me up and running (I've not updated for a few days), now to work out why it doesn't actually do anything. 😆


  • Admin

    Your regex should look like this instead /dc#\w+/gm



  • @psychobunny Turns out I'd also forgotten to rename one of julians vars from his comic plugin, changed the regex, doesn't notice it. 😕

    EDIT: Scratch that, my logs state "getting discog info VSN018" (the cat number I entered, so it's probably the request)

    I assume this could be related to

    Also the discogs api requires a User-Agent string that identifies itself – preferably something that follows RFC 1945. 
    

    Which I don't believe I'm using.


  • Admin

    You can pass in a user-agent field into the request options

    request.get({
            url: 'http://api.discogs.com/database/search?catno=' + discogNum + '&type=release&per_page=1',
            headers: {
                'User-Agent': 'request'
            }
        },
    


  • @psychobunny

    Found that through julians Github plugin, so I did that, and now I've got

    error: TypeError: Cannot read property 'statusCode' of undefined
    at Request._callback (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:76:21)
    at self.callback (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:123:22)
    at Request.emit (events.js:95:17)
    at Request.self._buildRequest (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:355:39)
    at Request.init (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:533:10)
    at new Request (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/request.js:99:8)
    at request (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/index.js:54:11)
    at Function.request.get (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/node_modules/request/index.js:127:27)
    at getDiscog (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:70:13)
    at async.map.appModule.render.discoginfo (/home/a_5mith/35hz/node_modules/nodebb-plugin-discogs/index.js:38:13)
    

    which is

        }, function(err, response, body) {
        if (response.statusCode === 200) {
            callback(null, JSON.parse(body));


  • Check for err

    }, function(err, response, body) {
    if (!err && response.statusCode === 200) {
        callback(null, JSON.parse(body));
    } else {
        console.log(err, response);
    }


  • @baris NodeBB crashes when I try to access the category the topic is posted in. Nothing in the console.

    EDIT: Sorry missed !err, will report back shortly. 😆

    [Error: Invalid protocol: null] undefined



  • Haha no idea maybe they want https?



  • @baris That was exactly the case, earlier on I'd removed http to check something and not added it back. Ok, the page loads now, with the partial tpl file. But no data, so I'm assuming doing {results.title} and {results.year} etc (as depicted by the API), isn't how I pull the info?



  • Yeah look at the data returned when you go to that page then you can use the data in the template with {data.title} as usual.



  • Right, narrowed it down somewhat.

    returnData { uri: undefined,
    thumbnail: undefined,
    catno: undefined,
    title: undefined,
    style: undefined,
    label: undefined,
    year: undefined }


  • Now we're all awake again, I'm going to have another stab at this if anyone has any suggestions... 🙂


  • Admin

    How's it going?



  • @psychobunny About where my last post is, I couldn't work out why it doesn't seem to be connecting to the api, or if it does, I just don't know how to pull the data that I'm looking for. I know what I want, and I think I know how to get it, but the only way it doesn't crash the plugin, it gives me the undefined error above. 😢

    Basically this is the json output of what I wish to target.

    {
    "pagination": {
        "per_page": 1,
        "items": 14256,
        "page": 1,
        "urls": {
            "last": "http://api.discogs.com/database/search?per_page=1&type=release&catno=VSN018&page=14256&f=json",
            "next": "http://api.discogs.com/database/search?per_page=1&type=release&catno=VSN018&page=2&f=json"
        },
        "pages": 14256
    },
    "results": [
        {
            "style": [
                "Drum n Bass"
            ],
            "thumb": "http://api.discogs.com/image/R-90-5844720-1404286626-1507.jpeg",
            "format": [
                "Vinyl",
                "12\"",
                "45 RPM",
                "EP",
                "File",
                "MP3"
            ],
            "country": "Netherlands",
            "title": "Noisia - Purpose EP",
            "uri": "/Noisia-Purpose-EP/release/5844720",
            "community": {
                "have": 17,
                "want": 27
            },
            "label": [
                "Vision Recordings"
            ],
            "catno": "VSN018",
            "year": "2014",
            "genre": [
                "Electronic"
            ],
            "resource_url": "http://api.discogs.com/releases/5844720",
            "type": "release",
            "id": 5844720
        }
    ]
    }
    

    But

    returnData = {
                    results: {
                        uri: results.uri,
                        thumbnail: results.thumb,
                        catno: results.catno,
                        title: results.title,
                        style: results.style,
                        label: results.label,
                        year: results.year
                    }
                };
    

    Returns undefined for everything, so I'd assume it doesn't connect. 🙂


Log in to reply
 

Suggested Topics

| |