diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index df8f8b82..c129f956 100644 --- a/application/admin/controller/Ajax.php +++ b/application/admin/controller/Ajax.php @@ -96,7 +96,7 @@ class Ajax extends Backend } catch (UploadException $e) { $this->error($e->getMessage()); } - $this->success(__('Uploaded successful'), '', ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); + $this->success(__('Uploaded successful'), '', $attachment->getBaseData()); } elseif ($method == 'clean') { //删除冗余的分片文件 try { @@ -129,7 +129,7 @@ class Ajax extends Backend $this->error($e->getMessage()); } - $this->success(__('Uploaded successful'), '', ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); + $this->success(__('Uploaded successful'), '', $attachment->getBaseData()); } } diff --git a/application/api/controller/Common.php b/application/api/controller/Common.php index 788126e8..87bd40eb 100644 --- a/application/api/controller/Common.php +++ b/application/api/controller/Common.php @@ -106,7 +106,7 @@ class Common extends Api } catch (UploadException $e) { $this->error($e->getMessage()); } - $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); + $this->success(__('Uploaded successful'), $attachment->getBaseData()); } elseif ($method == 'clean') { //删除冗余的分片文件 try { @@ -141,7 +141,7 @@ class Common extends Api $this->error($e->getMessage()); } - $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); + $this->success(__('Uploaded successful'), $attachment->getBaseData()); } } diff --git a/application/common/model/Attachment.php b/application/common/model/Attachment.php index 67f71787..c809d9f4 100644 --- a/application/common/model/Attachment.php +++ b/application/common/model/Attachment.php @@ -95,4 +95,20 @@ class Attachment extends Model $data['unclassed'] = __('Unclassed'); return $data; } + + /** + * 返回上传文件的相关信息 + */ + public function getBaseData() + { + $data = [ + 'url' => $this->url, + 'fullurl' => cdnurl($this->url, true), + 'category' => $this->category, + 'filename' => $this->filename, + 'filesize' => $this->filesize, + 'mimetype' => $this->mimetype, + ]; + return $data; + } }