Browse Source

add data save notify handler

master
filesite 8 months ago
parent
commit
e19cb3b937
  1. 72
      themes/tajian/controller/FrontapiController.php

72
themes/tajian/controller/FrontapiController.php

@ -148,7 +148,8 @@ Class FrontApiController extends SiteController {
//保存分享视频到任务文件 //保存分享视频到任务文件
protected function saveBotTask($url) { protected function saveBotTask($url) {
$task_dir = __DIR__ . '/../../../runtime/' . FSC::$app['config']['tajian']['task_dir']; $task_dir = realpath(__DIR__ . '/../../../runtime/'
. FSC::$app['config']['tajian']['task_dir']);
if (!is_dir($task_dir)) { if (!is_dir($task_dir)) {
mkdir($task_dir, 0755, true); mkdir($task_dir, 0755, true);
} }
@ -161,9 +162,9 @@ Class FrontApiController extends SiteController {
//保存分享视频到tag分类 //保存分享视频到tag分类
//TODO: 如果高并发,需要避免数据被覆盖的问题 //TODO: 如果高并发,需要避免数据被覆盖的问题
protected function saveVideoToTag($url, $tagName) { protected function saveVideoToTag($url, $tagName) {
$tag_dir = __DIR__ . '/../../../www/' $tag_dir = realpath(__DIR__ . '/../../../www/'
. FSC::$app['config']['content_directory'] . FSC::$app['config']['content_directory']
. '/' . FSC::$app['config']['tajian']['tag_dir']; . '/' . FSC::$app['config']['tajian']['tag_dir']);
if (!is_dir($tag_dir)) { if (!is_dir($tag_dir)) {
mkdir($tag_dir, 0755, true); mkdir($tag_dir, 0755, true);
} }
@ -213,23 +214,66 @@ Class FrontApiController extends SiteController {
return !empty($res) && $res['status'] == 200 ? $res['result'] : false; return !empty($res) && $res['status'] == 200 ? $res['result'] : false;
} }
//TODO: 保存快捷方式 //保存快捷方式
protected function saveUrlShortCut($task_id, $task_url) { protected function saveUrlShortCut($task_id, $task_url) {
$data_dir = realpath(__DIR__ . '/../../../runtime/'
. FSC::$app['config']['tajian']['data_dir']);
if (!is_dir($data_dir)) {
mkdir($data_dir, 0755, true);
}
$shortUrlContent = <<<eof
[InternetShortcut]
URL={$task_url}
eof;
try {
$filepath = "{$data_dir}/{$task_id}.url";
return file_put_contents($filepath, $shortUrlContent);
}catch(Exception $err) {
return false;
}
}
//保存描述文件:标题和图片
protected function saveDescriptionFiles($task_id, $task_data) {
$data_dir = realpath(__DIR__ . '/../../../runtime/'
. FSC::$app['config']['tajian']['data_dir']);
if (!is_dir($data_dir)) {
mkdir($data_dir, 0755, true);
} }
//TODO: 保存描述文件 $done = true;
try {
//保存标题
$filepath_title ="{$data_dir}/{$task_id}_title.txt";
file_put_contents($filepath_title, $task_data['title']);
//TODO: 保存封面图 //保存图片文件
if (!empty($task_data['cover_base64'])) {
$filepath_cover ="{$data_dir}/{$task_id}.{$task_data['cover_type']}";
file_put_contents($filepath_cover, $task_data['cover_base64']);
//TODO: HeroUnion任务数据通知回传接口 $filepath_desc ="{$data_dir}/{$task_id}_cover.txt";
file_put_contents($filepath_desc, "{$task_id}.{$task_data['cover_type']}");
}else if (!empty($task_data['cover'])) {
$filepath_desc ="{$data_dir}/{$task_id}_cover.txt";
file_put_contents($filepath_desc, "{$task_data['cover']}");
}
}catch(Exception $err) {
$done = false;
}
return $done;
}
//HeroUnion任务数据通知回传接口
/** /**
* let params = { * task_id
"task_id": task.id, * task_result
"task_result": task.results, * timestamp
"timestamp": common.getTimestamp(), * sign
"sign": ""
};
**/ **/
public function actionHuNotify() { public function actionHuNotify() {
$task_id = $this->post('task_id', ''); $task_id = $this->post('task_id', '');
@ -261,6 +305,8 @@ Class FrontApiController extends SiteController {
if (strtolower($mySign) != strtolower($sign)) { if (strtolower($mySign) != strtolower($sign)) {
$code = 0; $code = 0;
$err = '签名验证不通过!'; $err = '签名验证不通过!';
}else {
} }
} }

Loading…
Cancel
Save