# Kylin Storage

Kylin 多云文件存储包 — 本地/七牛/腾讯COS/阿里OSS/华为OBS/S3/金山KS3/百度BOS，内置 SDK。

## 功能特性

- **适配器模式**：统一 `StorageAdapterInterface` 接口
- **多云支持**：本地、七牛、腾讯云 COS、阿里云 OSS、华为云 OBS、AWS S3/MinIO、金山云 KS3、百度云 BOS
- **内置 SDK**：所有云存储 SDK Fork 到本地，无需外部依赖
- **统一操作**：上传、下载、删除、URL 生成、文件是否存在
- **动态切换**：运行时切换存储驱动
- **临时 URL**：生成带签名的临时访问链接
- **文件验证**：大小限制、类型检查

## 安装

```bash
composer require kylin/storage
```

## 配置发布

```bash
php artisan vendor:publish --tag=kylin-storage-config
```

## 使用示例

### Facade

```php
use Kylin\Storage\Facades\KylinStorage;

// 上传文件
$path = KylinStorage::upload($file, 'avatars');

// 获取 URL
$url = KylinStorage::url($path);

// 生成临时 URL（签名链接）
$tempUrl = KylinStorage::temporaryUrl($path, now()->addHour());

// 删除文件
KylinStorage::delete($path);

// 切换存储驱动
KylinStorage::disk('qiniu')->upload($file, 'uploads');
```

### 存储驱动配置

```php
// config/kylin-storage.php
'default' => env('KYLIN_STORAGE_DRIVER', 'local'),

'drivers' => [
    'local' => ['root' => storage_path('app')],
    'qiniu' => [
        'access_key' => env('QINIU_ACCESS_KEY'),
        'secret_key' => env('QINIU_SECRET_KEY'),
        'bucket' => env('QINIU_BUCKET'),
        'domain' => env('QINIU_DOMAIN'),
    ],
    'aliyun' => [
        'access_key_id' => env('ALIYUN_OSS_ACCESS_KEY_ID'),
        'access_key_secret' => env('ALIYUN_OSS_ACCESS_KEY_SECRET'),
        'bucket' => env('ALIYUN_OSS_BUCKET'),
        'endpoint' => env('ALIYUN_OSS_ENDPOINT'),
    ],
    'tencent' => [
        'secret_id' => env('TENCENT_COS_SECRET_ID'),
        'secret_key' => env('TENCENT_COS_SECRET_KEY'),
        'bucket' => env('TENCENT_COS_BUCKET'),
        'region' => env('TENCENT_COS_REGION'),
    ],
],
```

## SDK 目录结构

```
src/
├── Adapters/
│   ├── LocalAdapter.php
│   ├── QiniuAdapter.php
│   ├── AliyunAdapter.php
│   ├── TencentAdapter.php
│   ├── HuaweiAdapter.php
│   ├── S3Adapter.php
│   ├── KingsoftAdapter.php
│   └── BaiduAdapter.php
├── Aliyun/                # 阿里云 OSS SDK (Fork)
├── Tencent/               # 腾讯云 COS SDK (Fork)
├── Huawei/                # 华为云 OBS SDK (Fork)
├── Kingsoft/              # 金山云 KS3 SDK (Fork)
├── Qiniu/                 # 七牛 SDK (Fork)
├── Contracts/
│   └── StorageAdapterInterface.php
├── Facades/
│   └── KylinStorage.php
├── Http/Controllers/
│   └── StorageController.php
├── Models/
│   └── File.php
├── Services/
│   └── StorageService.php
└── StorageServiceProvider.php
```

## 依赖

- PHP ^8.5
- Laravel ^13.0
- kylin/core
- guzzlehttp/guzzle ^7.0

## 许可证

私有软件，未经授权禁止使用。
