Skip to content

Commit

Permalink
chore: prettify frontend code
Browse files Browse the repository at this point in the history
  • Loading branch information
Semesse committed Jan 22, 2024
1 parent 0e03c93 commit 90414a6
Show file tree
Hide file tree
Showing 82 changed files with 5,230 additions and 5,592 deletions.
2 changes: 2 additions & 0 deletions www/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/pb
out
41 changes: 41 additions & 0 deletions www/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module.exports = {
// max 120 characters per line
printWidth: 120,
// use 2 spaces for indentation
tabWidth: 2,
// use spaces instead of indentations
useTabs: false,
// semicolon at the end of the line
semi: false,
// use single quotes
singleQuote: true,
// object's key is quoted only when necessary
quoteProps: 'as-needed',
// use double quotes instead of single quotes in jsx
jsxSingleQuote: false,
// no comma at the end
trailingComma: 'all',
// spaces are required at the beginning and end of the braces
bracketSpacing: true,
// end tag of jsx need to wrap
bracketSameLine: false,
// brackets are required for arrow function parameter, even when there is only one parameter
arrowParens: 'always',
// format the entire contents of the file
rangeStart: 0,
rangeEnd: Infinity,
// no need to write the beginning @prettier of the file
requirePragma: false,
// No need to automatically insert @prettier at the beginning of the file
insertPragma: false,
// use default break criteria
proseWrap: 'preserve',
// decide whether to break the html according to the display style
htmlWhitespaceSensitivity: 'css',
// vue files script and style tags indentation
vueIndentScriptAndStyle: false,
// lf for newline
endOfLine: 'lf',
// formats quoted code embedded
embeddedLanguageFormatting: 'auto',
}
19 changes: 8 additions & 11 deletions www/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import http from '@/api/http'
import { API_PATH } from '@/lib/consts'
import {
LoginRequest, LoginResponse,
RegisterRequest, RegisterResponse
} from '@/lib/pb/api_auth'
import { LoginRequest, LoginResponse, RegisterRequest, RegisterResponse } from '@/lib/pb/api_auth'
import { CommonResponse } from '@/lib/pb/common'
import { BaseResponse } from '@/types/api'

export const login = async (req: LoginRequest) => {
const res = await http.post(API_PATH + '/auth/login', LoginRequest.toJson(req))
return LoginResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/auth/login', LoginRequest.toJson(req))
return LoginResponse.fromJson((res.data as BaseResponse).body)
}

export const register = async (req: RegisterRequest) => {
const res = await http.post(API_PATH + '/auth/register', RegisterRequest.toJson(req))
return RegisterResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/auth/register', RegisterRequest.toJson(req))
return RegisterResponse.fromJson((res.data as BaseResponse).body)
}

export const logout = async () => {
const res = await http.get(API_PATH + '/auth/logout')
return CommonResponse.fromJson((res.data as BaseResponse).body)
}
const res = await http.get(API_PATH + '/auth/logout')
return CommonResponse.fromJson((res.data as BaseResponse).body)
}
38 changes: 21 additions & 17 deletions www/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import http from '@/api/http'
import { API_PATH } from "@/lib/consts";
import { API_PATH } from '@/lib/consts'
import {
DeleteClientRequest, DeleteClientResponse,
GetClientRequest, GetClientResponse,
InitClientRequest, InitClientResponse,
ListClientsRequest, ListClientsResponse
} from '@/lib/pb/api_client';
import { BaseResponse } from "@/types/api";
DeleteClientRequest,
DeleteClientResponse,
GetClientRequest,
GetClientResponse,
InitClientRequest,
InitClientResponse,
ListClientsRequest,
ListClientsResponse,
} from '@/lib/pb/api_client'
import { BaseResponse } from '@/types/api'

export const getClient = async (req: GetClientRequest) => {
const res = await http.post(API_PATH + '/client/get', GetClientRequest.toJson(req))
return GetClientResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/client/get', GetClientRequest.toJson(req))
return GetClientResponse.fromJson((res.data as BaseResponse).body)
}

export const listClient = async (req: ListClientsRequest) => {
const res = await http.post(API_PATH + '/client/list', ListClientsRequest.toJson(req))
return ListClientsResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/client/list', ListClientsRequest.toJson(req))
return ListClientsResponse.fromJson((res.data as BaseResponse).body)
}

export const deleteClient = async (req: DeleteClientRequest) => {
const res = await http.post(API_PATH + '/client/delete', DeleteClientRequest.toJson(req))
return DeleteClientResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/client/delete', DeleteClientRequest.toJson(req))
return DeleteClientResponse.fromJson((res.data as BaseResponse).body)
}

export const initClient = async (req: InitClientRequest) => {
console.log("attempting init client:", InitClientRequest.toJsonString(req))
const res = await http.post(API_PATH + '/client/init', InitClientRequest.toJson(req))
return InitClientResponse.fromJson((res.data as BaseResponse).body)
}
console.log('attempting init client:', InitClientRequest.toJsonString(req))
const res = await http.post(API_PATH + '/client/init', InitClientRequest.toJson(req))
return InitClientResponse.fromJson((res.data as BaseResponse).body)
}
36 changes: 13 additions & 23 deletions www/api/frp.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
import http from '@/api/http'
import { API_PATH } from "@/lib/consts";
import {
RemoveFRPCRequest,
RemoveFRPCResponse,
UpdateFRPCRequest,
UpdateFRPCResponse
} from '@/lib/pb/api_client';
import {
RemoveFRPSRequest,
RemoveFRPSResponse,
UpdateFRPSRequest,
UpdateFRPSResponse
} from '@/lib/pb/api_server';
import { BaseResponse } from "@/types/api";
import { API_PATH } from '@/lib/consts'
import { RemoveFRPCRequest, RemoveFRPCResponse, UpdateFRPCRequest, UpdateFRPCResponse } from '@/lib/pb/api_client'
import { RemoveFRPSRequest, RemoveFRPSResponse, UpdateFRPSRequest, UpdateFRPSResponse } from '@/lib/pb/api_server'
import { BaseResponse } from '@/types/api'

export const updateFRPS = async (req: UpdateFRPSRequest) => {
const res = await http.post(API_PATH + '/frps/update', UpdateFRPSRequest.toJson(req))
return UpdateFRPSResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/frps/update', UpdateFRPSRequest.toJson(req))
return UpdateFRPSResponse.fromJson((res.data as BaseResponse).body)
}

export const removeFRPS = async (req: RemoveFRPSRequest) => {
const res = await http.post(API_PATH + '/frps/remove', RemoveFRPSRequest.toJson(req))
return RemoveFRPSResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/frps/remove', RemoveFRPSRequest.toJson(req))
return RemoveFRPSResponse.fromJson((res.data as BaseResponse).body)
}

export const updateFRPC = async (req: UpdateFRPCRequest) => {
const res = await http.post(API_PATH + '/frpc/update', UpdateFRPCRequest.toJson(req))
return UpdateFRPCResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/frpc/update', UpdateFRPCRequest.toJson(req))
return UpdateFRPCResponse.fromJson((res.data as BaseResponse).body)
}

export const removeFRPC = async (req: RemoveFRPCRequest) => {
const res = await http.post(API_PATH + '/frpc/remove', RemoveFRPCRequest.toJson(req))
return RemoveFRPCResponse.fromJson((res.data as BaseResponse).body)
}
const res = await http.post(API_PATH + '/frpc/remove', RemoveFRPCRequest.toJson(req))
return RemoveFRPCResponse.fromJson((res.data as BaseResponse).body)
}
36 changes: 18 additions & 18 deletions www/api/http.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { LOCAL_STORAGE_TOKEN_KEY, SET_TOKEN_HEADER, X_CLIENT_REQUEST_ID } from '@/lib/consts';
import { $token } from '@/store/user';
import { LOCAL_STORAGE_TOKEN_KEY, SET_TOKEN_HEADER, X_CLIENT_REQUEST_ID } from '@/lib/consts'
import { $token } from '@/store/user'
import axios from 'axios'
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from 'uuid'

const instance = axios.create({})

instance.interceptors.request.use((request) => {
let token = 'Bearer ' + localStorage.getItem(LOCAL_STORAGE_TOKEN_KEY)
if (token) {
request.headers.Authorization = token
$token.set(token)
}
request.headers[X_CLIENT_REQUEST_ID] = uuidv4();
return request
let token = 'Bearer ' + localStorage.getItem(LOCAL_STORAGE_TOKEN_KEY)
if (token) {
request.headers.Authorization = token
$token.set(token)
}
request.headers[X_CLIENT_REQUEST_ID] = uuidv4()
return request
})

instance.interceptors.response.use((response) => {
if (response.headers?.[SET_TOKEN_HEADER]) {
localStorage.setItem(LOCAL_STORAGE_TOKEN_KEY, response.headers[SET_TOKEN_HEADER])
$token.set(response.headers[SET_TOKEN_HEADER])
}
if (response.data.code != 200) {
throw response.data.msg
}
return response
if (response.headers?.[SET_TOKEN_HEADER]) {
localStorage.setItem(LOCAL_STORAGE_TOKEN_KEY, response.headers[SET_TOKEN_HEADER])
$token.set(response.headers[SET_TOKEN_HEADER])
}
if (response.data.code != 200) {
throw response.data.msg
}
return response
})

export default instance
19 changes: 7 additions & 12 deletions www/api/platform.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import http from '@/api/http'
import { API_PATH } from '@/lib/consts'
import {
GetClientsStatusRequest,
GetClientsStatusResponse
} from '@/lib/pb/api_master'
import {
GetPlatformInfoResponse,
} from '@/lib/pb/api_user'
import { GetClientsStatusRequest, GetClientsStatusResponse } from '@/lib/pb/api_master'
import { GetPlatformInfoResponse } from '@/lib/pb/api_user'
import { BaseResponse } from '@/types/api'

export const getPlatformInfo = async () => {
const res = await http.get(API_PATH + '/platform/baseinfo')
return GetPlatformInfoResponse.fromJson((res.data as BaseResponse).body)
const res = await http.get(API_PATH + '/platform/baseinfo')
return GetPlatformInfoResponse.fromJson((res.data as BaseResponse).body)
}

export const getClientsStatus = async (req: GetClientsStatusRequest) => {
const res = await http.post(API_PATH + '/platform/clientsstatus', GetClientsStatusRequest.toJson(req))
return GetClientsStatusResponse.fromJson((res.data as BaseResponse).body)
}
const res = await http.post(API_PATH + '/platform/clientsstatus', GetClientsStatusRequest.toJson(req))
return GetClientsStatusResponse.fromJson((res.data as BaseResponse).body)
}
38 changes: 20 additions & 18 deletions www/api/server.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import http from '@/api/http'
import { API_PATH } from "@/lib/consts";
import { API_PATH } from '@/lib/consts'
import {
DeleteServerRequest,
DeleteServerResponse,
GetServerRequest, GetServerResponse,
InitServerRequest,
InitServerResponse,
ListServersRequest, ListServersResponse
} from "@/lib/pb/api_server";
import { BaseResponse } from "@/types/api";
DeleteServerRequest,
DeleteServerResponse,
GetServerRequest,
GetServerResponse,
InitServerRequest,
InitServerResponse,
ListServersRequest,
ListServersResponse,
} from '@/lib/pb/api_server'
import { BaseResponse } from '@/types/api'

export const getServer = async (req: GetServerRequest) => {
const res = await http.post(API_PATH + '/server/get', GetServerRequest.toJson(req))
return GetServerResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/server/get', GetServerRequest.toJson(req))
return GetServerResponse.fromJson((res.data as BaseResponse).body)
}

export const listServer = async (req: ListServersRequest) => {
const res = await http.post(API_PATH + '/server/list', ListServersRequest.toJson(req))
return ListServersResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/server/list', ListServersRequest.toJson(req))
return ListServersResponse.fromJson((res.data as BaseResponse).body)
}

export const deleteServer = async (req: DeleteServerRequest) => {
const res = await http.post(API_PATH + '/server/delete', DeleteServerRequest.toJson(req))
return DeleteServerResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/server/delete', DeleteServerRequest.toJson(req))
return DeleteServerResponse.fromJson((res.data as BaseResponse).body)
}

export const initServer = async (req: InitServerRequest) => {
const res = await http.post(API_PATH + '/server/init', InitServerRequest.toJson(req))
return InitServerResponse.fromJson((res.data as BaseResponse).body)
}
const res = await http.post(API_PATH + '/server/init', InitServerRequest.toJson(req))
return InitServerResponse.fromJson((res.data as BaseResponse).body)
}
18 changes: 10 additions & 8 deletions www/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import http from '@/api/http'
import { API_PATH } from '@/lib/consts'
import {
GetUserInfoRequest, GetUserInfoResponse,
UpdateUserInfoRequest, UpdateUserInfoResponse
GetUserInfoRequest,
GetUserInfoResponse,
UpdateUserInfoRequest,
UpdateUserInfoResponse,
} from '@/lib/pb/api_user'
import { $userInfo } from '@/store/user'
import { BaseResponse } from '@/types/api'

export const getUserInfo = async (req: GetUserInfoRequest) => {
const res = await http.post(API_PATH + '/user/get', GetUserInfoRequest.toJson(req))
$userInfo.set(GetUserInfoResponse.fromJson((res.data as BaseResponse).body).userInfo)
return GetUserInfoResponse.fromJson((res.data as BaseResponse).body)
const res = await http.post(API_PATH + '/user/get', GetUserInfoRequest.toJson(req))
$userInfo.set(GetUserInfoResponse.fromJson((res.data as BaseResponse).body).userInfo)
return GetUserInfoResponse.fromJson((res.data as BaseResponse).body)
}

export const updateUserInfo = async (req: UpdateUserInfoRequest) => {
const res = await http.post(API_PATH + '/user/update', UpdateUserInfoRequest.toJson(req))
return UpdateUserInfoResponse.fromJson((res.data as BaseResponse).body)
}
const res = await http.post(API_PATH + '/user/update', UpdateUserInfoRequest.toJson(req))
return UpdateUserInfoResponse.fromJson((res.data as BaseResponse).body)
}
2 changes: 1 addition & 1 deletion www/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"components": "@/components",
"utils": "@/lib/utils"
}
}
}
Loading

0 comments on commit 90414a6

Please sign in to comment.