Skip to content

Commit

Permalink
language Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenfan committed Oct 24, 2019
1 parent c579b25 commit 8704434
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 43 deletions.
9 changes: 5 additions & 4 deletions composer.json
Expand Up @@ -22,18 +22,19 @@
},
"require": {
"flarum/core": "^0.1.0-beta.8",
"ramsey/uuid": "^3.5.2",
"overtrue/flysystem-qiniu":"1.0.4"
"ramsey/uuid": "^3.5.2"
},
"suggest": {
"league/flysystem-aws-s3-v3": "Uploads to AWS S3 using API version 3.",
"techyah/flysystem-ovh": "Uploads to OVH Swift vfs using API."
"techyah/flysystem-ovh": "Uploads to OVH Swift vfs using API.",
"overtrue/flysystem-qiniu":"Uploads to QiNiu using API."
},
"require-dev": {
"league/flysystem": "^1.0.32",
"league/flysystem-aws-s3-v3": "^1.0",
"techyah/flysystem-ovh": "^1.0",
"flagrow/steamroller": "dev-master"
"flagrow/steamroller": "dev-master",
"overtrue/flysystem-qiniu":"1.0.4"
},
"extra": {
"flarum-extension": {
Expand Down
1 change: 1 addition & 0 deletions resources/locale/cn.yml
Expand Up @@ -11,6 +11,7 @@ flagrow-upload:
upload_label: 文件上传设定
download_label: 下载文件
upload_methods:
qiniu: 七牛
local: 本地
aws-s3: 亚马逊 S3
imgur: Imgur
Expand Down
1 change: 1 addition & 0 deletions resources/locale/zh.yml
Expand Up @@ -11,6 +11,7 @@ flagrow-upload:
upload_label: 文件上传设定
download_label: 下载文件
upload_methods:
qiniu: 七牛
local: 本地
aws-s3: 亚马逊 S3
imgur: Imgur
Expand Down
4 changes: 2 additions & 2 deletions src/Adapters/Qiniu.php
Expand Up @@ -4,6 +4,7 @@
use Flagrow\Upload\Contracts\UploadAdapter;
use Flagrow\Upload\File;
use Flagrow\Upload\Helpers\Settings;
use Flarum\Foundation\ValidationException;

/**
*
Expand All @@ -22,8 +23,7 @@ protected function generateUrl(File $file)
if ($cdnUrl = $settings->get('cdnUrl')) {
$file->url = sprintf('%s/%s', $cdnUrl, $path);
} else {
$baseUrl = "http://pzs4lomfo.bkt.clouddn.com";
$file->url = sprintf('%s/%s', $baseUrl, $path);
throw new ValidationException(['upload' => 'QiNiu cloud CDN address is not configured.']);

}
}
Expand Down
20 changes: 13 additions & 7 deletions src/Helpers/Settings.php
Expand Up @@ -18,15 +18,15 @@
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Qiniu\Http\Client as QiniuClient;
use Techyah\Flysystem\OVH\OVHClient;
use Qiniu\Http\Client as QiniuClient;

/**
* @property int $maxFileSize
*/
class Settings
{
const DEFAULT_MAX_FILE_SIZE = 2048;
const DEFAULT_MAX_FILE_SIZE = 2048;
const DEFAULT_MAX_IMAGE_WIDTH = 100;

/**
Expand Down Expand Up @@ -85,6 +85,11 @@ class Settings
// Downloads
'disableHotlinkProtection',
'disableDownloadLogging',

//QiNiu
'qiniuKey',
'qiniuSecret',
'qiniuBucket',
];

protected $prefix = 'flagrow.upload.';
Expand All @@ -101,17 +106,17 @@ public function __construct(SettingsRepositoryInterface $settings)

public function __get($name)
{
return $this->settings->get($this->prefix . $name);
return $this->settings->get($this->prefix.$name);
}

public function __set($name, $value)
{
$this->settings->set($this->prefix . $name, $value);
$this->settings->set($this->prefix.$name, $value);
}

public function __isset($name)
{
return $this->settings->get($this->prefix . $name) !== null;
return $this->settings->get($this->prefix.$name) !== null;
}

/**
Expand All @@ -132,7 +137,7 @@ public function toArray($prefixed = true, array $only = null)

foreach ($definition as $property) {
if ($prefixed) {
$result[$this->prefix . $property] = $this->get($property);
$result[$this->prefix.$property] = $this->get($property);
} else {
$result[$property] = $this->get($property);
}
Expand Down Expand Up @@ -200,6 +205,7 @@ public function getAvailableUploadMethods()
if (class_exists(OVHClient::class)) {
$methods[] = 'ovh-svfs';
}

if (class_exists(QiniuClient::class)) {
$methods[] = 'qiniu';
}
Expand All @@ -211,7 +217,7 @@ public function getAvailableUploadMethods()
return $item;
})
->map(function ($item) {
return app('translator')->trans('flagrow-upload.admin.upload_methods.' . $item);
return app('translator')->trans('flagrow-upload.admin.upload_methods.'.$item);
});
}

Expand Down
51 changes: 21 additions & 30 deletions src/Providers/StorageServiceProvider.php
Expand Up @@ -15,7 +15,6 @@

use Aws\S3\S3Client;
use Flagrow\Upload\Adapters;
use Flagrow\Upload\Adapters\Qiniu;
use Flagrow\Upload\Helpers\Settings;
use GuzzleHttp\Client as Guzzle;
use Illuminate\Container\Container;
Expand All @@ -24,9 +23,10 @@
use League\Flysystem\Adapter as FlyAdapters;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use Overtrue\Flysystem\Qiniu\QiniuAdapter;
use Qiniu\Http\Client as QiniuClient;
use Techyah\Flysystem\OVH\OVHAdapter;
use Techyah\Flysystem\OVH\OVHClient;
use Flagrow\Upload\Adapters\Qiniu;
use Qiniu\Http\Client as QiniuClient;

class StorageServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -54,7 +54,6 @@ public function register()
*/
protected function instantiateUploadAdapters(Container $app)
{

/** @var Settings $settings */
$settings = $app->make(Settings::class);

Expand All @@ -68,7 +67,6 @@ protected function instantiateUploadAdapters(Container $app)
}

$app->bind("flagrow.upload-adapter.$adapter", function () use ($settings, $adapter) {

switch ($adapter) {
case 'aws-s3':
if (class_exists(S3Client::class)) {
Expand All @@ -81,12 +79,9 @@ protected function instantiateUploadAdapters(Container $app)
case 'imgur':
return $this->imgur($settings);
case 'qiniu':

if (class_exists(QiniuClient::class)) {

return $this->qiniu($settings);
}

default:
return $this->local($settings);
}
Expand All @@ -108,34 +103,14 @@ protected function awsS3(Settings $settings)
'key' => $settings->get('awsS3Key'),
'secret' => $settings->get('awsS3Secret'),
],
'region' => empty($settings->get('awsS3Region')) ? null : $settings->get('awsS3Region'),
'version' => 'latest',
'region' => empty($settings->get('awsS3Region')) ? null : $settings->get('awsS3Region'),
'version' => 'latest',
]),
$settings->get('awsS3Bucket')
)
);
}

/**
* [qiniu]
* @Author 王文凡
* @DateTime 2019-10-23
* @version 1.0
* @param Settings $settings [description]
* @return Adapters\Qiniu
*/
protected function qiniu(Settings $settings)
{

$client = new QiniuAdapter(
$settings->get('qiniuKey'),
$settings->get('qiniuSecret'),
$settings->get('qiniuBucket'),
$settings->get('cdnUrl')
);
return new Qiniu($client);
}

/**
* @param Settings $settings
*
Expand Down Expand Up @@ -167,7 +142,7 @@ protected function imgur(Settings $settings)
new Guzzle([
'base_uri' => 'https://api.imgur.com/3/',
'headers' => [
'Authorization' => 'Client-ID ' . $settings->get('imgurClientId'),
'Authorization' => 'Client-ID '.$settings->get('imgurClientId'),
],
])
);
Expand All @@ -184,4 +159,20 @@ protected function local(Settings $settings)
new FlyAdapters\Local(public_path('assets/files'))
);
}

/**
* @param Settings $settings
* @return Adapters\Qiniu
*/
protected function qiniu(Settings $settings)
{

$client = new QiniuAdapter(
$settings->get('qiniuKey'),
$settings->get('qiniuSecret'),
$settings->get('qiniuBucket'),
$settings->get('cdnUrl')
);
return new Qiniu($client);
}
}

0 comments on commit 8704434

Please sign in to comment.