-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added booru classes, booru type selector, server select, cors update …
…on server change, custom posts interface
- Loading branch information
Showing
14 changed files
with
282 additions
and
144 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,34 @@ | ||
import { BooruPostState } from "@/store/posts/posts.store"; | ||
import { App } from "vue"; | ||
import { VueAxiosInstance } from "../vue-axios/axios-typings"; | ||
import { createAxiosInstance } from "../vue-axios/axiosInstace"; | ||
export type BooruType = 'danbooru_v2' | 'danbooru_php'; | ||
export interface BooruHttpOptions { | ||
[key: string]: any; | ||
} | ||
export interface BooruContext { | ||
options: BooruOptions; | ||
vue: App<any>; | ||
httpClient: VueAxiosInstance; | ||
} | ||
export interface BooruHttp { | ||
get( | ||
page: number, | ||
options?: BooruHttpOptions | ||
): Promise<BooruPostState[]>; | ||
} | ||
export interface BooruOptions { | ||
auth?: { login: string; password: string }; | ||
origin?: string; | ||
} | ||
export class Booru implements BooruContext { | ||
options: any; | ||
vue: App<any>; | ||
httpClient: VueAxiosInstance; | ||
constructor(url: string, options?: Partial<BooruOptions>) { | ||
this.options = { ...(options || {}), origin: new URL(url).origin }; | ||
this.httpClient = createAxiosInstance({ | ||
baseURL: url, | ||
}); | ||
} | ||
} |
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,51 @@ | ||
import { BooruPostState } from "@/store/posts/posts.store"; | ||
import { Booru, BooruHttp, BooruHttpOptions, BooruOptions, BooruType } from "./Booru"; | ||
|
||
export class DanbooruHostV2 extends Booru { | ||
static typeName: BooruType = "danbooru_v2"; | ||
constructor(url: string, options?: Partial<BooruOptions>) { | ||
super(url, options); | ||
} | ||
|
||
async get(page: number = 1, args: BooruHttpOptions) { | ||
return await this.httpClient | ||
.$get(`/posts.json`, { | ||
params: { | ||
[`search[name_matches]`]: args?.q || "*", | ||
page, | ||
}, | ||
}) | ||
.then((x) => { | ||
if (x?.length > 0) { | ||
return x.map( | ||
({ | ||
id, | ||
image_height: height, | ||
image_width: width, | ||
md5: hash, | ||
score, | ||
tags_string: tags, | ||
file_url: image, | ||
large_file_url: sample, | ||
preview_file_url: thumbnail | ||
}: any) => { | ||
const next: BooruPostState = { | ||
id, | ||
height, | ||
width, | ||
hash, | ||
score, | ||
tags: tags?.split(" "), | ||
image, | ||
sample, | ||
thumbnail, | ||
source: image | ||
}; | ||
return next; | ||
} | ||
); | ||
} | ||
return []; | ||
}); | ||
} | ||
} |
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,60 @@ | ||
import { BooruPostState } from "@/store/posts/posts.store"; | ||
import { Booru, BooruContext, BooruOptions, BooruType } from "./Booru"; | ||
|
||
export class DanbooruHostPHP extends Booru { | ||
static typeName: BooruType = "danbooru_php"; | ||
readonly defaultParams: { [key: string]: any } = { | ||
page: "dapi", | ||
json: 1, | ||
s: "post", | ||
q: "index", | ||
}; | ||
constructor(url: string, options?: Partial<BooruOptions>) { | ||
super(url, options); | ||
} | ||
|
||
async get(page: number = 1): Promise<BooruPostState[]> { | ||
return await this.httpClient | ||
.$get(`/index.php`, { | ||
params: { | ||
...this.defaultParams, | ||
pid: page, | ||
}, | ||
}) | ||
.then((x) => { | ||
if (x?.length > 0) { | ||
return x.map( | ||
({ | ||
id, | ||
height, | ||
width, | ||
directory, | ||
hash, | ||
score, | ||
tags, | ||
image, | ||
}: any) => { | ||
const next: any = { | ||
id, | ||
directory, | ||
height, | ||
width, | ||
hash, | ||
score, | ||
tags: tags?.split(" "), | ||
image, | ||
}; | ||
next.imageId = image.match(/^(.*)\./)[1]; | ||
if (next.imageId) { | ||
next.thumbnail = `${this.options.origin}/thumbnails/${directory}/thumbnail_${next.imageId}.jpg`; | ||
next.sample = `${this.options.origin}/samples/${directory}/sample_${next.imageId}.jpg`; | ||
next.source = `${this.options.origin}/images/${directory}/${image}`; | ||
} | ||
return next as BooruPostState[]; | ||
} | ||
); | ||
} | ||
return x; | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.