Skip to content

Commit

Permalink
Expand the IUrl type into IRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Bionus committed May 14, 2022
1 parent b7b6adc commit 042b384
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/sites/Sankaku/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const source: ISource = {
auth: [],
maxLimit: 200,
search: {
url: (query: ISearchQuery, opts: IUrlOptions, previous: IPreviousSearch | undefined): IUrl => {
url: (query: ISearchQuery, opts: IUrlOptions, previous: IPreviousSearch | undefined): IRequest => {
const baseUrl = opts.baseUrl
.replace("//chan.", "//capi-v2.")
.replace("//idol.", "//iapi.");
Expand Down
41 changes: 31 additions & 10 deletions src/sites/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ interface IPool {
}

/**
* Object representing a generated URL.
* Object representing an HTTP request.
*
* Alternative to returning a simple string when we also want to return HTTP headers.
* Alternative to returning a simple string URL when we also want to return HTTP headers or use POST requests.
*/
interface IUrl {
interface IRequestBase {
/**
* The URL to load.
*/
Expand All @@ -184,6 +184,27 @@ interface IUrl {
headers?: { [key: string]: string };
}

interface IRequestGet extends IRequestBase {
/**
* The HTTP verb to use for this request. GET or POST.
*/
method?: "GET";
}

interface IRequestPost extends IRequestBase {
/**
* The HTTP verb to use for this request. GET or POST.
*/
method: "POST";

/**
* The data to send with the POST request.
*/
data?: string;
}

type IRequest = IRequestGet | IRequestPost;

/**
* An object reprensenting an error.
*/
Expand Down Expand Up @@ -742,7 +763,7 @@ interface IApi {
*/
parseInput?: boolean;
parseErrors?: boolean;
url: (query: ISearchQuery, opts: IUrlOptions, previous: IPreviousSearch | undefined) => IUrl | IError | string;
url: (query: ISearchQuery, opts: IUrlOptions, previous: IPreviousSearch | undefined) => IRequest | IError | string;
parse: (src: string, statusCode: number) => IParsedSearch | IError;
};

Expand All @@ -752,7 +773,7 @@ interface IApi {
details?: {
parseErrors?: boolean;
fullResults?: boolean;
url: (id: string, md5: string, opts: IUrlDetailsOptions) => IUrl | IError | string;
url: (id: string, md5: string, opts: IUrlDetailsOptions) => IRequest | IError | string;
parse: (src: string, statusCode: number) => IParsedDetails | IImage | IError;
};

Expand All @@ -761,7 +782,7 @@ interface IApi {
*/
gallery?: {
parseErrors?: boolean;
url: (query: IGalleryQuery, opts: IUrlOptions) => IUrl | IError | string;
url: (query: IGalleryQuery, opts: IUrlOptions) => IRequest | IError | string;
parse: (src: string, statusCode: number) => IParsedGallery | IError;
};

Expand All @@ -770,7 +791,7 @@ interface IApi {
*/
tagTypes?: {
parseErrors?: boolean;
url: () => IUrl | IError | string;
url: () => IRequest | IError | string;
parse: (src: string, statusCode: number) => IParsedTagTypes | IError;
} | false;

Expand All @@ -779,7 +800,7 @@ interface IApi {
*/
tags?: {
parseErrors?: boolean;
url: (query: ITagsQuery, opts: IUrlOptions) => IUrl | IError | string;
url: (query: ITagsQuery, opts: IUrlOptions) => IRequest | IError | string;
parse: (src: string, statusCode: number) => IParsedTags | IError;
};

Expand All @@ -788,7 +809,7 @@ interface IApi {
*/
check?: {
parseErrors?: boolean;
url: () => IUrl | IError | string;
url: () => IRequest | IError | string;
parse: (src: string, statusCode: number) => boolean | IError;
};
}
Expand Down Expand Up @@ -884,7 +905,7 @@ interface IDownloader {
name: string;
handlers: Array<{
regexes: string[];
url: (url: string) => IUrl | IError | string;
url: (url: string) => IRequest | IError | string;
parse: (src: string, statusCode: number) => IDownloadable | IError;
}>;
}
Expand Down

0 comments on commit 042b384

Please sign in to comment.