meisam-mulla/sfs-client

A client for interacting with a StretchFS to manage content and jobs.

v1.5 2024-04-09 18:29 UTC

This package is auto-updated.

Last update: 2024-12-09 23:11:28 UTC


README

The SFS Client is a PHP library for communicating with a StretchFS server to manage content and jobs. It leverages GuzzleHttp for HTTP requests, providing a simple interface for file uploads, downloads, and job management.

StretchFS

Installation

Install the package via Composer:

composer require meisam-mulla/sfs-client

Usage

First, include the SFS Client in your project:

use MeisamMulla\SfsClient\StretchFS;

Initialize the client with your server's configuration:

$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
]);

Authentication

Generate a new token:

$token = $client->generateToken();

Destroy a token:

$client->destroyToken(token: 'iu23gn43g2i4i');

Folder Management

Create a folder:

$client->folderCreate(folderPath: '/test');

Delete a folder:

$client->folderDelete(folderPath: '/test');

List all files in a directory:

$client->fileList(folderPath: '/');

File Management

Upload a file from path

$client->fileUpload(filePath: '/home/user/somefile.txt', folderPath: '/');

Upload a file from string

$client->fileUploadFromString(filePath: '/text.txt', contents: 'contents of text.txt');

Download a file

$contents = $client->fileDownload(filePath: '/text.txt');

Stream a file

$stream = $client->fileDownloadStream(filePath: '/text.txt');

Get file details

$contents = $client->fileDetail(filePath: '/text.txt');

Delete a file

$client->fileDelete(filePath: '/text.txt');

Temporary URLs

Generate url for temporary download

$response = $client->fileDownloadUrl(filePath: '/text.txt', seconds: 3600);

Job Management

Create a job

$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');

Update a job

$client->jobUpdate(handle: '5sE4674U4ft2', changes: [
    "resource" => [
        [
            "name" => 'somefile.zip',
            "request" => [
                "method" => "GET",
                "url" => "https://url.to/file.zip",
            ]
        ]
    ]
]);

Start a job

$client->jobStart(handle: 'FQukh4sIMN4F');

Get job details

$client->jobDetail(handle: 'FQukh4sIMN4F');

Abort a job

$client->jobAbort(handle: 'FQukh4sIMN4F');

Retry a job

$client->jobRetry(handle: 'FQukh4sIMN4F');

Delete a job

$client->jobRemove(handle: 'FQukh4sIMN4F');

Check if content exists in a job temporary directory

$client->jobContentExists(handle: 'FQukh4sIMN4F', file: 'file.zip');