fix omdb and id search
This commit is contained in:
parent
1cd1b63f15
commit
4366636d9b
5 changed files with 24 additions and 490 deletions
|
|
@ -8,7 +8,7 @@ async function fetchSchema() {
|
||||||
await $('bun openapi-typescript ./src/api/schemas/GiantBomb.json -o ./src/api/schemas/GiantBomb.ts');
|
await $('bun openapi-typescript ./src/api/schemas/GiantBomb.json -o ./src/api/schemas/GiantBomb.ts');
|
||||||
|
|
||||||
// https://www.omdbapi.com/swagger.json
|
// https://www.omdbapi.com/swagger.json
|
||||||
await $('bun openapi-typescript ./src/api/schemas/OMDb.json -o ./src/api/schemas/OMDb.ts');
|
// await $('bun openapi-typescript ./src/api/schemas/OMDb.json -o ./src/api/schemas/OMDb.ts');
|
||||||
|
|
||||||
// https://github.com/internetarchive/openlibrary-api/blob/main/swagger.yaml
|
// https://github.com/internetarchive/openlibrary-api/blob/main/swagger.yaml
|
||||||
await $('bun openapi-typescript ./src/api/schemas/OpenLibrary.json -o ./src/api/schemas/OpenLibrary.ts');
|
await $('bun openapi-typescript ./src/api/schemas/OpenLibrary.json -o ./src/api/schemas/OpenLibrary.ts');
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import createClient from 'openapi-fetch';
|
import { requestUrl } from 'obsidian';
|
||||||
import { obsidianFetch } from 'src/utils/Utils';
|
|
||||||
import type MediaDbPlugin from '../../main';
|
import type MediaDbPlugin from '../../main';
|
||||||
import { GameModel } from '../../models/GameModel';
|
import { GameModel } from '../../models/GameModel';
|
||||||
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
import type { MediaTypeModel } from '../../models/MediaTypeModel';
|
||||||
|
|
@ -7,7 +6,11 @@ import { MovieModel } from '../../models/MovieModel';
|
||||||
import { SeriesModel } from '../../models/SeriesModel';
|
import { SeriesModel } from '../../models/SeriesModel';
|
||||||
import { MediaType } from '../../utils/MediaType';
|
import { MediaType } from '../../utils/MediaType';
|
||||||
import { APIModel } from '../APIModel';
|
import { APIModel } from '../APIModel';
|
||||||
import type { paths } from '../schemas/OMDb';
|
|
||||||
|
interface ErrorResponse {
|
||||||
|
Response: 'False';
|
||||||
|
Error: string;
|
||||||
|
}
|
||||||
|
|
||||||
type SearchResponse =
|
type SearchResponse =
|
||||||
| {
|
| {
|
||||||
|
|
@ -21,10 +24,7 @@ type SearchResponse =
|
||||||
Type: string;
|
Type: string;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
| {
|
| ErrorResponse;
|
||||||
Response: 'False';
|
|
||||||
Error: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type IdResponse =
|
type IdResponse =
|
||||||
| {
|
| {
|
||||||
|
|
@ -53,10 +53,7 @@ type IdResponse =
|
||||||
Production: string;
|
Production: string;
|
||||||
Website: string;
|
Website: string;
|
||||||
}
|
}
|
||||||
| {
|
| ErrorResponse;
|
||||||
Response: 'False';
|
|
||||||
Error: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export class OMDbAPI extends APIModel {
|
export class OMDbAPI extends APIModel {
|
||||||
plugin: MediaDbPlugin;
|
plugin: MediaDbPlugin;
|
||||||
|
|
@ -84,26 +81,19 @@ export class OMDbAPI extends APIModel {
|
||||||
throw new Error(`MDB | API key for ${this.apiName} missing.`);
|
throw new Error(`MDB | API key for ${this.apiName} missing.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = createClient<paths>({ baseUrl: 'https://www.omdbapi.com/' });
|
const response = await requestUrl({
|
||||||
|
url: `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`,
|
||||||
const response = await client.GET('/?s', {
|
method: 'GET',
|
||||||
params: {
|
|
||||||
query: {
|
|
||||||
s: title,
|
|
||||||
apikey: this.plugin.settings.OMDbKey,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
fetch: obsidianFetch,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.response.status === 401) {
|
if (response.status === 401) {
|
||||||
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
}
|
}
|
||||||
if (response.response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw Error(`MDB | Received status code ${response.response.status} from ${this.apiName}.`);
|
throw Error(`MDB | Received status code ${response.status} from ${this.apiName}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = response.data as SearchResponse | undefined;
|
const data = response.json as SearchResponse | undefined;
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
throw Error(`MDB | No data received from ${this.apiName}.`);
|
throw Error(`MDB | No data received from ${this.apiName}.`);
|
||||||
|
|
@ -175,26 +165,19 @@ export class OMDbAPI extends APIModel {
|
||||||
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
throw Error(`MDB | API key for ${this.apiName} missing.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = createClient<paths>({ baseUrl: 'https://www.omdbapi.com/' });
|
const response = await requestUrl({
|
||||||
|
url: `https://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`,
|
||||||
const response = await client.GET('/?i', {
|
method: 'GET',
|
||||||
params: {
|
|
||||||
query: {
|
|
||||||
i: id,
|
|
||||||
apikey: this.plugin.settings.OMDbKey,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
fetch: obsidianFetch,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.response.status === 401) {
|
if (response.status === 401) {
|
||||||
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`);
|
||||||
}
|
}
|
||||||
if (response.response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw Error(`MDB | Received status code ${response.response.status} from ${this.apiName}.`);
|
throw Error(`MDB | Received status code ${response.status} from ${this.apiName}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = response.data as IdResponse | undefined;
|
const result = response.json as IdResponse | undefined;
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw Error(`MDB | No data received from ${this.apiName}.`);
|
throw Error(`MDB | No data received from ${this.apiName}.`);
|
||||||
|
|
|
||||||
|
|
@ -1,269 +0,0 @@
|
||||||
{
|
|
||||||
"openapi": "3.0.1",
|
|
||||||
"info": {
|
|
||||||
"title": "OMDb API",
|
|
||||||
"description": "This API requires authorization, you can get a free key here: [http://omdbapi.com/apikey.aspx](http://omdbapi.com/apikey.aspx)",
|
|
||||||
"termsOfService": "http://omdbapi.com/legal.htm",
|
|
||||||
"contact": {
|
|
||||||
"email": "bfritz@fadingsignal.com"
|
|
||||||
},
|
|
||||||
"license": {
|
|
||||||
"name": "CC BY-NC 4.0",
|
|
||||||
"url": "https://creativecommons.org/licenses/by-nc/4.0/"
|
|
||||||
},
|
|
||||||
"version": "1.0"
|
|
||||||
},
|
|
||||||
"externalDocs": {
|
|
||||||
"description": "Find out more about Swagger",
|
|
||||||
"url": "http://swagger.io"
|
|
||||||
},
|
|
||||||
"servers": [
|
|
||||||
{
|
|
||||||
"url": "http://omdbapi.com/"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://omdbapi.com/"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"APIKeyQueryParam": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
{
|
|
||||||
"name": "Title Parameter",
|
|
||||||
"description": "e.g. ?t=title"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ID Parameter",
|
|
||||||
"description": "e.g. ?i=tt0000001"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Search Parameter",
|
|
||||||
"description": "e.g. ?s=title"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"paths": {
|
|
||||||
"/?t": {
|
|
||||||
"get": {
|
|
||||||
"tags": ["Title Parameter"],
|
|
||||||
"summary": "Returns the most popular match for a given title",
|
|
||||||
"operationId": "getTitle",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "t",
|
|
||||||
"in": "query",
|
|
||||||
"description": "Title of movie or series",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "y",
|
|
||||||
"in": "query",
|
|
||||||
"description": "Year of release",
|
|
||||||
"schema": {
|
|
||||||
"type": "integer"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "type",
|
|
||||||
"in": "query",
|
|
||||||
"description": "Return movie or series",
|
|
||||||
"schema": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["movie", "series"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "plot",
|
|
||||||
"in": "query",
|
|
||||||
"description": "Return short or full plot",
|
|
||||||
"schema": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["short", "full"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "r",
|
|
||||||
"in": "query",
|
|
||||||
"description": "The response type to return",
|
|
||||||
"schema": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["json", "xml"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "callback",
|
|
||||||
"in": "query",
|
|
||||||
"description": "JSONP callback name",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Successful operation",
|
|
||||||
"content": {}
|
|
||||||
},
|
|
||||||
"401": {
|
|
||||||
"description": "Not authenticated",
|
|
||||||
"content": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"APIKeyQueryParam": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/?i": {
|
|
||||||
"get": {
|
|
||||||
"tags": ["ID Parameter"],
|
|
||||||
"summary": "Returns a single result based on the ID provided",
|
|
||||||
"operationId": "getId",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "i",
|
|
||||||
"in": "query",
|
|
||||||
"description": "A valid IMDb ID (e.g. tt0000001)",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "plot",
|
|
||||||
"in": "query",
|
|
||||||
"description": "Return short or full plot",
|
|
||||||
"schema": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["short", "full"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "r",
|
|
||||||
"in": "query",
|
|
||||||
"description": "The response type to return",
|
|
||||||
"schema": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["json", "xml"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "callback",
|
|
||||||
"in": "query",
|
|
||||||
"description": "JSONP callback name",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Successful operation",
|
|
||||||
"content": {}
|
|
||||||
},
|
|
||||||
"401": {
|
|
||||||
"description": "Not authenticated",
|
|
||||||
"content": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"APIKeyQueryParam": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/?s": {
|
|
||||||
"get": {
|
|
||||||
"tags": ["Search Parameter"],
|
|
||||||
"summary": "Returns an array of results for a given title",
|
|
||||||
"operationId": "titleSearch",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "s",
|
|
||||||
"in": "query",
|
|
||||||
"description": "Title of movie or series",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "y",
|
|
||||||
"in": "query",
|
|
||||||
"description": "Year of release",
|
|
||||||
"schema": {
|
|
||||||
"type": "integer"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "type",
|
|
||||||
"in": "query",
|
|
||||||
"description": "Return movie or series",
|
|
||||||
"schema": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["movie", "series"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "r",
|
|
||||||
"in": "query",
|
|
||||||
"description": "The response type to return",
|
|
||||||
"schema": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": ["json", "xml"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "page",
|
|
||||||
"in": "query",
|
|
||||||
"description": "Page number to return",
|
|
||||||
"schema": {
|
|
||||||
"type": "integer"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "callback",
|
|
||||||
"in": "query",
|
|
||||||
"description": "JSONP callback name",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Successful operation",
|
|
||||||
"content": {}
|
|
||||||
},
|
|
||||||
"401": {
|
|
||||||
"description": "Not authenticated",
|
|
||||||
"content": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"APIKeyQueryParam": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"components": {
|
|
||||||
"securitySchemes": {
|
|
||||||
"APIKeyQueryParam": {
|
|
||||||
"type": "apiKey",
|
|
||||||
"name": "apikey",
|
|
||||||
"in": "query"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"x-original-swagger-version": "2.0"
|
|
||||||
}
|
|
||||||
|
|
@ -1,180 +0,0 @@
|
||||||
/**
|
|
||||||
* This file was auto-generated by openapi-typescript.
|
|
||||||
* Do not make direct changes to the file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export interface paths {
|
|
||||||
'/?t': {
|
|
||||||
parameters: {
|
|
||||||
query?: never;
|
|
||||||
header?: never;
|
|
||||||
path?: never;
|
|
||||||
cookie?: never;
|
|
||||||
};
|
|
||||||
/** Returns the most popular match for a given title */
|
|
||||||
get: operations['getTitle'];
|
|
||||||
put?: never;
|
|
||||||
post?: never;
|
|
||||||
delete?: never;
|
|
||||||
options?: never;
|
|
||||||
head?: never;
|
|
||||||
patch?: never;
|
|
||||||
trace?: never;
|
|
||||||
};
|
|
||||||
'/?i': {
|
|
||||||
parameters: {
|
|
||||||
query?: never;
|
|
||||||
header?: never;
|
|
||||||
path?: never;
|
|
||||||
cookie?: never;
|
|
||||||
};
|
|
||||||
/** Returns a single result based on the ID provided */
|
|
||||||
get: operations['getId'];
|
|
||||||
put?: never;
|
|
||||||
post?: never;
|
|
||||||
delete?: never;
|
|
||||||
options?: never;
|
|
||||||
head?: never;
|
|
||||||
patch?: never;
|
|
||||||
trace?: never;
|
|
||||||
};
|
|
||||||
'/?s': {
|
|
||||||
parameters: {
|
|
||||||
query?: never;
|
|
||||||
header?: never;
|
|
||||||
path?: never;
|
|
||||||
cookie?: never;
|
|
||||||
};
|
|
||||||
/** Returns an array of results for a given title */
|
|
||||||
get: operations['titleSearch'];
|
|
||||||
put?: never;
|
|
||||||
post?: never;
|
|
||||||
delete?: never;
|
|
||||||
options?: never;
|
|
||||||
head?: never;
|
|
||||||
patch?: never;
|
|
||||||
trace?: never;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
export type webhooks = Record<string, never>;
|
|
||||||
export interface components {
|
|
||||||
schemas: never;
|
|
||||||
responses: never;
|
|
||||||
parameters: never;
|
|
||||||
requestBodies: never;
|
|
||||||
headers: never;
|
|
||||||
pathItems: never;
|
|
||||||
}
|
|
||||||
export type $defs = Record<string, never>;
|
|
||||||
export interface operations {
|
|
||||||
getTitle: {
|
|
||||||
parameters: {
|
|
||||||
query: {
|
|
||||||
/** @description Title of movie or series */
|
|
||||||
t: string;
|
|
||||||
/** @description Year of release */
|
|
||||||
y?: number;
|
|
||||||
/** @description Return movie or series */
|
|
||||||
type?: 'movie' | 'series';
|
|
||||||
/** @description Return short or full plot */
|
|
||||||
plot?: 'short' | 'full';
|
|
||||||
/** @description The response type to return */
|
|
||||||
r?: 'json' | 'xml';
|
|
||||||
/** @description JSONP callback name */
|
|
||||||
callback?: string;
|
|
||||||
};
|
|
||||||
header?: never;
|
|
||||||
path?: never;
|
|
||||||
cookie?: never;
|
|
||||||
};
|
|
||||||
requestBody?: never;
|
|
||||||
responses: {
|
|
||||||
/** @description Successful operation */
|
|
||||||
200: {
|
|
||||||
headers: {
|
|
||||||
[name: string]: unknown;
|
|
||||||
};
|
|
||||||
content?: never;
|
|
||||||
};
|
|
||||||
/** @description Not authenticated */
|
|
||||||
401: {
|
|
||||||
headers: {
|
|
||||||
[name: string]: unknown;
|
|
||||||
};
|
|
||||||
content?: never;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
getId: {
|
|
||||||
parameters: {
|
|
||||||
query: {
|
|
||||||
/** @description A valid IMDb ID (e.g. tt0000001) */
|
|
||||||
i: string;
|
|
||||||
/** @description Return short or full plot */
|
|
||||||
plot?: 'short' | 'full';
|
|
||||||
/** @description The response type to return */
|
|
||||||
r?: 'json' | 'xml';
|
|
||||||
/** @description JSONP callback name */
|
|
||||||
callback?: string;
|
|
||||||
};
|
|
||||||
header?: never;
|
|
||||||
path?: never;
|
|
||||||
cookie?: never;
|
|
||||||
};
|
|
||||||
requestBody?: never;
|
|
||||||
responses: {
|
|
||||||
/** @description Successful operation */
|
|
||||||
200: {
|
|
||||||
headers: {
|
|
||||||
[name: string]: unknown;
|
|
||||||
};
|
|
||||||
content?: never;
|
|
||||||
};
|
|
||||||
/** @description Not authenticated */
|
|
||||||
401: {
|
|
||||||
headers: {
|
|
||||||
[name: string]: unknown;
|
|
||||||
};
|
|
||||||
content?: never;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
titleSearch: {
|
|
||||||
parameters: {
|
|
||||||
query: {
|
|
||||||
/** @description Title of movie or series */
|
|
||||||
s: string;
|
|
||||||
/** @description Year of release */
|
|
||||||
y?: number;
|
|
||||||
/** @description Return movie or series */
|
|
||||||
type?: 'movie' | 'series';
|
|
||||||
/** @description The response type to return */
|
|
||||||
r?: 'json' | 'xml';
|
|
||||||
/** @description Page number to return */
|
|
||||||
page?: number;
|
|
||||||
/** @description JSONP callback name */
|
|
||||||
callback?: string;
|
|
||||||
};
|
|
||||||
header?: never;
|
|
||||||
path?: never;
|
|
||||||
cookie?: never;
|
|
||||||
};
|
|
||||||
requestBody?: never;
|
|
||||||
responses: {
|
|
||||||
/** @description Successful operation */
|
|
||||||
200: {
|
|
||||||
headers: {
|
|
||||||
[name: string]: unknown;
|
|
||||||
};
|
|
||||||
content?: never;
|
|
||||||
};
|
|
||||||
/** @description Not authenticated */
|
|
||||||
401: {
|
|
||||||
headers: {
|
|
||||||
[name: string]: unknown;
|
|
||||||
};
|
|
||||||
content?: never;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -189,7 +189,7 @@ export const ADVANCED_SEARCH_MODAL_DEFAULT_OPTIONS: AdvancedSearchModalOptions =
|
||||||
|
|
||||||
export const ID_SEARCH_MODAL_DEFAULT_OPTIONS: IdSearchModalOptions = {
|
export const ID_SEARCH_MODAL_DEFAULT_OPTIONS: IdSearchModalOptions = {
|
||||||
modalTitle: 'Media DB Id Search',
|
modalTitle: 'Media DB Id Search',
|
||||||
preselectedAPI: '',
|
preselectedAPI: undefined,
|
||||||
prefilledSearchString: '',
|
prefilledSearchString: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue