Skip to content

Commit

Permalink
chore: merge branch main
Browse files Browse the repository at this point in the history
  • Loading branch information
jiazengp committed Jan 20, 2025
2 parents 0a7ed8e + e6d45e2 commit 19189a0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 17 deletions.
11 changes: 6 additions & 5 deletions .vitepress/theme/apis/forum/gitee/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as labels from './labels'
import * as oauth from './oauth'
import * as user from './user'
import type ForumAPI from '../api'
import { isPlainObject } from 'lodash-es'

class HTTPError extends Error {}

Expand Down Expand Up @@ -95,20 +96,20 @@ const cachedApiCall = useMemoize(
async <T>(
method: HttpMethod,
endpoint: string,
{ params, body, hooks }: ApiCallParams,
{ params = {}, body, hooks }: ApiCallParams,
): ApiCallResult<T> => {
if (!isNodeEnvironment() && !endpoint.includes('oauth')) {
const { auth } = useUserAuthStore()

const accessToken = auth.accessToken

if (accessToken) {
if (params) {
params.access_token = accessToken
}
if (body) {
if (body instanceof FormData) body.append('access_token', accessToken)
else body.access_token = accessToken
else if (isPlainObject(body)) body.access_token = accessToken
else params.access_token = accessToken
} else {
params.access_token = accessToken
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/components/forum/ForumTopic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
<p class="mr-2" v-if="topic.type">
<span
class="inline-flex items-center px-1 pt-.5 text-nowrap text-center font-size-3 rounded-0.5 align-middle text-xs font-semibold transition-colors color-[#b2b2b2] border-[#bdbdbd] border border-solid"
>{{ topicTypeMap.get(topic.type) }}</span
>
{{ topicTypeMap.get(topic.type) }}
</span>
</p>
</h4>
</a>
Expand Down Expand Up @@ -121,10 +122,11 @@ const { title, author, topic } = defineProps<{
const [isExpanded, toggleExpand] = useToggle()
const renderText = computed(() => {
if (isAnn.value) return topic.contentRaw.replace(/!\[.*?\]\(.*?\)/g, '')
return topic.contentRaw
const contentSanitized = topic.contentRaw
.replace(/!\[.*?\]\(.*?\)/g, '')
.slice(0, isExpanded.value ? undefined : 180)
.replace(/<!--.*(?=-->)-->/giu, '')
if (isAnn.value) return contentSanitized
return contentSanitized.slice(0, isExpanded.value ? undefined : 180)
})
const hasOverflow = computed(
Expand Down
5 changes: 4 additions & 1 deletion src/components/forum/topic/ForumTopicPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import { useLocalized } from '@/hooks/useLocalized'
import { watchOnce } from '@vueuse/core'
import { useSharedTopicInfo } from '~/composables/sharedTopicInfo'
import ForumTopicFooter from './ForumTopicFooter.vue'
import { sanitizeMarkdown } from '~/composables/sanitizeMarkdown'
const userInfo = useUserInfoStore()
const number = getTopicNumber()
Expand All @@ -111,7 +112,9 @@ const isTeamMember = computed(
() => userInfo.isTeamMember(data.value?.user.id).value,
)
const renderedContent = computed(() =>
markdownit().render(data.value?.content.text || ''),
sanitizeMarkdown(
markdownit().render(sanitizeMarkdown(data.value?.contentRaw)),
),
)
if (sharedTopicInfo.value) {
Expand Down
12 changes: 12 additions & 0 deletions src/composables/composeTopicBody.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { uniq } from 'lodash-es'

export const composeTopicBody = (
body: string,
labels: (string | null | undefined)[],
): string => {
const meta = {
labels: uniq(labels.filter((v) => v)),
}
const content = `<!-- ${JSON.stringify(meta)} -->${body}`
return content
}
5 changes: 5 additions & 0 deletions src/composables/sanitizeMarkdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const sanitizeMarkdown = (
markdown: string | null | undefined,
): string => {
return (markdown || '').replace(/<!--.*(?=-->)-->/giu, '')
}
17 changes: 10 additions & 7 deletions src/stores/useForumData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { getForumLocaleLabelGetter } from '~/composables/getForumLocaleGetter'
import { getTopicTagLabelGetter } from '~/composables/getTopicTagLabelGetter'

import type ForumAPI from '@/apis/forum/api'
import { composeTopicBody } from '~/composables/composeTopicBody'

const typeLabelGetter = getTopicTypeLabelGetter()
const localeLabelGetter = getForumLocaleLabelGetter()
Expand Down Expand Up @@ -161,15 +162,17 @@ export const useForumData = defineStore('forum-data', () => {

userSelectedTags = body.tags

const labels = [
import.meta.env.DEV ? 'DEV-TEST' : 'WEB-FEEDBACK',
typeLabelGetter.getLabel(type),
localeLabelGetter.getLabel(lang.value.substring(0, 2).toUpperCase()),
...topicLabelGetter.toLabels(body.tags),
]

submit({
body: bodyText(),
body: composeTopicBody(bodyText(), labels),
title: `${type}:${body.title}`,
labels: [
import.meta.env.DEV ? 'DEV-TEST' : 'WEB-FEEDBACK',
typeLabelGetter.getLabel(type),
localeLabelGetter.getLabel(lang.value.substring(0, 2).toUpperCase()),
...topicLabelGetter.toLabels(body.tags),
].join(','),
labels: labels.join(','),
})
}

Expand Down

0 comments on commit 19189a0

Please sign in to comment.