Skip to content

Commit

Permalink
refactor(unsplash): switch to unsplash http api
Browse files Browse the repository at this point in the history
  • Loading branch information
Buzzertech committed Jun 16, 2019
1 parent 7eb9e70 commit 1024544
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions src/image.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
export const getUnsplashUrl = (tags: string) =>
`https://source.unsplash.com/1920x1080/?nature,${encodeURIComponent(
tags.split(' ').join(',')
)}`;
import axios from 'axios';
import config from './config';

export interface IUnsplashResponse {
id: string;
created_at: string;
updated_at: string;
width: number;
height: number;
color: string;
downloads: number;
likes: number;
liked_by_user: boolean;
description: string;
urls: Record<
'raw' | 'full' | 'regular' | 'small' | 'thumb' | 'custom',
string
>;
links: Record<'self' | 'html' | 'download' | 'download_location', string>;
user: {
id: string;
updated_at: string;
username: string;
name: string;
portfolio_url: string;
bio: string;
location: string;
total_likes: number;
total_photos: number;
total_collections: number;
instagram_username: string;
twitter_username: string;
links: Record<'self' | 'html' | 'photos' | 'likes' | 'portfolio', string>;
};
}

export const getUnsplashPhoto = async (tags: string) => {
return axios.get<IUnsplashResponse>(
`https://api.unsplash.com/photos/random`,
{
params: {
client_id: config.UNSPLASH_ACCESS_KEY,
query: ['nature', ...tags.split(' ')].join(','),
orientation: 'landscape',
w: 1920,
h: 1080,
},
}
);
};

0 comments on commit 1024544

Please sign in to comment.