-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support random photos (#4)
- Loading branch information
Showing
7 changed files
with
53 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fetch from 'node-fetch' | ||
|
||
import { PastvuItem } from './getPastvuPhotos' | ||
|
||
export type PastvuPhotos = { | ||
result: { photos: PastvuItem[] } | ||
} | ||
export const getPastvuRandomPhotos = async (): Promise<PastvuPhotos> => { | ||
const response = await fetch( | ||
`https://pastvu.com/api2?method=photo.givePS¶ms={"cid":1,"random":true}`, | ||
) | ||
|
||
if (!response.ok) { | ||
throw new Error(`Request failed: ${response.url}: ${response.status}`) | ||
} | ||
|
||
const json = (await response.json()) as { error: { error_msg: string } } | PastvuPhotos | ||
|
||
if ('error' in json) { | ||
throw new Error(`Request failed: ${response.url}: ${json.error.error_msg}`) | ||
} | ||
|
||
return json | ||
} |
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
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