diff --git a/conf/app.php b/conf/app.php index 13172e1..7b07703 100644 --- a/conf/app.php +++ b/conf/app.php @@ -53,6 +53,12 @@ $configs = array( 'data_dir' => 'data/', //数据目录 'tag_dir' => 'tags/', //tag分类目录 'task_dir' => 'task/', //分享视频下载任务文件保存目录 + 'supportedPlatforms' => array( + '抖音', + '快手', + '西瓜视频', + 'B站', + ), ), //目前支持的皮肤 diff --git a/themes/tajian/controller/ApiController.php b/themes/tajian/controller/ApiController.php index 1e109bf..b698a8b 100644 --- a/themes/tajian/controller/ApiController.php +++ b/themes/tajian/controller/ApiController.php @@ -4,6 +4,7 @@ */ require_once __DIR__ . '/../../../lib/DirScanner.php'; require_once __DIR__ . '/../../../plugins/Parsedown.php'; +require_once __DIR__ . '/../../../plugins/Html.php'; require_once __DIR__ . '/SiteController.php'; Class ApiController extends SiteController { @@ -62,8 +63,16 @@ Class ApiController extends SiteController { $content = urldecode($content); } + //分享内容来源平台检查 + $shareUrl = $this->getShareUrlFromContent($content); + $platform = Html::getShareVideosPlatform($shareUrl); + if (!in_array($platform, FSC::$app['config']['tajian']['supportedPlatforms'])) { + $code = 0; + $err = '目前只支持抖音、快手、西瓜视频和Bilibili的分享网址哦!'; + } + $tagName = ''; - if (!empty($tag) || !empty($tagid)) { //检查分类名称或id是否存在 + if ($code == 1 && (!empty($tag) || !empty($tagid))) { //检查分类名称或id是否存在 $scanner = new DirScanner(); $scanner->setWebRoot(FSC::$app['config']['content_directory']); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); @@ -107,19 +116,28 @@ Class ApiController extends SiteController { return md5($url); } - //保存分享视频 - protected function saveShareVideo($content, $title, $tagName) { - $done = true; - $newVideo = array(); + protected function getShareUrlFromContent($content) { + $url = ''; preg_match("/https:\/\/[\w\.]+(\/\w+){1,}\/?/i", $content, $matches); if (!empty($matches)) { - $newVideo['url'] = $matches[0]; - $done = $done && $this->saveBotTask($newVideo['url']); + $url = $matches[0]; } - if (!empty($tagName)) { - $done = $done && $this->saveVideoToTag($newVideo['url'], $tagName); + return $url; + } + + //保存分享视频 + protected function saveShareVideo($content, $title, $tagName) { + $done = true; + + $shareUrl = $this->getShareUrlFromContent($content); + if (!empty($shareUrl)) { + $done = $done && $this->saveBotTask($shareUrl); + + if (!empty($tagName)) { + $done = $done && $this->saveVideoToTag($shareUrl, $tagName); + } } return $done; diff --git a/www/js/tajian.js b/www/js/tajian.js index dadd008..84d01dc 100644 --- a/www/js/tajian.js +++ b/www/js/tajian.js @@ -51,7 +51,7 @@ $('input[name=share_content]').val(''); alert(data.msg || data.err); }else { - alert('保存失败,请稍后重试!'); + alert('保存失败!' + data.err); } }).fail(function(jqXHR, textStatus, errorThrown) { $(btn).props('disabled', false);