Skip to content

Commit

Permalink
add delete
Browse files Browse the repository at this point in the history
  • Loading branch information
loner233 committed Jan 8, 2024
1 parent f5829ce commit afad7c5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 59 deletions.
50 changes: 2 additions & 48 deletions web/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,10 @@ import { defaultGraph } from "./defaultGraph.js";
import { getPngMetadata, getWebpMetadata, importA1111, getLatentMetadata } from "./pnginfo.js";
import { addDomClippingSetting } from "./domWidget.js";
import { createImageHost, calculateImageGrid } from "./ui/imagePreview.js"

import { getUserId } from "./utils.js";
import { getWorkflow } from "./utils.js";
export const ANIM_PREVIEW_WIDGET = "$$comfy_animation_preview"

function setCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}

async function getWorkflow() {
let flow_json = null;
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const workflowId = urlParams.get('workflow');
if (workflowId){
await fetch('../workflows/' + workflowId + '/' + workflowId + '.json').then(
response => {
flow_json = response.json()
}
)
}
return flow_json;
}

function getUserId() {
var uid = getCookie('uid');
if (uid == null) {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const email = urlParams.get('email');
uid = prompt("Please enter your nickname \n(less than ten letters)", email ? email.split("@")[0] : "anonymous");
setCookie('uid', uid, 999);
}
return uid ? uid : "anonymous";
}


function sanitizeNodeName(string) {
Expand Down
35 changes: 24 additions & 11 deletions web/scripts/ui.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {api} from "./api.js";
import { getUserId } from "./utils.js";

export function $el(tag, propsOrChildren, children) {
const split = tag.split(".");
Expand Down Expand Up @@ -455,10 +456,17 @@ class ComfyList {
$el("div.comfy-list-items", [
...(this.#reverse ? items[section].reverse() : items[section]).map((item) => {
// Allow items to specify a custom remove action (e.g. for interrupt current prompt)
// const removeAction = item.remove || {
// name: "Delete",
// cb: () => api.deleteItem(this.#type, item.prompt[1]),
// };
const removeAction = item.remove || {
name: "Delete",
cb: () => {
var uid = getUserId();
if(uid == item.prompt[5]) {
api.deleteItem(this.#type, item.prompt[1])
} else {
alert("You can only delete your own prompts.")
}
},
};
return $el("div", {textContent: item.prompt[0] + " - " + (item.prompt[5].length <= 10 ? item.prompt[5] : item.prompt[5].substring(0, 10) + "...") + ": "}, [
$el("button", {
textContent: "Load",
Expand All @@ -469,13 +477,18 @@ class ComfyList {
}
},
}),
// $el("button", {
// textContent: removeAction.name,
// onclick: async () => {
// await removeAction.cb();
// await this.update();
// },
// }),
$el("button", {
textContent: removeAction.name,
onclick: async () => {
var uid = getUserId();
if(uid == item.prompt[5]) {
await removeAction.cb();
await this.update();
} else {
alert("You can only delete your own prompts.")
}
},
}),
]);
}),
]),
Expand Down
50 changes: 50 additions & 0 deletions web/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,53 @@ export function applyTextReplacements(app, value) {
return ((widget.value ?? "") + "").replaceAll(/\/|\\/g, "_");
});
}



function setCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}

function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}

export async function getWorkflow() {
let flow_json = null;
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const workflowId = urlParams.get('workflow');
if (workflowId){
await fetch('../workflows/' + workflowId + '/' + workflowId + '.json').then(
response => {
flow_json = response.json()
}
)
}
return flow_json;
}

export function getUserId() {
var uid = getCookie('uid');
if (uid == null) {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const email = urlParams.get('email');
uid = prompt("Please enter your nickname \n(less than ten letters)", email ? email.split("@")[0] : "anonymous");
setCookie('uid', uid, 999);
}
return uid ? uid : "anonymous";
}

0 comments on commit afad7c5

Please sign in to comment.