Skip to content

Commit

Permalink
improve translations, add admin status widget (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland authored Nov 23, 2024
1 parent 7c1f274 commit 96bdd04
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 62 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"homepage": "https://friendsofflarum.org",
"require": {
"php": "^8.0",
"flarum/core": "^1.3.1",
"flarum/core": "^1.8",
"league/flysystem-aws-s3-v3": "^1.0",
"vlucas/phpdotenv": "^5.4"
},
Expand Down
58 changes: 29 additions & 29 deletions js/src/admin/components/S3SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ export default class S3SettingsPage extends ExtensionPage {

!this.s3SetByEnv &&
items.add(
'aws-s3',
's3',
<div className="Section">
<h3>{app.translator.trans('fof-s3-assets.admin.settings.aws-s3.heading')}</h3>
<p className="helpText">{app.translator.trans('fof-s3-assets.admin.settings.aws-s3.help')}</p>
{this.awss3Items().toArray()}
<h3>{app.translator.trans('fof-s3-assets.admin.settings.s3.heading')}</h3>
<p className="helpText">{app.translator.trans('fof-s3-assets.admin.settings.s3.help')}</p>
{this.s3Items().toArray()}
</div>
);

!this.s3SetByEnv &&
items.add(
'aws-s3-compatible',
's3-compatible',
<div className="Section">
<h3>{app.translator.trans('fof-s3-assets.admin.settings.aws-s3-compatible.heading')}</h3>
<p className="helpText">{app.translator.trans('fof-s3-assets.admin.settings.aws-s3-compatible.help')}</p>
{this.awss3CompatibleItems().toArray()}
<h3>{app.translator.trans('fof-s3-assets.admin.settings.s3-compatible.heading')}</h3>
<p className="helpText">{app.translator.trans('fof-s3-assets.admin.settings.s3-compatible.help')}</p>
{this.s3CompatibleItems().toArray()}
</div>
);

Expand Down Expand Up @@ -95,26 +95,26 @@ export default class S3SettingsPage extends ExtensionPage {
return items;
}

awss3Items(): ItemList<Mithril.Children> {
s3Items(): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();

items.add(
'awsS3Key',
this.buildSettingComponent({
setting: `${this.settingPrefix}awsS3Key`,
type: 'string',
label: app.translator.trans('fof-s3-assets.admin.settings.s3key.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3key.help'),
label: app.translator.trans('fof-s3-assets.admin.settings.s3.keyid.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3.keyid.help'),
})
);

items.add(
'awsS3Secret',
this.buildSettingComponent({
setting: `${this.settingPrefix}awsS3Secret`,
type: 'string',
label: app.translator.trans('fof-s3-assets.admin.settings.s3secret.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3secret.help'),
type: 'password',
label: app.translator.trans('fof-s3-assets.admin.settings.s3.secret.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3.secret.help'),
})
);

Expand All @@ -123,8 +123,8 @@ export default class S3SettingsPage extends ExtensionPage {
this.buildSettingComponent({
setting: `${this.settingPrefix}awsS3Region`,
type: 'string',
label: app.translator.trans('fof-s3-assets.admin.settings.s3region.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3region.help'),
label: app.translator.trans('fof-s3-assets.admin.settings.s3.region.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3.region.help'),
})
);

Expand All @@ -133,8 +133,8 @@ export default class S3SettingsPage extends ExtensionPage {
this.buildSettingComponent({
setting: `${this.settingPrefix}awsS3Bucket`,
type: 'string',
label: app.translator.trans('fof-s3-assets.admin.settings.s3bucket.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3bucket.help'),
label: app.translator.trans('fof-s3-assets.admin.settings.s3.bucket.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3.bucket.help'),
})
);

Expand All @@ -143,8 +143,8 @@ export default class S3SettingsPage extends ExtensionPage {
this.buildSettingComponent({
setting: `${this.settingPrefix}awsS3ACL`,
type: 'string',
label: app.translator.trans('fof-s3-assets.admin.settings.s3acl.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3acl.help'),
label: app.translator.trans('fof-s3-assets.admin.settings.s3.acl.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3.acl.help'),
})
);

Expand All @@ -154,24 +154,24 @@ export default class S3SettingsPage extends ExtensionPage {
setting: `${this.settingPrefix}awsS3CacheControl`,
type: 'number',
min: 0,
label: app.translator.trans('fof-s3-assets.admin.settings.aws-s3.cache-control.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.aws-s3.cache-control.help'),
label: app.translator.trans('fof-s3-assets.admin.settings.s3.cache-control.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3.cache-control.help'),
})
);

return items;
}

awss3CompatibleItems(): ItemList<Mithril.Children> {
s3CompatibleItems(): ItemList<Mithril.Children> {
const items = new ItemList<Mithril.Children>();

items.add(
'cdnUrl',
this.buildSettingComponent({
setting: `${this.settingPrefix}cdnUrl`,
type: 'string',
label: app.translator.trans('fof-s3-assets.admin.settings.s3url.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3url.help'),
label: app.translator.trans('fof-s3-assets.admin.settings.s3-compatible.url.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3-compatible.url.help'),
})
);

Expand All @@ -180,8 +180,8 @@ export default class S3SettingsPage extends ExtensionPage {
this.buildSettingComponent({
setting: `${this.settingPrefix}awsS3Endpoint`,
type: 'string',
label: app.translator.trans('fof-s3-assets.admin.settings.s3endpoint.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3endpoint.help'),
label: app.translator.trans('fof-s3-assets.admin.settings.s3-compatible.endpoint.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3-compatible.endpoint.help'),
})
);

Expand All @@ -190,8 +190,8 @@ export default class S3SettingsPage extends ExtensionPage {
this.buildSettingComponent({
setting: `${this.settingPrefix}awsS3UsePathStyleEndpoint`,
type: 'boolean',
label: app.translator.trans('fof-s3-assets.admin.settings.s3path-style-endpoint.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3path-style-endpoint.help'),
label: app.translator.trans('fof-s3-assets.admin.settings.s3-compatible.path-style-endpoint.label'),
help: app.translator.trans('fof-s3-assets.admin.settings.s3-compatible.path-style-endpoint.help'),
})
);

Expand Down
9 changes: 9 additions & 0 deletions js/src/admin/extenders/addCDNToWidgets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import app from 'flarum/admin/app';
import { extend } from 'flarum/common/extend';
import StatusWidget from 'flarum/admin/components/StatusWidget';

export default function addCDNToWidgets() {
extend(StatusWidget.prototype, 'items', function (items) {
items.add('cdn', [<strong>CDN</strong>, <br />, app.data.cdn], 50);
});
}
3 changes: 3 additions & 0 deletions js/src/admin/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import app from 'flarum/admin/app';
import S3SettingsPage from './components/S3SettingsPage';
import addCDNToWidgets from './extenders/addCDNToWidgets';

app.initializers.add('fof/s3-assets', () => {
app.extensionData.for('fof-s3-assets').registerPage(S3SettingsPage);

addCDNToWidgets();
});
58 changes: 27 additions & 31 deletions locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,41 @@ fof-s3-assets:
shareWithFoFUpload:
label: Use FoF Upload S3 settings.
help: Re-use the S3 settings from the FoF Upload extension.
aws-s3:
s3:
cache-control:
label: Cache-Control
help: Sets the Cache-Control header for the uploaded files. 0 means no cache.
keyid:
label: Key ID
help: S3 access key ID.
secret:
label: Secret
help: S3 secret key.
region:
label: Region
help: S3 region your bucket is located in.
bucket:
label: Bucket
help: The name of your S3 bucket.
acl:
label: ACL
help: Specify the ACL for this bucket, if required.
heading: S3 Settings
help: Settings for AWS S3 and/or S3-compatible buckets. If you are using AWS S3, you only need to configure these settings.


aws-s3-compatible:
s3-compatible:
endpoint:
label: Endpoint
help: "The s3:// URL of your S3-compatible storage."
path-style-endpoint:
label: Path style endpoint
help: This is required for some S3-compatible storage providers. Check your provider's documentation to see if you need to enable this.
url:
label: URL
help: This is the public facing URL of your S3-compatible storage, including the protocol. This can also be set if you are using a custom hostname on AWS S3.
heading: S3-Compatible Settings
help: Settings needed for S3-compatible buckets only. Leave these settings blank if you are using AWS S3.
help: Settings needed for S3-compatible buckets. Leave these settings blank if you are using AWS S3, unless you are using a custom hostname.


aws-section: These settings are required for both AWS S3 and S3-compatible buckets
s3-compatible-section: These settings are only required for S3-compatible buckets
s3-compatible-section-help: Leave these settings blank if using AWS S3
s3key:
label: Key
help: S3 access key
s3secret:
label: Secret
help: S3 access secret
s3region:
label: Region
help: S3 region
s3bucket:
label: Bucket
help: S3 bucket
s3acl:
label: ACL
help: Specify the ACL for this bucket
s3url:
label: URL
help: S3 URL
s3endpoint:
label: Endpoint
help: S3 Endpoint
s3path-style-endpoint:
label: S3 path style endpoint
help: Switch to path style storage


1 change: 1 addition & 0 deletions src/Content/AdminPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ public function __invoke(Document $document)
{
$document->payload['s3SetByEnv'] = $this->s3Config->shouldUseEnv();
$document->payload['FoFS3ShareWithFoFUpload'] = $this->settings->get('fof-s3-assets.share_s3_config_with_fof_upload');
$document->payload['cdn'] = $this->s3->cdnHost();
}
}
10 changes: 9 additions & 1 deletion src/Repository/S3Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@

namespace FoF\S3Assets\Repository;

use FoF\S3Assets\Driver\Config as DriverConfig;
use Illuminate\Support\Arr;
use Psr\Log\LoggerInterface;

class S3Repository
{
public function __construct(
protected LoggerInterface $logger
protected LoggerInterface $logger,
protected DriverConfig $config
) {
}

public function cdnHost(): string
{
return Arr::get($this->config->config(), 'url');
}
}

0 comments on commit 96bdd04

Please sign in to comment.