-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
989 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { fetcher } from '.' | ||
|
||
export type PageInfoResponse = { | ||
code: number | ||
message?: string | ||
data: { | ||
good: number | ||
bad: number | ||
pageview: number | ||
lastupdate: number | ||
id: string | ||
record_id: string | ||
} | ||
} | ||
|
||
export const getPageInfo = async (page): Promise<PageInfoResponse> => | ||
await fetcher | ||
.get('docs/pageinfo', { | ||
searchParams: { | ||
path: String(page.value.filePath).replace('.md', ''), | ||
}, | ||
}) | ||
.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import ky from 'ky' | ||
import sha256 from 'crypto-js/sha256' | ||
import hmacSHA512 from 'crypto-js/hmac-sha512' | ||
import Base64 from 'crypto-js/enc-base64' | ||
|
||
const hmacDigest = (date) => | ||
Base64.stringify(hmacSHA512(sha256(parseInt(date)), 'site.yuanshen')) | ||
|
||
export const fetcher = ky.create({ | ||
prefixUrl: 'https://kongying-tavern-pin-feedback-api.vercel.app/apis/v1', | ||
timeout: 5000, | ||
retry: 0, | ||
hooks: { | ||
beforeRequest: [ | ||
(request) => { | ||
const currently = Date.now() | ||
request.headers.set( | ||
'authorization', | ||
`${currently}:${hmacDigest(currently)}`, | ||
) | ||
}, | ||
], | ||
afterResponse: [ | ||
(_request, _options, response) => { | ||
console.log(response) | ||
}, | ||
], | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Content } from 'vitepress' | ||
import { UAParser } from 'ua-parser-js' | ||
import { fetcher } from '.' | ||
|
||
const parser = new UAParser(window.navigator.userAgent) | ||
const result = parser.getResult() | ||
|
||
export type NewDocFeedbackResponse = { | ||
code: number | ||
message?: string | ||
data?: { | ||
id: string | ||
feedback_id: string | ||
record_id: string | ||
} | ||
} | ||
|
||
export const newDocFeedback = async (data: { | ||
path: string | ||
feedback_type?: Array<string> | ||
feedback_content?: string | ||
user_id?: string | ||
nickname?: string | ||
file?: Array<string> | ||
user_contact?: string | ||
}): Promise<NewDocFeedbackResponse> => { | ||
try { | ||
return await fetcher | ||
.post('docs/feedback/new', { | ||
json: { | ||
path: data.path, | ||
feedback_type: data.feedback_type, | ||
feedback_content: data.feedback_content, | ||
user_id: data.user_id, | ||
file: data.file, | ||
nickname: data.nickname, | ||
user_contract: data.user_contact, | ||
user_platform: `${result.os.name}-${result.browser.name}`, | ||
user_env_info: JSON.stringify({ | ||
userAgent: navigator.userAgent, | ||
screen: { | ||
availWidth: window.screen.availWidth, | ||
availHeight: window.screen.availHeight, | ||
width: window.screen.width, | ||
height: window.screen.height, | ||
}, | ||
}), | ||
}, | ||
}) | ||
.json() | ||
} catch (error) { | ||
console.log(error) | ||
return await error.response | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { fetcher } from '.' | ||
|
||
export type PageviewResponse = { | ||
code: number | ||
message?: string | ||
} | ||
|
||
export const pageview = async (record_id): Promise<PageviewResponse> => | ||
await fetcher | ||
.get('docs/pageview', { | ||
searchParams: { | ||
record_id, | ||
}, | ||
}) | ||
.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { fetcher } from '.' | ||
|
||
export type DocFeedbackResponse = { | ||
code: number | ||
message?: string | ||
} | ||
|
||
export const sendDocFeedback = async ( | ||
record_id: string, | ||
type: 'good' | 'bad', | ||
cancel?: boolean, | ||
): Promise<DocFeedbackResponse> => | ||
await fetcher | ||
.post('docs/feedback', { | ||
json: { | ||
record_id: record_id, | ||
type: type, | ||
cancel: cancel, | ||
}, | ||
}) | ||
.json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.