interface

This commit is contained in:
monoid 2021-01-15 20:20:55 +09:00
parent 90d329cfd8
commit dfc154b711

View File

@ -15,6 +15,12 @@ export class FetchFailError implements Error{
} }
} }
export class ClientDocumentAccessor implements DocumentAccessor{ export class ClientDocumentAccessor implements DocumentAccessor{
async findByPath(basepath: string, filename?: string): Promise<Document[]>{
throw new Error("not allowed");
};
async findDeleted(content_type: string): Promise<Document[]>{
throw new Error("not allowed");
};
async findList(option?: QueryListOption | undefined): Promise<Document[]>{ async findList(option?: QueryListOption | undefined): Promise<Document[]>{
let res = await fetch(`${baseurl}/search?${option !== undefined ? toQueryString(option) : ""}`); let res = await fetch(`${baseurl}/search?${option !== undefined ? toQueryString(option) : ""}`);
if(res.status !== 200) throw new FetchFailError("findList Failed"); if(res.status !== 200) throw new FetchFailError("findList Failed");
@ -38,7 +44,10 @@ export class ClientDocumentAccessor implements DocumentAccessor{
const {id,...rest} = c; const {id,...rest} = c;
const res = await fetch(`${baseurl}/${id}`,{ const res = await fetch(`${baseurl}/${id}`,{
method: "POST", method: "POST",
body: JSON.stringify(rest) body: JSON.stringify(rest),
headers:{
'content-type':"application/json"
}
}); });
const ret = await res.json(); const ret = await res.json();
return ret; return ret;
@ -47,7 +56,10 @@ export class ClientDocumentAccessor implements DocumentAccessor{
throw new Error("not allow"); throw new Error("not allow");
const res = await fetch(`${baseurl}`,{ const res = await fetch(`${baseurl}`,{
method: "POST", method: "POST",
body: JSON.stringify(c) body: JSON.stringify(c),
headers:{
'content-type':"application/json"
}
}); });
const ret = await res.json(); const ret = await res.json();
return ret; return ret;
@ -63,7 +75,10 @@ export class ClientDocumentAccessor implements DocumentAccessor{
const {id,...rest} = c; const {id,...rest} = c;
const res = await fetch(`${baseurl}/${id}/tags/${tag_name}`,{ const res = await fetch(`${baseurl}/${id}/tags/${tag_name}`,{
method: "POST", method: "POST",
body: JSON.stringify(rest) body: JSON.stringify(rest),
headers:{
'content-type':"application/json"
}
}); });
const ret = await res.json(); const ret = await res.json();
return ret; return ret;
@ -72,7 +87,10 @@ export class ClientDocumentAccessor implements DocumentAccessor{
const {id,...rest} = c; const {id,...rest} = c;
const res = await fetch(`${baseurl}/${id}/tags/${tag_name}`,{ const res = await fetch(`${baseurl}/${id}/tags/${tag_name}`,{
method: "DELETE", method: "DELETE",
body: JSON.stringify(rest) body: JSON.stringify(rest),
headers:{
'content-type':"application/json"
}
}); });
const ret = await res.json(); const ret = await res.json();
return ret; return ret;