后台图片管理增加"可疑图片"选项,鉴黄不直接拦截

This commit is contained in:
wispx
2019-01-19 11:04:07 +08:00
parent d9c2e23b52
commit f819df0f0f
6 changed files with 31 additions and 12 deletions
+2 -1
View File
@@ -217,7 +217,8 @@ EOT;
// 新建表字段
$tableFields = [
'lsky_images' => [
'folder_id' => "ALTER TABLE `lsky_images` ADD `folder_id` INT NOT NULL DEFAULT '0' COMMENT '文件夹ID' AFTER `user_id`;"
'folder_id' => "ALTER TABLE `lsky_images` ADD `folder_id` INT NOT NULL DEFAULT '0' COMMENT '文件夹ID' AFTER `user_id`;",
'suspicious' => "ALTER TABLE `lsky_images` ADD `suspicious` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '可疑图片' AFTER `ip`;",
],
'lsky_users' => [
'default_folder' => "ALTER TABLE `lsky_users` ADD `default_folder` VARCHAR(32) DEFAULT NULL COMMENT '默认上传文件夹' AFTER `quota`;"
+6 -3
View File
@@ -91,6 +91,7 @@ class Upload extends Base
$url = make_url($domain, $pathname);
// 图片鉴黄
$suspicious = 0;
if ($this->config['open_audit']) {
$client = new Client();
$response = $client->get("https://www.moderatecontent.com/api/v2?key={$this->config['audit_key']}&url={$url}");
@@ -98,8 +99,9 @@ class Upload extends Base
$result = json_decode($response->getBody()->getContents());
if (0 == $result->error_code) {
if ($result->rating_index >= $this->config['audit_index']) {
$strategy->delete($pathname);
throw new Exception('图片[' . $image->getInfo('name') . ']涉嫌违规,禁止上传!');
/*$strategy->delete($pathname);
throw new Exception('图片[' . $image->getInfo('name') . ']涉嫌违规,禁止上传!');*/
$suspicious = 1;
}
} else {
$strategy->delete($pathname);
@@ -117,7 +119,8 @@ class Upload extends Base
'size' => $size,
'mime' => $mime,
'sha1' => $sha1,
'md5' => $md5
'md5' => $md5,
'suspicious' => $suspicious
];
// 默认上传文件夹,暂只支持一级
+14 -5
View File
@@ -33,11 +33,17 @@ class Images extends Base
$this->assign('strategyList', $this->strategyList);
}
public function index($strategy = '', $keyword = '', $limit = 15)
public function index($where = '', $keyword = '', $limit = 15)
{
$where = json_decode($where, true);
if (null == $where) {
$where = [
'suspicious' => 0
];
}
$model = new ImagesModel();
if (!empty($strategy)) {
$model = $model->where('strategy', $strategy);
foreach ($where as $field => $value) {
$model = $model->where($field, $value);
}
if (!empty($keyword)) {
$model = $model->where('pathname|sha1|md5', 'like', "%{$keyword}%");
@@ -47,7 +53,8 @@ class Images extends Base
'keyword' => $keyword
]
])->each(function ($item) {
$item->username = Users::where('id', $item->user_id)->value('username');
$username = Users::where('id', $item->user_id)->value('username');
$item->username = $username ? $username : '访客';
$item->strategyStr = isset($this->strategyList[$item->strategy]) ? $this->strategyList[$item->strategy]['name'] : '未知';
return $item;
});
@@ -55,8 +62,10 @@ class Images extends Base
'images' => $images,
'keyword' => $keyword,
'strategyList' => $this->strategyList,
'strategy' => $strategy
'strategy' => isset($where['strategy']) ? $where['strategy'] : '',
'suspicious' => isset($where['suspicious']) ? $where['suspicious'] : 0
]);
return $this->fetch();
}
@@ -16,11 +16,12 @@
</div>
<div class="mdui-clearfix mdui-m-t-1"></div>
<form action="" method="post" id="search-form">
<select class="strategy mdui-select mdui-float-left" name="strategy" mdui-select>
<select class="where mdui-select mdui-float-left" name="where" mdui-select>
<option value="">全部</option>
{foreach $strategyList as $key => $value}
<option value="{$key}" {if $key eq $strategy}selected{/if}>{$value.name}</option>
<option value='{"strategy": "{$key}"}' {if $key eq $strategy}selected{/if}>{$value.name}</option>
{/foreach}
<option value='{"suspicious": "1"}' {eq name="suspicious" value="1"} selected{/eq}>可疑图片</option>
</select>
<input type="hidden" name="page" value="1">
<input class="mdui-textfield-input search-input mdui-float-left" type="text" name="keyword" placeholder="回车搜索..." value="{$keyword}" autocomplete="off"/>
@@ -98,6 +99,9 @@
}, {confirmText: '确定', cancelText: '取消'});
}
};
$('.mdui-select.where').on('close.mdui.select', function () {
$('#search-form').submit();
});
$('.mdui-select.operation').on('close.mdui.select', function () {
if ($(this).val() !== '') {
var selected = $('tr.mdui-table-row-selected');
+2 -1
View File
@@ -82,7 +82,7 @@ INSERT INTO `lsky_config` (`id`, `key`, `type`, `input_type`, `name`, `title`, `
(41, '', 'text', 'text', 'system_version', '系统版本', NULL, '1.4.2', ''),
(42, 'audit', 'bool', 'checkbox', 'open_audit', '开启图片鉴黄', '鉴黄接口申请地址:https://www.moderatecontent.com', '0', ''),
(42, 'audit', 'bool', 'checkbox', 'open_audit', '开启图片鉴黄', '接口申请地址:<a href="https://www.moderatecontent.com" target="_blank">https://www.moderatecontent.com</a>', '0', ''),
(43, 'audit', 'text', 'text', 'audit_key', 'Key', NULL, '', ''),
(44, 'audit', 'select', 'text', 'audit_index', '内容评级', '1=所有人,2=少年,3=成人', '3', '{\"1\": \"所有人\", \"2\": \"少年\", \"3\": \"成人\"}'),
(45, 'other', 'bool', 'checkbox', 'open_api', '开启API', '是否开放接口', '0', ''),
@@ -109,6 +109,7 @@ CREATE TABLE IF NOT EXISTS `lsky_images` (
`sha1` varchar(100) NOT NULL COMMENT 'hash sha1',
`md5` varchar(32) NOT NULL COMMENT 'hash md5',
`ip` varchar(128) DEFAULT NULL COMMENT '上传者IP',
`suspicious` tinyint(1) NOT NULL DEFAULT '0' COMMENT '可疑图片',
`create_time` int(11) NOT NULL COMMENT '创建时间'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='图片表';
+1
View File
@@ -49,6 +49,7 @@ UPDATE `lsky_images` SET `strategy` = 'kodo' WHERE `lsky_images`.`strategy` = 'q
-- v1.4.3
UPDATE `lsky_config` SET `value` = '1.4.3' WHERE `lsky_config`.`name` = 'system_version';
UPDATE `lsky_config` SET `tip` = '接口申请地址:<a href="https://www.moderatecontent.com" target="_blank">https://www.moderatecontent.com</a>' WHERE `lsky_config`.`name` = 'open_audit';
INSERT IGNORE INTO `lsky_config` (`id`, `key`, `type`, `input_type`, `name`, `title`, `tip`, `value`, `extend`) VALUES
(NULL, 'basics', 'textarea', 'textarea', 'custom_style', '自定义CSS', NULL, '<!-- 可以直接引入第三方css样式 -->\r\n<style>\r\n /* body {} */\r\n</style>', ''),
(NULL, 'basics', 'textarea', 'textarea', 'statistics_code', '统计代码', NULL, '<script>\r\n // js统计代码 \r\n</script>', '');