use DIRECTORIES const for comfy workflow path
This commit is contained in:
parent
46cc04c798
commit
8b5a56a99c
|
@ -23,6 +23,7 @@ const DIRECTORIES = {
|
||||||
backups: 'backups/',
|
backups: 'backups/',
|
||||||
quickreplies: 'public/QuickReplies',
|
quickreplies: 'public/QuickReplies',
|
||||||
assets: 'public/assets',
|
assets: 'public/assets',
|
||||||
|
comfyWorkflows: 'public/user/workflows',
|
||||||
};
|
};
|
||||||
|
|
||||||
const UNSAFE_EXTENSIONS = [
|
const UNSAFE_EXTENSIONS = [
|
||||||
|
|
|
@ -2,6 +2,7 @@ const fetch = require('node-fetch').default;
|
||||||
const sanitize = require('sanitize-filename');
|
const sanitize = require('sanitize-filename');
|
||||||
const { getBasicAuthHeader, delay } = require('./util');
|
const { getBasicAuthHeader, delay } = require('./util');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const { DIRECTORIES } = require('./constants.js');
|
||||||
const writeFileAtomicSync = require('write-file-atomic').sync;
|
const writeFileAtomicSync = require('write-file-atomic').sync;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,11 +43,8 @@ function removePattern(x, pattern) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getComfyWorkflows() {
|
function getComfyWorkflows() {
|
||||||
if (!fs.existsSync('public/user/workflows')) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
return fs
|
return fs
|
||||||
.readdirSync('public/user/workflows')
|
.readdirSync(DIRECTORIES.comfyWorkflows)
|
||||||
.filter(file => file[0]!='.' && file.toLowerCase().endsWith('.json'))
|
.filter(file => file[0]!='.' && file.toLowerCase().endsWith('.json'))
|
||||||
.sort(Intl.Collator().compare);
|
.sort(Intl.Collator().compare);
|
||||||
}
|
}
|
||||||
|
@ -461,9 +459,9 @@ function registerEndpoints(app, jsonParser) {
|
||||||
|
|
||||||
app.post('/api/sd/comfy/workflow', jsonParser, async (request, response) => {
|
app.post('/api/sd/comfy/workflow', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
let path = `public/user/workflows/${sanitize(String(request.body.file_name))}`;
|
let path = `${DIRECTORIES.comfyWorkflows}/${sanitize(String(request.body.file_name))}`;
|
||||||
if (!fs.existsSync(path)) {
|
if (!fs.existsSync(path)) {
|
||||||
path = 'public/user/workflows/Default_Comfy_Workflow.json';
|
path = `${DIRECTORIES.comfyWorkflows}/Default_Comfy_Workflow.json`;
|
||||||
}
|
}
|
||||||
const data = fs.readFileSync(
|
const data = fs.readFileSync(
|
||||||
path,
|
path,
|
||||||
|
@ -478,11 +476,8 @@ function registerEndpoints(app, jsonParser) {
|
||||||
|
|
||||||
app.post('/api/sd/comfy/saveWorkflow', jsonParser, async (request, response) => {
|
app.post('/api/sd/comfy/saveWorkflow', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync('public/user/workflows')) {
|
|
||||||
fs.mkdirSync('public/user/workflows');
|
|
||||||
}
|
|
||||||
writeFileAtomicSync(
|
writeFileAtomicSync(
|
||||||
`public/user/workflows/${sanitize(String(request.body.file_name))}`,
|
`${DIRECTORIES.comfyWorkflows}/${sanitize(String(request.body.file_name))}`,
|
||||||
request.body.workflow,
|
request.body.workflow,
|
||||||
'utf8'
|
'utf8'
|
||||||
);
|
);
|
||||||
|
@ -496,7 +491,7 @@ function registerEndpoints(app, jsonParser) {
|
||||||
|
|
||||||
app.post('/api/sd/comfy/deleteWorkflow', jsonParser, async (request, response) => {
|
app.post('/api/sd/comfy/deleteWorkflow', jsonParser, async (request, response) => {
|
||||||
try {
|
try {
|
||||||
let path = `public/user/workflows/${sanitize(String(request.body.file_name))}`;
|
let path = `${DIRECTORIES.comfyWorkflows}/${sanitize(String(request.body.file_name))}`;
|
||||||
if (fs.existsSync(path)) {
|
if (fs.existsSync(path)) {
|
||||||
fs.unlinkSync(path);
|
fs.unlinkSync(path);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue