-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add unsplash-js, isomorphic-fetch * /unsplash route/handling * RandomImage use unsplash api * Implement Photographer accredidation * Add referral link * Fetch photographer profile_url from unsplash api * Change credit copy * Add PhotoCredit component
- Loading branch information
Showing
8 changed files
with
167 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
|
||
export default ({ photographer }) => ( | ||
<div className="photo-credit"> | ||
Photo by{' '} | ||
<a href={`${photographer.profile_url}?utm_source=carbon&utm_medium=referral`}> | ||
{photographer.name} | ||
</a> | ||
<style jsx> | ||
{` | ||
.photo-credit { | ||
cursor: unset; | ||
user-select: none; | ||
text-align: left; | ||
font-size: 10px; | ||
color: #aaa; | ||
margin-bottom: -2px; | ||
} | ||
.photo-credit a { | ||
cursor: pointer; | ||
text-decoration: underline; | ||
} | ||
`} | ||
</style> | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require('isomorphic-fetch') | ||
const { default: Unsplash, toJson } = require('unsplash-js') | ||
|
||
const WALLPAPER_COLLECTION_ID = 136026 | ||
|
||
const client = new Unsplash({ | ||
applicationId: process.env.UNSPLASH_ACCESS_KEY, | ||
secret: process.env.UNSPLASH_SECRET_KEY, | ||
callbackUrl: process.env.UNSPLASH_CALLBACK_URL | ||
}) | ||
|
||
const parseImageResult = img => ({ | ||
id: img.id, | ||
photographer: { | ||
name: img.user.name, | ||
profile_url: img.user.links.html | ||
}, | ||
url: img.urls.small | ||
}) | ||
|
||
const getRandomImages = () => | ||
client.photos | ||
.getRandomPhoto({ | ||
collections: [WALLPAPER_COLLECTION_ID], | ||
count: 20 | ||
}) | ||
.then(toJson) | ||
.then(imgs => imgs.map(parseImageResult)) | ||
|
||
const downloadImage = imageId => | ||
client.photos | ||
.getPhoto(imageId) | ||
.then(toJson) | ||
.then(client.photos.downloadPhoto) | ||
.then(toJson) | ||
|
||
module.exports = { | ||
randomImages: (req, res) => getRandomImages().then(imgs => res.json(imgs)), | ||
downloadImage: (req, res) => downloadImage(req.params.imageId).then(url => res.json(url)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters