From 86ad0fdb2948aa5ebdda83a1e8b8373b52a8c253 Mon Sep 17 00:00:00 2001 From: lsy Date: Wed, 13 Nov 2024 00:05:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=EF=BC=9A=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=EF=BC=8C=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=98=AF=E5=90=A6=E5=BC=80=E5=90=AF=E9=9D=9E?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=E5=9E=8B=E6=95=B0=E6=8D=AE=E5=BA=93=EF=BC=9B?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=95=B0=E6=8D=AE=E5=BA=93=E7=BB=93=E6=9E=84?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=92=8C=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E8=A1=A8=EF=BC=8C?= =?UTF-8?q?=E7=BB=99=E6=A0=87=E7=AD=BE=E5=92=8C=E6=96=87=E7=AB=A0=E9=83=BD?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E5=9B=BE=E7=89=87=EF=BC=9B=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=EF=BC=9A=E4=BD=BF=E7=94=A8=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= =?UTF-8?q?=EF=BC=8C=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E9=80=89=E6=8B=A9=E6=98=AF=E5=90=A6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/config.rs | 20 +++--- .../database/relational/postgresql/init.sql | 63 ++++++++++++------- frontend/.env | 2 + frontend/app/env.d.ts | 20 ++++++ frontend/app/root.tsx | 2 + frontend/types/context.ts | 13 ---- frontend/types/plugin.ts | 2 +- frontend/types/theme.ts | 7 +++ 8 files changed, 83 insertions(+), 46 deletions(-) create mode 100644 frontend/.env create mode 100644 frontend/app/env.d.ts delete mode 100644 frontend/types/context.ts diff --git a/backend/src/config.rs b/backend/src/config.rs index f4c5c05..6a0a35e 100644 --- a/backend/src/config.rs +++ b/backend/src/config.rs @@ -8,24 +8,24 @@ use std::{env, fs}; #[derive(Deserialize)] pub struct Config { - pub info: Info, - pub db_config: DbConfig, + pub info: Info, // 配置信息 + pub db_config: DbConfig, // 数据库配置 } #[derive(Deserialize)] pub struct Info { - pub install: bool, - pub non_relational: bool, + pub install: bool, // 是否安装 + pub non_relational: bool, // 是否非关系型 } #[derive(Deserialize)] pub struct DbConfig { - pub db_type: String, - pub address: String, - pub prot: u32, - pub user: String, - pub password: String, - pub db_name: String, + pub db_type: String, // 数据库类型 + pub address: String, // 地址 + pub prot: u32, // 端口 + pub user: String, // 用户名 + pub password: String, // 密码 + pub db_name: String, // 数据库名称 } impl Config { diff --git a/backend/src/database/relational/postgresql/init.sql b/backend/src/database/relational/postgresql/init.sql index 9b9bc69..7a98a95 100644 --- a/backend/src/database/relational/postgresql/init.sql +++ b/backend/src/database/relational/postgresql/init.sql @@ -1,10 +1,24 @@ +--- 创建数据库 +CREATE DATABASE echoes; +--- 切换数据库 +\c echoes; --- 安装自动生成uuid插件 CREATE EXTENSION IF NOT EXISTS pgcrypto; ---- 网站信息表 -CREATE TABLE settings +--- 用户权限枚举 +CREATE TYPE privilege_level AS ENUM ('visitor', 'contributor', 'administrators'); +--- 用户信息表 +CREATE TABLE person ( - settings_keys VARCHAR(255) PRIMARY KEY, - settings_values TEXT NOT NULL + person_name VARCHAR(100) PRIMARY KEY, --- 用户名 + person_email VARCHAR(255) UNIQUE NOT NULL, --- 用户邮箱 + person_picture VARCHAR(255), --- 用户头像 + person_password VARCHAR(255) NOT NULL, --- 用户密码 + person_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 用户创建时间 + person_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 用户更新时间 + person_avatar VARCHAR(255), --- 用户头像URL + person_role VARCHAR(50), --- 用户角色 + person_last_login TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 最后登录时间 + person_level privilege_level NOT NULL --- 用户权限 ); --- 页面状态枚举 CREATE TYPE publication_status AS ENUM ('draft', 'published', 'private','hide'); @@ -24,24 +38,27 @@ CREATE TABLE pages --- 文章表 CREATE TABLE posts ( - post_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- 文章主键 - post_title VARCHAR(255) NOT NULL, --- 文章标题 - post_meta_keywords VARCHAR(255) NOT NULL, ---文章mata关键字 - post_meta_description VARCHAR(255) NOT NULL, ---文章mata描述 - post_content TEXT NOT NULL, --- 文章内容 - post_status publication_status DEFAULT 'draft', --- 文章状态 - post_editor BOOLEAN DEFAULT FALSE, --- 文章是否编辑未保存 - posts_unsaved_content TEXT, --- 未保存的文章 - posts_path VARCHAR(255), --- 文章路径 - post_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 文章创建时间 - post_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 文章更新时间 - post_published_at TIMESTAMP, --- 文章发布时间 - CONSTRAINT post_updated_at_check CHECK (post_updated_at >= post_created_at) --- 文章时间约束 + post_author VARCHAR(100) NOT NULL REFERENCES person (person_name) ON DELETE CASCADE, --- 文章作者 + post_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- 文章主键 + post_picture VARCHAR(255), --- 文章头图 + post_title VARCHAR(255) NOT NULL, --- 文章标题 + post_meta_keywords VARCHAR(255) NOT NULL, ---文章mata关键字 + post_meta_description VARCHAR(255) NOT NULL, ---文章mata描述 + post_content TEXT NOT NULL, --- 文章内容 + post_status publication_status DEFAULT 'draft', --- 文章状态 + post_editor BOOLEAN DEFAULT FALSE, --- 文章是否编辑未保存 + posts_unsaved_content TEXT, --- 未保存的文章 + posts_path VARCHAR(255), --- 文章路径 + post_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 文章创建时间 + post_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 文章更新时间 + post_published_at TIMESTAMP, --- 文章发布时间 + CONSTRAINT post_updated_at_check CHECK (post_updated_at >= post_created_at) --- 文章时间约束 ); --- 标签表 CREATE TABLE tags ( - tag_name VARCHAR(50) PRIMARY KEY CHECK (LOWER(tag_name) = tag_name) --- 标签名称主键 + tag_name VARCHAR(50) PRIMARY KEY CHECK (LOWER(tag_name) = tag_name), --- 标签名称主键 + tag_picture VARCHAR(255) --- 标签图标 ); --- 文章与标签的关系表 CREATE TABLE post_tags @@ -67,11 +84,13 @@ CREATE TABLE post_categories --- 资源库 CREATE TABLE library ( + library_author VARCHAR(100) NOT NULL REFERENCES person (person_name) ON DELETE CASCADE, --- 资源作者 library_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- 资源ID library_name VARCHAR(255) NOT NULL, --- 资源名称 library_size BIGINT NOT NULL, --- 大小 library_storage_path VARCHAR(255) NOT NULL UNIQUE, --- 储存路径 library_type VARCHAR(50) NOT NULL REFERENCES library_type (library_type) ON DELETE CASCADE, --- 资源类别 + library_class VARCHAR(50), --- 资源类 library_description VARCHAR(255), --- 资源描述 library_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP --- 创建时间 @@ -79,12 +98,12 @@ CREATE TABLE library --- 资源库类别 CREATE TABLE library_type ( - library_type VARCHAR(50) PRIMARY KEY, --- 资源类别 - library_description VARCHAR(200) --- 资源类别描述 + library_type VARCHAR(50) PRIMARY KEY CHECK (LOWER(library_type) = library_type), --- 资源类别 + library_description VARCHAR(200) --- 资源类别描述 ); --- 配置文件库 CREATE TABLE config ( - config_name VARCHAR(50) PRIMARY KEY, --- 配置文件名称 - config_config JSON --- 配置文件 + config_name VARCHAR(50) PRIMARY KEY CHECK (LOWER(config_name) = config_name), --- 配置文件名称 + config_config JSON --- 配置文件 ) diff --git a/frontend/.env b/frontend/.env new file mode 100644 index 0000000..7d49f92 --- /dev/null +++ b/frontend/.env @@ -0,0 +1,2 @@ +VITE_SOME_KEY = 1 +VITE_APP_SERVER = false \ No newline at end of file diff --git a/frontend/app/env.d.ts b/frontend/app/env.d.ts new file mode 100644 index 0000000..66cb48d --- /dev/null +++ b/frontend/app/env.d.ts @@ -0,0 +1,20 @@ +// File path: app/end.d.ts + +/** + * 配置 + */ + +/// + +interface ImportMetaEnv { + readonly VITE_APP_TYPE: boolean; //用于判断是动态博客还是静态博客 + readonly VITE_APP_API: string; // 用于访问API的基础URL + readonly VITE_THEME_PATH: string; // 存储主题文件的目录路径 + readonly VITE_CONTENT_PATH: string; //mark文章存储的位置 + readonly VITE_PLUGINS_PATH: string; // 存储插件文件的目录路径 + readonly VITE_ASSETS_PATH: string; // 存储静态资源的目录路径 +} + +interface ImportMeta { + readonly env: ImportMetaEnv +} \ No newline at end of file diff --git a/frontend/app/root.tsx b/frontend/app/root.tsx index 61c8b98..217994e 100644 --- a/frontend/app/root.tsx +++ b/frontend/app/root.tsx @@ -23,6 +23,8 @@ export const links: LinksFunction = () => [ ]; export function Layout({ children }: { children: React.ReactNode }) { + console.log(import.meta.env.VITE_THEME_NAME); + return ( diff --git a/frontend/types/context.ts b/frontend/types/context.ts deleted file mode 100644 index d38a717..0000000 --- a/frontend/types/context.ts +++ /dev/null @@ -1,13 +0,0 @@ -// File path: /d:/data/echoes/frontend/types/context.ts -/** - * 应用程序上下文配置接口 - * - * 此接口定义了应用程序的上下文配置,包括API基础URL、主题、插件和资源目录的路径。 - */ -export interface AppContext { - blogType:boolean; //用于判断是动态博客还是静态博客 - apiBaseUrl: string; // 用于访问API的基础URL - themesPath: string; // 存储主题文件的目录路径 - pluginsPath: string; // 存储插件文件的目录路径 - assetsPath: string; // 存储静态资源的目录路径 -} \ No newline at end of file diff --git a/frontend/types/plugin.ts b/frontend/types/plugin.ts index a806955..3fcd4b4 100644 --- a/frontend/types/plugin.ts +++ b/frontend/types/plugin.ts @@ -1,4 +1,4 @@ -// File path: /d:/data/echoes/frontend/types/plugin.ts +// File path: types/plugin.ts /** * 插件配置接口 diff --git a/frontend/types/theme.ts b/frontend/types/theme.ts index 7e3b49d..2a06256 100644 --- a/frontend/types/theme.ts +++ b/frontend/types/theme.ts @@ -39,6 +39,13 @@ export interface ThemeConfig { onActivate?: string; // 主题激活时执行的钩子 onDeactivate?: string; // 主题停用时执行的钩子 }; + /** 路由 */ + routes:{ + post:string; // 文章使用的模板 + tag:string; // 标签使用的模板 + category:string; // 分类使用的模板 + page:string; // 独立页面模板路径 + } } /**