79 lines
2.8 KiB
TypeScript
79 lines
2.8 KiB
TypeScript
import { create } from "zustand";
|
|
|
|
import { DEFAULT_DRAWING_ENGINE, type CanvasDrawingEngineSetting } from "@/lib/canvas/canvas-drawing-engine";
|
|
|
|
export type LocalUser = {
|
|
id: string;
|
|
username: string;
|
|
email?: string;
|
|
displayName: string;
|
|
avatarUrl?: string;
|
|
identityProvider?: string;
|
|
identityId?: string;
|
|
identityUsername?: string;
|
|
role: "admin" | "user";
|
|
status: "active" | "disabled";
|
|
lastLoginAt?: string;
|
|
createdAt?: string;
|
|
updatedAt?: string;
|
|
};
|
|
|
|
export type RuntimeLimits = {
|
|
activeTaskLimit: number;
|
|
resourceUploadMB: number;
|
|
recycleBinRetentionDays?: number;
|
|
};
|
|
|
|
export type FeatureAvailability = {
|
|
welcomeEnabled: boolean;
|
|
shortDramaEnabled: boolean;
|
|
taskCenterEnabled: boolean;
|
|
creditsEnabled: boolean;
|
|
customChannelsEnabled: boolean;
|
|
frontendModelsEnabled: boolean;
|
|
pluginCenterEnabled: boolean;
|
|
systemPluginsVisibleToUsers: boolean;
|
|
configured?: boolean;
|
|
updatedBy?: string;
|
|
updatedAt?: string;
|
|
};
|
|
|
|
export const defaultFeatureAvailability: FeatureAvailability = {
|
|
welcomeEnabled: true,
|
|
shortDramaEnabled: true,
|
|
taskCenterEnabled: true,
|
|
creditsEnabled: true,
|
|
customChannelsEnabled: true,
|
|
frontendModelsEnabled: false,
|
|
pluginCenterEnabled: true,
|
|
systemPluginsVisibleToUsers: true,
|
|
};
|
|
|
|
type UserStore = {
|
|
hydrated: boolean;
|
|
user: LocalUser | null;
|
|
runtimeLimits: RuntimeLimits;
|
|
drawingEngine: CanvasDrawingEngineSetting;
|
|
features: FeatureAvailability;
|
|
setUser: (user: LocalUser | null) => void;
|
|
setRuntimeLimits: (limits?: RuntimeLimits) => void;
|
|
setDrawingEngine: (setting?: CanvasDrawingEngineSetting) => void;
|
|
setFeatures: (features?: FeatureAvailability) => void;
|
|
setHydrated: (hydrated: boolean) => void;
|
|
clearSession: () => void;
|
|
};
|
|
|
|
export const useUserStore = create<UserStore>()((set) => ({
|
|
hydrated: false,
|
|
user: null,
|
|
runtimeLimits: { activeTaskLimit: 5, resourceUploadMB: 50, recycleBinRetentionDays: 30 },
|
|
drawingEngine: { defaultEngine: DEFAULT_DRAWING_ENGINE },
|
|
features: defaultFeatureAvailability,
|
|
setUser: (user) => set({ user }),
|
|
setRuntimeLimits: (runtimeLimits) => set({ runtimeLimits: runtimeLimits || { activeTaskLimit: 5, resourceUploadMB: 50, recycleBinRetentionDays: 30 } }),
|
|
setDrawingEngine: (drawingEngine) => set({ drawingEngine: drawingEngine || { defaultEngine: DEFAULT_DRAWING_ENGINE } }),
|
|
setFeatures: (features) => set({ features: features ? { ...defaultFeatureAvailability, ...features } : defaultFeatureAvailability }),
|
|
setHydrated: (hydrated) => set({ hydrated }),
|
|
clearSession: () => set({ user: null, runtimeLimits: { activeTaskLimit: 5, resourceUploadMB: 50, recycleBinRetentionDays: 30 }, drawingEngine: { defaultEngine: DEFAULT_DRAWING_ENGINE }, features: defaultFeatureAvailability }),
|
|
}));
|