### 1.1.3
- Added access to report from https://stash.axter.com/1.1/file.html
  - This allows access to report from any browser and access to report from a Docker Stash setup.
  - On Stash installation using passwords or non-standard URL, the file.html link should be accessed from the advance menu or from the Stash->Tools->[DupFileManager Report Menu].
- Added fields remoteReportDirURL and js_DirURL to allow users to setup their own private or alternate remote path for javascript files.
- On Stash installations having password, the Advance Menu can now be accessed from the Stash->Tools->[DupFileManager Report Menu].
This commit is contained in:
David Maisonave
2024-12-26 12:39:20 -05:00
parent 98f4a5291d
commit 8e5e451916
12 changed files with 716 additions and 361 deletions

View File

@@ -6,7 +6,83 @@
const GQL = PluginApi.GQL;
const { Button } = PluginApi.libraries.Bootstrap;
const { Link, NavLink } = PluginApi.libraries.ReactRouterDOM;
class StashPlugin {
#urlParams = new URLSearchParams(window.location.search);
#apiKey = "";
#doApiLog = true;
constructor(PluginID, doApiLog = true, DataType = "json", Async = false) {
this.#doApiLog = doApiLog;
this.PluginID = PluginID;
this.DataType = DataType;
this.Async = Async;
this.#apiKey = this.getParam("apiKey"); // For Stash installations with a password setup, populate this variable with the apiKey found in Stash->Settings->Security->[API Key]; ----- Or pass in the apiKey at the URL command line. Example: advance_options.html?apiKey=12345G4igiJdgssdgiwqInh5cCI6IkprewJ9hgdsfhgfdhd&GQL=http://localhost:9999/graphql
this.GraphQl_URL = this.getParam("GQL", "http://localhost:9999/graphql");// For Stash installations with non-standard ports or URL's, populate this variable with actual URL; ----- Or pass in the URL at the command line using GQL param. Example: advance_options.html?GQL=http://localhost:9900/graphql
console.log("GQL = " + this.GraphQl_URL + "; apiKey = " + this.#apiKey + "; urlParams = " + this.#urlParams + "; Cookies = " + document.cookie);
}
getParam(ParamName, DefaultValue = ""){
if (this.#urlParams.get(ParamName) != null && this.#urlParams.get(ParamName) !== "")
return this.#urlParams.get(ParamName);
return DefaultValue;
}
CallBackOnSuccess(result, Args, This){ // Only called on asynchronous calls
console.log("Ajax success.");
}
CallBackOnFail(textStatus, errorThrown, This){
console.log("Ajax failed with Status: " + textStatus + "; Error: " + errorThrown);
alert("Error on StashPlugin Ajax call!!!\nReturn-Status: " + textStatus + "\nThrow-Error: " + errorThrown);
}
RunPluginOperation(Args = {}, OnSuccess = this.CallBackOnSuccess, OnFail = this.CallBackOnFail) {
console.log("PluginID = " + this.PluginID + "; Args = " + Args + "; GQL = " + this.GraphQl_URL + "; DataType = " + this.DataType + "; Async = " + this.Async);
if (this.#apiKey !== ""){
if (this.#doApiLog) console.log("Using apiKey = " + this.#apiKey);
const apiKey = this.#apiKey;
$.ajaxSetup({beforeSend: function(xhr) {xhr.setRequestHeader('apiKey', apiKey);}});
}
const AjaxData = $.ajax({method: "POST", url: this.GraphQl_URL, contentType: "application/json", dataType: this.DataType, cache: this.Async, async: this.Async,
data: JSON.stringify({
query: `mutation RunPluginOperation($plugin_id:ID!,$args:Map!){runPluginOperation(plugin_id:$plugin_id,args:$args)}`,
variables: {"plugin_id": this.PluginID, "args": Args},
}), success: function(result){
if (this.Async == true) OnSuccess(result, Args, this);
}, error: function(jqXHR, textStatus, errorThrown) {
OnFail(textStatus, errorThrown, this);
}
});
if (this.Async == true) // Make sure to use callback functions for asynchronous calls.
return;
if (this.DataType == "text")
return AjaxData.responseText;
return AjaxData.responseJSON.data.runPluginOperation;
}
};
class Plugin_DupFileManager extends StashPlugin{
constructor() {
super("DupFileManager", "json", true);
this.IS_DOCKER = this.getParam("IS_DOCKER") === "True";
this.PageNo = parseInt(this.getParam("PageNo", "0"));
}
MyCallBackOnSuccess(result, Args, This){ // Only called on asynchronous calls
console.log("Ajax success.");
$( "#FileDiv" ).append( result );
}
GetFile(Mode = "getReport") {
this.RunPluginOperation({ "Target" : this.PageNo, "mode":Mode}, this.MyCallBackOnSuccess);
return;
//const strResults = JSON.stringify(results);
//if (strResults.indexOf("INF: 'Error: Nothing to do!!!") > -1){
// console.log("Ajax failed for function " + Mode +" and page " + this.PageNo + " with results = " + JSON.stringify(results));
// return "<p>Failed to get report do to ajax error!!!</p>";
//}
//var rootPath = window.location.href;
//if (rootPath.indexOf("://localhost:") > 0){
// results = results.replaceAll("://127.0.0.1:", "://localhost:");
//} else if (rootPath.indexOf("://127.0.0.1:") > 0){
// results = results.replaceAll("://localhost:", "//127.0.0.1:");
//}
//return results;
}
}
var PluginDupFileManager = new Plugin_DupFileManager();
var rootPath = window.location.href;
var myArray = rootPath.split("/");
rootPath = myArray[0] + "//" + myArray[2]
@@ -41,19 +117,20 @@
var apiKey = "";
var UrlParam = "";
var IS_DOCKER = "";
var remoteReportDirURL = "";
function GetLocalDuplicateReportPath(){
var LocalDuplicateReport = RunPluginDupFileManager("getLocalDupReportPath", "json");
var LocalDuplicateReportPath = "file://" + LocalDuplicateReport.Path;
console.log("LocalDuplicateReport=" + JSON.stringify(LocalDuplicateReport));
remoteReportDirURL = LocalDuplicateReport.remoteReportDirURL;
apiKey = LocalDuplicateReport.apiKey;
IS_DOCKER = LocalDuplicateReport.IS_DOCKER;
UrlParam = "?GQL=" + rootPath + "/graphql&IS_DOCKER=" + IS_DOCKER + "&apiKey=" + apiKey;
console.log("LocalDuplicateReportPath=" + JSON.stringify(LocalDuplicateReportPath) + "; document.cookie=" + document.cookie);
var LocalDuplicateReportPath = remoteReportDirURL + "file.html" + UrlParam; //"file://" + LocalDuplicateReport.Path;
AdvanceMenuOptionUrl = LocalDuplicateReport.AdvMenuUrl + UrlParam;
console.log("AdvanceMenuOptionUrl=" + AdvanceMenuOptionUrl);
LocalDupReportExist = LocalDuplicateReport.LocalDupReportExist;
return LocalDuplicateReportPath;
}
// ToolTip text
const CreateReportButtonToolTip = "Tag duplicate files, and create a new duplicate file report listing all duplicate files and using existing DupFileManager plugin options selected.";
const CreateReportNoTagButtonToolTip = "Create a new duplicate file report listing all duplicate files and using existing DupFileManager plugin options selected. Do NOT tag files.";
@@ -76,7 +153,7 @@
}
function GetAdvanceMenuButton()
{
return React.createElement("a", { href: "https://stash.axter.com/1.1.2/advance_options.html" + UrlParam, title: "Open link to the [Advance Duplicate File Menu].", target:"_blank"}, React.createElement(Button, null, "Show [Advance Duplicate File Menu]"));
return React.createElement("a", { href: remoteReportDirURL + "advance_options.html" + UrlParam, title: "Open link to the [Advance Duplicate File Menu].", target:"_blank"}, React.createElement(Button, null, "Advance Duplicate File Menu"));
// The following does not work with Chrome, or with an apiKey, or with a non-standard Stash URL.
//return React.createElement("a", { href: AdvanceMenuOptionUrl, title: "Open link to the [Advance Duplicate File Menu].", target:"_blank"}, React.createElement(Button, null, "Show [Advance Duplicate File Menu]"));
}
@@ -294,11 +371,39 @@
));
}
return ToolsAndUtilities();
};
const HomePageBeta = () => {
var LocalDuplicateReportPath = GetLocalDuplicateReportPath();
console.log(LocalDupReportExist);
var MyHeader = React.createElement("h1", null, "DupFileManager Report Menu");
if (LocalDupReportExist)
return (React.createElement("div", {id:"FileDiv"}, "FileDiv",
React.createElement("center", null,
MyHeader,
GetShowReportButton(LocalDuplicateReportPath, "Show Duplicate-File Report"),
React.createElement("p", null),
React.createElement(Link, { to: "/DupFileManager_AdvanceMenu" }, React.createElement(Button, null, "Advance Menu")),
React.createElement("p", null),
ToolsMenuOptionButton)
));
return (React.createElement("center", null,
MyHeader,
ToolsMenuOptionButton
));
};
const AdvanceMenu = () => {
PluginDupFileManager.GetFile("getAdvanceMenu");
//const html = PluginDupFileManager.GetFile("getAdvanceMenu");
//console.log("Sending file to FileDiv; html=" + html.substring(0, 50));
//$("body").append( html );
return (React.createElement("div", {id:"FileDiv"}));
};
PluginApi.register.route("/DupFileManager", HomePage);
PluginApi.register.route("/DupFileManager_CreateReport", CreateReport);
PluginApi.register.route("/DupFileManager_CreateReportWithNoTagging", CreateReportWithNoTagging);
PluginApi.register.route("/DupFileManager_ToolsAndUtilities", ToolsAndUtilities);
// PluginApi.register.route("/DupFileManager_HomePageBeta", HomePageBeta);
PluginApi.register.route("/DupFileManager_AdvanceMenu", AdvanceMenu);
PluginApi.register.route("/DupFileManager_ClearAllDuplicateTags", ClearAllDuplicateTags);
PluginApi.register.route("/DupFileManager_deleteLocalDupReportHtmlFiles", deleteLocalDupReportHtmlFiles);
PluginApi.register.route("/DupFileManager_deleteAllDupFileManagerTags", deleteAllDupFileManagerTags);
@@ -316,6 +421,7 @@
props.children,
React.createElement(Setting, { heading: React.createElement(Link, { to: "/DupFileManager", title: ReportMenuButtonToolTip }, React.createElement(Button, null, "Duplicate File Report (DupFileManager)"))}),
React.createElement(Setting, { heading: React.createElement(Link, { to: "/DupFileManager_ToolsAndUtilities", title: ToolsMenuToolTip }, React.createElement(Button, null, "DupFileManager Tools and Utilities"))}),
// React.createElement(Setting, { heading: React.createElement(Link, { to: "/DupFileManager_HomePageBeta", title: ReportMenuButtonToolTip }, React.createElement(Button, null, "Duplicate File Report [Beta]"))}),
)),
},
];