2024-10-19 10:00:35 +00:00
|
|
|
import { ReqUrlBuilder } from "../utils/url_builder.ts";
|
|
|
|
|
|
|
|
export const SAFEBOORU_HOST = "safebooru.org"
|
|
|
|
|
2024-10-27 09:12:11 +00:00
|
|
|
export interface SafebooruPostData {
|
2024-10-19 10:00:35 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-10-27 09:12:11 +00:00
|
|
|
// 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",
|
|
|
|
}
|
2024-10-19 10:00:35 +00:00
|
|
|
|
2024-10-27 09:12:11 +00:00
|
|
|
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
|
|
|
|
}
|
2024-10-19 10:00:35 +00:00
|
|
|
}
|
2024-10-27 09:12:11 +00:00
|
|
|
if (!hasNonEmpty) return this
|
|
|
|
this.setParams({ "tags:": tags.join(" ") })
|
2024-10-19 10:00:35 +00:00
|
|
|
}
|
2024-10-27 09:12:11 +00:00
|
|
|
return this
|
2024-10-19 10:00:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|