Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
chore: rename rsp to resp
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaumy committed Aug 8, 2023
1 parent 6ebae60 commit d6de2c4
Show file tree
Hide file tree
Showing 42 changed files with 101 additions and 103 deletions.
2 changes: 1 addition & 1 deletion components/CommentZone/CommentZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ import FCard from "@/components/field/f-card.vue"
import FSlider from "@/components/field/f-slider.vue"
import FDivider from "@/components/field/f-divider.vue"
import FTextRender from "@/components/field/f-text-render.vue"
import {Rsp as Comment} from "@/ws/client/api/comment/create/rsp"
import {Resp as Comment} from "@/ws/client/api/comment/create/resp"
import FData from "~/components/field/f-data.vue"
const props =
Expand Down
6 changes: 3 additions & 3 deletions components/common/SwitchZone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import {removeHtmlTags} from "@/scripts/util/text"
import {useRoute, useRouter, useState} from "#app"
import {Rsp} from "@/ws/client/api/post/get_one/rsp"
import {Resp} from "@/ws/client/api/post/get_one/resp"
const props =
defineProps<{
Expand All @@ -65,7 +65,7 @@ const prev_post = await (async () => {
if (post_id === "-1")
return null
else {
const cache = <Rsp>useState(`post:${post_id}`).value
const cache = <Resp>useState(`post:${post_id}`).value
if (cache)
return cache
else
Expand All @@ -91,7 +91,7 @@ const next_post = await (async () => {
if (post_id === "-1")
return null
else {
const cache = <Rsp>useState(`post:${post_id}`).value
const cache = <Resp>useState(`post:${post_id}`).value
if (cache)
return cache
else
Expand Down
4 changes: 2 additions & 2 deletions pages/index/[post_id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import SwitchZone from "@/components/common/SwitchZone.vue"
import PostCard from "@/components/PostCard/PostCard.vue"
import FLazy from "@/components/field/f-lazy.vue"
import {onMounted, watch} from "vue"
import {Rsp} from "@/ws/client/api/post/get_one/rsp"
import {Resp} from "@/ws/client/api/post/get_one/resp"
const route = useRoute()
const router = useRouter()
Expand Down Expand Up @@ -72,7 +72,7 @@ const post = await (async () => {
if (!post_id)
return null
else {
const cache = useState<Rsp | null>(`post:${post_id}`, () => null)
const cache = useState<Resp | null>(`post:${post_id}`, () => null)
if (cache.value) {
return cache.value
} else {
Expand Down
6 changes: 3 additions & 3 deletions pages/index/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
>
<f-data
:provider="()=>getPost(id)"
v-slot="post:Rsp"
v-slot="post:Resp"
>
<PostCard
:key="id"
Expand Down Expand Up @@ -62,7 +62,7 @@ import FData from "@/components/field/f-data.vue"
import FLazy from "@/components/field/f-lazy.vue"
import PostCard from "@/components/PostCard/PostCard.vue"
import {useRouter, useState} from "#app"
import {Rsp} from "@/ws/client/api/post/get_one/rsp"
import {Resp} from "@/ws/client/api/post/get_one/resp"
import {cache} from "browserslist"
const router = useRouter()
Expand Down Expand Up @@ -108,7 +108,7 @@ for (const post of posts)
useState(`post:${post.Id}`, () => post)
async function getPost(post_id: string) {
const cache = useState<Rsp | null>(`post:${post_id}`, () => null)
const cache = useState<Resp | null>(`post:${post_id}`, () => null)
if (cache.value) {
return cache.value
} else {
Expand Down
2 changes: 0 additions & 2 deletions public/config/config.json

This file was deleted.

4 changes: 2 additions & 2 deletions ws/client/api/comment/create/handler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Req} from "@/ws/client/api/comment/create/req"
import {Rsp} from "@/ws/client/api/comment/create/rsp"
import {Resp} from "@/ws/client/api/comment/create/resp"
import {makeHandler, makeWebSocket} from "@/ws/client/helper"

const api_path = '/comment/create'
let conn = makeWebSocket(api_path)

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req, conn)
makeHandler<Req, Resp>(api_path, req, conn)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Rsp = {
export type Resp = {
Id: string
UserName: string
UserSiteUrl: string
Expand Down
4 changes: 2 additions & 2 deletions ws/client/api/post/get_all_id/handler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Req} from "@/ws/client/api/post/get_all_id/req"
import {Rsp} from "@/ws/client/api/post/get_all_id/rsp"
import {Resp} from "@/ws/client/api/post/get_all_id/resp"
import {makeHandler, makeWebSocket} from "@/ws/client/helper"

const api_path = '/post/get_all_id'
let conn = makeWebSocket(api_path)

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req, conn)
makeHandler<Req, Resp>(api_path, req, conn)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type Rsp = {
export type Resp = {
PostIds: string[]
}
4 changes: 2 additions & 2 deletions ws/client/api/post/get_menu/handler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Req} from "@/ws/client/api/post/get_menu/req"
import {Rsp} from "@/ws/client/api/post/get_menu/rsp"
import {Resp} from "@/ws/client/api/post/get_menu/resp"
import {makeHandler, makeWebSocket} from "@/ws/client/helper"

const api_path = '/post/get_menu'
let conn = makeWebSocket(api_path)

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req, conn)
makeHandler<Req, Resp>(api_path, req, conn)
5 changes: 5 additions & 0 deletions ws/client/api/post/get_menu/resp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Resp as Item} from "@/ws/server/api/post/get_one/resp"

export type Resp = {
Collection: Item[]
}
5 changes: 0 additions & 5 deletions ws/client/api/post/get_menu/rsp.ts

This file was deleted.

4 changes: 2 additions & 2 deletions ws/client/api/post/get_next/handler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Req} from "@/ws/client/api/post/get_prev/req"
import {Rsp} from "@/ws/client/api/post/get_prev/rsp"
import {Resp} from "@/ws/client/api/post/get_prev/resp"
import {makeHandler, makeWebSocket} from "@/ws/client/helper"

const api_path = '/post/get_next'
let conn = makeWebSocket(api_path)

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req, conn)
makeHandler<Req, Resp>(api_path, req, conn)
3 changes: 3 additions & 0 deletions ws/client/api/post/get_next/resp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Resp as _Resp} from "@/ws/server/api/post/get_one/resp"

export type Resp = _Resp
3 changes: 0 additions & 3 deletions ws/client/api/post/get_next/rsp.ts

This file was deleted.

4 changes: 2 additions & 2 deletions ws/client/api/post/get_one/handler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Req} from "@/ws/client/api/post/get_one/req"
import {Rsp} from "@/ws/client/api/post/get_one/rsp"
import {Resp} from "@/ws/client/api/post/get_one/resp"
import {makeHandler, makeWebSocket} from "@/ws/client/helper"

const api_path = '/post/get_one'
let conn = makeWebSocket(api_path)

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req, conn)
makeHandler<Req, Resp>(api_path, req, conn)

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Rsp as Item} from "@/ws/client/api/comment/create/rsp"
import {Resp as Item} from "@/ws/client/api/comment/create/resp"

export type Rsp = {
export type Resp = {
Id: string
Title: string
Body: string
Expand Down
4 changes: 2 additions & 2 deletions ws/client/api/post/get_prev/handler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Req} from "@/ws/client/api/post/get_next/req"
import {Rsp} from "@/ws/client/api/post/get_next/rsp"
import {Resp} from "@/ws/client/api/post/get_next/resp"
import {makeHandler, makeWebSocket} from "@/ws/client/helper"

const api_path = '/post/get_prev'
let conn = makeWebSocket(api_path)

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req, conn)
makeHandler<Req, Resp>(api_path, req, conn)
3 changes: 3 additions & 0 deletions ws/client/api/post/get_prev/resp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Resp as _Resp} from "@/ws/server/api/post/get_one/resp"

export type Resp = _Resp
3 changes: 0 additions & 3 deletions ws/client/api/post/get_prev/rsp.ts

This file was deleted.

4 changes: 2 additions & 2 deletions ws/client/api/post/get_some/handler.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Req} from "@/ws/client/api/post/get_some/req"
import {Rsp} from "@/ws/client/api/post/get_some/rsp"
import {Resp} from "@/ws/client/api/post/get_some/resp"
import {makeHandler, makeWebSocket} from "@/ws/client/helper"

const api_path = '/post/get_some'
let conn = makeWebSocket(api_path)

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req, conn)
makeHandler<Req, Resp>(api_path, req, conn)
5 changes: 5 additions & 0 deletions ws/client/api/post/get_some/resp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Resp as Item} from "@/ws/server/api/post/get_one/resp"

export type Resp = {
Collection: Item[]
}
5 changes: 0 additions & 5 deletions ws/client/api/post/get_some/rsp.ts

This file was deleted.

24 changes: 12 additions & 12 deletions ws/client/helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {randomId, reqStringify, rspParse} from "@/ws/helper"
import {randomId, reqStringify, respParse} from "@/ws/helper"
import {ApiRequest, ApiResponse} from "@/ws/helper"
import build_meta from "~/field.meta"

Expand All @@ -11,21 +11,21 @@ function makeWebSocket(api_path: string) {
return new WebSocket(`${build_meta.wsClientRoot}${api_path}`)
}

async function makeHandler<REQ, RSP>
async function makeHandler<REQ, RESP>
(api_path: string, req: REQ, conn: WebSocket) {
if (conn.CLOSED) {
conn = makeWebSocket(api_path)
}
const api_rsp = request<REQ, RSP>(api_path, conn, req)
return await api_rsp
const api_resp = request<REQ, RESP>(api_path, conn, req)
return await api_resp
}

async function request<REQ, RSP>
async function request<REQ, RESP>
(loggingHead: string, ws: WebSocket, req: REQ) {
const api_req = {Seq: randomId(), Data: req}
const api_rsp = recvApiRsp<RSP>(loggingHead, ws, api_req.Seq)
const api_resp = recvApiResp<RESP>(loggingHead, ws, api_req.Seq)
sendApiReq(loggingHead, ws, api_req).then()
return await api_rsp
return await api_resp
}

// @ts-ignore
Expand Down Expand Up @@ -53,18 +53,18 @@ async function sendApiReq<T>
}, build_meta.wsClientRetryInterval)
}

async function recvApiRsp<T>
async function recvApiResp<T>
(loggingHead: string, ws: WebSocket, seq: number) {
const task = new Promise<ApiResponse<T>>(resolve => {
let handler = (ev: MessageEvent) => {
const msg = ev.data
const api_rsp = rspParse<T>(msg)
if (api_rsp.Seq === seq) {
const api_resp = respParse<T>(msg)
if (api_resp.Seq === seq) {
ws.removeEventListener("message", handler)
resolve(api_rsp)
resolve(api_resp)

if (build_meta.enableClientDevLog)
console.log(`recv ${loggingHead} rsp:\n${msg}`)
console.log(`recv ${loggingHead} resp:\n${msg}`)
}

// 当收到请求结果时, 按需从请求队列中发起请求
Expand Down
6 changes: 3 additions & 3 deletions ws/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {
rspParse,
respParse,
randomId,
EmptyReq,
ApiRequest,
Expand Down Expand Up @@ -60,7 +60,7 @@ function reqStringify<T>(req: ApiRequest<T>) {
return JSON.stringify(req, replacer)
}

function rspParse<T>(rsp: string) {
function respParse<T>(resp: string) {
function reviver(key: string, value: any) {
if (isBigIntKeys(key))
return value.map((id: any) => id.toString())
Expand All @@ -71,5 +71,5 @@ function rspParse<T>(rsp: string) {
return value
}

return <ApiResponse<T>>JSON.parse(rsp, reviver)
return <ApiResponse<T>>JSON.parse(resp, reviver)
}
4 changes: 2 additions & 2 deletions ws/server/api/post/get_all_id/handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Req} from "@/ws/server/api/post/get_all_id/req"
import {Rsp} from "@/ws/server/api/post/get_all_id/rsp"
import {Resp} from "@/ws/server/api/post/get_all_id/resp"
import {makeHandler} from "@/ws/server/helper"

const api_path = '/post/get_all_id'

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req)
makeHandler<Req, Resp>(api_path, req)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type Rsp = {
export type Resp = {
PostIds: string[]
}
4 changes: 2 additions & 2 deletions ws/server/api/post/get_menu/handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Req} from "@/ws/server/api/post/get_menu/req"
import {Rsp} from "@/ws/server/api/post/get_menu/rsp"
import {Resp} from "@/ws/server/api/post/get_menu/resp"
import {makeHandler} from "@/ws/server/helper"

const api_path = '/post/get_menu'

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req)
makeHandler<Req, Resp>(api_path, req)
5 changes: 5 additions & 0 deletions ws/server/api/post/get_menu/resp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Resp as Item} from "@/ws/server/api/post/get_one/resp"

export type Resp = {
Collection: Item[]
}
5 changes: 0 additions & 5 deletions ws/server/api/post/get_menu/rsp.ts

This file was deleted.

4 changes: 2 additions & 2 deletions ws/server/api/post/get_next/handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Req} from "@/ws/server/api/post/get_prev/req"
import {Rsp} from "@/ws/server/api/post/get_prev/rsp"
import {Resp} from "@/ws/server/api/post/get_prev/resp"
import {makeHandler} from "@/ws/server/helper"

const api_path = '/post/get_next'

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req)
makeHandler<Req, Resp>(api_path, req)
3 changes: 3 additions & 0 deletions ws/server/api/post/get_next/resp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {Resp as _Resp} from "@/ws/server/api/post/get_one/resp"

export type Resp = _Resp
3 changes: 0 additions & 3 deletions ws/server/api/post/get_next/rsp.ts

This file was deleted.

4 changes: 2 additions & 2 deletions ws/server/api/post/get_one/handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Req} from "@/ws/server/api/post/get_one/req"
import {Rsp} from "@/ws/server/api/post/get_one/rsp"
import {Resp} from "@/ws/server/api/post/get_one/resp"
import {makeHandler} from "@/ws/server/helper"

const api_path = '/post/get_one'

export let handler = async (req: Req) =>
makeHandler<Req, Rsp>(api_path, req)
makeHandler<Req, Resp>(api_path, req)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Rsp as Item} from "@/ws/client/api/comment/create/rsp"
import {Resp as Item} from "@/ws/client/api/comment/create/resp"

export type Rsp = {
export type Resp = {
Id: string
Title: string
Body: string
Expand Down
Loading

0 comments on commit d6de2c4

Please sign in to comment.