Skip to content

Commit

Permalink
fix: get params
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook committed Nov 27, 2023
1 parent d82f2a8 commit 6f5814a
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 20 deletions.
9 changes: 7 additions & 2 deletions playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ const app = easypanel({
token: process.env.EASYPANEL_TOKEN || '',
})

const dd = await app.projects.create({ name: 'ttt' })
console.warn(dd)
// const dd = await app.projects.create({ name: 'ttt' })
// console.warn(dd)

const response = await app.projects.inspect({
projectName: 'projects',
})
console.warn(response)
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ function client(config: ClientConfig): ClientResponse {
retryDelay: 1000, // ms
})

function get<T>(route: string, body: any): Promise<T> {
function get<T>(route: string, input?: any): Promise<T> {
return customClient(route, {
method: 'GET',
headers: {
Authorization: token,
},
body: JSON.stringify(body),
params: input,
})
}

Expand Down
16 changes: 12 additions & 4 deletions src/service/monitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,36 @@ import { routes } from '../utils/routes'
export function monitor({ get }: ClientResponse) {
async function getAdvancedStats() {
const res = await get<AdvancedStats>(routes.monitor.GetAdvancedStats, {
json: null,
input: {
json: null,
},
})
return res
}

async function getDockerTaskStats() {
const res = await get<DockerTaskStats>(routes.monitor.GetDockerTaskStats, {
json: null,
input: {
json: null,
},
})
return res
}

async function getMonitorTableData() {
const res = await get<ContainerStats>(routes.monitor.GetMonitorTableData, {
json: null,
input: {
json: null,
},
})
return res
}

async function getSystemStats() {
const res = await get<SystemStats>(routes.monitor.GetSystemStats, {
json: null,
input: {
json: null,
},
})
return res
}
Expand Down
16 changes: 12 additions & 4 deletions src/service/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import type {
export function projects({ get, post }: ClientResponse) {
async function canCreate() {
const res = await get<CanCreate>(routes.projets.CanCreate, {
json: null,
input: {
json: null,
},
})
return res
}
Expand All @@ -37,21 +39,27 @@ export function projects({ get, post }: ClientResponse) {

async function inspect(body: ProjectQueryConf) {
const res = await get<Project>(routes.projets.Inspect, {
json: body,
input: {
json: body,
},
})
return res
}

async function list() {
const res = await get<ListProjects>(routes.projets.List, {
json: null,
input: {
json: null,
},
})
return res
}

async function listWithServices() {
const res = await get<ListWithServices>(routes.projets.ListWithServices, {
json: null,
input: {
json: null,
},
})
return res
}
Expand Down
8 changes: 6 additions & 2 deletions src/service/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export function services({ get, post }: ClientResponse) {
body: SelectService,
) {
const Route = routes.services(serviceType).Inspect
const res = await get<ServiceRes>(Route, { json: body })
const res = await get<ServiceRes>(Route, { input: {
input: {
json: body,
},
} })
return res
}

Expand Down Expand Up @@ -255,7 +259,7 @@ export function services({ get, post }: ClientResponse) {
async function getServiceLogs(body: SelectService) {
const service = `${body.projectName}_${body.serviceName}`
const res = await get<StringResponse>(routes.services('').GetServiceLogs, {
json: {
input: {
service,
lines: 50,
},
Expand Down
22 changes: 17 additions & 5 deletions src/service/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export function settings({ get, post }: ClientResponse) {
*/
async function getGithubToken(): Promise<StringResponse> {
const res = await get<StringResponse>(routes.settings.GetGithubToken, {
json: null,
input: {
json: null,
},
})
return res
}
Expand All @@ -37,21 +39,29 @@ export function settings({ get, post }: ClientResponse) {
async function getLetsEncryptEmail(): Promise<StringResponse> {
const res = await get<StringResponse>(
routes.settings.GetLetsEncryptEmail,
{ json: null },
{
input: {
json: null,
},
},
)
return res
}

async function getPanelDomain(): Promise<PanelDomainRes> {
const res = await get<PanelDomainRes>(routes.settings.GetPanelDomain, {
json: null,
input: {
json: null,
},
})
return res
}

async function getServerIp(): Promise<StringResponse> {
const res = await get<StringResponse>(routes.settings.GetServerIp, {
json: null,
input: {
json: null,
},
})
return res
}
Expand All @@ -60,7 +70,9 @@ export function settings({ get, post }: ClientResponse) {
const res = await get<StringResponse>(
routes.settings.GetTraefikCustomConfig,
{
json: null,
input: {
json: null,
},
},
)
return res
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface ClientResponse {
get: <T>(route: string, body: any) => Promise<T>
get: <T>(route: string, input?: any) => Promise<T>
post: <T>(route: string, body: any) => Promise<T>
token: string
}
Expand Down

0 comments on commit 6f5814a

Please sign in to comment.