feat(client): add settings clients
This commit is contained in:
parent
76cf1274af
commit
83436eac6a
5 changed files with 56 additions and 2 deletions
|
@ -1,9 +1,12 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/ihexxa/quickshare/src/db/sitestore"
|
||||
"github.com/ihexxa/quickshare/src/handlers/settings"
|
||||
"github.com/parnurzeal/gorequest"
|
||||
)
|
||||
|
||||
|
@ -28,3 +31,26 @@ func (cl *SettingsClient) Health() (*http.Response, string, []error) {
|
|||
return cl.r.Options(cl.url("/v1/settings/health")).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SettingsClient) GetClientCfg(token *http.Cookie) (*http.Response, *settings.ClientCfgMsg, []error) {
|
||||
resp, body, errs := cl.r.Get(cl.url("/v1/settings/client")).
|
||||
AddCookie(token).
|
||||
End()
|
||||
|
||||
mResp := &settings.ClientCfgMsg{}
|
||||
err := json.Unmarshal([]byte(body), mResp)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
return nil, nil, errs
|
||||
}
|
||||
return resp, mResp, nil
|
||||
}
|
||||
|
||||
func (cl *SettingsClient) SetClientCfg(cfg *sitestore.ClientConfig, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Patch(cl.url("/v1/settings/client")).
|
||||
AddCookie(token).
|
||||
Send(&settings.ClientCfgMsg{
|
||||
ClientCfg: cfg,
|
||||
}).
|
||||
End()
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ const listDirQuery = "dp";
|
|||
|
||||
function translateResp(resp: Response<any>): Response<any> {
|
||||
if (resp.status === 500) {
|
||||
// TODO: replace following with error code
|
||||
if (
|
||||
resp.data == null ||
|
||||
resp.data === "" ||
|
||||
|
|
|
@ -65,6 +65,17 @@ export interface ListSharingsResp {
|
|||
sharingDirs: string[];
|
||||
}
|
||||
|
||||
export interface ClientConfig {
|
||||
siteName: string;
|
||||
siteDesc: string;
|
||||
bg: {
|
||||
url: string;
|
||||
repeat: string;
|
||||
position: string;
|
||||
align: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IUsersClient {
|
||||
login: (
|
||||
user: string,
|
||||
|
@ -110,6 +121,12 @@ export interface IFilesClient {
|
|||
generateHash: (filePath: string) => Promise<Response>;
|
||||
}
|
||||
|
||||
export interface ISettingsClient {
|
||||
health: () => Promise<Response>;
|
||||
getClientCfg: () => Promise<Response>;
|
||||
setClientCfg: (cfg: ClientConfig) => Promise<Response>;
|
||||
}
|
||||
|
||||
export interface Response<T = any> {
|
||||
status: number;
|
||||
statusText: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue