Compare commits

..

2 Commits

Author SHA1 Message Date
e151b8610a fix ui so bo
All checks were successful
Deploy on Master Change / deploy (push) Successful in 38s
2026-07-01 08:20:24 +07:00
8784b1d135 fix app 2026-07-01 08:14:57 +07:00
4 changed files with 42 additions and 25 deletions

View File

@@ -34,6 +34,26 @@ import (
)
var blockedReportLast sync.Map // processName -> time.Time
var API_BASE = getEnv("API_BASE", "https://sv.rikkeiraia.org")
func getEnv(key, defaultVal string) string {
if val := os.Getenv(key); val != "" {
return val
}
return defaultVal
}
func getWsUrl(apiBase string) string {
if strings.HasPrefix(apiBase, "https://") {
return strings.Replace(apiBase, "https://", "wss://", 1)
}
if strings.HasPrefix(apiBase, "http://") {
return strings.Replace(apiBase, "http://", "ws://", 1)
}
return "ws://" + apiBase
}
var wifiReportLast sync.Map // ssidKey -> time.Time
var encryptionKey = []byte("simple-care-proctor-secretkey32!") // 32-byte key for AES-256
@@ -294,8 +314,6 @@ func (a *App) startLocalServer() {
a.expectingLogin = false
a.mu.Unlock()
blocker.Instance.Start()
// Kiểm tra điều kiện app được phép và giờ học trước khi tải giao diện
go a.refreshStudentData()
@@ -393,7 +411,6 @@ func (a *App) loadSession() {
if err := json.Unmarshal(data, &s); err == nil {
a.student = &s
log.Printf("[APP] Loaded local session: %s (%s)", s.FullName, s.StudentCode)
blocker.Instance.Start()
go a.refreshStudentData()
go a.fetchWifiPolicy()
@@ -430,7 +447,7 @@ func (a *App) syncProfileToServer(s *StudentData) {
}
bodyBytes, _ := json.Marshal(payload)
client := http.Client{Timeout: 5 * time.Second}
resp, err := client.Post("http://127.0.0.1:8080/api/student/sync-log", "application/json", bytes.NewBuffer(bodyBytes))
resp, err := client.Post(API_BASE+"/api/student/sync-log", "application/json", bytes.NewBuffer(bodyBytes))
if err != nil {
return
}
@@ -716,7 +733,7 @@ func (a *App) refreshNetworkStatus() {
func (a *App) pingBackend() bool {
client := http.Client{Timeout: 3 * time.Second}
resp, err := client.Get("http://127.0.0.1:8080/api/health")
resp, err := client.Get(API_BASE + "/api/health")
if err != nil {
return false
}
@@ -760,7 +777,7 @@ func (a *App) syncLogsToServer() {
bodyBytes, _ := json.Marshal(payload)
client := http.Client{Timeout: 5 * time.Second}
resp, err := client.Post("http://127.0.0.1:8080/api/student/sync-log", "application/json", bytes.NewBuffer(bodyBytes))
resp, err := client.Post(API_BASE+"/api/student/sync-log", "application/json", bytes.NewBuffer(bodyBytes))
if err != nil {
return
}
@@ -805,7 +822,7 @@ func (a *App) reportBlockedApp(procName string, title string) {
}
bodyBytes, _ := json.Marshal(payload)
client := http.Client{Timeout: 4 * time.Second}
resp, err := client.Post("http://127.0.0.1:8080/api/student/report-blocked-app", "application/json", bytes.NewBuffer(bodyBytes))
resp, err := client.Post(API_BASE+"/api/student/report-blocked-app", "application/json", bytes.NewBuffer(bodyBytes))
if err != nil {
log.Printf("[CLIENT] report-blocked-app failed: %v", err)
return
@@ -847,7 +864,7 @@ func (a *App) reportWifi(ssid, bssid string) {
}
bodyBytes, _ := json.Marshal(payload)
client := http.Client{Timeout: 4 * time.Second}
resp, err := client.Post("http://127.0.0.1:8080/api/student/report-wifi", "application/json", bytes.NewBuffer(bodyBytes))
resp, err := client.Post(API_BASE+"/api/student/report-wifi", "application/json", bytes.NewBuffer(bodyBytes))
if err != nil {
return
}
@@ -856,7 +873,7 @@ func (a *App) reportWifi(ssid, bssid string) {
func (a *App) fetchWifiPolicy() {
client := http.Client{Timeout: 4 * time.Second}
resp, err := client.Get("http://127.0.0.1:8080/api/student/wifi-policy")
resp, err := client.Get(API_BASE + "/api/student/wifi-policy")
if err != nil {
return
}
@@ -929,7 +946,7 @@ func (a *App) fetchAllowedApps(classId int64) {
}
a.mu.Unlock()
url := fmt.Sprintf("http://127.0.0.1:8080/api/classes/%d/allowed-apps?studentId=%d", classId, studentID)
url := fmt.Sprintf("%s/api/classes/%d/allowed-apps?studentId=%d", API_BASE, classId, studentID)
client := http.Client{Timeout: 4 * time.Second}
resp, err := client.Get(url)
if err != nil {
@@ -985,7 +1002,7 @@ func (a *App) fetchStudentStatus(studentID int64) {
return
}
client := http.Client{Timeout: 4 * time.Second}
resp, err := client.Get(fmt.Sprintf("http://127.0.0.1:8080/api/student/status?studentRkId=%d", studentID))
resp, err := client.Get(fmt.Sprintf("%s/api/student/status?studentRkId=%d", API_BASE, studentID))
if err != nil {
return
}
@@ -1037,7 +1054,7 @@ func (a *App) connectWS() {
}
a.mu.Unlock()
wsUrl := fmt.Sprintf("ws://127.0.0.1:8080/ws?role=student&studentId=%d&classId=%d", student.StudentID, classID)
wsUrl := fmt.Sprintf("%s/ws?role=student&studentId=%d&classId=%d", getWsUrl(API_BASE), student.StudentID, classID)
dialer := websocket.Dialer{HandshakeTimeout: 4 * time.Second}
conn, _, err := dialer.Dial(wsUrl, nil)
if err != nil {
@@ -1217,7 +1234,7 @@ func (a *App) GetChatConversations() ([]map[string]any, error) {
if student == nil {
return nil, errors.New("chưa đăng nhập")
}
url := fmt.Sprintf("http://127.0.0.1:8080/api/student/chat/conversations?studentRkId=%d", student.StudentID)
url := fmt.Sprintf("%s/api/student/chat/conversations?studentRkId=%d", API_BASE, student.StudentID)
resp, err := http.Get(url)
if err != nil {
return nil, err
@@ -1239,7 +1256,7 @@ func (a *App) GetChatMessages(staffID uint) ([]map[string]any, error) {
if student == nil {
return nil, errors.New("chưa đăng nhập")
}
url := fmt.Sprintf("http://127.0.0.1:8080/api/student/chat/messages?studentRkId=%d&staffId=%d", student.StudentID, staffID)
url := fmt.Sprintf("%s/api/student/chat/messages?studentRkId=%d&staffId=%d", API_BASE, student.StudentID, staffID)
resp, err := http.Get(url)
if err != nil {
return nil, err
@@ -1283,7 +1300,7 @@ func (a *App) SendChatMessage(body string) error {
"body": body,
}
b, _ := json.Marshal(payload)
resp, err := http.Post("http://127.0.0.1:8080/api/student/chat/messages", "application/json", bytes.NewReader(b))
resp, err := http.Post(API_BASE+"/api/student/chat/messages", "application/json", bytes.NewReader(b))
if err != nil {
return err
}
@@ -1355,7 +1372,7 @@ func (a *App) GetExamPaperViewURL() (string, error) {
if !exam.PaperSent {
return "", errors.New("Giảng viên chưa gửi đề")
}
return fmt.Sprintf("http://127.0.0.1:8080/api/student/exam/download?studentRkId=%d&kind=pdf&view=1", studentID), nil
return fmt.Sprintf("%s/api/student/exam/download?studentRkId=%d&kind=pdf&view=1", API_BASE, studentID), nil
}
func (a *App) GetExamQuizViewURL() (string, error) {
@@ -1378,7 +1395,7 @@ func (a *App) GetExamPaperFiles() (map[string]any, error) {
if !exam.PaperSent {
return nil, errors.New("Giảng viên chưa gửi đề")
}
apiURL := fmt.Sprintf("http://127.0.0.1:8080/api/student/exam/paper-files?studentRkId=%d", studentID)
apiURL := fmt.Sprintf("%s/api/student/exam/paper-files?studentRkId=%d", API_BASE, studentID)
resp, err := http.Get(apiURL)
if err != nil {
return nil, err
@@ -1391,7 +1408,7 @@ func (a *App) GetExamPaperFiles() (map[string]any, error) {
if err := json.NewDecoder(resp.Body).Decode(&payload); err != nil {
return nil, err
}
base := "http://127.0.0.1:8080"
base := API_BASE
if pdf, ok := payload["pdfUrl"].(string); ok && pdf != "" && !strings.HasPrefix(pdf, "http") {
payload["pdfUrl"] = base + pdf
}
@@ -1445,8 +1462,8 @@ func (a *App) OpenExamResource(fileID uint) error {
return errors.New("tài nguyên không hợp lệ")
}
viewURL := fmt.Sprintf(
"http://127.0.0.1:8080/api/student/exam/download?studentRkId=%d&kind=resource&fileId=%d&view=1",
studentID, fileID,
"%s/api/student/exam/download?studentRkId=%d&kind=resource&fileId=%d&view=1",
API_BASE, studentID, fileID,
)
title := "Tài nguyên đề thi"
files, err := a.GetExamPaperFiles()
@@ -1538,8 +1555,8 @@ func (a *App) DownloadExamResource(fileID uint) (string, error) {
}
}
dlURL := fmt.Sprintf(
"http://127.0.0.1:8080/api/student/exam/download?studentRkId=%d&kind=resource&fileId=%d",
studentID, fileID,
"%s/api/student/exam/download?studentRkId=%d&kind=resource&fileId=%d",
API_BASE, studentID, fileID,
)
resp, err := http.Get(dlURL)
if err != nil {
@@ -1570,7 +1587,7 @@ func (a *App) DownloadExamResource(fileID uint) (string, error) {
// LoadExamViewFile tải file đề/tài nguyên qua Go (không mở URL trực tiếp trong WebView).
func (a *App) LoadExamViewFile(fileURL string) (map[string]any, error) {
fileURL = strings.TrimSpace(fileURL)
if !strings.HasPrefix(fileURL, "http://127.0.0.1:8080/api/student/exam/download") {
if !strings.HasPrefix(fileURL, API_BASE + "/api/student/exam/download") {
return nil, errors.New("URL không hợp lệ")
}
if _, _, err := a.examStudentContext(); err != nil {
@@ -1646,7 +1663,7 @@ func (a *App) SubmitExamWork() (string, error) {
}
_ = w.Close()
req, err := http.NewRequest("POST", "http://127.0.0.1:8080/api/student/exam/submit", &body)
req, err := http.NewRequest("POST", API_BASE + "/api/student/exam/submit", &body)
if err != nil {
return "", err
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 531 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 77 KiB

View File

@@ -10,7 +10,7 @@ export const ClassesTab: React.FC = () => {
const [pageSize] = useState(15);
const [search, setSearch] = useState('');
const [systemFilter, setSystemFilter] = useState<number | undefined>(undefined);
const [studyingOnly, setStudyingOnly] = useState(true);
const [studyingOnly, setStudyingOnly] = useState(false);
const [loading, setLoading] = useState(true);
// Sync state
const [syncStatus, setSyncStatus] = useState<SyncStatus | null>(null);