diff --git a/packages/@uppy/companion/src/server/provider/instagram/adapter.js b/packages/@uppy/companion/src/server/provider/instagram/adapter.js index 0b504330eb..ed00ca4c6b 100644 --- a/packages/@uppy/companion/src/server/provider/instagram/adapter.js +++ b/packages/@uppy/companion/src/server/provider/instagram/adapter.js @@ -1,10 +1,3 @@ -exports.getUsername = (data) => { - // @todo implement a better way to get usernames - if (data.data && data.data.length) { - return data.data[0].user.username - } -} - exports.isFolder = (item) => { return false } diff --git a/packages/@uppy/companion/src/server/provider/instagram/index.js b/packages/@uppy/companion/src/server/provider/instagram/index.js index d3a9290163..f3d0a41fbd 100644 --- a/packages/@uppy/companion/src/server/provider/instagram/index.js +++ b/packages/@uppy/companion/src/server/provider/instagram/index.js @@ -27,7 +27,24 @@ class Instagram { logger.error(err, 'provider.instagram.list.error') return done(err) } else { - done(null, this.adaptData(body)) + this._getUsername(token, (err, username) => { + err ? done(err) : done(null, this.adaptData(body, username)) + }) + } + }) + } + + _getUsername (token, done) { + this.client + .select('users/self') + .auth(token) + .request((err, resp, body) => { + if (err || resp.statusCode !== 200) { + err = this._error(err, resp) + logger.error(err, 'provider.instagram.user.error') + return done(err) + } else { + done(null, body.data.username) } }) } @@ -109,8 +126,8 @@ class Instagram { }) } - adaptData (res) { - const data = { username: adapter.getUsername(res), items: [] } + adaptData (res, username) { + const data = { username: username, items: [] } const items = adapter.getItemSubList(res) items.forEach((item) => { data.items.push({