65 lines
1.4 KiB
TypeScript
65 lines
1.4 KiB
TypeScript
import { ReqUrlBuilder } from "../utils/url_builder.ts";
|
|
|
|
export const SAFEBOORU_HOST = "safebooru.org"
|
|
|
|
export interface SafebooruPostData {
|
|
preview_url: string;
|
|
sample_url: string;
|
|
file_url: string;
|
|
directory: number;
|
|
hash: string;
|
|
width: number;
|
|
height: number;
|
|
id: number;
|
|
image: string;
|
|
change: number;
|
|
owner: string;
|
|
parent_id: number;
|
|
rating: string;
|
|
sample: boolean;
|
|
sample_height: number;
|
|
sample_width: number;
|
|
score: number | null;
|
|
tags: string;
|
|
source: string;
|
|
status: string;
|
|
has_notes: boolean;
|
|
comment_count: number;
|
|
}
|
|
|
|
// https://safebooru.org/index.php?page=help&topic=dapi
|
|
export class SfbrPostsReqQueryBuilder extends ReqUrlBuilder {
|
|
override host = SAFEBOORU_HOST
|
|
override path = "/index.php"
|
|
override params = {
|
|
"page": "dapi",
|
|
"s": "post",
|
|
"q": "index",
|
|
"json": "1",
|
|
}
|
|
|
|
setPostsLimit(limit: number) {
|
|
this.setParams({ "limit": limit.toString() })
|
|
return this
|
|
}
|
|
setPageID(pid: number) {
|
|
this.setParams({ "pid": pid.toString() })
|
|
return this
|
|
}
|
|
setTags(tags: string[]) {
|
|
if (tags.length > 0) {
|
|
let hasNonEmpty = false
|
|
for (let i = 0; i < tags.length; i++) {
|
|
if (tags[i].length > 0) {
|
|
hasNonEmpty = true
|
|
break
|
|
}
|
|
}
|
|
if (!hasNonEmpty) return this
|
|
this.setParams({ "tags:": tags.join(" ") })
|
|
}
|
|
return this
|
|
}
|
|
}
|
|
|