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

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)]
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 {

View File

@ -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,7 +38,9 @@ CREATE TABLE pages
--- 文章表
CREATE TABLE posts
(
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描述
@ -41,7 +57,8 @@ CREATE TABLE posts
--- 标签表
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_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_name VARCHAR(50) PRIMARY KEY CHECK (LOWER(config_name) = config_name), --- 配置文件名称
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 }) {
console.log(import.meta.env.VITE_THEME_NAME);
return (
<html lang="en">
<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; // 主题激活时执行的钩子
onDeactivate?: string; // 主题停用时执行的钩子
};
/** 路由 */
routes:{
post:string; // 文章使用的模板
tag:string; // 标签使用的模板
category:string; // 分类使用的模板
page:string; // 独立页面模板路径
}
}
/**