feat(fe): enable preferences in fe client and state

This commit is contained in:
hexxa 2021-10-17 17:30:36 +08:00 committed by Hexxa
parent 1f6fa6d370
commit 5ff6988e0d
8 changed files with 48 additions and 16 deletions

View file

@ -14,8 +14,15 @@ export interface Quota {
downloadSpeedLimit: number;
}
export interface Settings {
bgURL: string;
export interface BgConfig {
url: string;
repeat: string;
position: string;
align: string;
}
export interface Preferences {
bg: BgConfig;
cssURL: string;
lanPackURL: string;
}
@ -26,7 +33,7 @@ export interface User {
role: string;
quota: Quota;
usedSpace: string;
settings: Settings;
preferences: Preferences | undefined;
}
export interface ListUsersResp {
@ -74,16 +81,10 @@ export interface ListSharingsResp {
export interface ClientConfigMsg {
clientCfg: ClientConfig;
}
export interface ClientConfig {
siteName: string;
siteDesc: string;
bg: {
url: string;
repeat: string;
position: string;
align: string;
};
bg: BgConfig;
}
export interface IUsersClient {

View file

@ -81,6 +81,16 @@ export const resps = {
uploadSpeedLimit: 3,
downloadSpeedLimit: 3,
},
preferences: {
bg: {
url: "bgUrl",
repeat: "bgRepeat",
position: "bgPosition",
align: "bgAlign",
},
cssURL: "cssURL",
lanPackURL: "lanPackURL",
},
},
},
getCaptchaIDMockResp: {

View file

@ -6,7 +6,10 @@ import { initUploadMgr } from "../../worker/upload_mgr";
import { User, UploadInfo } from "../../client";
import { MockFilesClient, resps as filesResps } from "../../client/files_mock";
import { MockUsersClient, resps as usersResps } from "../../client/users_mock";
import { MockSettingsClient, resps as settingsResps } from "../../client/settings_mock";
import {
MockSettingsClient,
resps as settingsResps,
} from "../../client/settings_mock";
import { ICoreState, newState } from "../core_state";
import { MockWorker, UploadState, UploadEntry } from "../../worker/interface";
@ -115,6 +118,16 @@ describe("State Manager", () => {
uploadSpeedLimit: 0,
downloadSpeedLimit: 0,
},
preferences: {
bg: {
url: "bgUrl",
repeat: "bgRepeat",
position: "bgPosition",
align: "bgAlign",
},
cssURL: "cssURL",
lanPackURL: "lanPackURL",
},
},
};
const mockIsAuthedResp = { status: 401, statusText: "", data: {} };

View file

@ -24,6 +24,8 @@ export interface UIProps {
position: string;
align: string;
};
cssURL: string;
lanPackURL: string;
}
export interface ICoreState {
browser: BrowserProps;
@ -87,6 +89,8 @@ export function initState(): ICoreState {
position: "",
align: "",
},
cssURL: "",
lanPackURL: "",
},
};
}

View file

@ -400,6 +400,7 @@ export class AdminPane extends React.Component<Props, State, {}> {
role: this.state.newUserRole,
quota: undefined,
usedSpace: "0",
preferences: undefined,
})
.then((ok: boolean) => {
if (!ok) {

View file

@ -387,6 +387,9 @@ export class Updater {
this.props.login.userRole = resp.data.role;
this.props.login.usedSpace = resp.data.usedSpace;
this.props.login.quota = resp.data.quota;
this.props.ui.bg = resp.data.preferences.bg;
this.props.ui.cssURL = resp.data.preferences.cssURL;
this.props.ui.lanPackURL = resp.data.preferences.lanPackURL;
return true;
}
this.resetUser();

View file

@ -7,6 +7,7 @@ import (
"sync"
"time"
"github.com/ihexxa/quickshare/src/db/sitestore"
"github.com/ihexxa/quickshare/src/kvstore"
)
@ -44,9 +45,10 @@ type Quota struct {
}
type Preferences struct {
BgURL string `json:"bgURL"`
CSSURL string `json:"cssURL"`
LanPackURL string `json:"lanPackURL"`
Bg *sitestore.BgConfig `json:"bg"`
BgURL string `json:"bgURL"`
CSSURL string `json:"cssURL"`
LanPackURL string `json:"lanPackURL"`
}
type UserCfg struct {

View file

@ -698,8 +698,6 @@ func (h *MultiUsersSvc) SetPreferences(c *gin.Context) {
return
}
// userstore.setPreferences
uidStr, ok := claims[q.UserIDParam]
if !ok {
c.JSON(q.ErrResp(c, 500, errors.New("user id not found")))