meisam-mulla / sfs-client
用于与 StretchFS 交互以管理内容和作业的客户端。
v1.5
2024-04-09 18:29 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.0
README
SFS 客户端是一个用于与 StretchFS 服务器通信以管理内容和作业的 PHP 库。它利用 GuzzleHttp 进行 HTTP 请求,提供文件上传、下载和作业管理的简单接口。
安装
通过 Composer 安装此包
composer require meisam-mulla/sfs-client
使用方法
首先,将 SFS 客户端包含到您的项目中
use MeisamMulla\SfsClient\StretchFS;
使用您的服务器配置初始化客户端
$client = new StretchFS([ 'username' => 'your_username', // optional if you have a token 'password' => 'your_password', // optional if you have a token 'domain' => 'sfsserver.net', // SFS server 'port' => 8161, // Default port 'token' => 'your_token', // If you already have a token ]);
身份验证
生成新的令牌
$token = $client->generateToken();
销毁令牌
$client->destroyToken(token: 'iu23gn43g2i4i');
文件夹管理
创建文件夹
$client->folderCreate(folderPath: '/test');
删除文件夹
$client->folderDelete(folderPath: '/test');
列出目录中的所有文件
$client->fileList(folderPath: '/');
文件管理
从路径上传文件
$client->fileUpload(filePath: '/home/user/somefile.txt', folderPath: '/');
从字符串上传文件
$client->fileUploadFromString(filePath: '/text.txt', contents: 'contents of text.txt');
下载文件
$contents = $client->fileDownload(filePath: '/text.txt');
流式传输文件
$stream = $client->fileDownloadStream(filePath: '/text.txt');
获取文件详细信息
$contents = $client->fileDetail(filePath: '/text.txt');
删除文件
$client->fileDelete(filePath: '/text.txt');
临时 URL
生成临时下载 URL
$response = $client->fileDownloadUrl(filePath: '/text.txt', seconds: 3600);
作业管理
创建作业
$job = $client->jobCreate(description: [ "callback" => [ 'request' => [ 'method' => 'GET', 'url' => "http://some.url/job.complete", ], ], "resource" => [ [ "name" => 'somefile.zip', "request" => [ "method" => "GET", "url" => "https://url.to/file.zip", ] ] ] ], priority: 12, category: 'ingest');
更新作业
$client->jobUpdate(handle: '5sE4674U4ft2', changes: [ "resource" => [ [ "name" => 'somefile.zip', "request" => [ "method" => "GET", "url" => "https://url.to/file.zip", ] ] ] ]);
启动作业
$client->jobStart(handle: 'FQukh4sIMN4F');
获取作业详细信息
$client->jobDetail(handle: 'FQukh4sIMN4F');
中止作业
$client->jobAbort(handle: 'FQukh4sIMN4F');
重试作业
$client->jobRetry(handle: 'FQukh4sIMN4F');
删除作业
$client->jobRemove(handle: 'FQukh4sIMN4F');
检查作业临时目录中是否存在内容
$client->jobContentExists(handle: 'FQukh4sIMN4F', file: 'file.zip');