Skip to content

Commit

Permalink
Feat: correct login logic (#3)
Browse files Browse the repository at this point in the history
* chore: update gitignore

* feat: add llm debug page

* aider: The commit message for the provided diffs would be:

"Added functionality to fetch and display article content and is_advertorial field from the backend /craft-debug/advertorial API in the LLM Debug Page."

# Aider chat conversation:

USER: in llm-debug page, when user input a article url and click submit button , then make request to backend /craft-debug/advertorial api and get response, then extract the article content field and is_advertorial field, then show them in the page

ASSISTANT:  To implement the feature you described, we need to modify the `llm-debug.vue` file. Here are the changes:

web/admin/src/views/dashboard/llm-debug/llm-debug.vue


* aider: Commit message: "Refactored fetchArticle function to use axios for simplified HTTP POST requests."

# Aider chat conversation:

USER: use axios to make it more simple

ASSISTANT:  Sure, I can help you simplify the fetchArticle function in the `llm-debug.vue` file using axios. Here's the *SEARCH/REPLACE* block for the changes:

web/admin/src/views/dashboard/llm-debug/llm-debug.vue


This change simplifies the fetchArticle function by using axios to make the POST request. It also imports axios at the top of the script.

* feat: refactor api check-if-advertorial

* feat: update llm-debug page

* feat: handle login

* chore: update GitHub action config
  • Loading branch information
Colin-XKL authored May 18, 2024
1 parent e68f157 commit c991216
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 95 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ jobs:
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
type=schedule,pattern=nightly
type=pep440,pattern={{version}}
type=edge,branch=dev
type=pep440,pattern={{major}}.{{minor}},enable={{is_default_branch}}
type=pep440,pattern={{version}},enable={{is_default_branch}}
flavor: latest=false

# Build and push Docker image with Buildx (don't push on PR)
Expand Down
6 changes: 3 additions & 3 deletions web/admin/src/api/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { useUserStore } from '@/store';
import { getToken } from '@/utils/auth';

export interface HttpResponse<T = unknown> {
status: number;
status?: number;
msg: string;
code: number;
data: T;
data?: T;
}

if (import.meta.env.VITE_API_BASE_URL) {
Expand Down Expand Up @@ -40,7 +40,7 @@ axios.interceptors.response.use(
(response: AxiosResponse<HttpResponse>) => {
const res = response.data;
// if the custom code is not 20000, it is judged as an error.
if (res.code !== 20000) {
if (res.code !== 0) {
Message.error({
content: res.msg || 'Error',
duration: 5 * 1000,
Expand Down
2 changes: 1 addition & 1 deletion web/admin/src/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface LoginRes {
token: string;
}
export function login(data: LoginData) {
return axios.post<LoginRes>('/api/user/login', data);
return axios.post<LoginRes>('/api/login', data);
}

export function logout() {
Expand Down
124 changes: 62 additions & 62 deletions web/admin/src/mock/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,67 +39,67 @@ setupMock({
});

// 登录
Mock.mock(new RegExp('/api/user/login'), (params: MockParams) => {
const { username, password } = JSON.parse(params.body);
if (!username) {
return failResponseWrap(null, '用户名不能为空', 50000);
}
if (!password) {
return failResponseWrap(null, '密码不能为空', 50000);
}
if (username === 'admin' && password === 'admin') {
window.localStorage.setItem('userRole', 'admin');
return successResponseWrap({
token: '12345',
});
}
if (username === 'user' && password === 'user') {
window.localStorage.setItem('userRole', 'user');
return successResponseWrap({
token: '54321',
});
}
return failResponseWrap(null, '账号或者密码错误', 50000);
});

// 登出
Mock.mock(new RegExp('/api/user/logout'), () => {
return successResponseWrap(null);
});

// 用户的服务端菜单
Mock.mock(new RegExp('/api/user/menu'), () => {
const menuList = [
{
path: '/dashboard',
name: 'dashboard',
meta: {
locale: 'menu.server.dashboard',
requiresAuth: true,
icon: 'icon-dashboard',
order: 1,
},
children: [
{
path: 'workplace',
name: 'Workplace',
meta: {
locale: 'menu.server.workplace',
requiresAuth: true,
},
},
{
path: 'https://arco.design',
name: 'arcoWebsite',
meta: {
locale: 'menu.arcoWebsite',
requiresAuth: true,
},
},
],
},
];
return successResponseWrap(menuList);
});
// Mock.mock(new RegExp('/api/user/login'), (params: MockParams) => {
// const { username, password } = JSON.parse(params.body);
// if (!username) {
// return failResponseWrap(null, '用户名不能为空', 50000);
// }
// if (!password) {
// return failResponseWrap(null, '密码不能为空', 50000);
// }
// if (username === 'admin' && password === 'admin') {
// window.localStorage.setItem('userRole', 'admin');
// return successResponseWrap({
// token: '12345',
// });
// }
// if (username === 'user' && password === 'user') {
// window.localStorage.setItem('userRole', 'user');
// return successResponseWrap({
// token: '54321',
// });
// }
// return failResponseWrap(null, '账号或者密码错误', 50000);
// });
//
// // 登出
// Mock.mock(new RegExp('/api/user/logout'), () => {
// return successResponseWrap(null);
// });
//
// // 用户的服务端菜单
// Mock.mock(new RegExp('/api/user/menu'), () => {
// const menuList = [
// {
// path: '/dashboard',
// name: 'dashboard',
// meta: {
// locale: 'menu.server.dashboard',
// requiresAuth: true,
// icon: 'icon-dashboard',
// order: 1,
// },
// children: [
// {
// path: 'workplace',
// name: 'Workplace',
// meta: {
// locale: 'menu.server.workplace',
// requiresAuth: true,
// },
// },
// {
// path: 'https://arco.design',
// name: 'arcoWebsite',
// meta: {
// locale: 'menu.arcoWebsite',
// requiresAuth: true,
// },
// },
// ],
// },
// ];
// return successResponseWrap(menuList);
// });
},
});
2 changes: 1 addition & 1 deletion web/admin/src/utils/setup-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const successResponseWrap = (data: unknown) => {
data,
status: 'ok',
msg: '请求成功',
code: 20000,
code: 0,
};
};

Expand Down
56 changes: 32 additions & 24 deletions web/admin/src/views/dashboard/llm-debug/llm-debug.vue
Original file line number Diff line number Diff line change
@@ -1,49 +1,57 @@
<template>
<div class="py-8 px-16">
<h1 class="text-3xl font-bold">LLM Debug Page</h1>
<h1 class="text-3xl font-bold">LLM Debug Page - Check If Advertorial</h1>
<p>通过大模型能力,检测一个文章是不是广告或是推广的软文</p>
<a-card class="my-2" title="输入链接">
<p>输入要预览的RSS源地址 支持RSS/ATOM</p>
<p>输入要预览的文章链接</p>
<a-space>
<a-input
v-model="articleUrl"
type="text"
placeholder="Enter article URL"
class="w-full"
/>
<a-button @click="fetchArticle">Submit</a-button>
<a-button :loading="isLoading" @click="fetchArticle">Submit</a-button>
</a-space>
</a-card>
<a-card title="结果预览" class="my-4">
<div v-if="articleContent">
<p>Article Content: {{ articleContent }}</p>
<p>Is Advertorial: {{ isAdvertorial }}</p>
<a-card title="结果预览" class="my-4" :loading="isLoading">
<div v-if="articleContent?.length !== 0">
<p class="mb-2"><b>Is Advertorial:</b>{{ isAdvertorial }}</p>
<hr class="my-1" />
<p class="my-1"><b>Article Content: </b></p>
<p>{{ articleContent }}</p>
</div>
<a-empty v-else />
</a-card>
</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { Message } from '@arco-design/web-vue';
import { ref } from 'vue';
import { Message } from '@arco-design/web-vue';
const articleUrl = ref('');
const articleContent = ref('');
const isAdvertorial = ref(false);
import axios from 'axios';
import axios from 'axios';
const articleUrl = ref('');
const articleContent = ref('');
const isAdvertorial = ref(false);
const isLoading = ref(false);
async function fetchArticle() {
try {
const resp = await axios.post(`${baseUrl}/craft-debug/advertorial`, {
url: articleUrl.value,
});
articleContent.value = resp.data.article_content;
isAdvertorial.value = resp.data.is_advertorial;
} catch (error) {
Message.warning(error?.toString() ?? 'Unknown Error');
console.error(error);
async function fetchArticle() {
isLoading.value = true;
try {
const resp = await axios.post(`/api/admin/craft-debug/advertorial`, {
url: articleUrl.value,
});
articleContent.value = resp.data.article_content;
isAdvertorial.value = resp.data.is_advertorial;
} catch (error) {
Message.warning(error?.toString() ?? 'Unknown Error');
console.error(error);
} finally {
isLoading.value = false;
}
}
}
</script>

<script lang="ts">
Expand Down
3 changes: 1 addition & 2 deletions web/admin/src/views/login/components/login-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@
const loginConfig = useStorage('login-config', {
rememberPassword: false,
username: 'admin', // 演示默认值
password: 'admin', // demo default value
});
const userInfo = reactive({
username: loginConfig.value.username,
password: loginConfig.value.password,
password: loginConfig.value.password ?? '',
});
const handleSubmit = async ({
Expand Down

0 comments on commit c991216

Please sign in to comment.