refactor: 后端从 Django 换成 Bun + SQLite
Deploy / deploy (build, debian, 22) (push) Canceled after 0s
Deploy / deploy (build:staging, school, 8822) (push) Canceled after 0s

Django 多个 worker 内存占用 1-2 GB,换成 Bun 单进程后约 25 MB,
同时去掉 Postgres 和 Redis,只剩 Caddy + Bun 两个容器。

- server/:Hono + bun:sqlite + Bun 原生 WebSocket,接口与原 django-ninja
  保持兼容;表结构、时间/UUID 存储格式、密码哈希与 Django 一致,旧数据可直接使用
- 评分加权、贝叶斯平滑、成绩册的计算结果与原实现逐位一致(复刻 Python round/sum)
- scripts/:Postgres → SQLite 迁移、新建超管、提示词层级标注、重算分数
- 前端:Django Admin 去掉后,用户新建/修改改为页面内弹窗;
  非超管的挑战公开按钮置灰
- 权限不足返回 JSON 403(原来是重定向到不存在的登录页)
- docker-compose / Caddyfile / dev.sh / CLAUDE.md 更新,删除 AGENTS.md
- 服务器切换步骤见 docs/migrate-to-bun.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-26 17:45:09 +08:00
1 parent 47d4679984
commit 26f05d1d76
297 files changed
+4659 -42956

No files matched your search

-1
View File
@@ -1,4 +1,3 @@
PUBLIC_WEB_URL=http://localhost:8000
PUBLIC_BASE_URL=http://localhost:8000/api
PUBLIC_ADMIN_URL=http://localhost:8000/admin
PUBLIC_MAXKB_URL=https://maxkb.xuyue.cc/chat/api/embed?protocol=https&host=maxkb.xuyue.cc&token=df542e305f27dee6
-1
View File
@@ -1,5 +1,4 @@
PUBLIC_WEB_URL=https://web.xuyue.cc
PUBLIC_ADMIN_URL=https://web.xuyue.cc/admin
PUBLIC_BASE_URL=https://web.xuyue.cc/api
PUBLIC_MAXKB_URL=https://maxkb.xuyue.cc/chat/api/embed?protocol=https&host=maxkb.xuyue.cc&token=df542e305f27dee6
PUBLIC_ICONIFY_URL=https://icon.xuyue.cc
-1
View File
@@ -1,5 +1,4 @@
PUBLIC_WEB_URL=http://10.13.114.114:91
PUBLIC_ADMIN_URL=http://10.13.114.114:91/admin
PUBLIC_BASE_URL=http://10.13.114.114:91/api
PUBLIC_MAXKB_URL=http://10.13.114.114:92/chat/api/embed?protocol=http&host=10.13.114.114:92&token=df542e305f27dee6
PUBLIC_ICONIFY_URL=http://10.13.114.114:8098
+23
View File
@@ -82,6 +82,29 @@ export const Account = {
return res.data
},
async create(payload: {
username: string
password: string
role: string
classname: string
}) {
const res = await http.post("/account/create", payload)
return res.data
},
async update(
id: number,
payload: {
username?: string
password?: string
role?: string
classname?: string
},
) {
const res = await http.put(`/account/${id}`, payload)
return res.data
},
async toggleActive(id: number) {
const res = await http.put(`/account/active/${id}`)
return res.data
@@ -19,13 +19,19 @@
>
解封
</n-button>
<UserFormModal
v-model:show="showEdit"
:user="user"
@saved="emits('reload')"
/>
</n-flex>
</template>
<script lang="ts" setup>
import { ref } from "vue"
import { useMessage } from "naive-ui"
import { Account } from "../../api"
import { ADMIN_URL } from "../../utils/const"
import { Role, type User } from "../../utils/type"
import UserFormModal from "./UserFormModal.vue"
interface Props {
user: User
@@ -35,9 +41,10 @@ const props = defineProps<Props>()
const emits = defineEmits(["reload"])
const message = useMessage()
const showEdit = ref(false)
function edit() {
window.open(`${ADMIN_URL}/account/user/${props.user.id}/change/`)
showEdit.value = true
}
async function toggleUserActive() {
@@ -0,0 +1,95 @@
<template>
<n-modal
style="width: 360px"
:mask-closable="false"
preset="card"
:title="user ? `修改 ${user.username}` : '新建用户'"
:show="show"
@update:show="emit('update:show', $event)"
>
<n-form label-placement="left" label-width="60">
<n-form-item label="用户名">
<n-input v-model:value="form.username" />
</n-form-item>
<n-form-item label="密码">
<n-input
v-model:value="form.password"
:placeholder="user ? '不修改请留空' : '6 到 20 位'"
/>
</n-form-item>
<n-form-item label="权限">
<n-select v-model:value="form.role" :options="roles" />
</n-form-item>
<n-form-item label="班级">
<n-input v-model:value="form.classname" placeholder="可不填" />
</n-form-item>
</n-form>
<n-button
type="primary"
block
:loading="loading"
:disabled="!form.username || (!user && !form.password)"
@click="submit"
>
保存
</n-button>
</n-modal>
</template>
<script lang="ts" setup>
import { reactive, ref, watch } from "vue"
import { useMessage } from "naive-ui"
import { Account } from "../../api"
import { Role, type User } from "../../utils/type"
const props = defineProps<{ show: boolean; user?: User | null }>()
const emit = defineEmits(["update:show", "saved"])
const message = useMessage()
const loading = ref(false)
const form = reactive({
username: "",
password: "",
role: Role.Normal,
classname: "",
})
const roles = [
{ label: "普通用户", value: Role.Normal },
{ label: "管理员", value: Role.Admin },
]
watch(
() => props.show,
(show) => {
if (!show) return
form.username = props.user?.username ?? ""
form.password = ""
form.role = props.user?.role ?? Role.Normal
form.classname = props.user?.classname ?? ""
},
)
async function submit() {
loading.value = true
try {
const data = props.user
? await Account.update(props.user.id, {
username: form.username,
role: form.role,
classname: form.classname,
...(form.password ? { password: form.password } : {}),
})
: await Account.create({ ...form })
message.success(data.message)
emit("update:show", false)
emit("saved")
} catch (err: any) {
const detail = err.response?.data?.detail
message.error(
typeof detail === "string" ? detail : (detail?.[0]?.msg ?? "保存失败"),
)
} finally {
loading.value = false
}
}
</script>
+1 -21
View File
@@ -29,20 +29,13 @@
<script lang="ts" setup>
import { computed, h } from "vue"
import { Icon } from "@iconify/vue"
import {
authed,
roleAdmin,
roleNormal,
roleSuper,
user,
} from "../../store/user"
import { authed, roleAdmin, roleNormal, user } from "../../store/user"
import { loginModal } from "../../store/modal"
import { show, panelSize } from "../../store/panel"
import { taskId } from "../../store/task"
import { Account } from "../../api"
import { Role } from "../../utils/type"
import { router } from "../../router"
import { ADMIN_URL } from "../../utils/const"
const props = defineProps<{
submitLoading: boolean
@@ -64,16 +57,6 @@ const menu = computed(() => [
width: 20,
}),
},
{
label: "数据管理",
key: "admin",
show: roleSuper.value,
icon: () =>
h(Icon, {
icon: "skill-icons:django",
width: 20,
}),
},
{
label: "我的提交",
key: "submissions",
@@ -106,9 +89,6 @@ function clickMenu(name: string) {
router.push({ name: route, params: { display: 0 } })
break
}
case "admin":
window.open(ADMIN_URL)
break
case "submissions":
router.push({
name: "submissions",
-1
View File
@@ -1,7 +1,6 @@
interface ImportMetaEnv {
readonly PUBLIC_WEB_URL: string
readonly PUBLIC_BASE_URL: string
readonly PUBLIC_ADMIN_URL: string
readonly PUBLIC_MAXKB_URL: string
readonly PUBLIC_ICONIFY_URL: string
readonly PUBLIC_WS_URL: string
+22 -7
View File
@@ -17,7 +17,11 @@
>
<template #header>
<n-flex align="center">
<n-button text @click.stop="togglePublic(item.display)">
<n-button
text
:disabled="!roleSuper"
@click.stop="togglePublic(item.display)"
>
<Icon
width="24"
:icon="
@@ -29,7 +33,9 @@
</n-button>
<span>【{{ item.display }}】{{ item.title }}</span>
<n-tag size="small" type="warning">{{ item.score }}分</n-tag>
<n-tag size="small">出题人 {{ item.author_name || "未设置" }}</n-tag>
<n-tag size="small"
>出题人 {{ item.author_name || "未设置" }}</n-tag
>
</n-flex>
</template>
<template #header-extra>
@@ -111,9 +117,15 @@
:autosize="{ minRows: 10, maxRows: 30 }"
/>
<n-flex v-if="splitResult" style="margin-top: 8px">
<n-tag size="small" type="success">HTML · {{ splitResult.html.length }} 字符</n-tag>
<n-tag size="small" type="info">CSS · {{ splitResult.css.length }} 字符</n-tag>
<n-tag size="small" type="warning">JS · {{ splitResult.js.length }} 字符</n-tag>
<n-tag size="small" type="success"
>HTML · {{ splitResult.html.length }} 字符</n-tag
>
<n-tag size="small" type="info"
>CSS · {{ splitResult.css.length }} 字符</n-tag
>
<n-tag size="small" type="warning"
>JS · {{ splitResult.js.length }} 字符</n-tag
>
</n-flex>
</n-modal>
</template>
@@ -122,6 +134,7 @@ import { computed, onMounted, reactive, ref, watch } from "vue"
import { useRoute, useRouter } from "vue-router"
import { Icon } from "@iconify/vue"
import { Challenge } from "../api"
import { roleSuper } from "../store/user"
import type { ChallengeSlim } from "../utils/type"
import { useDialog, useMessage } from "naive-ui"
import MarkdownEditor from "../components/dashboard/MarkdownEditor.vue"
@@ -177,9 +190,11 @@ watch(rawCode, (val) => {
watch(showExampleModal, (visible) => {
if (!visible) return
const parts: string[] = []
if (challenge.example_css) parts.push(`<style>\n${challenge.example_css}\n</style>`)
if (challenge.example_css)
parts.push(`<style>\n${challenge.example_css}\n</style>`)
if (challenge.example_html) parts.push(challenge.example_html)
if (challenge.example_js) parts.push(`<script>\n${challenge.example_js}\n<\/script>`)
if (challenge.example_js)
parts.push(`<script>\n${challenge.example_js}\n<\/script>`)
rawCode.value = parts.join("\n\n")
})
const challenge = reactive({
+9 -7
View File
@@ -15,7 +15,7 @@
:options="roles"
/>
</div>
<n-button @click="goDjangoUserAdd">新建一个</n-button>
<n-button @click="showCreate = true">新建一个</n-button>
<n-button @click="showBatch = true">批量新建</n-button>
<n-pagination
v-model:page="query.page"
@@ -25,6 +25,7 @@
/>
</n-flex>
<n-data-table striped :columns="columns" :data="users"></n-data-table>
<UserFormModal v-model:show="showCreate" @saved="init" />
<n-modal
style="width: 300px"
:mask-closable="false"
@@ -62,8 +63,8 @@ import { Account } from "../api"
import { parseTime } from "../utils/helper"
import { useMessage, type DataTableColumn } from "naive-ui"
import { getRole, Role, type User } from "../utils/type"
import { ADMIN_URL } from "../utils/const"
import UserActions from "../components/dashboard/UserActions.vue"
import UserFormModal from "../components/dashboard/UserFormModal.vue"
import { useRoute, useRouter } from "vue-router"
import { watchDebounced } from "@vueuse/core"
@@ -78,6 +79,7 @@ const query = reactive({
role: "",
})
const showBatch = ref(false)
const showCreate = ref(false)
const classname = ref("")
const namesStr = ref("")
const names = computed(() => namesStr.value.split("\n").filter((it) => !!it))
@@ -113,6 +115,10 @@ const columns: DataTableColumn<User>[] = [
? parseTime(row.last_login, "YYYY-MM-DD HH:mm:ss")
: "从未登录",
},
{
title: "班级",
key: "classname",
},
{
title: "权限",
key: "role",
@@ -125,10 +131,6 @@ const columns: DataTableColumn<User>[] = [
},
]
function goDjangoUserAdd() {
window.open(`${ADMIN_URL}/account/user/add/`)
}
async function batchCreateUsers() {
if (!names.value.length) return
try {
@@ -145,7 +147,7 @@ async function batchCreateUsers() {
init()
} catch (err: any) {
batchLoading.value = false
message.error(err.detail ?? "批量创建失败")
message.error(err.response?.data?.detail ?? "批量创建失败")
}
}
-2
View File
@@ -35,8 +35,6 @@ export const STORAGE_KEY = {
FONTSIZE: "web-fontsize",
}
export const ADMIN_URL = import.meta.env.PUBLIC_ADMIN_URL
export const BASE_URL = import.meta.env.PUBLIC_BASE_URL
export const WS_BASE_URL =
+1
View File
@@ -124,6 +124,7 @@ export interface User {
date_joined: Date
last_login: Date
role: Role
classname: string
is_active: boolean
}