Skip to content

Commit

Permalink
chore: remove tmp notes
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Nov 23, 2024
1 parent 7d6b50b commit 3985097
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 61 deletions.
57 changes: 1 addition & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The S3 (or compatible) bucket can be configured either by environment variables
- `FOF_S3_ENDPOINT` - the ARN
- `FOF_S3_ACL` - The ACL, if any, that should be applied to the uploaded object. For possible values, see [AWS Docs](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl)
- `FOF_S3_PATH_STYLE_ENDPOINT` - boolean value
- `FOF_S3_CACHE_CONTROL` - Optional. Specify the `max-age` header files should be served with, for example `3153600` (1 year). `0` or not set = no caching.

`*` denotes the minimum requirements for using S3 on AWS. S3-compatible services will require more.

Expand All @@ -48,59 +49,3 @@ php flarum fof:s3:copy --move
## Links

- [Discuss](https://discuss.flarum.org/d/PUT_DISCUSS_SLUG_HERE)


[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"POST",
"GET",
"PUT"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 0
}
]


{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::nothing-forum-test/*"
}
]
}


{
"Version": "2012-10-17",
"Id": "http referer policy",
"Statement": [
{
"Sid": "Allow get requests originating from www.nothing.community and nothing.community.",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": "arn:aws:s3:::nothing-forum-test/*",
"Condition": {
"StringLike": {
"aws:Referer": "https://fstlnforum.bbxlk.cc*"
}
}
}
]

}
17 changes: 17 additions & 0 deletions js/src/admin/components/S3SettingsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import app from 'flarum/admin/app';
import ExtensionPage from 'flarum/admin/components/ExtensionPage';
import ItemList from 'flarum/common/utils/ItemList';
import Placeholder from 'flarum/common/components/Placeholder';
import type Mithril from 'mithril';

type AwsRegion = {
Expand Down Expand Up @@ -86,6 +87,11 @@ export default class S3SettingsPage extends ExtensionPage {
})
);

// If there are no items, add a placeholder to prevent the page from breaking
if (items.toArray().length === 0 && this.s3SetByEnv) {
items.add('setByEnv', <Placeholder text={app.translator.trans('fof-s3-assets.admin.settings.general.configured_by_environment')} />);
}

return items;
}

Expand Down Expand Up @@ -142,6 +148,17 @@ export default class S3SettingsPage extends ExtensionPage {
})
);

items.add(
'awsS3CacheControl',
this.buildSettingComponent({
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'),
})
);

return items;
}

Expand Down
8 changes: 7 additions & 1 deletion locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ fof-s3-assets:
admin:
settings:
general:
configured_by_environment: Your bucket settings have been pre-configured, nothing to see here.
heading: General Settings
help: General settings for the assets.
shareWithFoFUpload:
label: Use FoF Upload S3 settings.
help: Re-use the S3 settings from the FoF Upload extension.
aws-s3:
cache-control:
label: Cache-Control
help: Sets the Cache-Control header for the uploaded files. 0 means no cache.
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:
heading: S3-Compatible Settings
help: Settings needed for S3-compatible buckets only. Leave these settings blank if you are using AWS S3.

configured_by_environment: Your bucket settings have been pre-configured, nothing to see here.

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
Expand Down
8 changes: 6 additions & 2 deletions src/Driver/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function config(): array
return $config;
}

protected function buildConfigArray(string $key, string $secret, string $region, string $bucket, string $cdnUrl, ?string $endpoint, ?bool $pathStyle, ?string $acl, bool $setByEnv = false, string $cache = 'max-age=31536000', string $driver = 's3'): array
protected function buildConfigArray(string $key, string $secret, string $region, string $bucket, string $cdnUrl, ?string $endpoint, ?bool $pathStyle, ?string $acl, ?int $cache = null, bool $setByEnv = false, string $driver = 's3'): array
{
// These are the required values for AWS S3.
// Some S3-compatible services may require additional values, so we check if any of these are set below.
Expand Down Expand Up @@ -82,7 +82,7 @@ protected function buildConfigArray(string $key, string $secret, string $region,
}

if ($cache) {
$config['options']['CacheControl'] = $cache;
$config['options']['CacheControl'] = "max-age=$cache";
}

return $config;
Expand All @@ -96,6 +96,7 @@ protected function buildConfigFromEnv(): array
$endpoint = env('FOF_S3_ENDPOINT');
$pathStyle = (bool) env('FOF_S3_PATH_STYLE_ENDPOINT', false);
$acl = env('FOF_S3_ACL');
$cache = env('FOF_S3_CACHE_CONTROL');

return $this->buildConfigArray(
key: env('FOF_S3_ACCESS_KEY_ID'),
Expand All @@ -106,6 +107,7 @@ protected function buildConfigFromEnv(): array
endpoint: $endpoint,
pathStyle: $pathStyle,
acl: $acl,
cache: $cache,
setByEnv: true
);
}
Expand All @@ -118,6 +120,7 @@ protected function buildConfigFromSettings(): array
$endpoint = $this->getSetting('awsS3Endpoint');
$pathStyle = (bool) $this->getSetting('awsS3UsePathStyleEndpoint', false);
$acl = $this->getSetting('awsS3ACL');
$cache = $this->getSetting('awsS3CacheControl');

return $this->buildConfigArray(
key: $this->getSetting('awsS3Key', ''),
Expand All @@ -128,6 +131,7 @@ protected function buildConfigFromSettings(): array
endpoint: $endpoint,
pathStyle: $pathStyle,
acl: $acl,
cache: $cache,
setByEnv: false
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Validator/S3DiskConfigValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ class S3DiskConfigValidator extends AbstractValidator
'region' => ['required', 'string'],
'bucket' => ['required', 'string'],
'url' => ['url'],
//'endpoint' => ['url'],
'endpoint' => ['url'],
'use_path_style_endpoint' => ['required', 'bool'],
//'options.ACL' => ['string'],
'options.ACL' => ['string'],
'options.CacheControl' => ['string'],
'set_by_environment' => ['required', 'bool'],
];
}

0 comments on commit 3985097

Please sign in to comment.