给所有请求都加上jwt,隐藏生成jwt的secret(放到.env中),隐藏app-secret(放在pm2运行配置文件中,后续直接读取环境配置即可)
This commit is contained in:
+20
-10
@@ -113,9 +113,10 @@ export function convertToUITemplate(template: PromptTemplate): PromptTemplateUI
|
||||
/**
|
||||
* 获取提示词模板列表
|
||||
* @param searchParams 搜索参数
|
||||
* @param frontendJWT JWT token (可选)
|
||||
* @returns 提示词模板列表和总数
|
||||
*/
|
||||
export async function getPromptTemplates(searchParams: PromptSearchParams = {}): Promise<{
|
||||
export async function getPromptTemplates(searchParams: PromptSearchParams = {}, frontendJWT?: string): Promise<{
|
||||
data?: { templates: PromptTemplateUI[], total: number };
|
||||
error?: string;
|
||||
status?: number;
|
||||
@@ -147,7 +148,8 @@ export async function getPromptTemplates(searchParams: PromptSearchParams = {}):
|
||||
},
|
||||
limit: pageSize,
|
||||
offset: (page - 1) * pageSize,
|
||||
filter: {} as Record<string, string>
|
||||
filter: {} as Record<string, string>,
|
||||
token: frontendJWT
|
||||
};
|
||||
|
||||
// 添加筛选条件
|
||||
@@ -226,9 +228,10 @@ export async function getPromptTemplates(searchParams: PromptSearchParams = {}):
|
||||
/**
|
||||
* 获取提示词模板详情
|
||||
* @param id 模板ID
|
||||
* @param frontendJWT JWT token (可选)
|
||||
* @returns 提示词模板详情
|
||||
*/
|
||||
export async function getPromptTemplate(id: string): Promise<{
|
||||
export async function getPromptTemplate(id: string, frontendJWT?: string): Promise<{
|
||||
data?: PromptTemplateUI;
|
||||
error?: string;
|
||||
status?: number;
|
||||
@@ -254,7 +257,8 @@ export async function getPromptTemplate(id: string): Promise<{
|
||||
`,
|
||||
filter: {
|
||||
'id': `eq.${id}`
|
||||
}
|
||||
},
|
||||
token: frontendJWT
|
||||
};
|
||||
|
||||
const response = await postgrestGet<PromptTemplate[]>('prompt_templates', params);
|
||||
@@ -282,9 +286,10 @@ export async function getPromptTemplate(id: string): Promise<{
|
||||
/**
|
||||
* 创建提示词模板
|
||||
* @param template 提示词模板数据
|
||||
* @param frontendJWT JWT token (可选)
|
||||
* @returns 创建的提示词模板
|
||||
*/
|
||||
export async function createPromptTemplate(template: Partial<PromptTemplateUI>): Promise<{
|
||||
export async function createPromptTemplate(template: Partial<PromptTemplateUI>, frontendJWT?: string): Promise<{
|
||||
data?: PromptTemplateUI;
|
||||
error?: string;
|
||||
status?: number;
|
||||
@@ -326,7 +331,8 @@ export async function createPromptTemplate(template: Partial<PromptTemplateUI>):
|
||||
|
||||
const response = await postgrestPost<PromptTemplate, Partial<PromptTemplate>>(
|
||||
'prompt_templates',
|
||||
apiTemplate
|
||||
apiTemplate,
|
||||
frontendJWT
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
@@ -353,9 +359,10 @@ export async function createPromptTemplate(template: Partial<PromptTemplateUI>):
|
||||
* 更新提示词模板
|
||||
* @param id 模板ID
|
||||
* @param template 提示词模板数据
|
||||
* @param frontendJWT JWT token (可选)
|
||||
* @returns 更新后的提示词模板
|
||||
*/
|
||||
export async function updatePromptTemplate(id: string, template: Partial<PromptTemplateUI>): Promise<{
|
||||
export async function updatePromptTemplate(id: string, template: Partial<PromptTemplateUI>, frontendJWT?: string): Promise<{
|
||||
data?: PromptTemplateUI;
|
||||
error?: string;
|
||||
status?: number;
|
||||
@@ -416,7 +423,8 @@ export async function updatePromptTemplate(id: string, template: Partial<PromptT
|
||||
const response = await postgrestPut<PromptTemplate, Partial<PromptTemplate>>(
|
||||
'prompt_templates',
|
||||
apiTemplate,
|
||||
{ id }
|
||||
{ id },
|
||||
frontendJWT
|
||||
);
|
||||
|
||||
if (response.error) {
|
||||
@@ -442,9 +450,10 @@ export async function updatePromptTemplate(id: string, template: Partial<PromptT
|
||||
/**
|
||||
* 删除提示词模板
|
||||
* @param id 模板ID
|
||||
* @param frontendJWT JWT token (可选)
|
||||
* @returns 成功或失败信息
|
||||
*/
|
||||
export async function deletePromptTemplate(id: string): Promise<{
|
||||
export async function deletePromptTemplate(id: string, frontendJWT?: string): Promise<{
|
||||
success?: boolean;
|
||||
error?: string;
|
||||
status?: number;
|
||||
@@ -460,7 +469,8 @@ export async function deletePromptTemplate(id: string): Promise<{
|
||||
{
|
||||
filter: {
|
||||
'id': `eq.${id}`
|
||||
}
|
||||
},
|
||||
token: frontendJWT
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user