Support favoriting a single keyword #70

Former-commit-id: 2e59e3973fcb53279a9590b0c759f7d79e41926c
This commit is contained in:
Physton
2023-05-24 00:18:09 +08:00
parent a9aef15a8f
commit b886a0feff
12 changed files with 47 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ Thank you very much for your love and support. I have received your kindness.
| 2023-05-19 | M** | 大佬🐮🍺 | ¥5 |
| 2023-05-19 | 红** | 感谢作者,非常贴心的工具! | ¥20 |
| 2023-05-20 | ?unknown | 加油,还有谢谢 | ¥5 |
| 2023-05-24 | 覃** | 秒薄之力,支持一下。 | ¥50 |
## Buy me a coffee / *请我喝杯咖啡*

View File

@@ -1 +1 @@
e0e7f849bf230ae56dcbc6e5ba2760c09711e85f
8ddaa7801dab079bb64f56c024e3759914acd0dc

View File

@@ -1 +1 @@
91620ebc0315c537889c30411c80c92d9f2eeb32
cdf5fef898063577a1110b939ee54228c496a95c

View File

@@ -66,6 +66,18 @@ class history:
self.__save_histories(type)
return item
def push_favorite(self, type, tags, prompt, name=''):
item = {
'id': str(uuid.uuid1()),
'time': int(time.time()),
'name': name,
'tags': tags,
'prompt': prompt,
}
self.favorites[type].append(item)
self.__save_favorites(type)
return item
def get_latest_history(self, type):
if len(self.histoies[type]) > 0:
return self.histoies[type][-1]

View File

@@ -129,6 +129,14 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
hi.push_history(data['type'], data['tags'], data['prompt'], data.get('name', ''))
return {"success": True}
@app.post("/physton_prompt/push_favorite")
async def _push_favorite(request: Request):
data = await request.json()
if 'type' not in data or 'tags' not in data or 'prompt' not in data:
return {"success": False, "message": "type or tags or prompt is required"}
hi.push_favorite(data['type'], data['tags'], data['prompt'], data.get('name', ''))
return {"success": True}
@app.get("/physton_prompt/get_latest_history")
async def _get_latest_history(type: str):
return {"history": hi.get_latest_history(type)}

View File

@@ -8,6 +8,7 @@
:history-key="item.historyKey"
@click:show-history="onShowHistory(item.id, $event)"
:favorite-key="item.favoriteKey"
@refresh-favorites="onRefreshFavorites"
@click:show-favorite="onShowFavorite(item.id, $event)"
v-model:can-one-translate="canOneTranslate"
v-model:auto-translate="autoTranslate"
@@ -47,6 +48,7 @@
:translate-apis="translateApis" :languages="languages"
v-model:tag-complete-file="tagCompleteFile"
v-model:only-csv-on-auto="onlyCsvOnAuto"
@refresh-favorites="onRefreshFavorites"
@use="onUseHistory"/>
<favorite ref="favorite" v-model:language-code="languageCode"
:translate-apis="translateApis" :languages="languages"
@@ -655,6 +657,9 @@ export default {
if (!item) return
this.$refs[item.id][0].useFavorite(favorite)
},
onRefreshFavorites(key) {
this.$refs.favorite.getFavorites(key)
},
},
}
</script>

View File

@@ -111,6 +111,9 @@ export default {
},
emits: ['use'],
mounted() {
this.favorites.forEach(item => {
this.getFavorites(item.key)
})
},
methods: {
formatTime(time) {
@@ -130,6 +133,7 @@ export default {
})
favoriteItem.list = res
}
window.phystonPromptfavorites = this.favorites
this.emptyMsg = this.getLang('no_favorite')
this.loading = false
}).catch(err => {
@@ -181,12 +185,14 @@ export default {
this.gradioAPI.doFavorite(this.favoriteKey, favorite.id).then(res => {
if (res) {
favorite.is_favorite = true
window.phystonPromptfavorites = this.favorites
}
})
} else {
this.gradioAPI.unFavorite(this.favoriteKey, favorite.id).then(res => {
if (res) {
favorite.is_favorite = false
window.phystonPromptfavorites = this.favorites
}
})
}
@@ -215,6 +221,7 @@ export default {
this.gradioAPI.setFavoriteName(this.favoriteKey, favorite.id, value).then(res => {
if (res) {
favorite.name = value
window.phystonPromptfavorites = this.favorites
} else {
e.target.value = favorite.name
}

View File

@@ -116,7 +116,7 @@ export default {
currentItem: {}
}
},
emits: ['use'],
emits: ['use', 'refreshFavorites'],
mounted() {
},
methods: {
@@ -195,12 +195,14 @@ export default {
this.gradioAPI.doFavorite(this.historyKey, history.id).then(res => {
if (res) {
history.is_favorite = true
this.$emit('refreshFavorites', this.historyKey)
}
})
} else {
this.gradioAPI.unFavorite(this.historyKey, history.id).then(res => {
if (res) {
history.is_favorite = false
this.$emit('refreshFavorites', this.historyKey)
}
})
}
@@ -229,6 +231,7 @@ export default {
this.gradioAPI.setHistoryName(this.historyKey, history.id, value).then(res => {
if (res) {
history.name = value
this.$emit('refreshFavorites', this.historyKey)
} else {
e.target.value = history.name
}

View File

@@ -1 +1 @@
c179fbdfa125f6553fd99ad6ddc2153929facc13
9ebc714c0a82b62bc3a79b6667a90c8a78565063

View File

@@ -86,6 +86,10 @@ export default class GradioAPI {
return (await this.api.post("/push_history", {type, tags, prompt, name})).data.success
}
async pushFavorite(type, tags, prompt, name = '') {
return (await this.api.post("/push_favorite", {type, tags, prompt, name})).data.success
}
async getLatestHistory(type) {
return (await this.api.get("/get_latest_history", {params: {type}})).data.history
}

View File

@@ -468,6 +468,8 @@
.set-icon-svg(20px, 20px, #3c3c3c, icon-svg-copy);
.set-icon-svg(20px, 20px, #ff472f, icon-svg-disabled);
.set-icon-svg(20px, 20px, #2fff53, icon-svg-enable);
.set-icon-svg(20px, 20px, none, icon-svg-favorite-no);
.set-icon-svg(20px, 20px, none, icon-svg-favorite-yes);
}
.prompt-local-language {

2
styles/main.min.css vendored

File diff suppressed because one or more lines are too long