mirror of
https://github.com/jlengrand/picasa.git
synced 2026-03-10 08:31:19 +00:00
Adding photos properties
This commit is contained in:
@@ -27,12 +27,50 @@ function getPhotos (accessToken, options, callback) {
|
||||
this.picasaRequest(accessToken, 'get', 'photo', options, (error, body) => {
|
||||
if (error) return callback(error)
|
||||
|
||||
const photos = body.feed.entry.map(entry => { return entry.content })
|
||||
const photoSchema = {
|
||||
'gphoto$id' : 'id',
|
||||
'gphoto$albumid' : 'album_id',
|
||||
'gphoto$access' : 'access',
|
||||
'gphoto$width' : 'width',
|
||||
'gphoto$height' : 'height',
|
||||
'gphoto$size' : 'size' ,
|
||||
'gphoto$checksum' : 'checksum',
|
||||
'gphoto$timestamp' : 'timestamp',
|
||||
'gphoto$imageVersion' : 'image_version',
|
||||
'gphoto$commentingEnabled' : 'commenting_enabled',
|
||||
'gphoto$commentCount' : 'comment_count',
|
||||
'content' : 'content',
|
||||
'title' : 'title',
|
||||
'summary' : 'summary'
|
||||
}
|
||||
|
||||
const photos = body.feed.entry.map(entry => {
|
||||
let photo = {}
|
||||
|
||||
Object.keys(photoSchema).forEach(schemaKey => {
|
||||
const key = photoSchema[schemaKey]
|
||||
|
||||
if (key) photo[key] = checkParam(entry[schemaKey])
|
||||
})
|
||||
|
||||
return photo
|
||||
})
|
||||
|
||||
callback(null, photos)
|
||||
})
|
||||
}
|
||||
|
||||
function checkParam (param) {
|
||||
if (!param) return ''
|
||||
if (isValidType(param)) return param
|
||||
else if (isValidType(param['$t'])) return param['$t']
|
||||
else return param
|
||||
}
|
||||
|
||||
function isValidType (value) {
|
||||
return typeof value === 'string' || typeof value === 'number'
|
||||
}
|
||||
|
||||
function getAuthURL () {
|
||||
const authenticationParams = {
|
||||
access_type : 'offline',
|
||||
|
||||
@@ -68,8 +68,10 @@ describe('Picasa', () => {
|
||||
picasa.getPhotos(accessToken, { maxResults : 1 }, (error, photos) => {
|
||||
expect(error).to.be.equals(null)
|
||||
|
||||
expect(photos[0].src).to.contain('IMG_0327.JPG')
|
||||
expect(photos[0].type).to.be.equals('image/jpeg')
|
||||
|
||||
expect(photos[0].title).to.be.equals('IMG_0327.JPG')
|
||||
expect(photos[0].content.src).to.contain('IMG_0327.JPG')
|
||||
expect(photos[0].content.type).to.be.equals('image/jpeg')
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user