Skip to content

Commit

Permalink
source: add support for Szurubooru as a source (fix #2850)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed Dec 6, 2022
1 parent 4dac955 commit 3214f95
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
Binary file added src/sites/Szurubooru/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 86 additions & 0 deletions src/sites/Szurubooru/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const map: Record<string, string> = {
"id": "id",
"created_at": "creationTime",
"md5": "checksumMD5",
"source": "source",
"rating": "safety", // FIXME
"width": "canvasWidth",
"height": "canvasHeight",
"file_url": "contentUrl",
"preview_url": "thumbnailUrl",
"tags": "tags", // FIXME (names, category, usages)
"author": "user.name",
"score": "score",
};
const safetyMap: Record<string, string> = {
"safe": "safe",
"sketchy": "questionable",
"unsafe": "explicit",
};

function buildImage(data: any): IImage {
const img: IImage = Grabber.mapFields(data, map);
img.tags = data["tags"].map((tag: any) => ({
name: tag.names[0],
type: tag.category,
count: tag.usages,
}));
img.rating = safetyMap[data["safety"]]
return img;
}

export const source: ISource = {
name: "Szurubooru",
modifiers: [],
auth: {
basic: {
type: "http_basic",
passwordType: "password",
},
token: {
type: "http_basic",
passwordType: "apiKey",
tokenType: "Token",
},
},
apis: {
json: {
name: "JSON",
auth: ["basic", "token"],
search: {
url: (query: ISearchQuery, opts: IUrlOptions): IRequest => {
const offset = (query.page - 1) * opts.limit;
return {
url: "/api/posts/?offset=" + offset + "&limit=" + opts.limit + "&query=" + query.search,
headers: {
"Accept": "application/json",
},
};
},
parse: (src: string): IParsedSearch => {
console.log(src)
const data = JSON.parse(src);
return {
images: data.results.map(buildImage),
imageCount: data.total
};
},
},
details: {
fullResults: true,
url: (id: string): IRequest => {
return {
url: "/api/post/" + id,
headers: {
"Accept": "application/json",
},
};
},
parse: (src: string): IImage => {
const data = JSON.parse(src);
return buildImage(data);
},
},
},
},
};
Empty file added src/sites/Szurubooru/sites.txt
Empty file.

0 comments on commit 3214f95

Please sign in to comment.