Skip to content

Commit

Permalink
removing dead code and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahAlfaraj committed Jun 5, 2023
1 parent 4a0d45b commit 745d541
Show file tree
Hide file tree
Showing 12 changed files with 49,836 additions and 283 deletions.
37 changes: 3 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ let g_online_data_url =
const Enum = require('./enum')
const helper = require('./helper')
const sd_tab = require('./utility/tab/sd')
// let g_sdapi_path = 'sdapi_py_re'
// const sdapi = require(`./${g_sdapi_path}`)

const sdapi = require('./sdapi_py_re')

// const exportHelper = require('./export_png')
Expand Down Expand Up @@ -871,7 +870,6 @@ async function deleteTempInpaintMaskLayer() {
}
//REFACTOR: move to ui.js
async function postModeSelection() {
//
try {
if (g_sd_mode === generationMode['Inpaint']) {
//check if the we already have created a mask layer
Expand Down Expand Up @@ -1214,34 +1212,6 @@ function selectTool() {
//rectanglemarquee
// await require('photoshop').core.executeAsModal(newNormalLayer);
}
//Refactor: Delete testServerPath() method
async function testServerPath() {
// const serverPath = "https://api.github.com/users/abdullah"

try {
// const serverPath = 'https://api.weather.gov/points/123.4,342.5'
// const serverPath = 'https://api.github.com/users/abdullah'
// const serverPath = "https://api.coindesk.com/v1/bpi/currentprice.json"
// const serverPath = "http://127.0.0.1:3000"
// const serverPath = "http://localhost:3000"
const serverPath = 'http://127.0.0.1:8000/txt2img/random%20prompt'
// const serverPath = "https://3330-37-106-100-102.eu.ngrok.io"
console.log('testServerPath function was called')

let response = await fetch(serverPath)
console.log('testServerPath finished fetch')

if (!response.ok) {
throw new Error(
`HTTP error fetching weather station; status: ${response.status}`
)
}
let stationJson = await response.json()
console.dir(stationJson)
} catch (err) {
console.error('testServerPath error: ' + err.message)
}
}

// User picks an image file
// open a explorer for user to select a image file
Expand Down Expand Up @@ -2465,7 +2435,7 @@ async function easyModeGenerate(mode) {

if (g_generation_session.isActive()) {
//active session
//

if (g_generation_session.mode !== mode) {
//active session but it's a new mode

Expand Down Expand Up @@ -2904,7 +2874,7 @@ async function progressRecursive() {
if (g_generation_session.sudo_timer_id) {
//for sudo timer update
//for controlnet only: disable the sudo timer when the real timer start
// debugger
//
if (progress_value > 1) {
//disable the sudo timer at the end of the generation
g_generation_session.sudo_timer_id = clearInterval(
Expand Down Expand Up @@ -4001,7 +3971,6 @@ async function deleteNoneSelected(viewer_objects) {
g_viewer_manager.pathToViewerImage = {}
g_viewer_manager.initImageLayersJson = {}
g_viewer_manager.outputImages = []
//

g_generation_session.image_paths_to_layers = {}
})
Expand Down
49,816 changes: 49,816 additions & 0 deletions main/dist/all.bundle.js

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions outpaint.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ async function outpaintExe(session_id) {

await psapi.reSelectMarqueeExe(selectionInfo)

// await psapi.silentSetInitImageMask(snapshotMaskGroup,session_id)

const mask_name = mask_info['name']
const mask_path = `./server/python_server/init_images/${mask_name}`
await psapi.reSelectMarqueeExe(selectionInfo)
Expand Down Expand Up @@ -332,7 +330,6 @@ async function outpaintExe(session_id) {
}

async function inpaintFasterExe(session_id) {
//
//create a snapshot of canvas
//select opaque pixel and create black fill layer
//create a snapshot of mask
Expand Down Expand Up @@ -432,7 +429,7 @@ async function inpaintFasterExe(session_id) {
// await psapi.selectLayers([snapshotGroup])

await psapi.selectLayers([maskGroup])
// await psapi.silentSetInitImageMask(maskGroup,session_id)

const mask_info = await psapi.silentSetInitImageMask(
maskGroup,
session_id
Expand Down
92 changes: 0 additions & 92 deletions psapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -906,96 +906,6 @@ async function silentSetInitImageMask(layer, session_id) {
console.error(`psapi.js setInitImageMask error: `, e)
}
}
async function setInitImage(layer, session_id) {
try {
const html_manip = require('./utility/html_manip')
// const layer = await app.activeDocument.activeLayers[0]
const old_name = layer.name

// image_name = await app.activeDocument.activeLayers[0].name

//convert layer name to a file name
let image_name = layerNameToFileName(old_name, layer.id, session_id)
image_name = `${image_name}.png`

//the width and height of the exported image
const width = html_manip.getWidth()
const height = html_manip.getHeight()
const image_buffer = await newExportPng(
layer,
image_name,
width,
height
)
const base64_image = _arrayBufferToBase64(image_buffer) //convert the buffer to base64
//send the base64 to the server to save the file in the desired directory
await sdapi.requestSavePng(base64_image, image_name)

g_init_image_name = image_name
console.log(image_name)

const image_src = await sdapi.getInitImage(g_init_image_name)
let ini_image_element = document.getElementById('init_image')
ini_image_element.src = image_src
const path = `${g_init_images_dir}/${image_name}`

g_generation_session.base64initImages[path] = base64_image
g_generation_session.activeBase64InitImage =
g_generation_session.base64initImages[path]

const init_src = base64ToSrc(g_generation_session.activeBase64InitImage)
html_manip.setInitImageSrc(init_src)

return (image_info = { name: image_name, base64: base64_image })
} catch (e) {
console.error(`psapi.js setInitImage error:, ${e}`)
}
}
async function setInitImageMask(layer, session_id) {
try {
const html_manip = require('./utility/html_manip')

// const layer = await app.activeDocument.activeLayers[0]
const old_name = layer.name

//get the active layer name
// image_name = await app.activeDocument.activeLayers[0].name
// image_name = layerNameToFileName(old_name,layer.id,random_session_id)
image_name = layerNameToFileName(old_name, layer.id, session_id)
image_name = `${image_name}.png`
const width = html_manip.getWidth()
const height = html_manip.getHeight()
image_buffer = await newExportPng(layer, image_name, width, height)
g_init_image_mask_name = image_name // this is the name we will send to the server
// g_init_mask_layer = layer
// g_mask_related_layers = {}

console.log(image_name)
base64_image = _arrayBufferToBase64(image_buffer) //convert the buffer to base64
//send the base64 to the server to save the file in the desired directory
await sdapi.requestSavePng(base64_image, image_name)

const image_src = await sdapi.getInitImage(g_init_image_mask_name) // we should replace this with getInitImagePath which return path to local disk
const ini_image_mask_element =
document.getElementById('init_image_mask')
ini_image_mask_element.src = image_src
ini_image_mask_element.dataset.layer_id = layer.id

const path = `${g_init_images_dir}/${image_name}`
g_generation_session.base64maskImage[path] = base64_image
g_generation_session.activeBase64MaskImage =
g_generation_session.base64maskImage[path]
//create viewer init image obj
{
}
// return image_name
const mask_src = base64ToSrc(g_generation_session.activeBase64MaskImage)
html_manip.setInitImageMaskSrc(mask_src)
return (image_info = { name: image_name, base64: base64_image })
} catch (e) {
console.error(`psapi.js setInitImageMask error: `, e)
}
}

// remove the generated mask related layers from the canvas and "layers" panel

Expand Down Expand Up @@ -1568,8 +1478,6 @@ module.exports = {
snapshot_layerExe,
fillAndGroupExe,
fastSnapshot,
setInitImage,
setInitImageMask,

layerToFileName,
layerNameToFileName,
Expand Down
Loading

0 comments on commit 745d541

Please sign in to comment.