Skip to content

Commit

Permalink
Update V12
Browse files Browse the repository at this point in the history
  • Loading branch information
FaeyUmbrea committed May 31, 2024
1 parent ebbc6a1 commit 4633769
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions .idea/S3-Custom-URL.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,46 @@ This module allows for use of S3 Storage where the API Url and the Public URL do

## Why?

A lot of people, myself included, have bought cheap object storage with an alternative provider, only to realize that their provider of choice does not support the format that foundry wants from us.
A lot of people, myself included, have bought budget object storage with an alternative provider,
only to realize that their provider of choice does not support the format that foundry wants from us.

## How?

Foundry only ever actually touches the S3 API when you upload stuff or when you request a directory's item list.
As such, the backend actually never handles your S3 Object Storage after you leave the FilePicker.
This allows a frontend module to take what ever URL the backend gives us and transform it into the correct format.
This allows a frontend module to take whatever URL the backend gives us and transform it into the correct format.

S3 Custom URL patches the 2 FilePicker methods that interact with the Backend generated URLs using libWrapper and modifies the URL to fit the configured scheme automagically.
It also provides the method S3CustomURL.createS3URL which takes the bucket and the filepath and spits out the URL for you. This is mainly so modules can make use of it.
S3 Custom URL patches the two FilePicker methods that interact with the Backend generated URLs using libWrapper
and modifies the URL to fit the configured scheme automagically.
It also provides the method S3CustomURL.createS3URL which takes the bucket and the filepath
and spits out the URL for you.
This is mainly so modules can make use of it.

## Ok now how do I use this?

Simple, there really is only ~~2~~ 1 usecase~~s~~ this module covers (~~3~~ 2 if you count all features disabled)
Simple, there really is only ~~2~~ 1 use case~~s~~ this module covers (~~3~~ 2 if you count all features disabled)

### 1) I want Path Style URLs (most of you, probably)

This is built into foundry now! Just set "forcePathStyle" in S3.json and you're good.
This is built into foundry now! Set "forcePathStyle" in S3.json and you're good. You can uninstall the module.

~~If your urls look like this: "http(s)://\[url of endpoint]/\[bucket]/\[path to file]~~

~~Then all you have to do, is tick the "Path Style" checkbox in the Settings and leave the other one unchecked.~~
~~Then all you have to do is tick the "Path Style" checkbox in the Settings and leave the other one unchecked.~~

~~This is actually the default, so you can just install the module and are good to go!~~

### 2) My Provider does something wierd

If your urls don't look like anything like the stuff Amazon would give you, you can check the "Custom Style" checkbox in settings and enter what ever wierd prefix for the bucket your provider expects.
Please be advised that ALL URLs generated by this module will be modified for what ever you enter here, so you wont be able to change the bucket anymore.
If your urls don't look like anything like the stuff Amazon would give you, you can check the "Custom Style"
checkbox in settings and enter whatever unique prefix for the bucket your provider expects.
Please be advised that ALL URLs generated by this module will be modified for whatever you enter here,
so you won't be able to change the bucket anymore.
URLs from other buckets still work by just pasting them into the file pickers text-box.

## Compatibility
Tested Modules:
- D&D Beyond Importer: Fully works! Including munching to S3
- Moulinette: Fully supported for file upload and link generation

Feel free to let me know if there is any issues!
Feel free to let me know if there are any issues!
8 changes: 4 additions & 4 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"id": "s3-path-url",
"title": "Amazon S3 Utils",
"description": "This module allows client-side modifications to S3 URLs, allowing support for Path-Style and other weird configurations.",
"description": "This module allows client-side modifications to S3 URLs, allowing support for weird configurations.",
"version": "This is auto replaced",
"library": "false",
"manifestPlusVersion": "1.0.0",
"minimumCoreVersion": "10",
"minimumCoreVersion": "11",
"compatibility": {
"minimum": "11.302",
"verified": "11",
"maximum": "11"
"verified": "12",
"maximum": "12"
},
"authors": [
{
Expand Down
14 changes: 9 additions & 5 deletions scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ class S3Utils {
static registerSettings(){
game.settings.register(this.ID, this.SETTINGS.CUSTOM_PREFIX, {
name: `S3_PATH_URL.settings.${this.SETTINGS.CUSTOM_PREFIX}.Name`,
default: "url.to.endpoint.com",
default: "https://url.to.endpoint.com",
type: String,
scope: 'world',
config: true,
hint: `S3_PATH_URL.settings.${this.SETTINGS.CUSTOM_PREFIX}.Hint`,
requiresReload: true
});
game.settings.register(this.ID, this.SETTINGS.BUCKETNAME, {
name: `S3_PATH_URL.settings.${this.SETTINGS.BUCKETNAME}.Name`,
Expand All @@ -64,6 +65,7 @@ class S3Utils {
default: 'foundry',
config: true,
hint: `S3_PATH_URL.settings.${this.SETTINGS.BUCKETNAME}.Hint`,
requiresReload: true
});

game.settings.register(this.ID, this.SETTINGS.CUSTOM_STYLE, {
Expand All @@ -73,6 +75,7 @@ class S3Utils {
scope: 'world',
config: true,
hint: `S3_PATH_URL.settings.${this.SETTINGS.CUSTOM_STYLE}.Hint`,
requiresReload: true
});
game.settings.register(this.ID, this.SETTINGS.CUSTOMBUCKET, {
name: `S3_PATH_URL.settings.${this.SETTINGS.CUSTOMBUCKET}.Name`,
Expand All @@ -81,6 +84,7 @@ class S3Utils {
scope: 'world',
config: true,
hint: `S3_PATH_URL.settings.${this.SETTINGS.CUSTOMBUCKET}.Hint`,
requiresReload: true
});
}

Expand All @@ -106,7 +110,7 @@ class S3Utils {
if(result){
if (game.settings.get('s3-path-url', "custom_style")&&game.settings.get('s3-path-url', "custombucket")){
let bucketName = game.settings.get('s3-path-url', "bucketname");
if(result.groups.bucket != bucketName){
if(result.groups.bucket !== bucketName){
result.groups.key = result.groups.bucket + "/" + result.groups.key;
result.groups.bucket = bucketName;
}
Expand All @@ -117,7 +121,7 @@ class S3Utils {
if (game.modules.get('moulinette-core')?.active) {
libWrapper.register(this.ID, "game.moulinette.applications.MoulinetteFileUtil.getBaseURL", async function (wrapped, ...args){
let result = await wrapped(...args);
if(result != "" && result){
if(result !== "" && result){
result = S3Utils.transformURL(result);
}
return result;
Expand All @@ -131,8 +135,8 @@ class S3Utils {
* @returns string
*/
static transformURL(url) {
const splitHref = prevHref.split('//')
if(game.settings.get('s3-path-url', "custom_style")) {
if(game.settings.get('s3-path-url', this.SETTINGS.CUSTOM_STYLE)) {
const splitHref = prevHref.split('//')
if (url.startsWith(prevHref)) {
return url.replace(prevHref, game.data.files.s3.endpoint.href);
}
Expand Down

0 comments on commit 4633769

Please sign in to comment.