From 71279b2439afeb02b21004fb6f981387adf04907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=94=E5=AD=90?= <49477914+racns@users.noreply.github.com> Date: Mon, 13 Feb 2023 21:10:03 +0800 Subject: [PATCH] v2.0.1 --- app/admin/controller/Base.php | 2 +- app/api/controller/default/Location.php | 6 +- app/install/controller/Handle.php | 90 +++++++----------------- composer.json | 2 +- config/inis.php | 4 +- config/inis_db.php | 92 +++++++++++++++++++++++++ public/admin/js/install/index.js | 46 ++++--------- public/admin/js/pages/login.js | 16 +++++ 8 files changed, 152 insertions(+), 106 deletions(-) create mode 100644 config/inis_db.php diff --git a/app/admin/controller/Base.php b/app/admin/controller/Base.php index c819952..3d16e2b 100644 --- a/app/admin/controller/Base.php +++ b/app/admin/controller/Base.php @@ -59,7 +59,7 @@ public function initialize() // 开启了自动更新 $autoUpdate = Options::where(['keys'=>'config:system'])->value('opt'); - $autoUpdate = json_decode($autoUpdate, true); + $autoUpdate = json_decode($autoUpdate ?? '', true); $autoUpdate = $autoUpdate['system']['autoUpdate'] ?? false; $autoUpdate = $autoUpdate == 'true' or $autoUpdate === true ? true : false; diff --git a/app/api/controller/default/Location.php b/app/api/controller/default/Location.php index 65e6487..97aad43 100644 --- a/app/api/controller/default/Location.php +++ b/app/api/controller/default/Location.php @@ -108,7 +108,7 @@ public function ip($request) $code = 400; $msg = Lang::get('无数据!'); - $ip = !empty($param['ip']) ? $param['ip'] : $this->helper->GetClientIP(); + $ip = !empty($param['ip']) ? $param['ip'] : $this->utils->get->ip()['ip']; // 设置缓存名称 $cache_name = json_encode(array_merge(['IAPI'=>'location'], $param)); @@ -118,12 +118,12 @@ public function ip($request) else { // 获取数据 - $result = $this->helper->get($this->config['official']['api'] . 'gothe', ['ip'=>$ip], ['origin'=>$this->helper->domain()]); + $result = $this->utils->curl->get($this->config['official']['api'] . 'gothe', ['ip'=>$ip], ['origin'=>$this->helper->domain()]); if ($result['code'] == 200) $data = $result['data']; else $data = $result; - if ($this->ApiCache) Cache::tag(['gothe',$cache_name])->set($cache_name, json_encode($data)); + if ($this->ApiCache) Cache::tag(['gothe', $cache_name])->set($cache_name, json_encode($data)); } diff --git a/app/install/controller/Handle.php b/app/install/controller/Handle.php index d2f39a4..f3b22b0 100644 --- a/app/install/controller/Handle.php +++ b/app/install/controller/Handle.php @@ -11,13 +11,11 @@ class Handle extends BaseController { protected $File; protected $helper; - protected $DBUPDATE; public function __construct() { $this->File = new File; $this->helper = new helper; - $this->DBUPDATE = Config::get('dbupdate'); $path = app()->getRootPath() . '/extend'; $dir = $this->File->getDir($path)['dir']; @@ -164,58 +162,48 @@ public function fulfill() $this->File->unlinkFile('install.env'); $this->File->writeFile($route, $text); } - - // 批量建表 - public function createTables(Request $request) + + // 批量导入数据 + public function initDB(Request $request) { - if ($request->isPost()) - { + + if ($request->isPost()) { + $data = []; $code = 200; $msg = 'ok'; - + $param = $request->param(); $db = !empty($param['db']) ? $param['db'] : 'mysql'; - // 获取表信息 - $tabs = $this->helper->get(config('inis.official.api') . $db . '/created'); + // 获取数据信息 + $array = config('inis_db.' . $db); - if ($tabs['code'] != 200) return $this->create([], $tabs['msg'], 400); + try { - // 数据库 - $conn = Db::connect($db); + foreach ($array as $key => $val) { - // SQL 语句 - $sqls = []; - if (!empty($tabs['data'])) { + // 数据库 + $conn = Db::connect($db); - // mysql 驱动 - if ($db == 'mysql') foreach ($tabs['data'] as $key => $val) { + // 如果表不存在,先创建该表 + if (!in_array($key, $conn->getTables())) $conn->execute($val['sql']); - // 如果表已存在,先删除该表 - if (in_array($key, $conn->getTables())) $conn->execute('DROP TABLE '. $key); + if (!empty($val['data'])) { - $sqls[] = $val; - // 重新设置自增起始值 - $sqls[] = "ALTER TABLE " . $key . " AUTO_INCREMENT=1;"; - } - // sqlite 驱动 - else if ($db == 'sqlite') foreach ($tabs['data'] as $key => $val) { - - // 如果表已存在,先删除该表 - if (in_array($key, $conn->getTables())) $conn->execute('DROP TABLE '. $key); + // 重新设置自增起始值 + $conn->execute("ALTER TABLE " . $key . " AUTO_INCREMENT=1;"); + + // 清空表数据 + $conn->execute('TRUNCATE TABLE ' . $key); - $sqls[] = $val; + // 批量插入数据 + $conn->table($key)->insertAll($val['data']); + } } - } - - try { - // 执行 SQL 语句 - if (!empty($sqls)) foreach ($sqls as $val) $conn->execute($val); - } catch (\Exception $e) { - + $code = 400; $msg = $e->getMessage(); } @@ -223,32 +211,4 @@ public function createTables(Request $request) return $this->create($data, $msg, $code); } } - - // 批量导入数据 - public function insertAll(Request $request) - { - if ($request->isPost()) - { - $data = []; - $code = 200; - $msg = 'ok'; - $param = $request->param(); - - $db = !empty($param['db']) ? $param['db'] : 'mysql'; - - // 获取默认数据 - $result= $this->helper->get(config('inis.official.api') . $db . '/data'); - - // 估计是没有权限 - 或者网络问题 - if ($result['code'] != 200) return $this->create([], $result['msg'], (int)$result['code']); - - // 先判断数据有没有 - if (!empty($result['data'])) foreach ($result['data'] as $key => $val) { - // 批量插入数据 - Db::connect($db)->table($key)->insertAll($val); - } - - return $this->create($result, $msg, $code); - } - } } \ No newline at end of file diff --git a/composer.json b/composer.json index 84f323f..d3ccfc3 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": ">=7.1.0", + "php": ">=8.0.0", "topthink/framework": "^6.0.0", "topthink/think-orm": "^2.0", "topthink/think-view": "^1.0", diff --git a/config/inis.php b/config/inis.php index 68cbf5a..5821830 100644 --- a/config/inis.php +++ b/config/inis.php @@ -15,7 +15,7 @@ ], 'valid_time' => 5 * 60, // 验证码有效时间 - 单位秒 'jwt' => [ - 'key' => 'inis-api', // KEY - 用于校验 TOKEN 是否合法 + 'key' => 'inis-api-asd', // KEY - 用于校验 TOKEN 是否合法 'encrypt' => 'HS256', // 加密方式 'array' => ['HS256','HS384','HS512'], // 可用加密方式 ], @@ -65,5 +65,5 @@ ] ], - 'version' => '2.0.0', // inis 版本号 - 请不要自行更改,后果自负 + 'version' => '2.0.1', // inis 版本号 - 请不要自行更改,后果自负 ]; diff --git a/config/inis_db.php b/config/inis_db.php new file mode 100644 index 0000000..2937547 --- /dev/null +++ b/config/inis_db.php @@ -0,0 +1,92 @@ + [ + 'inis_article'=>[ + 'sql' => "CREATE TABLE `inis_article` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT '主键',\n `title` varchar(255) CHARACTER SET utf8mb4 DEFAULT '未命名文章' COMMENT '标题',\n `description` text CHARACTER SET utf8mb4 COMMENT '摘要',\n `content` longtext CHARACTER SET utf8mb4 COMMENT '内容',\n `is_top` int(255) DEFAULT '0' COMMENT '是否置顶',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `img_src` varchar(255) DEFAULT NULL COMMENT '图片地址',\n `views` int(255) DEFAULT NULL COMMENT '浏览次数',\n `font_count` int(255) DEFAULT NULL COMMENT '字数统计',\n `sort_id` text COMMENT '分类ID',\n `tag_id` text COMMENT '标签ID',\n `users_id` int(255) DEFAULT NULL COMMENT '用户ID',\n `expand` text COMMENT '拓展字段',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `delete_time` varchar(255) DEFAULT NULL COMMENT '删除时间',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间\\\n',\n `last_update_time` varchar(255) DEFAULT NULL COMMENT '最后修改时间',\n PRIMARY KEY (`id`),\n UNIQUE KEY `id` (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", + 'data' => [ + ['title'=>'欢迎使用,inis 博客系统','description'=>'当你看到这篇文章,就表示您的系统已经搭建成功!','content'=>'当你看到这篇文章,就表示您的系统已经搭建成功!','font_count'=>18,'users_id'=>1,'create_time'=>time(),'update_time'=>time(),'opt'=>'{"password":"","auth":"anyone","comments":{"show":"true","allow":"true"}}','last_update_time'=>time()], + ] + ], + 'inis_article_sort'=>[ + 'sql'=>"CREATE TABLE `inis_article_sort` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `name` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '分类名称',\n `description` text COMMENT '分类描述',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `expand` text COMMENT '拓展字段',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` int(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` int(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + 'data'=>[ + ['name'=>'默认分类','description'=>'默认分类','is_show'=>1,'create_time'=>time(),'update_time'=>time()], + ] + ], + 'inis_banner' => [ + 'sql'=>"CREATE TABLE `inis_banner` (\n `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `title` varchar(255) DEFAULT NULL COMMENT '标题',\n `description` varchar(255) DEFAULT NULL COMMENT '描述',\n `url` varchar(255) DEFAULT NULL COMMENT '跳转地址',\n `img` varchar(255) DEFAULT NULL COMMENT '图片地址',\n `expand` text COMMENT '拓展字段',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_comments'=>[ + 'sql'=>"CREATE TABLE `inis_comments` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT '主键',\n `pid` int(255) DEFAULT '0' COMMENT '父ID',\n `content` text CHARACTER SET utf8mb4 COMMENT '评论内容',\n `nickname` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '评论者昵称',\n `email` varchar(255) DEFAULT NULL COMMENT '用户邮箱',\n `url` varchar(255) DEFAULT NULL COMMENT '用户网址',\n `ip` varchar(255) DEFAULT NULL COMMENT 'IP',\n `type` varchar(255) DEFAULT 'article' COMMENT '评论属性',\n `status` int(255) DEFAULT '1' COMMENT '状态',\n `agent` text COMMENT '代理信息',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `users_id` int(255) DEFAULT NULL COMMENT '评论者',\n `article_id` int(255) DEFAULT NULL COMMENT '外键',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` int(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` int(255) DEFAULT NULL COMMENT '修改时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_music' => [ + 'sql'=>"CREATE TABLE `inis_music` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `title` varchar(255) DEFAULT NULL COMMENT '标题',\n `description` varchar(255) DEFAULT NULL COMMENT '描述',\n `url` varchar(255) DEFAULT NULL COMMENT '音乐地址',\n `head_img` varchar(255) DEFAULT NULL COMMENT '头像地址',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", + 'data'=>[ + ['title'=>'默认歌单','url'=>'https://c.y.qq.com/base/fcgi-bin/u?__=ZhpZFd43','head_img'=>'//q.qlogo.cn/g?b=qq&nk=97783391&s=640','create_time'=>time(),'update_time'=>time()] + ] + ], + 'inis_page' => [ + 'sql'=>"CREATE TABLE `inis_page` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `title` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '标题',\n `alias` varchar(255) DEFAULT NULL COMMENT '别名',\n `content` longtext CHARACTER SET utf8mb4 COMMENT '内容',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `opt` longtext COMMENT 'JSON字段',\n `expand` text COMMENT '拓展字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` varchar(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` varchar(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", + 'data'=>[ + ['title'=>'友链库','alias'=>'links','content'=>'友链库页面,自由发挥!','create_time'=>time(),'update_time'=>time()] + ] + ], + 'inis_links'=>[ + 'sql'=>"CREATE TABLE `inis_links` (\n `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',\n `name` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL COMMENT '昵称',\n `url` varchar(255) DEFAULT NULL COMMENT '地址',\n `head_img` varchar(255) DEFAULT NULL COMMENT '头像',\n `description` varchar(255) CHARACTER SET utf8mb4 DEFAULT '这是一个很神秘的人!' COMMENT '描述',\n `sort_id` int(255) DEFAULT NULL COMMENT '分类ID',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` int(11) DEFAULT NULL COMMENT '创建时间',\n `update_time` int(11) DEFAULT NULL COMMENT '修改时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + ], + 'inis_links_sort'=>[ + 'sql'=>"CREATE TABLE `inis_links_sort` (\n `id` int(255) NOT NULL AUTO_INCREMENT COMMENT 'ID',\n `name` varchar(255) DEFAULT NULL COMMENT '分类名称',\n `description` text COMMENT '分类描述',\n `is_show` int(255) DEFAULT '1' COMMENT '是否显示',\n `expand` text COMMENT '拓展字段',\n `opt` longtext COMMENT 'JSON字段',\n `longtext` longtext CHARACTER SET utf8mb4 COMMENT '自定义字段',\n `create_time` int(255) DEFAULT NULL COMMENT '创建时间',\n `update_time` int(255) DEFAULT NULL COMMENT '更新时间',\n PRIMARY KEY (`id`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8", + 'data'=>[ + ['name'=>'默认分组','description'=>'这是默认的友链分组','create_time'=>time(),'update_time'=>time()] + ] + ], + 'inis_options'=>[ + 'sql'=>"CREATE TABLE `inis_options` (\n `keys` varchar(255) NOT NULL COMMENT '键',\n `value` longtext CHARACTER SET utf8mb4 COMMENT '值',\n `opt` longtext CHARACTER SET utf8mb4 COMMENT 'JSON字段',\n PRIMARY KEY (`keys`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8", + 'data'=>[ + ['keys'=>'config:email-serve','opt'=>'{"port": "587", "smtp": "smtp.qq.com", "email": "", "encry": "tls", "encoded": "UTF-8", "email_cc": "", "nickname": "inis", "password": ""}','value'=>'{"template_1":"
","template_2":"您的评论:
{text}
{author} 给您的回复:
{content}
萤火虫消失之后,那光的轨迹仍久久地印在我的脑际。那微弱浅淡的光点,仿佛迷失方向的魂灵,在漆黑厚重的夜幕中彷徨。——《挪威的森林》村上春树
本邮件为系统自动发送,请勿直接回复~
©2019-2021 Copyright{site}
{email},您好! 以下是您用于验证身份的验证码,请在{valid_time}内输入并完成验证。如非本人操作,请忽略此邮件。 {code} 此邮件由系统自动发出,系统不接受回信,因此请勿直接回复。 安全使用您的帐号注意事项: 1、请不要在其他网站上使用相同的邮箱和密码进行注册。 2、请不要告知任何人您的帐号密码信息。 如果您错误的收到本电子邮件,请您忽略上述内容。 {site} {time} |