diff --git a/automation/fetchSchemas.ts b/automation/fetchSchemas.ts index 1dd9136..a692ee7 100644 --- a/automation/fetchSchemas.ts +++ b/automation/fetchSchemas.ts @@ -8,7 +8,7 @@ async function fetchSchema() { await $('bun openapi-typescript ./src/api/schemas/GiantBomb.json -o ./src/api/schemas/GiantBomb.ts'); // 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 await $('bun openapi-typescript ./src/api/schemas/OpenLibrary.json -o ./src/api/schemas/OpenLibrary.ts'); diff --git a/manifest-beta.json b/manifest-beta.json index 5246434..8926eae 100644 --- a/manifest-beta.json +++ b/manifest-beta.json @@ -1,7 +1,7 @@ { "id": "obsidian-media-db-plugin", "name": "Media DB", - "version": "0.8.0-canary.20250808T144907", + "version": "0.8.0-canary.20250810T120325", "minAppVersion": "1.5.0", "description": "A plugin that can query multiple APIs for movies, series, anime, games, music and wiki articles, and import them into your vault.", "author": "Moritz Jung", diff --git a/src/api/apis/OMDbAPI.ts b/src/api/apis/OMDbAPI.ts index 48e2b9c..51b4f17 100644 --- a/src/api/apis/OMDbAPI.ts +++ b/src/api/apis/OMDbAPI.ts @@ -1,5 +1,4 @@ -import createClient from 'openapi-fetch'; -import { obsidianFetch } from 'src/utils/Utils'; +import { requestUrl } from 'obsidian'; import type MediaDbPlugin from '../../main'; import { GameModel } from '../../models/GameModel'; import type { MediaTypeModel } from '../../models/MediaTypeModel'; @@ -7,7 +6,11 @@ import { MovieModel } from '../../models/MovieModel'; import { SeriesModel } from '../../models/SeriesModel'; import { MediaType } from '../../utils/MediaType'; import { APIModel } from '../APIModel'; -import type { paths } from '../schemas/OMDb'; + +interface ErrorResponse { + Response: 'False'; + Error: string; +} type SearchResponse = | { @@ -21,10 +24,7 @@ type SearchResponse = Type: string; }[]; } - | { - Response: 'False'; - Error: string; - }; + | ErrorResponse; type IdResponse = | { @@ -53,10 +53,7 @@ type IdResponse = Production: string; Website: string; } - | { - Response: 'False'; - Error: string; - }; + | ErrorResponse; export class OMDbAPI extends APIModel { plugin: MediaDbPlugin; @@ -84,26 +81,19 @@ export class OMDbAPI extends APIModel { throw new Error(`MDB | API key for ${this.apiName} missing.`); } - const client = createClient({ baseUrl: 'https://www.omdbapi.com/' }); - - const response = await client.GET('/?s', { - params: { - query: { - s: title, - apikey: this.plugin.settings.OMDbKey, - }, - }, - fetch: obsidianFetch, + const response = await requestUrl({ + url: `https://www.omdbapi.com/?s=${encodeURIComponent(title)}&apikey=${this.plugin.settings.OMDbKey}`, + method: 'GET', }); - if (response.response.status === 401) { + if (response.status === 401) { throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); } - if (response.response.status !== 200) { - throw Error(`MDB | Received status code ${response.response.status} from ${this.apiName}.`); + if (response.status !== 200) { + 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) { 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.`); } - const client = createClient({ baseUrl: 'https://www.omdbapi.com/' }); - - const response = await client.GET('/?i', { - params: { - query: { - i: id, - apikey: this.plugin.settings.OMDbKey, - }, - }, - fetch: obsidianFetch, + const response = await requestUrl({ + url: `https://www.omdbapi.com/?i=${encodeURIComponent(id)}&apikey=${this.plugin.settings.OMDbKey}`, + method: 'GET', }); - if (response.response.status === 401) { + if (response.status === 401) { throw Error(`MDB | Authentication for ${this.apiName} failed. Check the API key.`); } - if (response.response.status !== 200) { - throw Error(`MDB | Received status code ${response.response.status} from ${this.apiName}.`); + if (response.status !== 200) { + 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) { throw Error(`MDB | No data received from ${this.apiName}.`); diff --git a/src/api/schemas/OMDb.json b/src/api/schemas/OMDb.json deleted file mode 100644 index 5d31eac..0000000 --- a/src/api/schemas/OMDb.json +++ /dev/null @@ -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" -} diff --git a/src/api/schemas/OMDb.ts b/src/api/schemas/OMDb.ts deleted file mode 100644 index 4142fa4..0000000 --- a/src/api/schemas/OMDb.ts +++ /dev/null @@ -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; -export interface components { - schemas: never; - responses: never; - parameters: never; - requestBodies: never; - headers: never; - pathItems: never; -} -export type $defs = Record; -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; - }; - }; - }; -} diff --git a/src/utils/ModalHelper.ts b/src/utils/ModalHelper.ts index fce0f5c..4aeae61 100644 --- a/src/utils/ModalHelper.ts +++ b/src/utils/ModalHelper.ts @@ -189,7 +189,7 @@ export const ADVANCED_SEARCH_MODAL_DEFAULT_OPTIONS: AdvancedSearchModalOptions = export const ID_SEARCH_MODAL_DEFAULT_OPTIONS: IdSearchModalOptions = { modalTitle: 'Media DB Id Search', - preselectedAPI: '', + preselectedAPI: undefined, prefilledSearchString: '', };