给所有请求都加上jwt,隐藏生成jwt的secret(放到.env中),隐藏app-secret(放在pm2运行配置文件中,后续直接读取环境配置即可)
This commit is contained in:
@@ -50,7 +50,7 @@ export async function getConfigLists(params: {
|
||||
is_active?: boolean;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}): Promise<{data: ConfigItem[]; total: number; error?: never} | {data?: never; error: string}> {
|
||||
}, token?: string): Promise<{data: ConfigItem[]; total: number; error?: never} | {data?: never; error: string}> {
|
||||
try {
|
||||
const {
|
||||
name,
|
||||
@@ -90,7 +90,7 @@ export async function getConfigLists(params: {
|
||||
queryParams.filter = filter;
|
||||
|
||||
// 获取数据
|
||||
const response = await postgrestGet<ConfigItem[]>('configurations', queryParams);
|
||||
const response = await postgrestGet<ConfigItem[]>('configurations', { ...queryParams, token });
|
||||
|
||||
if (response.error) {
|
||||
return { error: response.error };
|
||||
@@ -132,11 +132,12 @@ export async function getConfigLists(params: {
|
||||
}
|
||||
|
||||
// 获取配置类型和环境选项
|
||||
export async function getConfigOptions(): Promise<{data: {types: string[]; environments: string[]}; error?: never} | {data?: never; error: string}> {
|
||||
export async function getConfigOptions(token?: string): Promise<{data: {types: string[]; environments: string[]}; error?: never} | {data?: never; error: string}> {
|
||||
try {
|
||||
// 获取类型选项
|
||||
const typeResponse = await postgrestGet<{type: string}[]>('configurations', {
|
||||
select: 'type'
|
||||
select: 'type',
|
||||
token
|
||||
});
|
||||
|
||||
if (typeResponse.error) {
|
||||
@@ -150,7 +151,8 @@ export async function getConfigOptions(): Promise<{data: {types: string[]; envir
|
||||
|
||||
// 获取环境选项
|
||||
const envResponse = await postgrestGet<{environment: string}[]>('configurations', {
|
||||
select: 'environment'
|
||||
select: 'environment',
|
||||
token
|
||||
});
|
||||
|
||||
if (envResponse.error) {
|
||||
@@ -179,12 +181,13 @@ export async function getConfigOptions(): Promise<{data: {types: string[]; envir
|
||||
}
|
||||
|
||||
// 获取配置详情
|
||||
export async function getConfigDetail(id: string): Promise<{data: ConfigItem; error?: never} | {data?: never; error: string}> {
|
||||
export async function getConfigDetail(id: string, token?: string): Promise<{data: ConfigItem; error?: never} | {data?: never; error: string}> {
|
||||
try {
|
||||
const response = await postgrestGet<ConfigItem[]>('configurations', {
|
||||
filter: {
|
||||
'id': `eq.${id}`
|
||||
}
|
||||
},
|
||||
token
|
||||
});
|
||||
|
||||
if (response.error) {
|
||||
@@ -218,9 +221,9 @@ export async function createConfig(data: {
|
||||
config: Record<string, unknown>;
|
||||
is_active: boolean;
|
||||
remark?: string;
|
||||
}): Promise<{data: ConfigItem; error?: never} | {data?: never; error: string}> {
|
||||
}, token?: string): Promise<{data: ConfigItem; error?: never} | {data?: never; error: string}> {
|
||||
try {
|
||||
const response = await postgrestPost<ConfigItem, typeof data>('configurations', data);
|
||||
const response = await postgrestPost<ConfigItem, typeof data>('configurations', data, token);
|
||||
|
||||
if (response.error) {
|
||||
return { error: response.error };
|
||||
@@ -252,11 +255,11 @@ export async function updateConfig(id: string, data: {
|
||||
config: Record<string, unknown>;
|
||||
is_active: boolean;
|
||||
remark?: string;
|
||||
}): Promise<{data: ConfigItem; error?: never} | {data?: never; error: string}> {
|
||||
}, token?: string): Promise<{data: ConfigItem; error?: never} | {data?: never; error: string}> {
|
||||
try {
|
||||
const response = await postgrestPut<ConfigItem, typeof data>('configurations', data, {
|
||||
id: id.toString()
|
||||
});
|
||||
}, token);
|
||||
|
||||
if (response.error) {
|
||||
return { error: response.error };
|
||||
@@ -281,12 +284,13 @@ export async function updateConfig(id: string, data: {
|
||||
}
|
||||
|
||||
// 更新配置状态
|
||||
export async function updateConfigStatus(id: number, is_active: boolean): Promise<{success: boolean; error?: string}> {
|
||||
export async function updateConfigStatus(id: number, is_active: boolean, token?: string): Promise<{success: boolean; error?: string}> {
|
||||
try {
|
||||
const response = await postgrestPut<ConfigItem, {is_active: boolean}>(
|
||||
'configurations',
|
||||
{ is_active },
|
||||
{ id: id.toString() }
|
||||
{ id: id.toString() },
|
||||
token
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
|
||||
Reference in New Issue
Block a user