定制 pinarkive/pinarkive-sdk-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pinarkive/pinarkive-sdk-php

Composer 安装命令:

composer require pinarkive/pinarkive-sdk-php

包简介

PHP SDK for PinArkive API v3 – minimal client (upload, pin, remove, users/me, uploads, tokens, status, allocations). See https://docs.pinarkive.com

README 文档

README

Minimal PHP client for the PinArkive API v3. Upload files, pin by CID, manage tokens, and check status. See docs.pinarkive.com.

Version: 3.1.2

Installation

composer require pinarkive/pinarkive-sdk-php

Quick Start

<?php

use Pinarkive\PinarkiveClient;
use Pinarkive\PinarkiveException;

// Auth: token, apiKey, baseUrl (default: https://api.pinarkive.com/api/v3)
$client = new PinarkiveClient(null, 'your-api-key-here');

// Upload a file
$response = $client->uploadFile('document.pdf');
$data = json_decode($response->getBody(), true);
echo $data['cid'];

// Or login first
$login = $client->login('user@example.com', 'password');
$data = json_decode($login->getBody(), true);
$client = new PinarkiveClient($data['token'], null);

// List uploads
$response = $client->listUploads(1, 20);
$data = json_decode($response->getBody(), true);
print_r($data['uploads']);

Directory DAG (uploadDirectoryDAG)

The API expects multipart field files (repeated); each part’s filename is the path inside the DAG. The response root CID is cid.

$response = $client->uploadDirectoryDAG(['1.png', '2.png'], 'mydag', 'cl0-global');
$data = json_decode($response->getBody(), true);
echo $data['cid']; // gateway …/ipfs/<cid>/1.png

Authentication

  • Constructor: new PinarkiveClient($token = null, $apiKey = null, $baseUrl = '...', $sendRequestSourceWeb = false)
  • API Key is sent as X-API-Key header; token as Authorization: Bearer <token>.
  • $sendRequestSourceWeb: when true, sends X-Request-Source: web on every Bearer-authenticated request (not when using API Key). Use from web apps so the backend classifies requests as WEB in logs instead of JWT.

API Methods (minimal set)

Method Description
health() GET /health
getPlans() GET /plans/
getPeers() GET /peers/
login($email, $password) POST /auth/login
verify2FALogin($temporaryToken, $code) POST /auth/2fa/verify-login
uploadFile($filePath, $clusterId = null, $timelock = null) POST /files/
uploadDirectory($dirPath, $clusterId = null, $timelock = null) POST /files/directory
uploadDirectoryDAG($files, $dirName = null, $clusterId = null, $timelock = null) POST /files/directory-dag
pinCid($cid, $originalName = null, $customName = null, $clusterId = null, $timelock = null) POST /files/pin/:cid
removeFile($cid) DELETE /files/remove/:cid
getMe() GET /users/me
listUploads($page = 1, $limit = 20) GET /users/me/uploads
generateToken($name, $label = null, $expiresInDays = null, $scopes = null, $totpCode = null) POST /tokens/generate
listTokens() GET /tokens/list
revokeToken($name, $totpCode = null) DELETE /tokens/revoke/:name
getStatus($cid, $clusterId = null) GET /status/:cid
getAllocations($cid, $clusterId = null) GET /allocations/:cid

Optional $clusterId and $timelock (ISO 8601, premium) follow the API docs.

Error handling

On HTTP 4xx/5xx the client throws PinarkiveException with:

  • getStatusCode() — HTTP status
  • getApiError() — API field error
  • getApiMessage() — API field message
  • getApiCode() — API field code (e.g. email_not_verified, missing_scope)
  • getRequired() — for 403 missing_scope: the required scope
  • getRetryAfter() — for 429: seconds until retry (from body or Retry-After header)
  • getBody() — full response array
try {
    $client->uploadFile('file.pdf');
} catch (PinarkiveException $e) {
    echo $e->getStatusCode() . ' ' . $e->getApiMessage() . ' ' . $e->getApiCode();
}

Changelog

3.1.2

3.1.0

  • Request source: Constructor 4th param $sendRequestSourceWeb = true sends X-Request-Source: web on Bearer requests.
  • Scopes & 2FA: generateToken(..., $scopes, $totpCode); revokeToken($name, $totpCode). verify2FALogin($temporaryToken, $code) for login with 2FA.
  • Errors: getRequired() (403 missing_scope), getRetryAfter() (429).

3.1.1

  • Fix: uploadDirectoryDAG now sends multipart with repeated field name files, with each part’s filename equal to the relative path in the DAG (backend multer upload.array('files')). The previous files[i][path] / files[i][content] format is not accepted by the backend.

See also CHANGELOG.md.

3.0.0

  • API v3: Base URL is now https://api.pinarkive.com/api/v3 (was /api/v2). v1/v2 are deprecated (410).
  • Errors: On 4xx/5xx the client throws PinarkiveException with getStatusCode(), getApiError(), getApiMessage(), getApiCode(), getBody() (no raw Guzzle response on failure).
  • Minimal surface: Only endpoints documented at docs.pinarkive.com: health, plans, peers, login, files (upload, directory, directory-dag, pin, remove), users/me, uploads, tokens (generate with name / label / expiresInDays), status, allocations. Optional $clusterId and $timelock (ISO 8601) on upload/pin.
  • Removed: renameFile; token options permissions, ipAllowlist. Use API label and expiresInDays only.
  • Constructor: PinarkiveClient($token = null, $apiKey = null, $baseUrl = '...') — third argument is base URL (v2 had only apiKey and baseUrl).
  • Pin: pinCid now accepts $originalName, $customName (replacing the old single $filename).

Upgrading from 2.x

  1. Change base URL to /api/v3 or use the new default.
  2. Add the third constructor argument if you use a custom base URL: new PinarkiveClient(null, $apiKey, 'https://api.pinarkive.com/api/v3').
  3. Catch PinarkiveException and use getStatusCode(), getApiMessage(), getApiCode() instead of Guzzle’s RequestException.
  4. Use pinCid($cid, $originalName, $customName, $clusterId, $timelock) instead of pinCid($cid, $filename).
  5. Use generateToken($name, $label, $expiresInDays); drop permissions and ipAllowlist from options.
  6. Require pinarkive/pinarkive-sdk-php: ^3.0 for v3.

Links

pinarkive/pinarkive-sdk-php 适用场景与选型建议

pinarkive/pinarkive-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「php」 「api」 「sdk」 「laravel」 「v3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pinarkive/pinarkive-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pinarkive/pinarkive-sdk-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 pinarkive/pinarkive-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-13