Skip to content

Commit

Permalink
Add getTemporaryUrl() for laravel FilesystemAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Feb 17, 2022
1 parent cd49bc6 commit 44c35f1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
36 changes: 22 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
Flysystem Adapter for Qiniu Cloud Storage
---
## Flysystem Adapter for Qiniu Cloud Storage

:floppy_disk: Flysystem adapter for the Qiniu cloud storage.

[![Build Status](https://travis-ci.org/overtrue/flysystem-qiniu.svg?branch=master)](https://travis-ci.org/overtrue/flysystem-qiniu)
[![Latest Stable Version](https://poser.pugx.org/overtrue/flysystem-qiniu/v/stable.svg)](https://packagist.org/packages/overtrue/flysystem-qiniu)
[![Latest Unstable Version](https://poser.pugx.org/overtrue/flysystem-qiniu/v/unstable.svg)](https://packagist.org/packages/overtrue/flysystem-qiniu)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/overtrue/flysystem-qiniu/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/overtrue/flysystem-qiniu/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/overtrue/flysystem-qiniu/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/overtrue/flysystem-qiniu/?branch=master)
[![Total Downloads](https://poser.pugx.org/overtrue/flysystem-qiniu/downloads)](https://packagist.org/packages/overtrue/flysystem-qiniu)
[![Build Status](https://travis-ci.org/overtrue/flysystem-qiniu.svg?branch=master)](https://travis-ci.org/overtrue/flysystem-qiniu)
[![Latest Stable Version](https://poser.pugx.org/overtrue/flysystem-qiniu/v/stable.svg)](https://packagist.org/packages/overtrue/flysystem-qiniu)
[![Latest Unstable Version](https://poser.pugx.org/overtrue/flysystem-qiniu/v/unstable.svg)](https://packagist.org/packages/overtrue/flysystem-qiniu)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/overtrue/flysystem-qiniu/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/overtrue/flysystem-qiniu/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/overtrue/flysystem-qiniu/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/overtrue/flysystem-qiniu/?branch=master)
[![Total Downloads](https://poser.pugx.org/overtrue/flysystem-qiniu/downloads)](https://packagist.org/packages/overtrue/flysystem-qiniu)
[![License](https://poser.pugx.org/overtrue/flysystem-qiniu/license)](https://packagist.org/packages/overtrue/flysystem-qiniu)

[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue)

# Requirement

- PHP >= 8.0.2
- PHP >= 8.0.2

# Installation

Expand Down Expand Up @@ -55,22 +54,31 @@ bool $flysystem->directoryExists('path/to/dir');
string|false $flysystem->read('file.md');
array $flysystem->listContents();
int $flysystem->fileSize('file.md');
string $flysystem->getAdapter()->getUrl('file.md');
string $flysystem->mimeType('file.md');
```

Adapter extended methods:

```php
string $adapter->getUrl('file.md');
bool|array $adapter->fetch(string $path, string $url);
array $adapter->refresh(string $path);
string $adapter->getTemporaryUrl($path, int|string|\DateTimeInterface $expiration);
string $adapter->privateDownloadUrl(string $path, int $expires = 3600);
string $adapter->getUploadToken(string $key = null, int $expires = 3600, string $policy = null, string $strictPolice = null)
```

# Integration

- Laravel 5: [overtrue/laravel-filesystem-qiniu](https://github.com/overtrue/laravel-filesystem-qiniu)
- Yii2: [krissss/yii2-filesystem-qiniu](https://github.com/krissss/yii2-filesystem-qiniu)
- Laravel: [overtrue/laravel-filesystem-qiniu](https://github.com/overtrue/laravel-filesystem-qiniu)
- Yii2: [krissss/yii2-filesystem-qiniu](https://github.com/krissss/yii2-filesystem-qiniu)

## :heart: Sponsor me
## :heart: Sponsor me

[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue)

如果你喜欢我的项目并想支持它,[点击这里 :heart:](https://github.com/sponsors/overtrue)


## Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
Expand Down
33 changes: 25 additions & 8 deletions src/QiniuAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ public function copy(string $source, string $destination, Config $config): void
}
}

protected function getMetadata($path): FileAttributes|array
{
$result = $this->getBucketManager()->stat($this->bucket, $path);
$result[0]['key'] = $path;

return $this->normalizeFileInfo($result[0]);
}

public function getUrl(string $path): string
{
$segments = $this->parseUrl($path);
Expand All @@ -190,13 +198,6 @@ public function getUrl(string $path): string
return $this->normalizeHost($this->domain) . ltrim(implode('/', array_map('rawurlencode', explode('/', $segments['path']))), '/') . $query;
}

protected function getMetadata($path): FileAttributes|array
{
$result = $this->getBucketManager()->stat($this->bucket, $path);
$result[0]['key'] = $path;

return $this->normalizeFileInfo($result[0]);
}

public function fetch(string $path, string $url): bool|array
{
Expand All @@ -209,12 +210,28 @@ public function fetch(string $path, string $url): bool|array
return $response;
}

/**
* For laravel FilesystemAdapter.
*/
public function getTemporaryUrl($path, int|string|\DateTimeInterface $expiration): string
{
if ($expiration instanceof \DateTimeInterface) {
$expiration = $expiration->getTimestamp();
}

if (is_string($expiration)) {
$expiration = strtotime($expiration);
}

return $this->privateDownloadUrl($path, $expiration);
}

public function privateDownloadUrl(string $path, int $expires = 3600): string
{
return $this->getAuthManager()->privateDownloadUrl($this->getUrl($path), $expires);
}

public function refresh($path)
public function refresh(string $path)
{
if (is_string($path)) {
$path = [$path];
Expand Down

0 comments on commit 44c35f1

Please sign in to comment.