Implemented GelbooruApiService
This commit is contained in:
parent
2f7b1cc07d
commit
953dcfe38b
|
@ -0,0 +1,42 @@
|
||||||
|
export default interface GelbooruApiResponse {
|
||||||
|
"@attributes": Attributes
|
||||||
|
post: Post[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Attributes {
|
||||||
|
limit: number
|
||||||
|
offset: number
|
||||||
|
count: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Post {
|
||||||
|
id: number
|
||||||
|
created_at: string
|
||||||
|
score: number
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
md5: string
|
||||||
|
directory: string
|
||||||
|
image: string
|
||||||
|
rating: string
|
||||||
|
source: string
|
||||||
|
change: number
|
||||||
|
owner: string
|
||||||
|
creator_id: number
|
||||||
|
parent_id: number
|
||||||
|
sample: number
|
||||||
|
preview_height: number
|
||||||
|
preview_width: number
|
||||||
|
tags: string
|
||||||
|
title: string
|
||||||
|
has_notes: string
|
||||||
|
has_comments: string
|
||||||
|
file_url: string
|
||||||
|
preview_url: string
|
||||||
|
sample_url: string
|
||||||
|
sample_height: number
|
||||||
|
sample_width: number
|
||||||
|
status: string
|
||||||
|
post_locked: number
|
||||||
|
has_children: string
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
export default interface GelbooruServiceResponse {
|
||||||
|
posts: GelbooruPostResponse[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GelbooruPostResponse {
|
||||||
|
url: string;
|
||||||
|
tags: string[];
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
interface IImageData {
|
export default interface Image {
|
||||||
url: string;
|
url: string;
|
||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
import GelbooruServiceResponse from "../models/GelbooruServiceResponse";
|
||||||
|
import GelbooruApiResponse from "../models/GelbooruApiResponse";
|
||||||
|
|
||||||
|
class GelbooruApiService {
|
||||||
|
async get(): Promise<GelbooruServiceResponse> {
|
||||||
|
const limit = 100;
|
||||||
|
const url: string = `https://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=${limit}&json=1&tags=2girls+sleeping`
|
||||||
|
|
||||||
|
const response: GelbooruApiResponse = await fetch(url)
|
||||||
|
.then(res => {
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error("Error fetching images");
|
||||||
|
} else {
|
||||||
|
res.json();
|
||||||
|
}
|
||||||
|
}) as GelbooruApiResponse;
|
||||||
|
|
||||||
|
return { posts: response.post.map(post => ({ url: post.file_url, tags: post.tags.split(" ") })) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new GelbooruApiService();
|
Loading…
Reference in New Issue