From 5ff6988e0dae38ba100041b27e42318b679164c5 Mon Sep 17 00:00:00 2001 From: hexxa Date: Sun, 17 Oct 2021 17:30:36 +0800 Subject: [PATCH] feat(fe): enable preferences in fe client and state --- src/client/web/src/client/index.ts | 21 ++++++++++--------- src/client/web/src/client/users_mock.ts | 10 +++++++++ .../components/__test__/state_mgr.test.tsx | 15 ++++++++++++- src/client/web/src/components/core_state.ts | 4 ++++ src/client/web/src/components/pane_admin.tsx | 1 + .../web/src/components/state_updater.ts | 3 +++ src/db/userstore/user_store.go | 8 ++++--- src/handlers/multiusers/handlers.go | 2 -- 8 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/client/web/src/client/index.ts b/src/client/web/src/client/index.ts index 50da248..ba6f1c5 100644 --- a/src/client/web/src/client/index.ts +++ b/src/client/web/src/client/index.ts @@ -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 { diff --git a/src/client/web/src/client/users_mock.ts b/src/client/web/src/client/users_mock.ts index 5d6cba1..a6af5fd 100644 --- a/src/client/web/src/client/users_mock.ts +++ b/src/client/web/src/client/users_mock.ts @@ -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: { diff --git a/src/client/web/src/components/__test__/state_mgr.test.tsx b/src/client/web/src/components/__test__/state_mgr.test.tsx index 3e77e86..beb28a7 100644 --- a/src/client/web/src/components/__test__/state_mgr.test.tsx +++ b/src/client/web/src/components/__test__/state_mgr.test.tsx @@ -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: {} }; diff --git a/src/client/web/src/components/core_state.ts b/src/client/web/src/components/core_state.ts index bd00c7d..d9d41c0 100644 --- a/src/client/web/src/components/core_state.ts +++ b/src/client/web/src/components/core_state.ts @@ -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: "", }, }; } diff --git a/src/client/web/src/components/pane_admin.tsx b/src/client/web/src/components/pane_admin.tsx index 7b7f756..e0918a5 100644 --- a/src/client/web/src/components/pane_admin.tsx +++ b/src/client/web/src/components/pane_admin.tsx @@ -400,6 +400,7 @@ export class AdminPane extends React.Component { role: this.state.newUserRole, quota: undefined, usedSpace: "0", + preferences: undefined, }) .then((ok: boolean) => { if (!ok) { diff --git a/src/client/web/src/components/state_updater.ts b/src/client/web/src/components/state_updater.ts index ef5db01..c17359b 100644 --- a/src/client/web/src/components/state_updater.ts +++ b/src/client/web/src/components/state_updater.ts @@ -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(); diff --git a/src/db/userstore/user_store.go b/src/db/userstore/user_store.go index 91fc710..ca85595 100644 --- a/src/db/userstore/user_store.go +++ b/src/db/userstore/user_store.go @@ -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 { diff --git a/src/handlers/multiusers/handlers.go b/src/handlers/multiusers/handlers.go index a5fc894..903f9fb 100644 --- a/src/handlers/multiusers/handlers.go +++ b/src/handlers/multiusers/handlers.go @@ -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")))