补全job文件

This commit is contained in:
wangjinlei
2026-05-26 17:30:49 +08:00
parent 92b8a16d5e
commit a776f068d7
8 changed files with 481 additions and 26 deletions

View File

@@ -183,11 +183,18 @@ class Plagiarism extends Base
}
/**
* 取在线查看 URL;过期则自动刷新
* 取在线查看 URLTurnitin 一次性会话链接,关闭报告页后勿复用旧 URL
*
* 入参:
* check_id 必填
* editor_id 选填,当前打开报告的编辑 user_id与 viewer_user_id 对应,避免 session 认证失败)
* reuse 选填1=在未过期时复用库内缓存;默认 0每次调用重新向 Turnitin 申请
*/
public function getReportUrl()
{
$checkId = intval($this->request->param('check_id', 0));
$editorId = intval($this->request->param('editor_id', 0));
$reuse = intval($this->request->param('reuse', 0)) === 1;
if ($checkId <= 0) {
return jsonError('check_id required');
}
@@ -199,25 +206,37 @@ class Plagiarism extends Base
if ($row['state'] != 3) {
return jsonError('check not completed yet, state=' . $row['state']);
}
$needRefresh = empty($row['view_only_url'])
$viewerContext = [];
if ($editorId > 0) {
$viewerContext['editor_id'] = $editorId;
}
$needRefresh = !$reuse
|| empty($row['view_only_url'])
|| intval($row['view_only_url_expire']) < time() + 60;
$usageHint = '每次打开请先调用本接口获取新链接;勿收藏或再次打开旧链接。请在新标签页打开,并允许 Turnitin 域名 Cookie。';
if ($needRefresh) {
$svc = new PlagiarismService();
$info = $svc->refreshViewerUrlFor($checkId);
$info = $svc->refreshViewerUrlFor($checkId, $viewerContext);
if ($info['url'] === '') {
return jsonError('Turnitin returned empty viewer_url');
}
return jsonSuccess([
'view_only_url' => $info['url'],
'expire' => $info['expire'],
'has_pdf' => !empty($info['local_pdf']),
'view_only_url' => $info['url'],
'expire' => $info['expire'],
'has_pdf' => !empty($info['local_pdf']),
'viewer_user_id' => $info['viewer_user_id'],
'refreshed' => true,
'usage_hint' => $usageHint,
]);
}
return jsonSuccess([
'view_only_url' => $row['view_only_url'],
'expire' => intval($row['view_only_url_expire']),
'has_pdf' => !empty($row['pdf_local_path']),
'view_only_url' => $row['view_only_url'],
'expire' => intval($row['view_only_url_expire']),
'has_pdf' => !empty($row['pdf_local_path']),
'refreshed' => false,
'usage_hint' => $usageHint,
]);
} catch (\Throwable $e) {
if (!empty($row['pdf_local_path'])) {