mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 20:43:36 +00:00
refactor: streamline ALLOWED_ROOT_DIRECTORY handling and remove legacy support
This commit refactors the handling of ALLOWED_ROOT_DIRECTORY by removing legacy support for ALLOWED_PROJECT_DIRS and simplifying the security logic. Key changes include: - Removed deprecated ALLOWED_PROJECT_DIRS references from .env.example and security.ts. - Updated initAllowedPaths() to focus solely on ALLOWED_ROOT_DIRECTORY and DATA_DIR. - Enhanced logging for ALLOWED_ROOT_DIRECTORY configuration status. - Adjusted route handlers to utilize the new workspace directory logic. - Introduced a centralized storage module for localStorage operations to improve consistency and error handling. These changes aim to enhance security and maintainability by consolidating directory management into a single variable. Tests: All unit tests passing.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// Type definitions for Electron IPC API
|
||||
import type { SessionListItem, Message } from "@/types/electron";
|
||||
import { getJSON, setJSON, removeItem } from "./storage";
|
||||
|
||||
export interface FileEntry {
|
||||
name: string;
|
||||
@@ -2667,28 +2668,22 @@ export interface TrashedProject extends Project {
|
||||
}
|
||||
|
||||
export const getStoredProjects = (): Project[] => {
|
||||
if (typeof window === "undefined") return [];
|
||||
const stored = localStorage.getItem(STORAGE_KEYS.PROJECTS);
|
||||
return stored ? JSON.parse(stored) : [];
|
||||
return getJSON<Project[]>(STORAGE_KEYS.PROJECTS) ?? [];
|
||||
};
|
||||
|
||||
export const saveProjects = (projects: Project[]): void => {
|
||||
if (typeof window === "undefined") return;
|
||||
localStorage.setItem(STORAGE_KEYS.PROJECTS, JSON.stringify(projects));
|
||||
setJSON(STORAGE_KEYS.PROJECTS, projects);
|
||||
};
|
||||
|
||||
export const getCurrentProject = (): Project | null => {
|
||||
if (typeof window === "undefined") return null;
|
||||
const stored = localStorage.getItem(STORAGE_KEYS.CURRENT_PROJECT);
|
||||
return stored ? JSON.parse(stored) : null;
|
||||
return getJSON<Project>(STORAGE_KEYS.CURRENT_PROJECT);
|
||||
};
|
||||
|
||||
export const setCurrentProject = (project: Project | null): void => {
|
||||
if (typeof window === "undefined") return;
|
||||
if (project) {
|
||||
localStorage.setItem(STORAGE_KEYS.CURRENT_PROJECT, JSON.stringify(project));
|
||||
setJSON(STORAGE_KEYS.CURRENT_PROJECT, project);
|
||||
} else {
|
||||
localStorage.removeItem(STORAGE_KEYS.CURRENT_PROJECT);
|
||||
removeItem(STORAGE_KEYS.CURRENT_PROJECT);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2709,12 +2704,9 @@ export const removeProject = (projectId: string): void => {
|
||||
};
|
||||
|
||||
export const getStoredTrashedProjects = (): TrashedProject[] => {
|
||||
if (typeof window === "undefined") return [];
|
||||
const stored = localStorage.getItem(STORAGE_KEYS.TRASHED_PROJECTS);
|
||||
return stored ? JSON.parse(stored) : [];
|
||||
return getJSON<TrashedProject[]>(STORAGE_KEYS.TRASHED_PROJECTS) ?? [];
|
||||
};
|
||||
|
||||
export const saveTrashedProjects = (projects: TrashedProject[]): void => {
|
||||
if (typeof window === "undefined") return;
|
||||
localStorage.setItem(STORAGE_KEYS.TRASHED_PROJECTS, JSON.stringify(projects));
|
||||
setJSON(STORAGE_KEYS.TRASHED_PROJECTS, projects);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user