Skip to content

Commit

Permalink
Make sure we ALWAYS generate a valid imgix url
Browse files Browse the repository at this point in the history
  • Loading branch information
NuckChorris authored Aug 15, 2024
1 parent 34177e4 commit 46bc575
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions app/helpers/imgix-url.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { helper } from 'ember-helper';

export function imgixUrl([src, params = {}]) {
const url = new URL(
src
.replace('https://media.kitsu.app/', 'https://kitsu.imgix.net/')
.replace(
'https://media-staging.kitsu.app/',
'https://kitsu-staging.imgix.net/'
)
);
const url = new URL(src);
switch (url.hostname) {
case 'media.kitsu.io':
case 'media.kitsu.app':
url.hostname = 'kitsu.imgix.net';
break;
case 'media-staging.kitsu.io':
case 'media-staging.kitsu.app':
url.hostname = 'kitsu-staging.imgix.net'
}

const existingParams = Object.fromEntries(new URLSearchParams(url.search));
const options = new URLSearchParams({
...existingParams,
Expand Down

0 comments on commit 46bc575

Please sign in to comment.