Remove app.storageLocation handling (#1731)

This commit is contained in:
Chenlei Hu
2024-11-28 10:35:08 -08:00
committed by GitHub
parent 7f9c70386f
commit b0085114d7
5 changed files with 35 additions and 79 deletions

View File

@@ -85,46 +85,34 @@ class ManageTemplates extends ComfyDialog {
async load() {
let templates = []
if (app.storageLocation === 'server') {
if (app.isNewUserSession) {
// New user so migrate existing templates
const json = localStorage.getItem(id)
if (json) {
templates = JSON.parse(json)
}
await api.storeUserData(file, json, { stringify: false })
} else {
const res = await api.getUserData(file)
if (res.status === 200) {
try {
templates = await res.json()
} catch (error) {}
} else if (res.status !== 404) {
console.error(res.status + ' ' + res.statusText)
}
}
} else {
if (app.isNewUserSession) {
// New user so migrate existing templates
const json = localStorage.getItem(id)
if (json) {
templates = JSON.parse(json)
}
await api.storeUserData(file, json, { stringify: false })
} else {
const res = await api.getUserData(file)
if (res.status === 200) {
try {
templates = await res.json()
} catch (error) {}
} else if (res.status !== 404) {
console.error(res.status + ' ' + res.statusText)
}
}
return templates ?? []
}
async store() {
if (app.storageLocation === 'server') {
const templates = JSON.stringify(this.templates, undefined, 4)
localStorage.setItem(id, templates) // Backwards compatibility
try {
await api.storeUserData(file, templates, { stringify: false })
} catch (error) {
console.error(error)
useToastStore().addAlert(error.message)
}
} else {
localStorage.setItem(id, JSON.stringify(this.templates))
const templates = JSON.stringify(this.templates, undefined, 4)
localStorage.setItem(id, templates) // Backwards compatibility
try {
await api.storeUserData(file, templates, { stringify: false })
} catch (error) {
console.error(error)
useToastStore().addAlert(error.message)
}
}