up.
This commit is contained in:
parent
5d194115c9
commit
f2c336f043
@ -30,7 +30,7 @@ class FileController extends BaseController
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$paginate = CurdService::getPaginate($this->request, $model);
|
$paginate = CurdService::getPaginate($this->request, $model->append(['previewUrl','downloadUrl']));
|
||||||
|
|
||||||
return $this->writeSuccess('ok', $paginate);
|
return $this->writeSuccess('ok', $paginate);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,4 +44,13 @@ class SysFileRecord extends BaseModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getPreviewUrlAttr($previewUrl, $data)
|
||||||
|
{
|
||||||
|
return filesystem()->getFileUrl($data['rule_id'], $data['path'].'/'.$data['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDownloadUrlAttr($downloadUrl, $data)
|
||||||
|
{
|
||||||
|
return filesystem()->getDownloadUrl($data['id']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -6,6 +6,9 @@ use app\entity\file\UploadResult;
|
|||||||
use app\entity\SysFileRecord;
|
use app\entity\SysFileRecord;
|
||||||
use app\entity\SysFileRule;
|
use app\entity\SysFileRule;
|
||||||
use app\entity\SysUserFile;
|
use app\entity\SysUserFile;
|
||||||
|
use think\db\exception\DataNotFoundException;
|
||||||
|
use think\db\exception\DbException;
|
||||||
|
use think\db\exception\ModelNotFoundException;
|
||||||
use think\facade\Event;
|
use think\facade\Event;
|
||||||
use think\facade\Request;
|
use think\facade\Request;
|
||||||
use think\App;
|
use think\App;
|
||||||
@ -26,12 +29,39 @@ class FilesystemService
|
|||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDownloadUrl($fileId)
|
||||||
|
{
|
||||||
|
return $this->getFilesystemApiUrl()."/i/down/".hashids(4)->encode($fileId)."?token=".md5(uniqid());
|
||||||
|
}
|
||||||
|
public function getFilesystemApiUrl()
|
||||||
|
{
|
||||||
|
$filesystem_apiUrl = $this->app->config->get('filesystem.api_url');
|
||||||
|
if ($filesystem_apiUrl == "#") {
|
||||||
|
$filesystem_apiUrl = Request::domain();
|
||||||
|
} else if (!Validate::url($filesystem_apiUrl)) {
|
||||||
|
throw new FileException('请正确配置filesystem.api_url');
|
||||||
|
}
|
||||||
|
return $filesystem_apiUrl;
|
||||||
|
}
|
||||||
|
public function getFileUrl($rule_id, $file_path)
|
||||||
|
{
|
||||||
|
$rule = SysFileRule::find($rule_id);
|
||||||
|
if ($rule) {
|
||||||
|
$putUrl = $rule->url ? $rule->url : $this->getFilesystemApiUrl();
|
||||||
|
return $putUrl.$file_path;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param UploadedFile $file 上传的文件
|
* @param UploadedFile $file 上传的文件
|
||||||
* @param int $directory_id 存储的目录位置
|
* @param int $directory_id 存储的目录位置
|
||||||
* @param int $user_id 用户ID
|
* @param int $user_id 用户ID
|
||||||
* @param array $vars
|
* @param array $vars
|
||||||
* @return UploadResult
|
* @return UploadResult
|
||||||
|
* @throws DataNotFoundException
|
||||||
|
* @throws DbException
|
||||||
|
* @throws ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public function upload(UploadedFile $file, int $directory_id, int $user_id, array $vars = []): UploadResult
|
public function upload(UploadedFile $file, int $directory_id, int $user_id, array $vars = []): UploadResult
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user