diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-07-14 12:21:03 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-07-14 12:21:03 +0200 |
commit | a15c3fefe33f96c8f85147c61ee266abc43b4f65 (patch) | |
tree | 806290c8390199374dc30b38446eb72cc353536a /core | |
parent | 28fb362147358819afeb0f0a5fa7a4ad136499ac (diff) |
fix http client/server + add deinflection test case
Diffstat (limited to 'core')
-rw-r--r-- | core/http/client.ts | 13 | ||||
-rw-r--r-- | core/http/server.ts | 13 | ||||
-rw-r--r-- | core/http/types.ts | 12 |
3 files changed, 35 insertions, 3 deletions
diff --git a/core/http/client.ts b/core/http/client.ts index 80f77b3..36f361b 100644 --- a/core/http/client.ts +++ b/core/http/client.ts @@ -2,7 +2,7 @@ import "../../util/array.ts"; import Core, { CoreExport, CoreImport, CoreSearch, CoreUser } from "../api.ts"; import { ConnectionProps, ConnectionPropsDefault } from "./props.ts"; -import { CoreRequest, CoreRequestSearchSentence, CoreRequestSearchTerms, CoreResponseSearchSentence, CoreResponseSearchTerms } from "./types.ts"; +import { CoreRequest, CoreRequestSearchSentence, CoreRequestSearchTerms, CoreRequestUserTermPriority, CoreResponseSearchSentence, CoreResponseSearchTerms, CoreResponseUserTermPriority } from "./types.ts"; /** * @summary HTTP Core client @@ -50,7 +50,16 @@ export default class RemoteCoreClient implements Core { }, }; - public user: CoreUser = {}; + public user: CoreUser = { + termPriority: async (userID, expression, reading, priority) => { + var request: CoreRequestUserTermPriority = { + command: "user.termPriority", + options: { userID, expression, reading, priority, }, + }; + var { response } = await this.request(request) as CoreResponseUserTermPriority; + return response; + }, + }; public import: CoreImport = {}; diff --git a/core/http/server.ts b/core/http/server.ts index 7e77e19..0518289 100644 --- a/core/http/server.ts +++ b/core/http/server.ts @@ -4,7 +4,7 @@ import "../../util/string.ts"; import RawCore from "../raw/api.ts"; import { ConnectionProps, ConnectionPropsDefault } from "./props.ts"; -import { CoreRequest, CoreRequestSearchSentence, CoreRequestSearchTerms, CoreResponseSearchSentence, CoreResponseSearchTerms } from "./types.ts"; +import { CoreRequest, CoreRequestSearchSentence, CoreRequestSearchTerms, CoreRequestUserTermPriority, CoreResponseSearchSentence, CoreResponseSearchTerms, CoreResponseUserTermPriority } from "./types.ts"; export default class RemoteCoreServer extends RawCore { @@ -27,6 +27,17 @@ export default class RemoteCoreServer extends RawCore { response: await this.search.sentence(sentence, optional), } as CoreResponseSearchSentence)); }, + "user.termPriority": async _req => { + var req = _req as CoreRequestUserTermPriority; + var ok = true; + ok = ok && (typeof req.options?.userID === "number"); + ok = ok && !!(req.options?.expression); + ok = ok && !!(req.options?.reading); + ok = ok && (typeof req.options?.priority === "number"); + if (!ok) return new Response("", { status: 404 }); + await this.user.termPriority(req.options!.userID, req.options!.expression, req.options!.reading, req.options!.priority); + return new Response(JSON.stringify({} as CoreResponseUserTermPriority)); + }, }; constructor(options?: ConnectionProps) { diff --git a/core/http/types.ts b/core/http/types.ts index 9edc2dc..5ea445e 100644 --- a/core/http/types.ts +++ b/core/http/types.ts @@ -33,3 +33,15 @@ export interface CoreRequestSearchTerms extends CoreRequest { export interface CoreResponseSearchTerms extends CoreResponse { response: Array<SearchTermResult>; }; + +export interface CoreRequestUserTermPriority extends CoreRequest { + command: "user.termPriority"; + options: { + userID: number; + expression: string; + reading: string; + priority: number; + }; +}; + +export interface CoreResponseUserTermPriority extends CoreResponse { }; |