opt: optimize the formula show styles

This commit is contained in:
RockYang 2024-03-21 11:04:12 +08:00
parent 264e77f383
commit 6aa1d27711
7 changed files with 76 additions and 20 deletions

View File

@ -154,7 +154,7 @@ func authorizeMiddleware(s *AppServer, client *redis.Client) gin.HandlerFunc {
}
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok && needLogin(c) {
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
if isAdminApi {

View File

@ -1,6 +1,10 @@
package main
import "fmt"
import (
"fmt"
"regexp"
"strings"
)
type Person struct {
Name string
@ -14,9 +18,27 @@ type Student struct {
func main() {
stu := Student{Person: Person{
Name: "xiaoming",
Age: 12,
}, School: "xxxxx soll"}
fmt.Println(stu.Name, stu.Age, stu.School)
text := `
开始创作您的LOGO了基于您提供的描述我将设计一个主题内容为一个小人推着一个购物车的卡通风格LOGO稍等片刻您的创意即将变为现实
{"prompt":"Create a cartoon-style logo featuring a character pushing a shopping cart. The design should be colorful, vibrant, and engaging, showcasing the character in a dynamic and cheerful pose. The shopping cart should be noticeable but not overpower the character. Use bright and welcoming colors to make the logo inviting and fun. The character can be stylized in a cute and approachable manner, suitable for a wide range of audiences. Ensure the logo is clear and easily recognizable at small sizes.","size":"1024x1024"}
![image1](https://filesystem.site/cdn/20240320/JQIliW99JMPZRjMkgS2PlWNlfUtqDu.webp)
[下载1](https://filesystem.site/cdn/download/20240320/JQIliW99JMPZRjMkgS2PlWNlfUtqDu.webp)
这是为您设计的卡通风格LOGO主题是一个小人推着购物车请查看图像看它是否满足您的需求如果您对这个设计满意请访问 [Vectorizer.ai](https://vectorizer.ai/) 将其转换为矢量图,以便在不同大小和格式下保持清晰度。如果您觉得需要进一步的调整或改进,请告诉我,我们可以继续优化设计。`
pattern := `!\[([^\]]*)]\(([^)]+)\)`
re := regexp.MustCompile(pattern)
matches := re.FindAllStringSubmatch(text, -1)
// 下载图片并替换链接地址
for _, match := range matches {
imageURL := match[2]
fmt.Println(imageURL)
// 对于相同地址的图片,已经被替换了,就不再重复下载了
if !strings.Contains(text, imageURL) {
continue
}
}
}

View File

@ -82,6 +82,7 @@ import {useRouter} from 'vue-router';
import {ArrowDown, ArrowRight, Expand, Fold} from "@element-plus/icons-vue";
import {httpGet} from "@/utils/http";
import {ElMessage} from "element-plus";
import {removeAdminToken} from "@/store/session";
const message = ref(5);
const sysTitle = ref(process.env.VUE_APP_TITLE)
@ -153,6 +154,7 @@ onMounted(() => {
const logout = function () {
httpGet("/api/admin/logout").then(() => {
removeAdminToken()
router.replace('/admin/login')
}).catch((e) => {
ElMessage.error("注销失败: " + e.message);

View File

@ -39,7 +39,7 @@ export function removeUserToken() {
}
export function getAdminToken() {
return Storage.get(AdminTokenKey)
return Storage.get(AdminTokenKey) ?? ""
}
export function setAdminToken(token) {

View File

@ -167,7 +167,7 @@ export function isImage(url) {
}
export function processContent(content) {
//process img url
// 如果是图片链接地址,则直接替换成图片标签
const linkRegex = /(https?:\/\/\S+)/g;
const links = content.match(linkRegex);
if (links) {
@ -181,20 +181,31 @@ export function processContent(content) {
}
}
// 处理引用块
if (content.indexOf("\n") === -1) {
const lines = content.split("\n")
if (lines.length <= 1) {
return content
}
const texts = content.split("\n")
const lines = []
for (let txt of texts) {
lines.push(txt)
if (txt.startsWith(">")) {
lines.push("\n")
const texts = []
// 定义匹配数学公式的正则表达式
const formulaRegex = /^\s*[a-z|A-Z]+[^=]+\s*=\s*[^=]+$/;
for (let i = 0; i < lines.length; i++) {
// 处理引用块换行
if (lines[i].startsWith(">")) {
texts.push(lines[i])
texts.push("\n")
continue
}
console.log(formulaRegex.test(lines[i]))
// 识别并处理数学公式,需要排除那些已经被识别出来的公式
if (i > 0 && formulaRegex.test(lines[i]) && lines[i - 1].indexOf("$$") === -1) {
texts.push("$$")
texts.push(lines[i])
texts.push("$$")
continue
}
texts.push(lines[i])
}
return lines.join("\n")
return texts.join("\n")
}
export function escapeHTML(html) {
@ -203,3 +214,23 @@ export function escapeHTML(html) {
.replace(/>/g, "&gt;");
}
// 处理数学公式
export function processMathFormula(input) {
const arr = []
const lines = input.split("\n")
if (lines.length <= 1) {
return input
}
// 定义匹配数学公式的正则表达式
const mathFormulaRegex = /[+\-*/^()\d.]/;
for (let i = 0; i < lines.length; i++) {
if (i > 0 && mathFormulaRegex.test(lines) && lines[i - 1].indexOf("$$") === -1) {
arr.push("$$")
arr.push(lines[i])
arr.push("$$")
} else {
arr.push(lines[i])
}
}
return arr.join("\n")
}

View File

@ -817,7 +817,7 @@ const logout = function () {
activelyClose.value = true;
httpGet('/api/user/logout').then(() => {
removeUserToken()
location.reload()
router.push("/login")
}).catch(() => {
ElMessage.error('注销失败!');
})

View File

@ -17,6 +17,7 @@
<el-image v-if="scope.row.vip" :src="vipImg" style="height: 20px;position: relative; top:5px; left: 5px"/>
</template>
</el-table-column>
<el-table-column prop="nickname" label="昵称"/>
<el-table-column prop="power" label="剩余算力"/>
<el-table-column label="状态" width="80">
<template #default="scope">