Skip to content

Commit

Permalink
chore(forum): 发送反馈数据接口改为FormData提交
Browse files Browse the repository at this point in the history
  • Loading branch information
boxsnake committed Jan 16, 2025
1 parent 880a85b commit fb02b77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 9 additions & 6 deletions .vitepress/theme/apis/forum/gitee/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { normalizeComment, normalizeIssue, setFilterTags } from './utils'

import type ForumAPI from '../api'
import { extractOfficialAndAuthorComments } from './inBrowserUtils'
import { buildFormData } from '@/apis/utils'

export const getTopic = async (number: string): Promise<ForumAPI.Topic> => {
const [data] = await apiCall<GITEE.IssueInfo>(
Expand Down Expand Up @@ -134,16 +135,18 @@ export const postTopic = async (
accessToken: ForumAPI.AccessToken,
data: { body: string; title: string; labels?: string },
): Promise<ForumAPI.Topic> => {
const form = buildFormData({
owner: GITEE_OWNER,
repo: GITEE_REPO,
access_token: accessToken,
...data,
})

const [issueInfo] = await apiCall<GITEE.IssueInfo>(
'post',
`repos/${GITEE_OWNER}/issues`,
{
body: {
owner: GITEE_OWNER,
repo: GITEE_REPO,
access_token: accessToken,
...data,
},
body: form,
},
)
console.log(issueInfo)
Expand Down
13 changes: 13 additions & 0 deletions .vitepress/theme/apis/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,16 @@ export const getHeader = (

return [result, undefined]
}

export const buildFormData = <T extends {}>(body: T): FormData => {
const form = new FormData()
for (let key in body) {
const value = body[key]
if (value instanceof Blob) {
form.append(key, value)
} else {
form.append(key, String(value))
}
}
return form
}

0 comments on commit fb02b77

Please sign in to comment.