Skip to content

Commit

Permalink
Fix gnarly action urls edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgrayisok committed Mar 16, 2023
1 parent 984dc25 commit 495df3c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes for Dall-E Fieldtype for Craft CMS

## 1.0.4 - 2023-03-16

### Fixed

- Action URLs used by the plugin were broken if both omitScriptNameInUrls was false and multisite was being used

## 1.0.3 - 2022-11-14

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "servd/craft-dalle",
"description": "A field type to integrate with the Dall-E Image Generation API",
"version": "1.0.3",
"version": "1.0.4",
"type": "craft-plugin",
"keywords": [
"cms",
Expand Down
20 changes: 14 additions & 6 deletions src/web/assets/dallefieldtype.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,13 +720,21 @@
}

function createActionUrl(path, queryData) {
let baseUrl = Craft.actionUrl.replace(/\/+$/, '');
let fullUrl = baseUrl + '/' + path;
if (fullUrl.indexOf('?') >= 0) {
fullUrl += '&'
let baseUrl = Craft.actionUrl;
let parsedUrl = new URL(baseUrl);
if(parsedUrl.searchParams.get('p') && parsedUrl.searchParams.get('p').length > 0){
let existingPValue = parsedUrl.searchParams.get('p');
let newPValue = existingPValue.replace(/\/+$/, '') + '/' + path;
parsedUrl.searchParams.set('p', newPValue)
} else {
fullUrl += '?'
parsedUrl.pathname = parsedUrl.pathname.replace(/\/+$/, '') + '/' + path;
}
return fullUrl + new URLSearchParams(queryData);

let updatedParams = new URLSearchParams(queryData);
for (let [key, val] of updatedParams.entries()) {
parsedUrl.searchParams.append(key, val);
}

return parsedUrl.toString();
}
})();

0 comments on commit 495df3c

Please sign in to comment.