Browse Source

limit platforms for api/addfav

master
filesite 1 year ago
parent
commit
45aabae32e
  1. 6
      conf/app.php
  2. 34
      themes/tajian/controller/ApiController.php
  3. 2
      www/js/tajian.js

6
conf/app.php

@ -53,6 +53,12 @@ $configs = array(
'data_dir' => 'data/', //数据目录 'data_dir' => 'data/', //数据目录
'tag_dir' => 'tags/', //tag分类目录 'tag_dir' => 'tags/', //tag分类目录
'task_dir' => 'task/', //分享视频下载任务文件保存目录 'task_dir' => 'task/', //分享视频下载任务文件保存目录
'supportedPlatforms' => array(
'抖音',
'快手',
'西瓜视频',
'B站',
),
), ),
//目前支持的皮肤 //目前支持的皮肤

34
themes/tajian/controller/ApiController.php

@ -4,6 +4,7 @@
*/ */
require_once __DIR__ . '/../../../lib/DirScanner.php'; require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php'; require_once __DIR__ . '/../../../plugins/Parsedown.php';
require_once __DIR__ . '/../../../plugins/Html.php';
require_once __DIR__ . '/SiteController.php'; require_once __DIR__ . '/SiteController.php';
Class ApiController extends SiteController { Class ApiController extends SiteController {
@ -62,8 +63,16 @@ Class ApiController extends SiteController {
$content = urldecode($content); $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 = ''; $tagName = '';
if (!empty($tag) || !empty($tagid)) { //检查分类名称或id是否存在 if ($code == 1 && (!empty($tag) || !empty($tagid))) { //检查分类名称或id是否存在
$scanner = new DirScanner(); $scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']); $scanner->setWebRoot(FSC::$app['config']['content_directory']);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3);
@ -107,19 +116,28 @@ Class ApiController extends SiteController {
return md5($url); return md5($url);
} }
//保存分享视频 protected function getShareUrlFromContent($content) {
protected function saveShareVideo($content, $title, $tagName) { $url = '';
$done = true;
$newVideo = array();
preg_match("/https:\/\/[\w\.]+(\/\w+){1,}\/?/i", $content, $matches); preg_match("/https:\/\/[\w\.]+(\/\w+){1,}\/?/i", $content, $matches);
if (!empty($matches)) { if (!empty($matches)) {
$newVideo['url'] = $matches[0]; $url = $matches[0];
$done = $done && $this->saveBotTask($newVideo['url']); }
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)) { if (!empty($tagName)) {
$done = $done && $this->saveVideoToTag($newVideo['url'], $tagName); $done = $done && $this->saveVideoToTag($shareUrl, $tagName);
}
} }
return $done; return $done;

2
www/js/tajian.js

@ -51,7 +51,7 @@
$('input[name=share_content]').val(''); $('input[name=share_content]').val('');
alert(data.msg || data.err); alert(data.msg || data.err);
}else { }else {
alert('保存失败,请稍后重试!'); alert('保存失败!' + data.err);
} }
}).fail(function(jqXHR, textStatus, errorThrown) { }).fail(function(jqXHR, textStatus, errorThrown) {
$(btn).props('disabled', false); $(btn).props('disabled', false);

Loading…
Cancel
Save