1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 20:06:09 +08:00

放弃部分地方缓存的使用

This commit is contained in:
xiaochong0302 2023-12-09 19:02:05 +08:00
parent 51428ac97a
commit 817b32b067
23 changed files with 120 additions and 56 deletions

View File

@ -27,10 +27,10 @@ class AppInfo extends Cache
$appInfo = new \App\Library\AppInfo(); $appInfo = new \App\Library\AppInfo();
return [ return [
'name' => $appInfo->name, 'name' => $appInfo->get('name'),
'alias' => $appInfo->alias, 'alias' => $appInfo->get('alias'),
'link' => $appInfo->link, 'link' => $appInfo->get('link'),
'version' => $appInfo->version, 'version' => $appInfo->get('version'),
]; ];
} }

View File

@ -160,6 +160,10 @@ class Article extends Service
$data['title'] = $validator->checkTitle($post['title']); $data['title'] = $validator->checkTitle($post['title']);
} }
if (isset($post['cover'])) {
$data['cover'] = $validator->checkCover($post['cover']);
}
if (isset($post['summary'])) { if (isset($post['summary'])) {
$data['summary'] = $validator->checkSummary($post['summary']); $data['summary'] = $validator->checkSummary($post['summary']);
} }

View File

@ -28,24 +28,28 @@
</div> </div>
</div> </div>
<div class="layout-sidebar writer-sidebar wrap"> <div class="layout-sidebar writer-sidebar wrap">
<div class="layui-form-item"> {% if category_options|length > 0 %}
<label class="layui-form-label">文章分类</label> <div class="layui-form-item">
<div class="layui-input-block"> <label class="layui-form-label">文章分类</label>
<select name="category_id" lay-search="true" lay-verify="required"> <div class="layui-input-block">
<option value="">请选择</option> <select name="category_id" lay-search="true" lay-verify="required">
{% for option in category_options %} <option value="">请选择</option>
{% set selected = article.category_id == option.id ? 'selected="selected"' : '' %} {% for option in category_options %}
<option value="{{ option.id }}" {{ selected }}>{{ option.name }}</option> {% set selected = article.category_id == option.id ? 'selected="selected"' : '' %}
{% endfor %} <option value="{{ option.id }}" {{ selected }}>{{ option.name }}</option>
</select> {% endfor %}
</select>
</div>
</div> </div>
</div> {% endif %}
<div class="layui-form-item"> {% if xm_tags|length > 0 %}
<label class="layui-form-label">文章标签</label> <div class="layui-form-item">
<div class="layui-input-block"> <label class="layui-form-label">文章标签</label>
<div id="xm-tag-ids"></div> <div class="layui-input-block">
<div id="xm-tag-ids"></div>
</div>
</div> </div>
</div> {% endif %}
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">来源类型</label> <label class="layui-form-label">来源类型</label>
<div class="layui-input-block"> <div class="layui-input-block">

View File

@ -2,7 +2,7 @@
{% block content %} {% block content %}
{% set title = question.id > 0 ? '编辑问题' : '问题' %} {% set title = question.id > 0 ? '编辑问题' : '发布问题' %}
{% set action_url = question.id > 0 ? url({'for':'home.question.update','id':question.id}) : url({'for':'home.question.create'}) %} {% set action_url = question.id > 0 ? url({'for':'home.question.update','id':question.id}) : url({'for':'home.question.create'}) %}
<div class="breadcrumb"> <div class="breadcrumb">
@ -27,24 +27,28 @@
</div> </div>
</div> </div>
<div class="layout-sidebar writer-sidebar wrap"> <div class="layout-sidebar writer-sidebar wrap">
<div class="layui-form-item"> {% if category_options|length > 0 %}
<label class="layui-form-label">问题分类</label> <div class="layui-form-item">
<div class="layui-input-block"> <label class="layui-form-label">问题分类</label>
<select name="category_id" lay-search="true" lay-verify="required"> <div class="layui-input-block">
<option value="">请选择</option> <select name="category_id" lay-search="true" lay-verify="required">
{% for option in category_options %} <option value="">请选择</option>
{% set selected = question.category_id == option.id ? 'selected="selected"' : '' %} {% for option in category_options %}
<option value="{{ option.id }}" {{ selected }}>{{ option.name }}</option> {% set selected = question.category_id == option.id ? 'selected="selected"' : '' %}
{% endfor %} <option value="{{ option.id }}" {{ selected }}>{{ option.name }}</option>
</select> {% endfor %}
</select>
</div>
</div> </div>
</div> {% endif %}
<div class="layui-form-item"> {% if xm_tags|length > 0 %}
<label class="layui-form-label">问题标签</label> <div class="layui-form-item">
<div class="layui-input-block"> <label class="layui-form-label">问题标签</label>
<div id="xm-tag-ids"></div> <div class="layui-input-block">
<div id="xm-tag-ids"></div>
</div>
</div> </div>
</div> {% endif %}
<div class="layui-form-item"> <div class="layui-form-item">
<div class="layui-input-block"> <div class="layui-input-block">
<button class="layui-btn layui-btn-fluid kg-submit" lay-submit="true" lay-filter="go">确认发布</button> <button class="layui-btn layui-btn-fluid kg-submit" lay-submit="true" lay-filter="go">确认发布</button>

View File

@ -114,4 +114,13 @@ class Common
return $str == $date; return $str == $date;
} }
public static function image($path)
{
$exts = ['png', 'gif', 'jpg', 'jpeg', 'webp'];
$ext = pathinfo($path, PATHINFO_EXTENSION);
return in_array(strtolower($ext), $exts);
}
} }

View File

@ -249,9 +249,7 @@ class Article extends Model
public function beforeSave() public function beforeSave()
{ {
if (empty($this->cover)) { if (Text::startsWith($this->cover, 'http')) {
$this->cover = kg_default_article_cover_path();
} elseif (Text::startsWith($this->cover, 'http')) {
$this->cover = self::getCoverPath($this->cover); $this->cover = self::getCoverPath($this->cover);
} }
@ -269,7 +267,7 @@ class Article extends Model
public function afterFetch() public function afterFetch()
{ {
if (!Text::startsWith($this->cover, 'http')) { if (!empty($this->cover) && !Text::startsWith($this->cover, 'http')) {
$this->cover = kg_cos_article_cover_url($this->cover); $this->cover = kg_cos_article_cover_url($this->cover);
} }

View File

@ -351,9 +351,7 @@ class Course extends Model
public function beforeSave() public function beforeSave()
{ {
if (empty($this->cover)) { if (Text::startsWith($this->cover, 'http')) {
$this->cover = kg_default_course_cover_path();
} elseif (Text::startsWith($this->cover, 'http')) {
$this->cover = self::getCoverPath($this->cover); $this->cover = self::getCoverPath($this->cover);
} }

View File

@ -11,6 +11,7 @@ use App\Caches\MaxQuestionId as MaxQuestionIdCache;
use App\Services\Sync\QuestionIndex as QuestionIndexSync; use App\Services\Sync\QuestionIndex as QuestionIndexSync;
use App\Services\Sync\QuestionScore as QuestionScoreSync; use App\Services\Sync\QuestionScore as QuestionScoreSync;
use Phalcon\Mvc\Model\Behavior\SoftDelete; use Phalcon\Mvc\Model\Behavior\SoftDelete;
use Phalcon\Text;
class Question extends Model class Question extends Model
{ {
@ -269,6 +270,10 @@ class Question extends Model
public function beforeSave() public function beforeSave()
{ {
if (Text::startsWith($this->cover, 'http')) {
$this->cover = self::getCoverPath($this->cover);
}
if (is_array($this->tags) || is_object($this->tags)) { if (is_array($this->tags) || is_object($this->tags)) {
$this->tags = kg_json_encode($this->tags); $this->tags = kg_json_encode($this->tags);
} }
@ -283,11 +288,24 @@ class Question extends Model
public function afterFetch() public function afterFetch()
{ {
if (!empty($this->cover) && !Text::startsWith($this->cover, 'http')) {
$this->cover = kg_cos_article_cover_url($this->cover);
}
if (is_string($this->tags)) { if (is_string($this->tags)) {
$this->tags = json_decode($this->tags, true); $this->tags = json_decode($this->tags, true);
} }
} }
public static function getCoverPath($url)
{
if (Text::startsWith($url, 'http')) {
return parse_url($url, PHP_URL_PATH);
}
return $url;
}
public static function publishTypes() public static function publishTypes()
{ {
return [ return [

View File

@ -26,7 +26,7 @@ class ArticleInfo extends LogicService
{ {
$article = $this->checkArticle($id); $article = $this->checkArticle($id);
$user = $this->getCurrentUser(true); $user = $this->getCurrentUser();
$result = $this->handleArticle($article, $user); $result = $this->handleArticle($article, $user);

View File

@ -14,6 +14,7 @@ use App\Repos\Article as ArticleRepo;
use App\Services\Category as CategoryService; use App\Services\Category as CategoryService;
use App\Services\Logic\Service as LogicService; use App\Services\Logic\Service as LogicService;
use App\Validators\ArticleQuery as ArticleQueryValidator; use App\Validators\ArticleQuery as ArticleQueryValidator;
use Phalcon\Text;
class ArticleList extends LogicService class ArticleList extends LogicService
{ {
@ -77,10 +78,20 @@ class ArticleList extends LogicService
$items = []; $items = [];
$baseUrl = kg_cos_url();
foreach ($articles as $article) { foreach ($articles as $article) {
$article['tags'] = json_decode($article['tags'], true); $article['tags'] = json_decode($article['tags'], true);
if (empty($article['cover'])) {
$article['cover'] = kg_default_article_cover_path();
}
if (!Text::startsWith($article['cover'], 'http')) {
$article['cover'] = $baseUrl . $article['cover'];
}
$category = $categories[$article['category_id']] ?? new \stdClass(); $category = $categories[$article['category_id']] ?? new \stdClass();
$owner = $users[$article['owner_id']] ?? new \stdClass(); $owner = $users[$article['owner_id']] ?? new \stdClass();

View File

@ -25,7 +25,7 @@ class CommentInfo extends LogicService
{ {
$comment = $this->checkComment($id); $comment = $this->checkComment($id);
$user = $this->getCurrentUser(true); $user = $this->getCurrentUser();
return $this->handleComment($comment, $user); return $this->handleComment($comment, $user);
} }

View File

@ -24,7 +24,7 @@ class ConsultInfo extends LogicService
{ {
$consult = $this->checkConsult($id); $consult = $this->checkConsult($id);
$user = $this->getCurrentUser(true); $user = $this->getCurrentUser();
return $this->handleConsult($consult, $user); return $this->handleConsult($consult, $user);
} }

View File

@ -21,7 +21,7 @@ class ResourceList extends LogicService
{ {
$course = $this->checkCourse($id); $course = $this->checkCourse($id);
$user = $this->getCurrentUser(true); $user = $this->getCurrentUser();
$this->setCourseUser($course, $user); $this->setCourseUser($course, $user);

View File

@ -25,7 +25,7 @@ class QuestionInfo extends LogicService
public function handle($id) public function handle($id)
{ {
$user = $this->getCurrentUser(true); $user = $this->getCurrentUser();
$question = $this->checkQuestion($id); $question = $this->checkQuestion($id);

View File

@ -14,6 +14,7 @@ use App\Repos\Question as QuestionRepo;
use App\Services\Category as CategoryService; use App\Services\Category as CategoryService;
use App\Services\Logic\Service as LogicService; use App\Services\Logic\Service as LogicService;
use App\Validators\QuestionQuery as QuestionQueryValidator; use App\Validators\QuestionQuery as QuestionQueryValidator;
use Phalcon\Text;
class QuestionList extends LogicService class QuestionList extends LogicService
{ {
@ -77,8 +78,14 @@ class QuestionList extends LogicService
$items = []; $items = [];
$cosUrl = kg_cos_url();
foreach ($questions as $question) { foreach ($questions as $question) {
if (!empty($question['cover']) && !Text::startsWith($question['cover'], 'http')) {
$question['cover'] = $cosUrl . $question['cover'];
}
$question['tags'] = json_decode($question['tags'], true); $question['tags'] = json_decode($question['tags'], true);
$category = $categories[$question['category_id']] ?? new \stdClass(); $category = $categories[$question['category_id']] ?? new \stdClass();

View File

@ -26,7 +26,7 @@ class TradeInfo extends LogicService
{ {
$trade = $this->checkTradeBySn($sn); $trade = $this->checkTradeBySn($sn);
$user = $this->getCurrentUser(true); $user = $this->getCurrentUser();
return $this->handleTrade($trade, $user); return $this->handleTrade($trade, $user);
} }

View File

@ -90,6 +90,17 @@ class Article extends Validator
return $value; return $value;
} }
public function checkCover($cover)
{
$value = $this->filter->sanitize($cover, ['trim', 'string']);
if (!CommonValidator::image($value)) {
throw new BadRequestException('article.invalid_cover');
}
return kg_cos_img_style_trim($value);
}
public function checkSummary($summary) public function checkSummary($summary)
{ {
$value = $this->filter->sanitize($summary, ['trim', 'string']); $value = $this->filter->sanitize($summary, ['trim', 'string']);

View File

@ -106,7 +106,7 @@ class Course extends Validator
{ {
$value = $this->filter->sanitize($cover, ['trim', 'string']); $value = $this->filter->sanitize($cover, ['trim', 'string']);
if (!CommonValidator::url($value)) { if (!CommonValidator::image($value)) {
throw new BadRequestException('course.invalid_cover'); throw new BadRequestException('course.invalid_cover');
} }

View File

@ -69,7 +69,7 @@ class Package extends Validator
{ {
$value = $this->filter->sanitize($cover, ['trim', 'string']); $value = $this->filter->sanitize($cover, ['trim', 'string']);
if (!CommonValidator::url($value)) { if (!CommonValidator::image($value)) {
throw new BadRequestException('package.invalid_cover'); throw new BadRequestException('package.invalid_cover');
} }

View File

@ -104,7 +104,7 @@ class PointGift extends Validator
{ {
$value = $this->filter->sanitize($cover, ['trim', 'string']); $value = $this->filter->sanitize($cover, ['trim', 'string']);
if (!CommonValidator::url($value)) { if (!CommonValidator::image($value)) {
throw new BadRequestException('point_gift.invalid_cover'); throw new BadRequestException('point_gift.invalid_cover');
} }

View File

@ -63,7 +63,7 @@ class Slide extends Validator
{ {
$value = $this->filter->sanitize($cover, ['trim', 'string']); $value = $this->filter->sanitize($cover, ['trim', 'string']);
if (!CommonValidator::url($value)) { if (!CommonValidator::image($value)) {
throw new BadRequestException('slide.invalid_cover'); throw new BadRequestException('slide.invalid_cover');
} }

View File

@ -86,7 +86,7 @@ class Topic extends Validator
{ {
$value = $this->filter->sanitize($cover, ['trim', 'string']); $value = $this->filter->sanitize($cover, ['trim', 'string']);
if (!CommonValidator::url($value)) { if (!CommonValidator::image($value)) {
throw new BadRequestException('topic.invalid_cover'); throw new BadRequestException('topic.invalid_cover');
} }

View File

@ -48,7 +48,7 @@ class Vip extends Validator
{ {
$value = $this->filter->sanitize($cover, ['trim', 'string']); $value = $this->filter->sanitize($cover, ['trim', 'string']);
if (!CommonValidator::url($value)) { if (!CommonValidator::image($value)) {
throw new BadRequestException('vip.invalid_cover'); throw new BadRequestException('vip.invalid_cover');
} }