diff --git a/git.py b/git.py index 0a1fd2f..7da9297 100644 --- a/git.py +++ b/git.py @@ -2,11 +2,26 @@ from git import Repo, InvalidGitRepositoryError import os import copy import re +from custom_nodes.EternalKernelLiteGraphNodes.shared import ETK_PATH NODE_CLASS_MAPPINGS = {} NODE_DISPLAY_NAME_MAPPINGS = {} +def check_for_js_extension(): + # here we check to see that the js extension is installed at ../../web/extensions/etk/ui_modifications.js + # if it is not, we will copy it there from the ETK_PATH + # check if the file exists + import shutil + check_full_path = os.path.normpath(os.path.join(ETK_PATH, "../../web/extensions/etk/ui_modifications.js")) + if not os.path.exists(check_full_path): + # copy the file + shutil.copy(os.path.join(ETK_PATH, "ui_modifications.js"), check_full_path) + + +check_for_js_extension() + + def ETK_git_base(cls): cls.FUNCTION = "func" cls.CATEGORY = "ETK/git" @@ -64,11 +79,33 @@ class CloneRepoNode: repo_url = kwargs.get('repo_url') path = kwargs.get('path') token = kwargs.get('token') + + # clone a repo into a new directory, using the custom ssh command + # token actually is the path to the private key + # so we already know where the private key is + # we just need to tell git to use it + + cmd = 'ssh -i {} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'.format(token) + repo = Repo.clone_from(repo_url, path, env={'GIT_SSH_COMMAND': cmd}) + + # this should not work but it does. Repo.clone_from(repo_url, path, env={'GIT_ASKPASS': 'echo', 'GIT_USERNAME': token}) + # linux / not windows ? + # this actually worked on linux + # GIT_SSH_COMMAND="ssh -i /root/.ssh/git.private.key" clone https://github.com/gitpython-developers/GitPython.git + # + + # use the key at /root/.ssh/git.private.key + # below needs tested + ssh_cmd = 'ssh -i /root/.ssh/git.private.key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + repo = Repo(path) + with repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd): + repo.clone_from(repo_url, path) + # return the file structure of the repo ld = os.listdir(path) - return (path,"".join(ld), ld,) + return (path, "".join(ld), ld,) @ETK_git_base diff --git a/shared.py b/shared.py new file mode 100644 index 0000000..3557214 --- /dev/null +++ b/shared.py @@ -0,0 +1,5 @@ +import os + +# state that is shared, available to all modules + +ETK_PATH = os.path.dirname(os.path.abspath(__file__)) diff --git a/ui_modifications.js b/ui_modifications.js new file mode 100644 index 0000000..5d93eef --- /dev/null +++ b/ui_modifications.js @@ -0,0 +1,60 @@ +import { app } from "../../../scripts/app.js"; +import { api } from "../../../scripts/api.js"; + +app.registerExtension({ + name: "GDE.UI.RemoveDefaultButtons", + async setup(app) { + document.getElementById("comfy-load-default-button").remove(); + document.getElementById("comfy-clipspace-button").remove(); + }, +}); + +app.registerExtension({ + name: "GDE.UI", + async setup() { + const menu = document.querySelector(".comfy-menu"); + const separator = document.createElement("hr"); + + separator.style.margin = "20px 0"; + separator.style.width = "100%"; + menu.append(separator); + + // Save To Git Button + const saveButton = document.createElement("button"); + saveButton.textContent = "Save To Git"; + saveButton.onclick = async () => { + try { + const json = JSON.stringify(app.graph.serialize(), null, 2); + await api.fetchApi("/gde/git/save", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ data: json }), + }); + } catch (error) { + console.error(error); + } + }; + menu.append(saveButton); + + // Load From Git Button + const loadButton = document.createElement("button"); + loadButton.textContent = "Load From Git"; + loadButton.onclick = async () => { + try { + const response = await api.fetchApi("/gde/git/load", { + method: "POST", + headers: { + "Content-Type": "application/json", + } + }); + const data = await response.json(); + app.loadGraphData(JSON.parse(data.data)); + } catch (error) { + console.error(error); + } + }; + menu.append(loadButton); + } +}); \ No newline at end of file