Skip to content

Commit

Permalink
unsplash: rearrange code
Browse files Browse the repository at this point in the history
  • Loading branch information
linroid committed Dec 10, 2019
1 parent 2154baa commit 8933a9a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
56 changes: 29 additions & 27 deletions unsplash/components/index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
module.exports = {
type: 'list',
type: "list",
translucent: true,
actions: [{
title: '官网',
route: $route('https://unsplash.com/')
}],

async fetch({ page }) {
page = page || 1
let quality = $prefs.get('quality')
let photos = await unsplash.photos.listPhotos(page, 15, "latest")
let photos = await unsplash.photos
.listPhotos(page, 15, "latest")
.then(res => res.json())
return {
nextPage: page + 1,
items: photos.map((item) => {
let image_url = item.urls.regular;
if (quality == 'full') {
image_url = item.urls.full
} else if (quality == 'raw') {
image_url = item.urls.raw
}
return {
title: item.description,
route: $route('@image', {
url: image_url,
color: item.color,
aspect: (item.width * 1.0 / item.height).toFixed(3),
}),
style: 'gallery',
summary: item.description || item.alt_description,
author: {
name: item.user.name,
avatar: item.user.profile_image.medium,
route: $route(item.user.links.html)
},
thumb: item.urls.small,
color: item.color,
aspect: (item.width * 1.0 / item.height).toFixed(3)
}
items: photos.map(photo => {
return this.convert(photo, quality)
})
}
},

convert(photo, quality) {
return {
title: photo.title,
route: $route('@image', {
url: photo.urls[quality]
}),
style: 'gallery',
summary: photo.description || photo.alt_description,
author: {
name: photo.user.name,
avatar: photo.user.profile_image.small,
route: $route(photo.user.links.html)
},
thumb: photo.urls.small,
color: photo.color,
aspect: photo.width / photo.height
}
}
}
6 changes: 3 additions & 3 deletions unsplash/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// require syntax
const Unsplash = require('unsplash-js').default;
const fetch = require('node-fetch');
const Unsplash = require('unsplash-js').default
const fetch = require('node-fetch')
const ASSESS_TOKEN = '7a96a77d719e9967f935da53784d6a3eb58a4fb174dda25e89ec69059e46c815'
$http.defaults.headers.common['Authorization'] = `Client-ID ${ASSESS_TOKEN}`
module.exports = {
fetch: fetch,
unsplash: new Unsplash({ accessKey: ASSESS_TOKEN })
}
$http.defaults.headers.common['Authorization'] = `Client-ID ${ASSESS_TOKEN}`;
2 changes: 1 addition & 1 deletion unsplash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"uuid": "8ce7453e-dc59-11e9-9d36-2a2ae2dbcce4",
"name": "@dora.js/unsplash",
"displayName": "Unsplash",
"version": "1.1.0",
"version": "1.2.0",
"author": {
"name": "linroid"
},
Expand Down

0 comments on commit 8933a9a

Please sign in to comment.