Skip to content

Commit

Permalink
updated ffapi to use token
Browse files Browse the repository at this point in the history
  • Loading branch information
revenz committed Apr 22, 2024
1 parent afdd1a6 commit aaeb7a9
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions Scripts/Shared/FileFlowsApi.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/**
* Class that interacts with the FileFlows API
* @name FileFlows API
* @revision 6
* @minimumVersion 1.0.0.0
* @revision 7
* @minimumVersion 24.4.1.3000
*/
export class FileFlowsApi
{
URL;

constructor(){
this.URL = Variables['FileFlows.Url'];
this.AccessToken = Variables['FileFlows.AccessToken'];
if(!this.URL)
MissingVariable('FileFlows.Url');
}
Expand All @@ -19,20 +20,53 @@ export class FileFlowsApi
let url = '' + this.URL;
if(url.endsWith('/') === false)
url += '/';
if(endpoint.startsWith('remote/'))
return url + endpoint;
return url + 'api/' + endpoint;
}

fetchRemote(endpoint)
{
let url = this.getUrl('remote/' + endpoint);
Logger.ILog('Fetching remote: ' + url);

if(this.AccessToken)
{
Logger.ILog('Access Token: ' + this.AccessToken);
http.DefaultRequestHeaders.Add("x-token", this.AccessToken);
}
else
{
Logger.ILog('No Access Token');
}

try
{
let response = http.GetAsync(url).Result;
let responseBody = response.Content.ReadAsStringAsync().Result;
Logger.ILog('Status Code: ' + response.StatusCode);
Logger.ILog('Response: ' + responseBody);
if(response.IsSuccessStatusCode === false)
throw responseBody;
return responseBody;
}
finally
{
if(this.AccessToken)
{
Logger.ILog('Removing Access Token');
http.DefaultRequestHeaders.Remove("x-token");
}
}
}

/**
* Gets the total of each file status in the system
* @returns the file status
*/
getStatus()
{
let url = this.getUrl('library-file/status');
let response = http.GetAsync(url).Result;
let responseBody = response.Content.ReadAsStringAsync().Result;
if(response.IsSuccessStatusCode === false)
throw responseBody;
let responseBody = this.fetchRemote('info/library-status');
let data = JSON.parse(responseBody);
let status = {
Unprocessed: 0, // 0
Expand Down

0 comments on commit aaeb7a9

Please sign in to comment.