mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
29 lines
734 B
JavaScript
29 lines
734 B
JavaScript
import { remark } from 'remark'
|
|
import stripMarkdown from 'strip-markdown'
|
|
export function markdownToText (markdown) {
|
|
return remark()
|
|
.use(stripMarkdown)
|
|
.processSync(markdown ?? '')
|
|
.toString()
|
|
}
|
|
|
|
export async function upsertMessage (message) {
|
|
await redis.set(`CHATGPT:MESSAGE:${message.id}`, JSON.stringify(message))
|
|
}
|
|
|
|
export async function getMessageById (id) {
|
|
let messageStr = await redis.get(`CHATGPT:MESSAGE:${id}`)
|
|
return JSON.parse(messageStr)
|
|
}
|
|
|
|
export async function tryTimes (promiseFn, maxTries = 10) {
|
|
try {
|
|
return await promiseFn()
|
|
} catch (e) {
|
|
if (maxTries > 0) {
|
|
logger.warn('Failed, retry ' + maxTries)
|
|
return tryTimes(promiseFn, maxTries - 1)
|
|
}
|
|
throw e
|
|
}
|
|
}
|