后端:更新配置文件,可以选择是否开启非关系型数据库;重构数据库结构,新增用户权限和用户信息表,给标签和文章都加上图片;前端:使用环境变量,可以通过环境变量选择是否使用前端

This commit is contained in:
lsy 2024-11-13 00:05:49 +08:00
parent 828090e365
commit 86ad0fdb29
8 changed files with 83 additions and 46 deletions

View File

@ -8,24 +8,24 @@ use std::{env, fs};
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Config { pub struct Config {
pub info: Info, pub info: Info, // 配置信息
pub db_config: DbConfig, pub db_config: DbConfig, // 数据库配置
} }
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct Info { pub struct Info {
pub install: bool, pub install: bool, // 是否安装
pub non_relational: bool, pub non_relational: bool, // 是否非关系型
} }
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct DbConfig { pub struct DbConfig {
pub db_type: String, pub db_type: String, // 数据库类型
pub address: String, pub address: String, // 地址
pub prot: u32, pub prot: u32, // 端口
pub user: String, pub user: String, // 用户名
pub password: String, pub password: String, // 密码
pub db_name: String, pub db_name: String, // 数据库名称
} }
impl Config { impl Config {

View File

@ -1,10 +1,24 @@
--- 创建数据库
CREATE DATABASE echoes;
--- 切换数据库
\c echoes;
--- 安装自动生成uuid插件 --- 安装自动生成uuid插件
CREATE EXTENSION IF NOT EXISTS pgcrypto; 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, person_name VARCHAR(100) PRIMARY KEY, --- 用户名
settings_values TEXT NOT NULL 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'); CREATE TYPE publication_status AS ENUM ('draft', 'published', 'private','hide');
@ -24,24 +38,27 @@ CREATE TABLE pages
--- 文章表 --- 文章表
CREATE TABLE posts CREATE TABLE posts
( (
post_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- 文章主键 post_author VARCHAR(100) NOT NULL REFERENCES person (person_name) ON DELETE CASCADE, --- 文章作者
post_title VARCHAR(255) NOT NULL, --- 文章标题 post_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- 文章主键
post_meta_keywords VARCHAR(255) NOT NULL, ---mata关键字 post_picture VARCHAR(255), --- 文章头图
post_meta_description VARCHAR(255) NOT NULL, ---mata描述 post_title VARCHAR(255) NOT NULL, --- 文章标题
post_content TEXT NOT NULL, --- 文章内容 post_meta_keywords VARCHAR(255) NOT NULL, ---mata关键字
post_status publication_status DEFAULT 'draft', --- 文章状态 post_meta_description VARCHAR(255) NOT NULL, ---mata描述
post_editor BOOLEAN DEFAULT FALSE, --- 文章是否编辑未保存 post_content TEXT NOT NULL, --- 文章内容
posts_unsaved_content TEXT, --- 未保存的文章 post_status publication_status DEFAULT 'draft', --- 文章状态
posts_path VARCHAR(255), --- 文章路径 post_editor BOOLEAN DEFAULT FALSE, --- 文章是否编辑未保存
post_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 文章创建时间 posts_unsaved_content TEXT, --- 未保存的文章
post_updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 文章更新时间 posts_path VARCHAR(255), --- 文章路径
post_published_at TIMESTAMP, --- 文章发布时间 post_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, --- 文章创建时间
CONSTRAINT post_updated_at_check CHECK (post_updated_at >= post_created_at) --- 文章时间约束 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 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 CREATE TABLE post_tags
@ -67,11 +84,13 @@ CREATE TABLE post_categories
--- 资源库 --- 资源库
CREATE TABLE library 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_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), --- 资源ID
library_name VARCHAR(255) NOT NULL, --- 资源名称 library_name VARCHAR(255) NOT NULL, --- 资源名称
library_size BIGINT NOT NULL, --- 大小 library_size BIGINT NOT NULL, --- 大小
library_storage_path VARCHAR(255) NOT NULL UNIQUE, --- 储存路径 library_storage_path VARCHAR(255) NOT NULL UNIQUE, --- 储存路径
library_type VARCHAR(50) NOT NULL REFERENCES library_type (library_type) ON DELETE CASCADE, --- 资源类别 library_type VARCHAR(50) NOT NULL REFERENCES library_type (library_type) ON DELETE CASCADE, --- 资源类别
library_class VARCHAR(50), --- 资源类
library_description VARCHAR(255), --- 资源描述 library_description VARCHAR(255), --- 资源描述
library_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP --- 创建时间 library_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP --- 创建时间
@ -79,12 +98,12 @@ CREATE TABLE library
--- 资源库类别 --- 资源库类别
CREATE TABLE library_type CREATE TABLE library_type
( (
library_type VARCHAR(50) PRIMARY KEY, --- 资源类别 library_type VARCHAR(50) PRIMARY KEY CHECK (LOWER(library_type) = library_type), --- 资源类别
library_description VARCHAR(200) --- 资源类别描述 library_description VARCHAR(200) --- 资源类别描述
); );
--- 配置文件库 --- 配置文件库
CREATE TABLE config CREATE TABLE config
( (
config_name VARCHAR(50) PRIMARY KEY, --- 配置文件名称 config_name VARCHAR(50) PRIMARY KEY CHECK (LOWER(config_name) = config_name), --- 配置文件名称
config_config JSON --- 配置文件 config_config JSON --- 配置文件
) )

2
frontend/.env Normal file
View File

@ -0,0 +1,2 @@
VITE_SOME_KEY = 1
VITE_APP_SERVER = false

20
frontend/app/env.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
// File path: app/end.d.ts
/**
*
*/
/// <reference types="vite/client" />
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
}

View File

@ -23,6 +23,8 @@ export const links: LinksFunction = () => [
]; ];
export function Layout({ children }: { children: React.ReactNode }) { export function Layout({ children }: { children: React.ReactNode }) {
console.log(import.meta.env.VITE_THEME_NAME);
return ( return (
<html lang="en"> <html lang="en">
<head> <head>

View File

@ -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; // 存储静态资源的目录路径
}

View File

@ -1,4 +1,4 @@
// File path: /d:/data/echoes/frontend/types/plugin.ts // File path: types/plugin.ts
/** /**
* *

View File

@ -39,6 +39,13 @@ export interface ThemeConfig {
onActivate?: string; // 主题激活时执行的钩子 onActivate?: string; // 主题激活时执行的钩子
onDeactivate?: string; // 主题停用时执行的钩子 onDeactivate?: string; // 主题停用时执行的钩子
}; };
/** 路由 */
routes:{
post:string; // 文章使用的模板
tag:string; // 标签使用的模板
category:string; // 分类使用的模板
page:string; // 独立页面模板路径
}
} }
/** /**