Skip to content

Commit d4f004e

Browse files
Merge pull request #10 from AtlasSystems/feature/addUserAgent
Send UserAgent in API calls
2 parents 0da6bd6 + dacfd76 commit d4f004e

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

Aeon-ArchivesSpace-Addon/Aeon-ArchivesSpace.lua

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ settings.AutoGroupResults = GetSetting("AutoGroupResults");
2525
local types = {};
2626

2727
luanet.load_assembly("System.Net");
28+
luanet.load_assembly("System.Windows.Forms");
29+
2830
types["System.Net.WebClient"] = luanet.import_type("System.Net.WebClient");
2931
types["System.IO.StreamReader"] = luanet.import_type("System.IO.StreamReader");
3032
types["System.Text.Encoding"] = luanet.import_type("System.Text.Encoding");
3133
types["System.DBNull"] = luanet.import_type("System.DBNull");
34+
types["System.Windows.Forms.Application"] = luanet.import_type("System.Windows.Forms.Application");
3235

3336
luanet.load_assembly("System");
3437
types["System.Collections.Specialized.NameValueCollection"] = luanet.import_type("System.Collections.Specialized.NameValueCollection");
@@ -80,10 +83,20 @@ local archiveSpaceAddonScript = [[
8083
var objectUrl = buildObjectUrl(objectId);
8184
atlasAddonAsync.executeAddonFunction('NodeChanged', currentRepositoryPath, objectUrl);
8285
86+
//Try to get the app_prefix to remove any additional web paths from the URL
87+
var appPrefix = "/";
88+
if (AS) {
89+
appPrefix = AS.app_prefix("");
90+
}
91+
8392
// This Injects the NodeChanged function into the Ajax callback that changes the record pages
8493
var originalAjaxThePane = AjaxTree.prototype._ajax_the_pane;
8594
AjaxTree.prototype._ajax_the_pane = function(url, params, callback) {
86-
atlasAddonAsync.executeAddonFunction('NodeChanged', currentRepositoryPath, url);
95+
//If the appPrefix is anything other than "/", replace it with just "/"
96+
var updateUrl = url.replace(appPrefix, "/");
97+
updateUrl.startsWith(updateUrl) ? updateUrl : "/" + updateUrl;
98+
atlasAddonAsync.executeAddonFunction('NodeChanged', currentRepositoryPath, updateUrl);
99+
//Preserve the original call using the original ASpace URL parameter
87100
originalAjaxThePane.call(this, url, params, callback);
88101
};
89102
}
@@ -164,6 +177,10 @@ function Init()
164177
catalogSearchForm.Browser:Navigate(settings.BaseURL);
165178
end
166179

180+
function Version()
181+
return types["System.Windows.Forms.Application"].ProductVersion;
182+
end
183+
167184
function WebView2Enabled()
168185
return AddonInfo.Browsers ~= nil and AddonInfo.Browsers.WebView2 ~= nil and AddonInfo.Browsers.WebView2 == true;
169186
end
@@ -745,8 +762,10 @@ function SendApiRequest(apiPath, method, parameters, authToken)
745762
LogDebug('apiPath: ' .. apiPath);
746763

747764
local webClient = types["System.Net.WebClient"]();
748-
765+
webClient.Encoding = types["System.Text.Encoding"].UTF8;
749766
webClient.Headers:Clear();
767+
-- Add a user-agent for the API request to support ArchivesSpace API hosted by Lyrasis
768+
webClient.Headers:Add("user-agent", "AtlasAeon/" .. Version());
750769
if (authToken ~= nil and authToken ~= "") then
751770
webClient.Headers:Add("X-ArchivesSpace-Session", authToken);
752771
end

Aeon-ArchivesSpace-Addon/Config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
33
<Name>ArchivesSpace Interface</Name>
44
<Author>Atlas Systems, Inc.</Author>
5-
<Version>3.0.2</Version>
5+
<Version>3.0.3</Version>
66
<Active>True</Active>
77
<Type>Addon</Type>
88
<Description>This addon performs searches in ArchivesSpace using the staff interface. This addon supports ArchivesSpace versions v2.8.0 and later.</Description>

Readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Aeon ArchivesSpace Client Addon
22

33
## Version
4+
5+
- 3.0.3:
6+
- A UserAgent HTTP Header is sent in API calls to better support ArchivesSapces hosted by Lyrasis.
7+
- Better support for ArchivesSpace LibraryHost instances where the AppPrefix is not standard.
8+
- Set API to use UTF8 for ArchivesSpace API requests
49
- 3.0:
510
- Added support for embedded WebView2 browser. The addon will use this browser if it is available (Aeon 5.2+), and will use the embedded Chromium browser otherwise.
611
- 2.1:

0 commit comments

Comments
 (0)