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

View file

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

View file

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

View file

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

View file

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

View file

@ -387,6 +387,9 @@ export class Updater {
this.props.login.userRole = resp.data.role; this.props.login.userRole = resp.data.role;
this.props.login.usedSpace = resp.data.usedSpace; this.props.login.usedSpace = resp.data.usedSpace;
this.props.login.quota = resp.data.quota; 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; return true;
} }
this.resetUser(); this.resetUser();

View file

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

View file

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