|
|
|
|
|
|
|
|
|
class FavoriteItem { |
|
|
|
|
|
|
|
|
|
id = '' |
|
|
|
|
|
|
|
|
|
name = '' |
|
|
|
|
|
|
|
|
|
tags = [] |
|
|
|
|
|
|
|
|
|
prompt = '' |
|
|
|
|
|
|
|
|
|
time = 0 |
|
|
|
constructor(id = '') { |
|
this.id = id ? id : Math.random().toString(36).slice(2) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
setName(name) { |
|
this.name = name |
|
return this |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
setTags(tags) { |
|
this.tags = tags |
|
return this |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
setPrompt(prompt) { |
|
this.prompt = prompt |
|
return this |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
setTime(time = 0) { |
|
this.time = time || Date.now() |
|
return this |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isEqualTags(tags, ignoreId = false) { |
|
if (this.tags.length !== tags.length) return false |
|
for (let i = 0; i < tags.length; i++) { |
|
for (let key in tags[i]) { |
|
if (ignoreId && key === 'id') continue |
|
if (this.tags[i][key] !== tags[i][key]) return false |
|
} |
|
for (let key in this.tags[i]) { |
|
if (ignoreId && key === 'id') continue |
|
if (this.tags[i][key] !== tags[i][key]) return false |
|
} |
|
} |
|
return true |
|
} |
|
|
|
|
|
|
|
|
|
|
|
toObject() { |
|
return { |
|
id: this.id, |
|
name: this.name, |
|
tags: this.tags, |
|
prompt: this.prompt, |
|
time: this.time, |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
toString() { |
|
return JSON.stringify(this.toObject()) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
static fromObject(obj) { |
|
return new FavoriteItem(obj.id || '').setName(obj.name || '').setTags(obj.tags || []).setPrompt(obj.prompt || '').setTime(obj.time || 0) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
static fromString(str) { |
|
return FavoriteItem.fromObject(JSON.parse(str)) |
|
} |
|
} |
|
|
|
export default FavoriteItem |