上传图片接口

This commit is contained in:
Wisp X
2022-02-20 12:54:39 +08:00
parent b9b3bde750
commit 33884c3fd1
5 changed files with 329 additions and 92 deletions
Generated
+100 -91
View File
@@ -6,68 +6,6 @@
],
"content-hash": "2a6f1476b71a2ab6a252565c5c2a39c7",
"packages": [
{
"name": "asm89/stack-cors",
"version": "v2.1.1",
"source": {
"type": "git",
"url": "https://github.com/asm89/stack-cors.git",
"reference": "73e5b88775c64ccc0b84fb60836b30dc9d92ac4a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/asm89/stack-cors/zipball/73e5b88775c64ccc0b84fb60836b30dc9d92ac4a",
"reference": "73e5b88775c64ccc0b84fb60836b30dc9d92ac4a",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": "^7.2|^8.0",
"symfony/http-foundation": "^4|^5|^6",
"symfony/http-kernel": "^4|^5|^6"
},
"require-dev": {
"phpunit/phpunit": "^7|^9",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"autoload": {
"psr-4": {
"Asm89\\Stack\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alexander",
"email": "iam.asm89@gmail.com"
}
],
"description": "Cross-origin resource sharing library and stack middleware",
"homepage": "https://github.com/asm89/stack-cors",
"keywords": [
"cors",
"stack"
],
"support": {
"issues": "https://github.com/asm89/stack-cors/issues",
"source": "https://github.com/asm89/stack-cors/tree/v2.1.1"
},
"time": "2022-01-18T09:12:03+00:00"
},
{
"name": "aws/aws-crt-php",
"version": "v1.0.2",
@@ -126,16 +64,16 @@
},
{
"name": "aws/aws-sdk-php",
"version": "3.209.26",
"version": "3.209.27",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "bf29058fc637e4949ec42281e9572b9c968b38cc"
"reference": "4a0ded3a5f380f7654da5dc194161588a87d9d3b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/bf29058fc637e4949ec42281e9572b9c968b38cc",
"reference": "bf29058fc637e4949ec42281e9572b9c968b38cc",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/4a0ded3a5f380f7654da5dc194161588a87d9d3b",
"reference": "4a0ded3a5f380f7654da5dc194161588a87d9d3b",
"shasum": "",
"mirrors": [
{
@@ -217,9 +155,9 @@
"support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues",
"source": "https://github.com/aws/aws-sdk-php/tree/3.209.26"
"source": "https://github.com/aws/aws-sdk-php/tree/3.209.27"
},
"time": "2022-02-17T19:15:52+00:00"
"time": "2022-02-18T19:19:17+00:00"
},
{
"name": "brick/math",
@@ -690,16 +628,16 @@
},
{
"name": "fruitcake/laravel-cors",
"version": "v2.0.5",
"version": "v2.1.0",
"source": {
"type": "git",
"url": "https://github.com/fruitcake/laravel-cors.git",
"reference": "3a066e5cac32e2d1cdaacd6b961692778f37b5fc"
"reference": "361d71f00a0eea8b74da26ae75d0d207c53aa5b3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fruitcake/laravel-cors/zipball/3a066e5cac32e2d1cdaacd6b961692778f37b5fc",
"reference": "3a066e5cac32e2d1cdaacd6b961692778f37b5fc",
"url": "https://api.github.com/repos/fruitcake/laravel-cors/zipball/361d71f00a0eea8b74da26ae75d0d207c53aa5b3",
"reference": "361d71f00a0eea8b74da26ae75d0d207c53aa5b3",
"shasum": "",
"mirrors": [
{
@@ -709,12 +647,10 @@
]
},
"require": {
"asm89/stack-cors": "^2.0.1",
"fruitcake/php-cors": "^1",
"illuminate/contracts": "^6|^7|^8|^9",
"illuminate/support": "^6|^7|^8|^9",
"php": ">=7.2",
"symfony/http-foundation": "^4|^5|^6",
"symfony/http-kernel": "^4.3.4|^5|^6"
"php": ">=7.2"
},
"require-dev": {
"laravel/framework": "^6|^7.24|^8",
@@ -725,7 +661,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
"dev-master": "2.1-dev"
},
"laravel": {
"providers": [
@@ -761,7 +697,7 @@
],
"support": {
"issues": "https://github.com/fruitcake/laravel-cors/issues",
"source": "https://github.com/fruitcake/laravel-cors/tree/v2.0.5"
"source": "https://github.com/fruitcake/laravel-cors/tree/v2.1.0"
},
"funding": [
{
@@ -773,7 +709,80 @@
"type": "github"
}
],
"time": "2022-01-03T14:53:04+00:00"
"time": "2022-02-19T14:17:28+00:00"
},
{
"name": "fruitcake/php-cors",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://github.com/fruitcake/php-cors.git",
"reference": "07611b4d603a72f097aeeeeb1e67d5ae7a6d0798"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fruitcake/php-cors/zipball/07611b4d603a72f097aeeeeb1e67d5ae7a6d0798",
"reference": "07611b4d603a72f097aeeeeb1e67d5ae7a6d0798",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": "^7.2|^8.0",
"symfony/http-foundation": "^4|^5|^6"
},
"require-dev": {
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^7|^9",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Fruitcake\\Cors\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barryvdh",
"email": "barryvdh@gmail.com"
}
],
"description": "Cross-origin resource sharing library for the Symfony HttpFoundation",
"homepage": "https://github.com/fruitcake/php-cors",
"keywords": [
"cors",
"laravel",
"symfony"
],
"support": {
"issues": "https://github.com/fruitcake/php-cors/issues",
"source": "https://github.com/fruitcake/php-cors/tree/v1.0.1"
},
"funding": [
{
"url": "https://fruitcake.nl",
"type": "custom"
},
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
"time": "2022-02-19T16:21:54+00:00"
},
{
"name": "graham-campbell/result-type",
@@ -8236,16 +8245,16 @@
},
{
"name": "phpunit/php-code-coverage",
"version": "9.2.10",
"version": "9.2.11",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "d5850aaf931743067f4bfc1ae4cbd06468400687"
"reference": "665a1ac0a763c51afc30d6d130dac0813092b17f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d5850aaf931743067f4bfc1ae4cbd06468400687",
"reference": "d5850aaf931743067f4bfc1ae4cbd06468400687",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/665a1ac0a763c51afc30d6d130dac0813092b17f",
"reference": "665a1ac0a763c51afc30d6d130dac0813092b17f",
"shasum": "",
"mirrors": [
{
@@ -8307,7 +8316,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.10"
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.11"
},
"funding": [
{
@@ -8315,7 +8324,7 @@
"type": "github"
}
],
"time": "2021-12-05T09:12:13+00:00"
"time": "2022-02-18T12:46:09+00:00"
},
{
"name": "phpunit/php-file-iterator",
@@ -8584,16 +8593,16 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.13",
"version": "9.5.14",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "597cb647654ede35e43b137926dfdfef0fb11743"
"reference": "1883687169c017d6ae37c58883ca3994cfc34189"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/597cb647654ede35e43b137926dfdfef0fb11743",
"reference": "597cb647654ede35e43b137926dfdfef0fb11743",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1883687169c017d6ae37c58883ca3994cfc34189",
"reference": "1883687169c017d6ae37c58883ca3994cfc34189",
"shasum": "",
"mirrors": [
{
@@ -8677,7 +8686,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.13"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.14"
},
"funding": [
{
@@ -8689,7 +8698,7 @@
"type": "github"
}
],
"time": "2022-01-24T07:33:35+00:00"
"time": "2022-02-18T12:54:07+00:00"
},
{
"name": "sebastian/cli-parser",
+38
View File
@@ -748,6 +748,14 @@ select {
margin-top: -0.5rem;
margin-bottom: -0.5rem;
}
.mx-1 {
margin-left: 0.25rem;
margin-right: 0.25rem;
}
.my-1 {
margin-top: 0.25rem;
margin-bottom: 0.25rem;
}
.ml-3 {
margin-left: 0.75rem;
}
@@ -823,6 +831,9 @@ select {
.-mr-2 {
margin-right: -0.5rem;
}
.mb-1 {
margin-bottom: 0.25rem;
}
.block {
display: block;
}
@@ -1174,6 +1185,11 @@ select {
border-top-width: calc(1px * calc(1 - var(--tw-divide-y-reverse)));
border-bottom-width: calc(1px * var(--tw-divide-y-reverse));
}
.divide-x > :not([hidden]) ~ :not([hidden]) {
--tw-divide-x-reverse: 0;
border-right-width: calc(1px * var(--tw-divide-x-reverse));
border-left-width: calc(1px * calc(1 - var(--tw-divide-x-reverse)));
}
.divide-solid > :not([hidden]) ~ :not([hidden]) {
border-style: solid;
}
@@ -1375,6 +1391,10 @@ select {
--tw-bg-opacity: 1;
background-color: rgb(254 242 242 / var(--tw-bg-opacity));
}
.bg-gray-400 {
--tw-bg-opacity: 1;
background-color: rgb(156 163 175 / var(--tw-bg-opacity));
}
.bg-opacity-75 {
--tw-bg-opacity: 0.75;
}
@@ -1515,6 +1535,21 @@ select {
.pb-1 {
padding-bottom: 0.25rem;
}
.pl-2 {
padding-left: 0.5rem;
}
.pl-6 {
padding-left: 1.5rem;
}
.pl-12 {
padding-left: 3rem;
}
.pl-8 {
padding-left: 2rem;
}
.pl-10 {
padding-left: 2.5rem;
}
.text-left {
text-align: left;
}
@@ -1575,6 +1610,9 @@ select {
.font-bold {
font-weight: 700;
}
.font-normal {
font-weight: 400;
}
.uppercase {
text-transform: uppercase;
}
+185 -1
View File
@@ -2,7 +2,191 @@
<x-app-layout>
<div class="my-6 md:my-9">
{{ Auth::user()->tokens }}
<p class="text-xl mb-2 text-gray-800 font-semibold">接口说明</p>
<div class="space-y-4 bg-gray-50 p-3 rounded-md mb-5">
<div>
<p class="text-lg text-gray-700 font-semibold">接口URL</p>
<x-code>{{ request()->getSchemeAndHttpHost() }}/api/v1</x-code>
<p class="text-sm text-red-500">请求接口时,必须设置 header 标头 Accept: application/json。</p>
</div>
<div>
<p class="text-lg text-gray-700 font-semibold">验证方式</p>
<div class="my-2 text-sm bg-white rounded-md p-4 overflow-x-auto">
当前版本接口采用 「HTTP 基本验证」的方式验证授权,通过接口获取 token 后,通过设置请求 header 标头来验证请求,例如:
<b class="block my-2 text-gray-600 text-sm">"Authorization": "1|1bJbwlqBfnggmOMEZqXT5XusaIwqiZjCDs7r1Ob5"</b>
或者:
<b class="block my-2 text-gray-600 text-sm">"Authorization": "Bearer 1|1bJbwlqBfnggmOMEZqXT5XusaIwqiZjCDs7r1Ob5"</b>
<p class="text-sm">如果未设置 Authorization 的情况下请求上传接口,将被视为游客上传。</p>
</div>
</div>
</div>
<p class="text-xl mb-2 text-gray-800 font-semibold">图片相关</p>
<div class="space-y-4 bg-gray-50 p-3 rounded-md mb-5">
<div>
<p class="text-lg text-gray-700 font-semibold">上传图片</p>
<x-code><span class="text-green-500">POST</span> /upload</x-code>
<div class="my-4 overflow-x-auto">
<p class="text-sm mb-2">Headers</p>
<table class="min-w-full">
<thead class="bg-gray-50 border">
<tr>
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap">
字段
</th>
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap">
类型
</th>
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap">
说明
</th>
</tr>
</thead>
<tbody class="bg-white border divide-y text-sm">
<tr>
<td class="px-3 py-2 whitespace-nowrap">Content-Type</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">需要设置为 multipart/form-data</td>
</tr>
</tbody>
</table>
</div>
<div class="my-4 overflow-x-auto">
<p class="text-sm mb-2">请求参数</p>
<table class="min-w-full">
<thead class="bg-gray-50 border">
<tr>
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap">
字段
</th>
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap">
类型
</th>
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap">
说明
</th>
</tr>
</thead>
<tbody class="bg-white border divide-y text-sm">
<tr>
<td class="px-3 py-2 whitespace-nowrap">file</td>
<td class="px-3 py-2 whitespace-nowrap">File</td>
<td class="px-3 py-2 whitespace-nowrap">图片文件</td>
</tr>
</tbody>
</table>
</div>
<div class="my-4 overflow-x-auto">
<p class="text-sm mb-2">返回参数</p>
<table class="min-w-full">
<thead class="bg-gray-50 border">
<tr>
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap">
字段
</th>
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap">
类型
</th>
<th scope="col" class="px-3 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider whitespace-nowrap">
说明
</th>
</tr>
</thead>
<tbody class="bg-white border divide-y text-sm">
<tr>
<td class="px-3 py-2 whitespace-nowrap">status</td>
<td class="px-3 py-2 whitespace-nowrap">Boolean</td>
<td class="px-3 py-2 whitespace-nowrap">状态,true false</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap">message</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">描述信息</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap">data</td>
<td class="px-3 py-2 whitespace-nowrap">Object</td>
<td class="px-3 py-2 whitespace-nowrap">图片数据</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-6">id</td>
<td class="px-3 py-2 whitespace-nowrap">Integer</td>
<td class="px-3 py-2 whitespace-nowrap">图片唯一ID</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-6">pathname</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">图片路径名</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-6">origin_name</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">图片原始名</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-6">size</td>
<td class="px-3 py-2 whitespace-nowrap">Float</td>
<td class="px-3 py-2 whitespace-nowrap">图片大小,单位 KB</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-6">mimetype</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">图片类型</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-6">md5</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">图片 md5 </td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-6">sha1</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">图片 sha1 </td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-6">links</td>
<td class="px-3 py-2 whitespace-nowrap">Object</td>
<td class="px-3 py-2 whitespace-nowrap">链接</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-10">url</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">图片访问 url</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-10">html</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">-</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-10">bbcode</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">-</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-10">markdown</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">-</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-10">markdown_with_link</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">-</td>
</tr>
<tr>
<td class="px-3 py-2 whitespace-nowrap pl-10">thumbnail_url</td>
<td class="px-3 py-2 whitespace-nowrap">String</td>
<td class="px-3 py-2 whitespace-nowrap">缩略图 url</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
@push('scripts')
@@ -0,0 +1,3 @@
<pre {{ $attributes->merge(['class' => 'my-2 bg-white rounded-md p-4 text-sm bg-gray-500 text-white overflow-x-auto']) }}>
{{ $slot ?? '' }}
</pre>
+3
View File
@@ -2,6 +2,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Controller;
/*
|--------------------------------------------------------------------------
@@ -17,6 +18,8 @@ use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\V1\TokenController;
Route::group(['prefix' => 'v1'], function () {
Route::post('upload', [Controller::class, 'upload']);
Route::group([
'middleware' => 'auth:sanctum',
], function () {