aaron-lin/internal-api

此软件包最新版本(dev-main)没有提供许可证信息。

dev-main 2023-05-26 07:34 UTC

This package is auto-updated.

Last update: 2024-09-26 11:03:50 UTC


README

简介

本文档描述了应用程序的内部API。内部API用于后端通信。内部API不对公众开放,仅供后端使用。

授权

以下API使用Bearer类型令牌授权。远程服务器必须通过HTTP头部的Authorization字段以Bearer类型令牌发送API密钥。API密钥由后端生成,每个远程服务器都是唯一的。API密钥用于标识远程服务器。散列后的API密钥存储在文件系统中。API密钥由以下命令生成

$NewApiKey = random_bytes(40);
$HashedApiKey = crypt($newApiKey, 'salt');  //server only stores hashed API key

API密钥存储文件示例在此

1. 客户端缓存

1.1 在客户端创建缓存

POST /iapi/cache

远程服务器请求服务器在其文件系统中创建缓存。

请求:HTTP头部的字符串,HTTP体中的参数

头部

Authorization: Bearer b01fd1c05d93e77a887fa6c8c91088bb7f053fb220eaf87d51e5efa30fea9d25

fromDB: user_info.intro_json
storePath: ./cache/user-intro
keys: id001,id002,id003
filenames: about-us.json,contact-us.json,privacy-policy.json

成功响应:HTTP头部的字符串

Status: 200 OK
[
    "/var/www/cache/user-intro/about-us.json",
    "/var/www/cache/user-intro/contact-us.json",
    "/var/www/cache/user-intro/privacy-policy.json"
]

错误响应

Status: 400 Bad Request
{
    "status": "error",
    "message": "keys and filenames count not match"
}

2. 文件传输

2.1 下载文件

GET /iapi/file

远程服务器从服务器下载文件。

请求:HTTP头部的字符串,查询字符串中的参数

头部

Authorization: Bearer b01fd1c05d93e77a887fa6c8c91088bb7f053fb220eaf87d51e5efa30fea9d25

查询字符串

https://example.com/iapi/file?filename=public/images/1.jpg

成功响应:HTTP头部的字符串

Status: 200 OK
Content-Type: image/jpg

错误响应

Status: 400 Bad Request
{
    "status": "error",
    "message": "keys and filenames count not match"
}

2.2 上传文件

POST /iapi/file

远程服务器向服务器上传文件。

请求:HTTP头部的字符串,HTTP体中的参数

头部

Authorization: Bearer b01fd1c05d93e77a887fa6c8c91088bb7f053fb220eaf87d51e5efa30fea9d25

content: (binary)
filename: ./public/images/1.jpg

成功响应:HTTP头部的字符串

Status: 204 No Content

错误响应

Status: 400 Bad Request
{
    "status": "error",
    "message": "keys and filenames count not match"
}