Spaces:
Running
Running
Deploy Upload ThTuanIT Full-stack (Go + Next.js + Python hf_xet + MongoDB)
Browse files- Dockerfile +44 -50
- README.md +101 -3
- auth.go +544 -0
- file_owners.json +73 -0
- frontend/next-env.d.ts +5 -0
- frontend/next.config.mjs +20 -0
- frontend/package-lock.json +1618 -0
- frontend/package.json +25 -0
- frontend/postcss.config.js +6 -0
- frontend/src/app/activity/layout.tsx +14 -0
- frontend/src/app/activity/page.tsx +50 -0
- frontend/src/app/admin/layout.tsx +15 -0
- frontend/src/app/admin/page.tsx +240 -0
- frontend/src/app/dashboard/layout.tsx +14 -0
- frontend/src/app/dashboard/page.tsx +260 -0
- frontend/src/app/developers/layout.tsx +14 -0
- frontend/src/app/developers/page.tsx +95 -0
- frontend/src/app/explorer/layout.tsx +14 -0
- frontend/src/app/explorer/page.tsx +505 -0
- frontend/src/app/globals.css +71 -0
- frontend/src/app/layout.tsx +181 -0
- frontend/src/app/login/layout.tsx +14 -0
- frontend/src/app/login/page.tsx +124 -0
- frontend/src/app/page.tsx +310 -0
- frontend/src/app/register/layout.tsx +14 -0
- frontend/src/app/register/page.tsx +132 -0
- frontend/src/app/robots.ts +12 -0
- frontend/src/app/share/page.tsx +427 -0
- frontend/src/app/sitemap.ts +49 -0
- frontend/src/components/FileInspectorDrawer.tsx +137 -0
- frontend/src/components/GlobalModals.tsx +769 -0
- frontend/src/components/NavbarPublic.tsx +84 -0
- frontend/src/components/WorkspaceShell.tsx +463 -0
- frontend/src/context/CloudContext.tsx +889 -0
- frontend/src/lib/api.ts +76 -0
- frontend/src/types/cloud.ts +91 -0
- frontend/tailwind.config.ts +23 -0
- frontend/tsconfig.json +26 -0
- go.mod +18 -0
- go.sum +50 -0
- hf_worker.go +223 -0
- main.go +1225 -0
- main_test.go +150 -0
- mongo.go +247 -0
- ownership.go +299 -0
- share.go +373 -0
- shares.json +14 -0
- start.sh +8 -5
- users.json +44 -0
- web/index.html +1266 -0
Dockerfile
CHANGED
|
@@ -1,50 +1,44 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# Kiểm tra các thành phần đã cài đặt
|
| 47 |
-
RUN go version && yt-dlp --version
|
| 48 |
-
|
| 49 |
-
EXPOSE 3001
|
| 50 |
-
CMD ["/start.sh"]
|
|
|
|
| 1 |
+
FROM golang:1.23-bookworm AS go-build
|
| 2 |
+
WORKDIR /src
|
| 3 |
+
COPY go.mod go.sum ./
|
| 4 |
+
RUN go mod download
|
| 5 |
+
COPY *.go ./
|
| 6 |
+
COPY web ./web
|
| 7 |
+
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/server .
|
| 8 |
+
|
| 9 |
+
FROM node:20-bookworm-slim AS fe-build
|
| 10 |
+
WORKDIR /frontend
|
| 11 |
+
COPY frontend/package*.json ./
|
| 12 |
+
RUN npm install --no-audit --no-fund
|
| 13 |
+
COPY frontend/ ./
|
| 14 |
+
RUN npm run build
|
| 15 |
+
|
| 16 |
+
FROM python:3.12-slim-bookworm
|
| 17 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 18 |
+
PIP_NO_CACHE_DIR=1 \
|
| 19 |
+
NODE_ENV=production \
|
| 20 |
+
LISTEN_ADDR=:7860 \
|
| 21 |
+
FRONTEND_URL=http://127.0.0.1:3000 \
|
| 22 |
+
TEMP_DIR=/tmp/hf-upload
|
| 23 |
+
|
| 24 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 25 |
+
ca-certificates \
|
| 26 |
+
libstdc++6 \
|
| 27 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 28 |
+
&& pip install --no-cache-dir -U huggingface_hub hf_xet \
|
| 29 |
+
&& useradd --create-home --uid 1000 app
|
| 30 |
+
|
| 31 |
+
COPY --from=fe-build /usr/local/bin/node /usr/local/bin/node
|
| 32 |
+
WORKDIR /app
|
| 33 |
+
COPY --from=go-build /out/server /app/server
|
| 34 |
+
COPY --from=fe-build /frontend/.next/standalone /app/frontend
|
| 35 |
+
COPY --from=fe-build /frontend/.next/static /app/frontend/.next/static
|
| 36 |
+
COPY users.json file_owners.json shares.json /app/
|
| 37 |
+
COPY start.sh /app/start.sh
|
| 38 |
+
|
| 39 |
+
RUN sed -i 's/\r$//' /app/start.sh && chmod +x /app/start.sh \
|
| 40 |
+
&& mkdir -p /tmp/hf-upload && chown -R app:app /app /tmp/hf-upload
|
| 41 |
+
|
| 42 |
+
USER app
|
| 43 |
+
EXPOSE 7860
|
| 44 |
+
CMD ["/app/start.sh"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -1,11 +1,109 @@
|
|
| 1 |
---
|
| 2 |
-
title: Upload
|
| 3 |
emoji: 🔥
|
| 4 |
colorFrom: pink
|
| 5 |
colorTo: purple
|
| 6 |
sdk: docker
|
| 7 |
pinned: true
|
| 8 |
-
app_port:
|
| 9 |
---
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Upload ThTuanIT
|
| 3 |
emoji: 🔥
|
| 4 |
colorFrom: pink
|
| 5 |
colorTo: purple
|
| 6 |
sdk: docker
|
| 7 |
pinned: true
|
| 8 |
+
app_port: 7860
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Hugging Face Bucket Go API & Upload ThTuanIT Cloud
|
| 12 |
+
|
| 13 |
+
REST API viết bằng Go cho bucket `Shshshzhzhs/1222`. Go xử lý HTTP/API; việc truyền dữ liệu Xet được thực hiện qua Hugging Face CLI (`hf`) để dùng đúng giao thức Xet chính thức.
|
| 14 |
+
|
| 15 |
+
## API
|
| 16 |
+
|
| 17 |
+
- `GET /health` — kiểm tra server và lệnh `hf`.
|
| 18 |
+
- `POST /api/upload` — multipart form, field `file`; field `path` tùy chọn để đặt đường dẫn đích.
|
| 19 |
+
- `GET /api/files?prefix=folder` — liệt kê nội dung bucket hoặc prefix.
|
| 20 |
+
- `GET /api/download?path=folder/file.ext` — tải file về.
|
| 21 |
+
|
| 22 |
+
Các API ngoài `/health` yêu cầu `X-API-Key: <API_KEY>` hoặc `Authorization: Bearer <API_KEY>`.
|
| 23 |
+
|
| 24 |
+
## Chạy trực tiếp
|
| 25 |
+
|
| 26 |
+
Yêu cầu Go 1.22+ và Python 3.10+.
|
| 27 |
+
|
| 28 |
+
```bash
|
| 29 |
+
python -m pip install -U huggingface_hub hf_xet
|
| 30 |
+
hf --version
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
Linux/macOS:
|
| 34 |
+
|
| 35 |
+
```bash
|
| 36 |
+
export HF_TOKEN='hf_...'
|
| 37 |
+
export API_KEY='a-long-random-private-key'
|
| 38 |
+
export LISTEN_ADDR=':8080'
|
| 39 |
+
go run .
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Windows PowerShell:
|
| 43 |
+
|
| 44 |
+
```powershell
|
| 45 |
+
$env:HF_TOKEN="hf_..."
|
| 46 |
+
$env:API_KEY="a-long-random-private-key"
|
| 47 |
+
$env:LISTEN_ADDR=":8080"
|
| 48 |
+
go run .
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Token cần quyền ghi bucket. Không dùng token/session token trích từ HAR; hãy tạo User Access Token riêng trong Hugging Face Settings.
|
| 52 |
+
|
| 53 |
+
## Kiểm thử
|
| 54 |
+
|
| 55 |
+
Health:
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
curl http://localhost:8080/health
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
Upload:
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
curl -X POST http://localhost:8080/api/upload \
|
| 65 |
+
-H 'X-API-Key: a-long-random-private-key' \
|
| 66 |
+
-F 'file=@./hello.txt' \
|
| 67 |
+
-F 'path=tests/hello.txt'
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
List:
|
| 71 |
+
|
| 72 |
+
```bash
|
| 73 |
+
curl 'http://localhost:8080/api/files?prefix=tests' \
|
| 74 |
+
-H 'X-API-Key: a-long-random-private-key'
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
Download:
|
| 78 |
+
|
| 79 |
+
```bash
|
| 80 |
+
curl 'http://localhost:8080/api/download?path=tests/hello.txt' \
|
| 81 |
+
-H 'X-API-Key: a-long-random-private-key' \
|
| 82 |
+
-o hello-downloaded.txt
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
Windows PowerShell upload:
|
| 86 |
+
|
| 87 |
+
```powershell
|
| 88 |
+
curl.exe -X POST http://localhost:8080/api/upload `
|
| 89 |
+
-H "X-API-Key: a-long-random-private-key" `
|
| 90 |
+
-F "file=@hello.txt" `
|
| 91 |
+
-F "path=tests/hello.txt"
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
## Docker
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
docker build -t hf-bucket-go .
|
| 98 |
+
docker run --rm -p 8080:8080 \
|
| 99 |
+
-e HF_TOKEN='hf_...' \
|
| 100 |
+
-e API_KEY='a-long-random-private-key' \
|
| 101 |
+
hf-bucket-go
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
## Notes
|
| 105 |
+
|
| 106 |
+
- Bucket ID được cố định trong `main.go` là `Shshshzhzhs/1222`.
|
| 107 |
+
- `GET /api/files` trả cả `entries` dạng dòng và `raw` nguyên văn từ CLI; định dạng hiển thị có thể thay đổi theo phiên bản CLI.
|
| 108 |
+
- Upload API nhận một file mỗi request. Có thể gửi nhiều request đồng thời; không có endpoint xóa file trong bản này.
|
| 109 |
+
- Đặt API sau HTTPS/reverse proxy khi triển khai công khai. Không ghi log hoặc trả `HF_TOKEN` cho client.
|
auth.go
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"crypto/hmac"
|
| 5 |
+
"crypto/rand"
|
| 6 |
+
"crypto/sha256"
|
| 7 |
+
"crypto/subtle"
|
| 8 |
+
"encoding/base64"
|
| 9 |
+
"encoding/hex"
|
| 10 |
+
"encoding/json"
|
| 11 |
+
"errors"
|
| 12 |
+
"net/http"
|
| 13 |
+
"os"
|
| 14 |
+
"strings"
|
| 15 |
+
"sync"
|
| 16 |
+
"time"
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
type PermissionSet struct {
|
| 20 |
+
CanUpload bool `json:"can_upload" bson:"can_upload"`
|
| 21 |
+
CanDelete bool `json:"can_delete" bson:"can_delete"`
|
| 22 |
+
CanRename bool `json:"can_rename" bson:"can_rename"`
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
type UserAccount struct {
|
| 26 |
+
Username string `json:"username" bson:"username"`
|
| 27 |
+
DisplayName string `json:"display_name" bson:"display_name"`
|
| 28 |
+
Role string `json:"role" bson:"role"` // "admin" | "user"
|
| 29 |
+
PasswordSalt string `json:"password_salt,omitempty" bson:"password_salt"`
|
| 30 |
+
PasswordHash string `json:"password_hash,omitempty" bson:"password_hash"`
|
| 31 |
+
Permissions PermissionSet `json:"permissions" bson:"permissions"`
|
| 32 |
+
Active bool `json:"active" bson:"active"`
|
| 33 |
+
CreatedAt string `json:"created_at" bson:"created_at"`
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
type PublicUser struct {
|
| 37 |
+
Username string `json:"username"`
|
| 38 |
+
DisplayName string `json:"display_name"`
|
| 39 |
+
Role string `json:"role"`
|
| 40 |
+
Permissions PermissionSet `json:"permissions"`
|
| 41 |
+
Active bool `json:"active"`
|
| 42 |
+
CreatedAt string `json:"created_at"`
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
func (u UserAccount) Public() PublicUser {
|
| 46 |
+
return PublicUser{
|
| 47 |
+
Username: u.Username,
|
| 48 |
+
DisplayName: u.DisplayName,
|
| 49 |
+
Role: u.Role,
|
| 50 |
+
Permissions: u.Permissions,
|
| 51 |
+
Active: u.Active,
|
| 52 |
+
CreatedAt: u.CreatedAt,
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
type UserStore struct {
|
| 57 |
+
mu sync.RWMutex
|
| 58 |
+
path string
|
| 59 |
+
secret []byte
|
| 60 |
+
users map[string]UserAccount
|
| 61 |
+
mongo *MongoStore
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
func (s *UserStore) AttachMongo(m *MongoStore) {
|
| 65 |
+
if m == nil {
|
| 66 |
+
return
|
| 67 |
+
}
|
| 68 |
+
s.mu.Lock()
|
| 69 |
+
defer s.mu.Unlock()
|
| 70 |
+
s.mongo = m
|
| 71 |
+
|
| 72 |
+
dbUsers, err := m.LoadAllUsers()
|
| 73 |
+
if err == nil {
|
| 74 |
+
inMongo := make(map[string]bool)
|
| 75 |
+
for _, u := range dbUsers {
|
| 76 |
+
key := strings.ToLower(strings.TrimSpace(u.Username))
|
| 77 |
+
if key != "" {
|
| 78 |
+
s.users[key] = u
|
| 79 |
+
inMongo[key] = true
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
// Migrate any local users not yet in MongoDB
|
| 83 |
+
for key, u := range s.users {
|
| 84 |
+
if !inMongo[key] {
|
| 85 |
+
_ = m.UpsertUserDoc(u)
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
_ = s.saveLocked()
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
func NewUserStore(filePath, secretKey string) (*UserStore, error) {
|
| 93 |
+
s := &UserStore{
|
| 94 |
+
path: filePath,
|
| 95 |
+
secret: []byte(secretKey),
|
| 96 |
+
users: make(map[string]UserAccount),
|
| 97 |
+
}
|
| 98 |
+
if err := s.load(); err != nil {
|
| 99 |
+
return nil, err
|
| 100 |
+
}
|
| 101 |
+
return s, nil
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
func hashPassword(password, salt string) string {
|
| 105 |
+
h := sha256.New()
|
| 106 |
+
h.Write([]byte(salt + ":" + password))
|
| 107 |
+
return hex.EncodeToString(h.Sum(nil))
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
func randomHex(n int) string {
|
| 111 |
+
b := make([]byte, n)
|
| 112 |
+
_, _ = rand.Read(b)
|
| 113 |
+
return hex.EncodeToString(b)
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
func (s *UserStore) load() error {
|
| 117 |
+
s.mu.Lock()
|
| 118 |
+
defer s.mu.Unlock()
|
| 119 |
+
|
| 120 |
+
data, err := os.ReadFile(s.path)
|
| 121 |
+
if err != nil {
|
| 122 |
+
if !errors.Is(err, os.ErrNotExist) {
|
| 123 |
+
return err
|
| 124 |
+
}
|
| 125 |
+
// Seed default admin ("admin" / "admin") and demo user ("user" / "user123")
|
| 126 |
+
now := time.Now().Format("2006-01-02 15:04:05")
|
| 127 |
+
adminSalt := randomHex(16)
|
| 128 |
+
userSalt := randomHex(16)
|
| 129 |
+
s.users["admin"] = UserAccount{
|
| 130 |
+
Username: "admin",
|
| 131 |
+
DisplayName: "Administrator",
|
| 132 |
+
Role: "admin",
|
| 133 |
+
PasswordSalt: adminSalt,
|
| 134 |
+
PasswordHash: hashPassword("admin", adminSalt),
|
| 135 |
+
Permissions: PermissionSet{
|
| 136 |
+
CanUpload: true,
|
| 137 |
+
CanDelete: true,
|
| 138 |
+
CanRename: true,
|
| 139 |
+
},
|
| 140 |
+
Active: true,
|
| 141 |
+
CreatedAt: now,
|
| 142 |
+
}
|
| 143 |
+
s.users["user"] = UserAccount{
|
| 144 |
+
Username: "user",
|
| 145 |
+
DisplayName: "Khách hàng / User",
|
| 146 |
+
Role: "user",
|
| 147 |
+
PasswordSalt: userSalt,
|
| 148 |
+
PasswordHash: hashPassword("user123", userSalt),
|
| 149 |
+
Permissions: PermissionSet{
|
| 150 |
+
CanUpload: true,
|
| 151 |
+
CanDelete: false,
|
| 152 |
+
CanRename: false,
|
| 153 |
+
},
|
| 154 |
+
Active: true,
|
| 155 |
+
CreatedAt: now,
|
| 156 |
+
}
|
| 157 |
+
return s.saveLocked()
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
var list []UserAccount
|
| 161 |
+
if err := json.Unmarshal(data, &list); err != nil {
|
| 162 |
+
return err
|
| 163 |
+
}
|
| 164 |
+
for _, u := range list {
|
| 165 |
+
s.users[strings.ToLower(u.Username)] = u
|
| 166 |
+
}
|
| 167 |
+
return nil
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
func (s *UserStore) saveLocked() error {
|
| 171 |
+
list := make([]UserAccount, 0, len(s.users))
|
| 172 |
+
for _, u := range s.users {
|
| 173 |
+
list = append(list, u)
|
| 174 |
+
}
|
| 175 |
+
data, err := json.MarshalIndent(list, "", " ")
|
| 176 |
+
if err != nil {
|
| 177 |
+
return err
|
| 178 |
+
}
|
| 179 |
+
return os.WriteFile(s.path, data, 0600)
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
func (s *UserStore) Authenticate(username, password string) (UserAccount, bool) {
|
| 183 |
+
s.mu.RLock()
|
| 184 |
+
defer s.mu.RUnlock()
|
| 185 |
+
u, ok := s.users[strings.ToLower(strings.TrimSpace(username))]
|
| 186 |
+
if !ok || !u.Active {
|
| 187 |
+
return UserAccount{}, false
|
| 188 |
+
}
|
| 189 |
+
expected := hashPassword(password, u.PasswordSalt)
|
| 190 |
+
if subtle.ConstantTimeCompare([]byte(expected), []byte(u.PasswordHash)) != 1 {
|
| 191 |
+
return UserAccount{}, false
|
| 192 |
+
}
|
| 193 |
+
return u, true
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
func (s *UserStore) Get(username string) (UserAccount, bool) {
|
| 197 |
+
s.mu.RLock()
|
| 198 |
+
defer s.mu.RUnlock()
|
| 199 |
+
u, ok := s.users[strings.ToLower(strings.TrimSpace(username))]
|
| 200 |
+
return u, ok
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
func (s *UserStore) List() []PublicUser {
|
| 204 |
+
s.mu.RLock()
|
| 205 |
+
defer s.mu.RUnlock()
|
| 206 |
+
out := make([]PublicUser, 0, len(s.users))
|
| 207 |
+
for _, u := range s.users {
|
| 208 |
+
out = append(out, u.Public())
|
| 209 |
+
}
|
| 210 |
+
return out
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
func (s *UserStore) UpsertUser(username, displayName, role, password string, perms PermissionSet, active bool) (PublicUser, error) {
|
| 214 |
+
s.mu.Lock()
|
| 215 |
+
defer s.mu.Unlock()
|
| 216 |
+
|
| 217 |
+
key := strings.ToLower(strings.TrimSpace(username))
|
| 218 |
+
if key == "" {
|
| 219 |
+
return PublicUser{}, errors.New("username is required")
|
| 220 |
+
}
|
| 221 |
+
if role != "admin" && role != "user" {
|
| 222 |
+
role = "user"
|
| 223 |
+
}
|
| 224 |
+
if role == "admin" {
|
| 225 |
+
perms = PermissionSet{CanUpload: true, CanDelete: true, CanRename: true}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
existing, exists := s.users[key]
|
| 229 |
+
if !exists {
|
| 230 |
+
if strings.TrimSpace(password) == "" {
|
| 231 |
+
return PublicUser{}, errors.New("password is required for new user")
|
| 232 |
+
}
|
| 233 |
+
salt := randomHex(16)
|
| 234 |
+
existing = UserAccount{
|
| 235 |
+
Username: strings.TrimSpace(username),
|
| 236 |
+
DisplayName: strings.TrimSpace(displayName),
|
| 237 |
+
Role: role,
|
| 238 |
+
PasswordSalt: salt,
|
| 239 |
+
PasswordHash: hashPassword(password, salt),
|
| 240 |
+
Permissions: perms,
|
| 241 |
+
Active: active,
|
| 242 |
+
CreatedAt: time.Now().Format("2006-01-02 15:04:05"),
|
| 243 |
+
}
|
| 244 |
+
if existing.DisplayName == "" {
|
| 245 |
+
existing.DisplayName = existing.Username
|
| 246 |
+
}
|
| 247 |
+
} else {
|
| 248 |
+
if displayName != "" {
|
| 249 |
+
existing.DisplayName = strings.TrimSpace(displayName)
|
| 250 |
+
}
|
| 251 |
+
existing.Role = role
|
| 252 |
+
existing.Permissions = perms
|
| 253 |
+
existing.Active = active
|
| 254 |
+
if strings.TrimSpace(password) != "" {
|
| 255 |
+
salt := randomHex(16)
|
| 256 |
+
existing.PasswordSalt = salt
|
| 257 |
+
existing.PasswordHash = hashPassword(password, salt)
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
s.users[key] = existing
|
| 262 |
+
if s.mongo != nil {
|
| 263 |
+
if err := s.mongo.UpsertUserDoc(existing); err != nil {
|
| 264 |
+
return PublicUser{}, err
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
if err := s.saveLocked(); err != nil {
|
| 268 |
+
return PublicUser{}, err
|
| 269 |
+
}
|
| 270 |
+
return existing.Public(), nil
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
func (s *UserStore) DeleteUser(username string) error {
|
| 274 |
+
s.mu.Lock()
|
| 275 |
+
defer s.mu.Unlock()
|
| 276 |
+
key := strings.ToLower(strings.TrimSpace(username))
|
| 277 |
+
if key == "admin" {
|
| 278 |
+
return errors.New("không thể xóa tài khoản admin gốc")
|
| 279 |
+
}
|
| 280 |
+
if _, ok := s.users[key]; !ok {
|
| 281 |
+
return errors.New("không tìm thấy tài khoản")
|
| 282 |
+
}
|
| 283 |
+
delete(s.users, key)
|
| 284 |
+
if s.mongo != nil {
|
| 285 |
+
if err := s.mongo.DeleteUserDoc(key); err != nil {
|
| 286 |
+
return err
|
| 287 |
+
}
|
| 288 |
+
}
|
| 289 |
+
return s.saveLocked()
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
// --- Stateless HMAC Token ---
|
| 293 |
+
|
| 294 |
+
type tokenPayload struct {
|
| 295 |
+
Username string `json:"u"`
|
| 296 |
+
Exp int64 `json:"e"`
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
func (s *UserStore) IssueToken(username string, ttl time.Duration) (string, error) {
|
| 300 |
+
payload := tokenPayload{
|
| 301 |
+
Username: strings.ToLower(strings.TrimSpace(username)),
|
| 302 |
+
Exp: time.Now().Add(ttl).Unix(),
|
| 303 |
+
}
|
| 304 |
+
b, err := json.Marshal(payload)
|
| 305 |
+
if err != nil {
|
| 306 |
+
return "", err
|
| 307 |
+
}
|
| 308 |
+
p64 := base64.RawURLEncoding.EncodeToString(b)
|
| 309 |
+
mac := hmac.New(sha256.New, s.secret)
|
| 310 |
+
mac.Write([]byte(p64))
|
| 311 |
+
sig := base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
|
| 312 |
+
return p64 + "." + sig, nil
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
func (s *UserStore) VerifyToken(token string) (UserAccount, bool) {
|
| 316 |
+
parts := strings.Split(token, ".")
|
| 317 |
+
if len(parts) != 2 {
|
| 318 |
+
return UserAccount{}, false
|
| 319 |
+
}
|
| 320 |
+
mac := hmac.New(sha256.New, s.secret)
|
| 321 |
+
mac.Write([]byte(parts[0]))
|
| 322 |
+
expectedSig := base64.RawURLEncoding.EncodeToString(mac.Sum(nil))
|
| 323 |
+
if subtle.ConstantTimeCompare([]byte(parts[1]), []byte(expectedSig)) != 1 {
|
| 324 |
+
return UserAccount{}, false
|
| 325 |
+
}
|
| 326 |
+
raw, err := base64.RawURLEncoding.DecodeString(parts[0])
|
| 327 |
+
if err != nil {
|
| 328 |
+
return UserAccount{}, false
|
| 329 |
+
}
|
| 330 |
+
var p tokenPayload
|
| 331 |
+
if err := json.Unmarshal(raw, &p); err != nil {
|
| 332 |
+
return UserAccount{}, false
|
| 333 |
+
}
|
| 334 |
+
if time.Now().Unix() > p.Exp {
|
| 335 |
+
return UserAccount{}, false
|
| 336 |
+
}
|
| 337 |
+
u, ok := s.Get(p.Username)
|
| 338 |
+
if !ok || !u.Active {
|
| 339 |
+
return UserAccount{}, false
|
| 340 |
+
}
|
| 341 |
+
return u, true
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
// --- HTTP Handlers for Auth & User Management ---
|
| 345 |
+
|
| 346 |
+
func (a *App) resolveRequestUser(r *http.Request) (UserAccount, bool) {
|
| 347 |
+
// 1. Check API Key (legacy / CLI / admin root key)
|
| 348 |
+
providedKey := r.Header.Get("X-API-Key")
|
| 349 |
+
if providedKey == "" {
|
| 350 |
+
providedKey = r.URL.Query().Get("api_key")
|
| 351 |
+
}
|
| 352 |
+
if len(providedKey) == len(a.cfg.APIKey) && subtle.ConstantTimeCompare([]byte(providedKey), []byte(a.cfg.APIKey)) == 1 {
|
| 353 |
+
if u, ok := a.users.Get("admin"); ok {
|
| 354 |
+
return u, true
|
| 355 |
+
}
|
| 356 |
+
return UserAccount{
|
| 357 |
+
Username: "admin",
|
| 358 |
+
DisplayName: "API Key Admin",
|
| 359 |
+
Role: "admin",
|
| 360 |
+
Permissions: PermissionSet{CanUpload: true, CanDelete: true, CanRename: true},
|
| 361 |
+
Active: true,
|
| 362 |
+
}, true
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
// 2. Check Bearer token or query token or cookie
|
| 366 |
+
token := ""
|
| 367 |
+
if authHeader := r.Header.Get("Authorization"); strings.HasPrefix(authHeader, "Bearer ") {
|
| 368 |
+
token = strings.TrimPrefix(authHeader, "Bearer ")
|
| 369 |
+
}
|
| 370 |
+
if token == "" {
|
| 371 |
+
token = r.URL.Query().Get("token")
|
| 372 |
+
}
|
| 373 |
+
if token == "" {
|
| 374 |
+
if c, err := r.Cookie("hf_session"); err == nil {
|
| 375 |
+
token = c.Value
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
if token == "" {
|
| 379 |
+
return UserAccount{}, false
|
| 380 |
+
}
|
| 381 |
+
// Allow Bearer <API_KEY> as well
|
| 382 |
+
if len(token) == len(a.cfg.APIKey) && subtle.ConstantTimeCompare([]byte(token), []byte(a.cfg.APIKey)) == 1 {
|
| 383 |
+
if u, ok := a.users.Get("admin"); ok {
|
| 384 |
+
return u, true
|
| 385 |
+
}
|
| 386 |
+
}
|
| 387 |
+
return a.users.VerifyToken(token)
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
func (a *App) handleLogin(w http.ResponseWriter, r *http.Request) {
|
| 391 |
+
var body struct {
|
| 392 |
+
Username string `json:"username"`
|
| 393 |
+
Password string `json:"password"`
|
| 394 |
+
}
|
| 395 |
+
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
| 396 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_json", Detail: err.Error()})
|
| 397 |
+
return
|
| 398 |
+
}
|
| 399 |
+
u, ok := a.users.Authenticate(body.Username, body.Password)
|
| 400 |
+
if !ok {
|
| 401 |
+
writeJSON(w, http.StatusUnauthorized, APIError{Error: "invalid_credentials", Detail: "Sai tài khoản, mật khẩu hoặc tài khoản đã bị khóa"})
|
| 402 |
+
return
|
| 403 |
+
}
|
| 404 |
+
token, err := a.users.IssueToken(u.Username, 7*24*time.Hour)
|
| 405 |
+
if err != nil {
|
| 406 |
+
writeJSON(w, http.StatusInternalServerError, APIError{Error: "token_error", Detail: err.Error()})
|
| 407 |
+
return
|
| 408 |
+
}
|
| 409 |
+
http.SetCookie(w, &http.Cookie{
|
| 410 |
+
Name: "hf_session",
|
| 411 |
+
Value: token,
|
| 412 |
+
Path: "/",
|
| 413 |
+
HttpOnly: true,
|
| 414 |
+
SameSite: http.SameSiteLaxMode,
|
| 415 |
+
MaxAge: 7 * 24 * 3600,
|
| 416 |
+
})
|
| 417 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 418 |
+
"ok": true,
|
| 419 |
+
"token": token,
|
| 420 |
+
"user": u.Public(),
|
| 421 |
+
})
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
func (a *App) handleRegister(w http.ResponseWriter, r *http.Request) {
|
| 425 |
+
var body struct {
|
| 426 |
+
Username string `json:"username"`
|
| 427 |
+
DisplayName string `json:"display_name"`
|
| 428 |
+
Password string `json:"password"`
|
| 429 |
+
}
|
| 430 |
+
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
| 431 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_json", Detail: err.Error()})
|
| 432 |
+
return
|
| 433 |
+
}
|
| 434 |
+
username := strings.TrimSpace(body.Username)
|
| 435 |
+
if len(username) < 3 || len(body.Password) < 4 {
|
| 436 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "weak_input", Detail: "Tên đăng nhập tối thiểu 3 ký tự, mật khẩu tối thiểu 4 ký tự"})
|
| 437 |
+
return
|
| 438 |
+
}
|
| 439 |
+
if _, exists := a.users.Get(username); exists {
|
| 440 |
+
writeJSON(w, http.StatusConflict, APIError{Error: "user_exists", Detail: "Tên tài khoản này đã tồn tại"})
|
| 441 |
+
return
|
| 442 |
+
}
|
| 443 |
+
pub, err := a.users.UpsertUser(username, body.DisplayName, "user", body.Password, PermissionSet{
|
| 444 |
+
CanUpload: true,
|
| 445 |
+
CanDelete: false,
|
| 446 |
+
CanRename: false,
|
| 447 |
+
}, true)
|
| 448 |
+
if err != nil {
|
| 449 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "register_failed", Detail: err.Error()})
|
| 450 |
+
return
|
| 451 |
+
}
|
| 452 |
+
token, _ := a.users.IssueToken(pub.Username, 7*24*time.Hour)
|
| 453 |
+
http.SetCookie(w, &http.Cookie{
|
| 454 |
+
Name: "hf_session",
|
| 455 |
+
Value: token,
|
| 456 |
+
Path: "/",
|
| 457 |
+
HttpOnly: true,
|
| 458 |
+
SameSite: http.SameSiteLaxMode,
|
| 459 |
+
MaxAge: 7 * 24 * 3600,
|
| 460 |
+
})
|
| 461 |
+
writeJSON(w, http.StatusCreated, map[string]any{
|
| 462 |
+
"ok": true,
|
| 463 |
+
"token": token,
|
| 464 |
+
"user": pub,
|
| 465 |
+
})
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
func (a *App) handleLogout(w http.ResponseWriter, r *http.Request) {
|
| 469 |
+
http.SetCookie(w, &http.Cookie{
|
| 470 |
+
Name: "hf_session",
|
| 471 |
+
Value: "",
|
| 472 |
+
Path: "/",
|
| 473 |
+
HttpOnly: true,
|
| 474 |
+
MaxAge: -1,
|
| 475 |
+
})
|
| 476 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true})
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
func (a *App) handleMe(w http.ResponseWriter, r *http.Request) {
|
| 480 |
+
u, ok := a.resolveRequestUser(r)
|
| 481 |
+
if !ok {
|
| 482 |
+
writeJSON(w, http.StatusUnauthorized, APIError{Error: "unauthorized", Detail: "Vui lòng đăng nhập"})
|
| 483 |
+
return
|
| 484 |
+
}
|
| 485 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 486 |
+
"ok": true,
|
| 487 |
+
"user": u.Public(),
|
| 488 |
+
})
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
func (a *App) handleAdminListUsers(w http.ResponseWriter, r *http.Request) {
|
| 492 |
+
u, ok := a.resolveRequestUser(r)
|
| 493 |
+
if !ok || u.Role != "admin" {
|
| 494 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Chỉ Admin mới có quyền quản lý người dùng"})
|
| 495 |
+
return
|
| 496 |
+
}
|
| 497 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 498 |
+
"ok": true,
|
| 499 |
+
"users": a.users.List(),
|
| 500 |
+
})
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
func (a *App) handleAdminSaveUser(w http.ResponseWriter, r *http.Request) {
|
| 504 |
+
u, ok := a.resolveRequestUser(r)
|
| 505 |
+
if !ok || u.Role != "admin" {
|
| 506 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Chỉ Admin mới có quyền chỉnh sửa người dùng"})
|
| 507 |
+
return
|
| 508 |
+
}
|
| 509 |
+
var body struct {
|
| 510 |
+
Username string `json:"username"`
|
| 511 |
+
DisplayName string `json:"display_name"`
|
| 512 |
+
Role string `json:"role"`
|
| 513 |
+
Password string `json:"password"`
|
| 514 |
+
Permissions PermissionSet `json:"permissions"`
|
| 515 |
+
Active bool `json:"active"`
|
| 516 |
+
}
|
| 517 |
+
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
| 518 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_json", Detail: err.Error()})
|
| 519 |
+
return
|
| 520 |
+
}
|
| 521 |
+
saved, err := a.users.UpsertUser(body.Username, body.DisplayName, body.Role, body.Password, body.Permissions, body.Active)
|
| 522 |
+
if err != nil {
|
| 523 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "save_user_failed", Detail: err.Error()})
|
| 524 |
+
return
|
| 525 |
+
}
|
| 526 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 527 |
+
"ok": true,
|
| 528 |
+
"user": saved,
|
| 529 |
+
})
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
func (a *App) handleAdminDeleteUser(w http.ResponseWriter, r *http.Request) {
|
| 533 |
+
u, ok := a.resolveRequestUser(r)
|
| 534 |
+
if !ok || u.Role != "admin" {
|
| 535 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Chỉ Admin mới có quyền xóa người dùng"})
|
| 536 |
+
return
|
| 537 |
+
}
|
| 538 |
+
username := r.URL.Query().Get("username")
|
| 539 |
+
if err := a.users.DeleteUser(username); err != nil {
|
| 540 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "delete_user_failed", Detail: err.Error()})
|
| 541 |
+
return
|
| 542 |
+
}
|
| 543 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "username": username})
|
| 544 |
+
}
|
file_owners.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"111.mp4": [
|
| 3 |
+
"admin"
|
| 4 |
+
],
|
| 5 |
+
"22.mp4": [
|
| 6 |
+
"admin"
|
| 7 |
+
],
|
| 8 |
+
"BEupload-main.zip": [
|
| 9 |
+
"admin"
|
| 10 |
+
],
|
| 11 |
+
"ChienTuyenHuongDuong_12.2_MOD_3PRO.apk": [
|
| 12 |
+
"admin"
|
| 13 |
+
],
|
| 14 |
+
"LegacyLauncher.exe": [
|
| 15 |
+
"user",
|
| 16 |
+
"admin"
|
| 17 |
+
],
|
| 18 |
+
"LegacyLauncher_installer_torrent.torrent": [
|
| 19 |
+
"user",
|
| 20 |
+
"admin"
|
| 21 |
+
],
|
| 22 |
+
"Nhom_Phan_tich_bo_may_to_chuc_Foxconn.pptx": [
|
| 23 |
+
"user",
|
| 24 |
+
"admin"
|
| 25 |
+
],
|
| 26 |
+
"Phan_tich_bo_may_to_chuc_Foxconn_EPU.pptx": [
|
| 27 |
+
"user",
|
| 28 |
+
"admin"
|
| 29 |
+
],
|
| 30 |
+
"Phan_tich_bo_may_to_chuc_Foxconn_EPU_Dep.pptx": [
|
| 31 |
+
"user",
|
| 32 |
+
"admin"
|
| 33 |
+
],
|
| 34 |
+
"Phan_tich_bo_may_to_chuc_Foxconn_EPU_Fix.pptx": [
|
| 35 |
+
"user",
|
| 36 |
+
"admin"
|
| 37 |
+
],
|
| 38 |
+
"Phan_tich_bo_may_to_chuc_Foxconn_Pro20Y.pptx": [
|
| 39 |
+
"user",
|
| 40 |
+
"admin"
|
| 41 |
+
],
|
| 42 |
+
"Phan_tich_bo_may_to_chuc_Foxconn_SV.pptx": [
|
| 43 |
+
"user",
|
| 44 |
+
"admin"
|
| 45 |
+
],
|
| 46 |
+
"Radmin_VPN_2.1.4952.2.exe": [
|
| 47 |
+
"admin"
|
| 48 |
+
],
|
| 49 |
+
"Thành Đô - GUrbane x Tuấn Siêu Remix Ngày Nào Mà Còn Thiếu Vắng Bóng Em... Nhạc Remix Hot 2026 - Hân Hân Remix (720p, h264).mp4": [
|
| 50 |
+
"thtuanit",
|
| 51 |
+
"admin"
|
| 52 |
+
],
|
| 53 |
+
"admin/Bài thuyết trình - Phân tích bộ máy tổ chức Foxconn.pptx": [
|
| 54 |
+
"admin"
|
| 55 |
+
],
|
| 56 |
+
"admin/snaptik.vn_7704550036016778516.mp4": [
|
| 57 |
+
"admin"
|
| 58 |
+
],
|
| 59 |
+
"meteor-client-26.3-15.jar": [
|
| 60 |
+
"user",
|
| 61 |
+
"admin"
|
| 62 |
+
],
|
| 63 |
+
"snaptik.vn_7704550036016778516.mp4": [
|
| 64 |
+
"user",
|
| 65 |
+
"admin"
|
| 66 |
+
],
|
| 67 |
+
"thtuanit/Bài thuyết trình - Phân tích bộ máy tổ chức Foxconn.pptx": [
|
| 68 |
+
"thtuanit"
|
| 69 |
+
],
|
| 70 |
+
"thtuanit/snaptik.vn_7704550036016778516.mp4": [
|
| 71 |
+
"thtuanit"
|
| 72 |
+
]
|
| 73 |
+
}
|
frontend/next-env.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/// <reference types="next" />
|
| 2 |
+
/// <reference types="next/image-types/global" />
|
| 3 |
+
|
| 4 |
+
// NOTE: This file should not be edited
|
| 5 |
+
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
|
frontend/next.config.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/** @type {import('next').NextConfig} */
|
| 2 |
+
const nextConfig = {
|
| 3 |
+
output: 'standalone',
|
| 4 |
+
reactStrictMode: true,
|
| 5 |
+
async rewrites() {
|
| 6 |
+
const apiBase = process.env.BACKEND_URL || 'http://127.0.0.1:8080';
|
| 7 |
+
return [
|
| 8 |
+
{
|
| 9 |
+
source: '/api/:path*',
|
| 10 |
+
destination: `${apiBase}/api/:path*`,
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
source: '/health',
|
| 14 |
+
destination: `${apiBase}/health`,
|
| 15 |
+
},
|
| 16 |
+
];
|
| 17 |
+
},
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
export default nextConfig;
|
frontend/package-lock.json
ADDED
|
@@ -0,0 +1,1618 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "xetcloud-nextjs",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"lockfileVersion": 3,
|
| 5 |
+
"requires": true,
|
| 6 |
+
"packages": {
|
| 7 |
+
"": {
|
| 8 |
+
"name": "xetcloud-nextjs",
|
| 9 |
+
"version": "1.0.0",
|
| 10 |
+
"dependencies": {
|
| 11 |
+
"lucide-react": "^0.454.0",
|
| 12 |
+
"next": "14.2.16",
|
| 13 |
+
"react": "^18.3.1",
|
| 14 |
+
"react-dom": "^18.3.1"
|
| 15 |
+
},
|
| 16 |
+
"devDependencies": {
|
| 17 |
+
"@types/node": "^20.17.0",
|
| 18 |
+
"@types/react": "^18.3.12",
|
| 19 |
+
"@types/react-dom": "^18.3.1",
|
| 20 |
+
"autoprefixer": "^10.4.20",
|
| 21 |
+
"postcss": "^8.4.47",
|
| 22 |
+
"tailwindcss": "^3.4.14",
|
| 23 |
+
"typescript": "^5.6.3"
|
| 24 |
+
}
|
| 25 |
+
},
|
| 26 |
+
"node_modules/@alloc/quick-lru": {
|
| 27 |
+
"version": "5.3.0",
|
| 28 |
+
"resolved": "https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.3.0.tgz",
|
| 29 |
+
"integrity": "sha512-U4+70Pc5ZS9osnCBCE5Jha/ciHM+Yp+CNMNC/7HvYbNRk1Ldd+f7qO65W5qfhu/TCv+/ozljlXXe9Nj8419DMA==",
|
| 30 |
+
"dev": true,
|
| 31 |
+
"license": "MIT",
|
| 32 |
+
"engines": {
|
| 33 |
+
"node": ">=10"
|
| 34 |
+
},
|
| 35 |
+
"funding": {
|
| 36 |
+
"url": "https://github.com/sponsors/sindresorhus"
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"node_modules/@jridgewell/gen-mapping": {
|
| 40 |
+
"version": "0.3.13",
|
| 41 |
+
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
|
| 42 |
+
"integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==",
|
| 43 |
+
"dev": true,
|
| 44 |
+
"license": "MIT",
|
| 45 |
+
"dependencies": {
|
| 46 |
+
"@jridgewell/sourcemap-codec": "^1.5.0",
|
| 47 |
+
"@jridgewell/trace-mapping": "^0.3.24"
|
| 48 |
+
}
|
| 49 |
+
},
|
| 50 |
+
"node_modules/@jridgewell/resolve-uri": {
|
| 51 |
+
"version": "3.1.2",
|
| 52 |
+
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
|
| 53 |
+
"integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
|
| 54 |
+
"dev": true,
|
| 55 |
+
"license": "MIT",
|
| 56 |
+
"engines": {
|
| 57 |
+
"node": ">=6.0.0"
|
| 58 |
+
}
|
| 59 |
+
},
|
| 60 |
+
"node_modules/@jridgewell/sourcemap-codec": {
|
| 61 |
+
"version": "1.6.0",
|
| 62 |
+
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz",
|
| 63 |
+
"integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==",
|
| 64 |
+
"dev": true,
|
| 65 |
+
"license": "MIT"
|
| 66 |
+
},
|
| 67 |
+
"node_modules/@jridgewell/trace-mapping": {
|
| 68 |
+
"version": "0.3.31",
|
| 69 |
+
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz",
|
| 70 |
+
"integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==",
|
| 71 |
+
"dev": true,
|
| 72 |
+
"license": "MIT",
|
| 73 |
+
"dependencies": {
|
| 74 |
+
"@jridgewell/resolve-uri": "^3.1.0",
|
| 75 |
+
"@jridgewell/sourcemap-codec": "^1.4.14"
|
| 76 |
+
}
|
| 77 |
+
},
|
| 78 |
+
"node_modules/@next/env": {
|
| 79 |
+
"version": "14.2.16",
|
| 80 |
+
"resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.16.tgz",
|
| 81 |
+
"integrity": "sha512-fLrX5TfJzHCbnZ9YUSnGW63tMV3L4nSfhgOQ0iCcX21Pt+VSTDuaLsSuL8J/2XAiVA5AnzvXDpf6pMs60QxOag==",
|
| 82 |
+
"license": "MIT"
|
| 83 |
+
},
|
| 84 |
+
"node_modules/@next/swc-darwin-arm64": {
|
| 85 |
+
"version": "14.2.16",
|
| 86 |
+
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.16.tgz",
|
| 87 |
+
"integrity": "sha512-uFT34QojYkf0+nn6MEZ4gIWQ5aqGF11uIZ1HSxG+cSbj+Mg3+tYm8qXYd3dKN5jqKUm5rBVvf1PBRO/MeQ6rxw==",
|
| 88 |
+
"cpu": [
|
| 89 |
+
"arm64"
|
| 90 |
+
],
|
| 91 |
+
"license": "MIT",
|
| 92 |
+
"optional": true,
|
| 93 |
+
"os": [
|
| 94 |
+
"darwin"
|
| 95 |
+
],
|
| 96 |
+
"engines": {
|
| 97 |
+
"node": ">= 10"
|
| 98 |
+
}
|
| 99 |
+
},
|
| 100 |
+
"node_modules/@next/swc-darwin-x64": {
|
| 101 |
+
"version": "14.2.16",
|
| 102 |
+
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.16.tgz",
|
| 103 |
+
"integrity": "sha512-mCecsFkYezem0QiZlg2bau3Xul77VxUD38b/auAjohMA22G9KTJneUYMv78vWoCCFkleFAhY1NIvbyjj1ncG9g==",
|
| 104 |
+
"cpu": [
|
| 105 |
+
"x64"
|
| 106 |
+
],
|
| 107 |
+
"license": "MIT",
|
| 108 |
+
"optional": true,
|
| 109 |
+
"os": [
|
| 110 |
+
"darwin"
|
| 111 |
+
],
|
| 112 |
+
"engines": {
|
| 113 |
+
"node": ">= 10"
|
| 114 |
+
}
|
| 115 |
+
},
|
| 116 |
+
"node_modules/@next/swc-linux-arm64-gnu": {
|
| 117 |
+
"version": "14.2.16",
|
| 118 |
+
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.16.tgz",
|
| 119 |
+
"integrity": "sha512-yhkNA36+ECTC91KSyZcgWgKrYIyDnXZj8PqtJ+c2pMvj45xf7y/HrgI17hLdrcYamLfVt7pBaJUMxADtPaczHA==",
|
| 120 |
+
"cpu": [
|
| 121 |
+
"arm64"
|
| 122 |
+
],
|
| 123 |
+
"license": "MIT",
|
| 124 |
+
"optional": true,
|
| 125 |
+
"os": [
|
| 126 |
+
"linux"
|
| 127 |
+
],
|
| 128 |
+
"engines": {
|
| 129 |
+
"node": ">= 10"
|
| 130 |
+
}
|
| 131 |
+
},
|
| 132 |
+
"node_modules/@next/swc-linux-arm64-musl": {
|
| 133 |
+
"version": "14.2.16",
|
| 134 |
+
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.16.tgz",
|
| 135 |
+
"integrity": "sha512-X2YSyu5RMys8R2lA0yLMCOCtqFOoLxrq2YbazFvcPOE4i/isubYjkh+JCpRmqYfEuCVltvlo+oGfj/b5T2pKUA==",
|
| 136 |
+
"cpu": [
|
| 137 |
+
"arm64"
|
| 138 |
+
],
|
| 139 |
+
"license": "MIT",
|
| 140 |
+
"optional": true,
|
| 141 |
+
"os": [
|
| 142 |
+
"linux"
|
| 143 |
+
],
|
| 144 |
+
"engines": {
|
| 145 |
+
"node": ">= 10"
|
| 146 |
+
}
|
| 147 |
+
},
|
| 148 |
+
"node_modules/@next/swc-linux-x64-gnu": {
|
| 149 |
+
"version": "14.2.16",
|
| 150 |
+
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.16.tgz",
|
| 151 |
+
"integrity": "sha512-9AGcX7VAkGbc5zTSa+bjQ757tkjr6C/pKS7OK8cX7QEiK6MHIIezBLcQ7gQqbDW2k5yaqba2aDtaBeyyZh1i6Q==",
|
| 152 |
+
"cpu": [
|
| 153 |
+
"x64"
|
| 154 |
+
],
|
| 155 |
+
"license": "MIT",
|
| 156 |
+
"optional": true,
|
| 157 |
+
"os": [
|
| 158 |
+
"linux"
|
| 159 |
+
],
|
| 160 |
+
"engines": {
|
| 161 |
+
"node": ">= 10"
|
| 162 |
+
}
|
| 163 |
+
},
|
| 164 |
+
"node_modules/@next/swc-linux-x64-musl": {
|
| 165 |
+
"version": "14.2.16",
|
| 166 |
+
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.16.tgz",
|
| 167 |
+
"integrity": "sha512-Klgeagrdun4WWDaOizdbtIIm8khUDQJ/5cRzdpXHfkbY91LxBXeejL4kbZBrpR/nmgRrQvmz4l3OtttNVkz2Sg==",
|
| 168 |
+
"cpu": [
|
| 169 |
+
"x64"
|
| 170 |
+
],
|
| 171 |
+
"license": "MIT",
|
| 172 |
+
"optional": true,
|
| 173 |
+
"os": [
|
| 174 |
+
"linux"
|
| 175 |
+
],
|
| 176 |
+
"engines": {
|
| 177 |
+
"node": ">= 10"
|
| 178 |
+
}
|
| 179 |
+
},
|
| 180 |
+
"node_modules/@next/swc-win32-arm64-msvc": {
|
| 181 |
+
"version": "14.2.16",
|
| 182 |
+
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.16.tgz",
|
| 183 |
+
"integrity": "sha512-PwW8A1UC1Y0xIm83G3yFGPiOBftJK4zukTmk7DI1CebyMOoaVpd8aSy7K6GhobzhkjYvqS/QmzcfsWG2Dwizdg==",
|
| 184 |
+
"cpu": [
|
| 185 |
+
"arm64"
|
| 186 |
+
],
|
| 187 |
+
"license": "MIT",
|
| 188 |
+
"optional": true,
|
| 189 |
+
"os": [
|
| 190 |
+
"win32"
|
| 191 |
+
],
|
| 192 |
+
"engines": {
|
| 193 |
+
"node": ">= 10"
|
| 194 |
+
}
|
| 195 |
+
},
|
| 196 |
+
"node_modules/@next/swc-win32-ia32-msvc": {
|
| 197 |
+
"version": "14.2.16",
|
| 198 |
+
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.16.tgz",
|
| 199 |
+
"integrity": "sha512-jhPl3nN0oKEshJBNDAo0etGMzv0j3q3VYorTSFqH1o3rwv1MQRdor27u1zhkgsHPNeY1jxcgyx1ZsCkDD1IHgg==",
|
| 200 |
+
"cpu": [
|
| 201 |
+
"ia32"
|
| 202 |
+
],
|
| 203 |
+
"license": "MIT",
|
| 204 |
+
"optional": true,
|
| 205 |
+
"os": [
|
| 206 |
+
"win32"
|
| 207 |
+
],
|
| 208 |
+
"engines": {
|
| 209 |
+
"node": ">= 10"
|
| 210 |
+
}
|
| 211 |
+
},
|
| 212 |
+
"node_modules/@next/swc-win32-x64-msvc": {
|
| 213 |
+
"version": "14.2.16",
|
| 214 |
+
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.16.tgz",
|
| 215 |
+
"integrity": "sha512-OA7NtfxgirCjfqt+02BqxC3MIgM/JaGjw9tOe4fyZgPsqfseNiMPnCRP44Pfs+Gpo9zPN+SXaFsgP6vk8d571A==",
|
| 216 |
+
"cpu": [
|
| 217 |
+
"x64"
|
| 218 |
+
],
|
| 219 |
+
"license": "MIT",
|
| 220 |
+
"optional": true,
|
| 221 |
+
"os": [
|
| 222 |
+
"win32"
|
| 223 |
+
],
|
| 224 |
+
"engines": {
|
| 225 |
+
"node": ">= 10"
|
| 226 |
+
}
|
| 227 |
+
},
|
| 228 |
+
"node_modules/@nodelib/fs.scandir": {
|
| 229 |
+
"version": "2.1.5",
|
| 230 |
+
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
| 231 |
+
"integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==",
|
| 232 |
+
"dev": true,
|
| 233 |
+
"license": "MIT",
|
| 234 |
+
"dependencies": {
|
| 235 |
+
"@nodelib/fs.stat": "2.0.5",
|
| 236 |
+
"run-parallel": "^1.1.9"
|
| 237 |
+
},
|
| 238 |
+
"engines": {
|
| 239 |
+
"node": ">= 8"
|
| 240 |
+
}
|
| 241 |
+
},
|
| 242 |
+
"node_modules/@nodelib/fs.stat": {
|
| 243 |
+
"version": "2.0.5",
|
| 244 |
+
"resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz",
|
| 245 |
+
"integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==",
|
| 246 |
+
"dev": true,
|
| 247 |
+
"license": "MIT",
|
| 248 |
+
"engines": {
|
| 249 |
+
"node": ">= 8"
|
| 250 |
+
}
|
| 251 |
+
},
|
| 252 |
+
"node_modules/@nodelib/fs.walk": {
|
| 253 |
+
"version": "1.2.8",
|
| 254 |
+
"resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz",
|
| 255 |
+
"integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==",
|
| 256 |
+
"dev": true,
|
| 257 |
+
"license": "MIT",
|
| 258 |
+
"dependencies": {
|
| 259 |
+
"@nodelib/fs.scandir": "2.1.5",
|
| 260 |
+
"fastq": "^1.6.0"
|
| 261 |
+
},
|
| 262 |
+
"engines": {
|
| 263 |
+
"node": ">= 8"
|
| 264 |
+
}
|
| 265 |
+
},
|
| 266 |
+
"node_modules/@swc/counter": {
|
| 267 |
+
"version": "0.1.3",
|
| 268 |
+
"resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz",
|
| 269 |
+
"integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==",
|
| 270 |
+
"license": "Apache-2.0"
|
| 271 |
+
},
|
| 272 |
+
"node_modules/@swc/helpers": {
|
| 273 |
+
"version": "0.5.5",
|
| 274 |
+
"resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.5.tgz",
|
| 275 |
+
"integrity": "sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==",
|
| 276 |
+
"license": "Apache-2.0",
|
| 277 |
+
"dependencies": {
|
| 278 |
+
"@swc/counter": "^0.1.3",
|
| 279 |
+
"tslib": "^2.4.0"
|
| 280 |
+
}
|
| 281 |
+
},
|
| 282 |
+
"node_modules/@types/node": {
|
| 283 |
+
"version": "20.19.43",
|
| 284 |
+
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.43.tgz",
|
| 285 |
+
"integrity": "sha512-6oYBAi5ikg4Pl+kGsoYtawUMBT2zZMCvPNF7pVLnHZfd1zf38DRiWn/gT01RYCdUqkv7Fhr+C9ot4/tb+2sVvA==",
|
| 286 |
+
"dev": true,
|
| 287 |
+
"license": "MIT",
|
| 288 |
+
"dependencies": {
|
| 289 |
+
"undici-types": "~6.21.0"
|
| 290 |
+
}
|
| 291 |
+
},
|
| 292 |
+
"node_modules/@types/prop-types": {
|
| 293 |
+
"version": "15.7.15",
|
| 294 |
+
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz",
|
| 295 |
+
"integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==",
|
| 296 |
+
"dev": true,
|
| 297 |
+
"license": "MIT"
|
| 298 |
+
},
|
| 299 |
+
"node_modules/@types/react": {
|
| 300 |
+
"version": "18.3.31",
|
| 301 |
+
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.31.tgz",
|
| 302 |
+
"integrity": "sha512-vfEqpXTvwT91yhmwdfouStN2hSKwTvyRs8qpLfADyrq/kxDw0hZM7Wk9Ug1FELj8hIby+S/+kQCSRFF32nv2Qw==",
|
| 303 |
+
"dev": true,
|
| 304 |
+
"license": "MIT",
|
| 305 |
+
"dependencies": {
|
| 306 |
+
"@types/prop-types": "*",
|
| 307 |
+
"csstype": "^3.2.2"
|
| 308 |
+
}
|
| 309 |
+
},
|
| 310 |
+
"node_modules/@types/react-dom": {
|
| 311 |
+
"version": "18.3.7",
|
| 312 |
+
"resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.7.tgz",
|
| 313 |
+
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
|
| 314 |
+
"dev": true,
|
| 315 |
+
"license": "MIT",
|
| 316 |
+
"peerDependencies": {
|
| 317 |
+
"@types/react": "^18.0.0"
|
| 318 |
+
}
|
| 319 |
+
},
|
| 320 |
+
"node_modules/any-promise": {
|
| 321 |
+
"version": "1.3.0",
|
| 322 |
+
"resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz",
|
| 323 |
+
"integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==",
|
| 324 |
+
"dev": true,
|
| 325 |
+
"license": "MIT"
|
| 326 |
+
},
|
| 327 |
+
"node_modules/anymatch": {
|
| 328 |
+
"version": "3.1.3",
|
| 329 |
+
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
| 330 |
+
"integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==",
|
| 331 |
+
"dev": true,
|
| 332 |
+
"license": "ISC",
|
| 333 |
+
"dependencies": {
|
| 334 |
+
"normalize-path": "^3.0.0",
|
| 335 |
+
"picomatch": "^2.0.4"
|
| 336 |
+
},
|
| 337 |
+
"engines": {
|
| 338 |
+
"node": ">= 8"
|
| 339 |
+
}
|
| 340 |
+
},
|
| 341 |
+
"node_modules/arg": {
|
| 342 |
+
"version": "5.0.2",
|
| 343 |
+
"resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz",
|
| 344 |
+
"integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==",
|
| 345 |
+
"dev": true,
|
| 346 |
+
"license": "MIT"
|
| 347 |
+
},
|
| 348 |
+
"node_modules/autoprefixer": {
|
| 349 |
+
"version": "10.6.2",
|
| 350 |
+
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.6.2.tgz",
|
| 351 |
+
"integrity": "sha512-VOw9/yGTGwPPgzFcODtcv6zhEPIeIWkRSe10L2ri2f5vZ7ID7lCt6jZzRF5/ubgOZ+szYydmEF5AYsA5jxX1tA==",
|
| 352 |
+
"dev": true,
|
| 353 |
+
"funding": [
|
| 354 |
+
{
|
| 355 |
+
"type": "opencollective",
|
| 356 |
+
"url": "https://opencollective.com/postcss/"
|
| 357 |
+
},
|
| 358 |
+
{
|
| 359 |
+
"type": "tidelift",
|
| 360 |
+
"url": "https://tidelift.com/funding/github/npm/autoprefixer"
|
| 361 |
+
},
|
| 362 |
+
{
|
| 363 |
+
"type": "github",
|
| 364 |
+
"url": "https://github.com/sponsors/ai"
|
| 365 |
+
}
|
| 366 |
+
],
|
| 367 |
+
"license": "MIT",
|
| 368 |
+
"dependencies": {
|
| 369 |
+
"browserslist": "^4.28.9",
|
| 370 |
+
"caniuse-lite": "^1.0.30001810",
|
| 371 |
+
"fraction.js": "^5.3.4",
|
| 372 |
+
"picocolors": "^1.1.1",
|
| 373 |
+
"postcss-value-parser": "^4.2.0"
|
| 374 |
+
},
|
| 375 |
+
"bin": {
|
| 376 |
+
"autoprefixer": "bin/autoprefixer"
|
| 377 |
+
},
|
| 378 |
+
"engines": {
|
| 379 |
+
"node": "^10 || ^12 || >=14"
|
| 380 |
+
},
|
| 381 |
+
"peerDependencies": {
|
| 382 |
+
"postcss": "^8.1.0"
|
| 383 |
+
}
|
| 384 |
+
},
|
| 385 |
+
"node_modules/baseline-browser-mapping": {
|
| 386 |
+
"version": "2.11.35",
|
| 387 |
+
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.35.tgz",
|
| 388 |
+
"integrity": "sha512-GNk8KX52CHqeNKGk8+7tZnQab/2k1t/BgrUHPKNdijzpEhF1saPQZHVKb6m5loSAxB39gyrTYw34Qf9CQ3u1qQ==",
|
| 389 |
+
"dev": true,
|
| 390 |
+
"license": "Apache-2.0",
|
| 391 |
+
"bin": {
|
| 392 |
+
"baseline-browser-mapping": "dist/cli.cjs"
|
| 393 |
+
},
|
| 394 |
+
"engines": {
|
| 395 |
+
"node": ">=6.0.0"
|
| 396 |
+
}
|
| 397 |
+
},
|
| 398 |
+
"node_modules/binary-extensions": {
|
| 399 |
+
"version": "2.3.0",
|
| 400 |
+
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz",
|
| 401 |
+
"integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==",
|
| 402 |
+
"dev": true,
|
| 403 |
+
"license": "MIT",
|
| 404 |
+
"engines": {
|
| 405 |
+
"node": ">=8"
|
| 406 |
+
},
|
| 407 |
+
"funding": {
|
| 408 |
+
"url": "https://github.com/sponsors/sindresorhus"
|
| 409 |
+
}
|
| 410 |
+
},
|
| 411 |
+
"node_modules/braces": {
|
| 412 |
+
"version": "3.0.3",
|
| 413 |
+
"resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz",
|
| 414 |
+
"integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==",
|
| 415 |
+
"dev": true,
|
| 416 |
+
"license": "MIT",
|
| 417 |
+
"dependencies": {
|
| 418 |
+
"fill-range": "^7.1.1"
|
| 419 |
+
},
|
| 420 |
+
"engines": {
|
| 421 |
+
"node": ">=8"
|
| 422 |
+
}
|
| 423 |
+
},
|
| 424 |
+
"node_modules/browserslist": {
|
| 425 |
+
"version": "4.29.5",
|
| 426 |
+
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.29.5.tgz",
|
| 427 |
+
"integrity": "sha512-khTmKu5NGYTotqcYo8Bew2k4RAE9PuXRSFRXG2lQBrCEQHyeQ/vX6gKMxfokwywBsLiXZMnHsmWMG1pnO8J7uQ==",
|
| 428 |
+
"dev": true,
|
| 429 |
+
"funding": [
|
| 430 |
+
{
|
| 431 |
+
"type": "opencollective",
|
| 432 |
+
"url": "https://opencollective.com/browserslist"
|
| 433 |
+
},
|
| 434 |
+
{
|
| 435 |
+
"type": "tidelift",
|
| 436 |
+
"url": "https://tidelift.com/funding/github/npm/browserslist"
|
| 437 |
+
},
|
| 438 |
+
{
|
| 439 |
+
"type": "github",
|
| 440 |
+
"url": "https://github.com/sponsors/ai"
|
| 441 |
+
}
|
| 442 |
+
],
|
| 443 |
+
"license": "MIT",
|
| 444 |
+
"dependencies": {
|
| 445 |
+
"baseline-browser-mapping": "^2.11.33",
|
| 446 |
+
"caniuse-lite": "^1.0.30001819",
|
| 447 |
+
"electron-to-chromium": "^1.5.464",
|
| 448 |
+
"node-releases": "^2.0.60",
|
| 449 |
+
"update-browserslist-db": "^1.3.4"
|
| 450 |
+
},
|
| 451 |
+
"bin": {
|
| 452 |
+
"browserslist": "cli.js"
|
| 453 |
+
},
|
| 454 |
+
"engines": {
|
| 455 |
+
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
|
| 456 |
+
}
|
| 457 |
+
},
|
| 458 |
+
"node_modules/busboy": {
|
| 459 |
+
"version": "1.6.0",
|
| 460 |
+
"resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz",
|
| 461 |
+
"integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==",
|
| 462 |
+
"dependencies": {
|
| 463 |
+
"streamsearch": "^1.1.0"
|
| 464 |
+
},
|
| 465 |
+
"engines": {
|
| 466 |
+
"node": ">=10.16.0"
|
| 467 |
+
}
|
| 468 |
+
},
|
| 469 |
+
"node_modules/camelcase-css": {
|
| 470 |
+
"version": "2.0.1",
|
| 471 |
+
"resolved": "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz",
|
| 472 |
+
"integrity": "sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==",
|
| 473 |
+
"dev": true,
|
| 474 |
+
"license": "MIT",
|
| 475 |
+
"engines": {
|
| 476 |
+
"node": ">= 6"
|
| 477 |
+
}
|
| 478 |
+
},
|
| 479 |
+
"node_modules/caniuse-lite": {
|
| 480 |
+
"version": "1.0.30001823",
|
| 481 |
+
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001823.tgz",
|
| 482 |
+
"integrity": "sha512-TQ5s/djDjNk1axreUW+4rULH+BmdCMLiJkhaXnO5wqivG7tITkSUj4ItIdzqdZHKaXcHAV8dhH3JxOM7/7bwqw==",
|
| 483 |
+
"funding": [
|
| 484 |
+
{
|
| 485 |
+
"type": "opencollective",
|
| 486 |
+
"url": "https://opencollective.com/browserslist"
|
| 487 |
+
},
|
| 488 |
+
{
|
| 489 |
+
"type": "tidelift",
|
| 490 |
+
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
|
| 491 |
+
},
|
| 492 |
+
{
|
| 493 |
+
"type": "github",
|
| 494 |
+
"url": "https://github.com/sponsors/ai"
|
| 495 |
+
}
|
| 496 |
+
],
|
| 497 |
+
"license": "CC-BY-4.0"
|
| 498 |
+
},
|
| 499 |
+
"node_modules/chokidar": {
|
| 500 |
+
"version": "3.6.0",
|
| 501 |
+
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
| 502 |
+
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
|
| 503 |
+
"dev": true,
|
| 504 |
+
"license": "MIT",
|
| 505 |
+
"dependencies": {
|
| 506 |
+
"anymatch": "~3.1.2",
|
| 507 |
+
"braces": "~3.0.2",
|
| 508 |
+
"glob-parent": "~5.1.2",
|
| 509 |
+
"is-binary-path": "~2.1.0",
|
| 510 |
+
"is-glob": "~4.0.1",
|
| 511 |
+
"normalize-path": "~3.0.0",
|
| 512 |
+
"readdirp": "~3.6.0"
|
| 513 |
+
},
|
| 514 |
+
"engines": {
|
| 515 |
+
"node": ">= 8.10.0"
|
| 516 |
+
},
|
| 517 |
+
"funding": {
|
| 518 |
+
"url": "https://paulmillr.com/funding/"
|
| 519 |
+
},
|
| 520 |
+
"optionalDependencies": {
|
| 521 |
+
"fsevents": "~2.3.2"
|
| 522 |
+
}
|
| 523 |
+
},
|
| 524 |
+
"node_modules/chokidar/node_modules/glob-parent": {
|
| 525 |
+
"version": "5.1.2",
|
| 526 |
+
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
| 527 |
+
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
| 528 |
+
"dev": true,
|
| 529 |
+
"license": "ISC",
|
| 530 |
+
"dependencies": {
|
| 531 |
+
"is-glob": "^4.0.1"
|
| 532 |
+
},
|
| 533 |
+
"engines": {
|
| 534 |
+
"node": ">= 6"
|
| 535 |
+
}
|
| 536 |
+
},
|
| 537 |
+
"node_modules/client-only": {
|
| 538 |
+
"version": "0.0.1",
|
| 539 |
+
"resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz",
|
| 540 |
+
"integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==",
|
| 541 |
+
"license": "MIT"
|
| 542 |
+
},
|
| 543 |
+
"node_modules/commander": {
|
| 544 |
+
"version": "4.1.1",
|
| 545 |
+
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
|
| 546 |
+
"integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==",
|
| 547 |
+
"dev": true,
|
| 548 |
+
"license": "MIT",
|
| 549 |
+
"engines": {
|
| 550 |
+
"node": ">= 6"
|
| 551 |
+
}
|
| 552 |
+
},
|
| 553 |
+
"node_modules/csstype": {
|
| 554 |
+
"version": "3.2.3",
|
| 555 |
+
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
|
| 556 |
+
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
|
| 557 |
+
"dev": true,
|
| 558 |
+
"license": "MIT"
|
| 559 |
+
},
|
| 560 |
+
"node_modules/didyoumean": {
|
| 561 |
+
"version": "1.2.2",
|
| 562 |
+
"resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz",
|
| 563 |
+
"integrity": "sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==",
|
| 564 |
+
"dev": true,
|
| 565 |
+
"license": "Apache-2.0"
|
| 566 |
+
},
|
| 567 |
+
"node_modules/dlv": {
|
| 568 |
+
"version": "1.1.3",
|
| 569 |
+
"resolved": "https://registry.npmjs.org/dlv/-/dlv-1.1.3.tgz",
|
| 570 |
+
"integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==",
|
| 571 |
+
"dev": true,
|
| 572 |
+
"license": "MIT"
|
| 573 |
+
},
|
| 574 |
+
"node_modules/electron-to-chromium": {
|
| 575 |
+
"version": "1.5.479",
|
| 576 |
+
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.479.tgz",
|
| 577 |
+
"integrity": "sha512-uAJdJQ7vHa4TvPfzt1TOqoRgHmav5gwmqHMPLxBH6m8Cbj5R9/z/rygTOQiZ8pe5g0ZAEogga1bP6HoKcOzx/Q==",
|
| 578 |
+
"dev": true,
|
| 579 |
+
"license": "ISC"
|
| 580 |
+
},
|
| 581 |
+
"node_modules/es-errors": {
|
| 582 |
+
"version": "1.3.0",
|
| 583 |
+
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
| 584 |
+
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
| 585 |
+
"dev": true,
|
| 586 |
+
"license": "MIT",
|
| 587 |
+
"engines": {
|
| 588 |
+
"node": ">= 0.4"
|
| 589 |
+
}
|
| 590 |
+
},
|
| 591 |
+
"node_modules/escalade": {
|
| 592 |
+
"version": "3.2.0",
|
| 593 |
+
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
|
| 594 |
+
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
|
| 595 |
+
"dev": true,
|
| 596 |
+
"license": "MIT",
|
| 597 |
+
"engines": {
|
| 598 |
+
"node": ">=6"
|
| 599 |
+
}
|
| 600 |
+
},
|
| 601 |
+
"node_modules/fast-glob": {
|
| 602 |
+
"version": "3.3.3",
|
| 603 |
+
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz",
|
| 604 |
+
"integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==",
|
| 605 |
+
"dev": true,
|
| 606 |
+
"license": "MIT",
|
| 607 |
+
"dependencies": {
|
| 608 |
+
"@nodelib/fs.stat": "^2.0.2",
|
| 609 |
+
"@nodelib/fs.walk": "^1.2.3",
|
| 610 |
+
"glob-parent": "^5.1.2",
|
| 611 |
+
"merge2": "^1.3.0",
|
| 612 |
+
"micromatch": "^4.0.8"
|
| 613 |
+
},
|
| 614 |
+
"engines": {
|
| 615 |
+
"node": ">=8.6.0"
|
| 616 |
+
}
|
| 617 |
+
},
|
| 618 |
+
"node_modules/fast-glob/node_modules/glob-parent": {
|
| 619 |
+
"version": "5.1.2",
|
| 620 |
+
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
|
| 621 |
+
"integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
|
| 622 |
+
"dev": true,
|
| 623 |
+
"license": "ISC",
|
| 624 |
+
"dependencies": {
|
| 625 |
+
"is-glob": "^4.0.1"
|
| 626 |
+
},
|
| 627 |
+
"engines": {
|
| 628 |
+
"node": ">= 6"
|
| 629 |
+
}
|
| 630 |
+
},
|
| 631 |
+
"node_modules/fastq": {
|
| 632 |
+
"version": "1.20.3",
|
| 633 |
+
"resolved": "https://registry.npmjs.org/fastq/-/fastq-1.20.3.tgz",
|
| 634 |
+
"integrity": "sha512-XKv5nnLs6nLF71NgiKJLIZFLkPyIEuOselLG7ujZnGrRfQK8HpvY+WqKhAJUAdLomwVHErVS4LfxFlPq0/FTAw==",
|
| 635 |
+
"dev": true,
|
| 636 |
+
"license": "ISC",
|
| 637 |
+
"dependencies": {
|
| 638 |
+
"reusify": "^1.0.4"
|
| 639 |
+
}
|
| 640 |
+
},
|
| 641 |
+
"node_modules/fill-range": {
|
| 642 |
+
"version": "7.1.1",
|
| 643 |
+
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
|
| 644 |
+
"integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==",
|
| 645 |
+
"dev": true,
|
| 646 |
+
"license": "MIT",
|
| 647 |
+
"dependencies": {
|
| 648 |
+
"to-regex-range": "^5.0.1"
|
| 649 |
+
},
|
| 650 |
+
"engines": {
|
| 651 |
+
"node": ">=8"
|
| 652 |
+
}
|
| 653 |
+
},
|
| 654 |
+
"node_modules/fraction.js": {
|
| 655 |
+
"version": "5.3.4",
|
| 656 |
+
"resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-5.3.4.tgz",
|
| 657 |
+
"integrity": "sha512-1X1NTtiJphryn/uLQz3whtY6jK3fTqoE3ohKs0tT+Ujr1W59oopxmoEh7Lu5p6vBaPbgoM0bzveAW4Qi5RyWDQ==",
|
| 658 |
+
"dev": true,
|
| 659 |
+
"license": "MIT",
|
| 660 |
+
"engines": {
|
| 661 |
+
"node": "*"
|
| 662 |
+
},
|
| 663 |
+
"funding": {
|
| 664 |
+
"type": "github",
|
| 665 |
+
"url": "https://github.com/sponsors/rawify"
|
| 666 |
+
}
|
| 667 |
+
},
|
| 668 |
+
"node_modules/fsevents": {
|
| 669 |
+
"version": "2.3.3",
|
| 670 |
+
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
|
| 671 |
+
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
|
| 672 |
+
"dev": true,
|
| 673 |
+
"hasInstallScript": true,
|
| 674 |
+
"license": "MIT",
|
| 675 |
+
"optional": true,
|
| 676 |
+
"os": [
|
| 677 |
+
"darwin"
|
| 678 |
+
],
|
| 679 |
+
"engines": {
|
| 680 |
+
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
| 681 |
+
}
|
| 682 |
+
},
|
| 683 |
+
"node_modules/function-bind": {
|
| 684 |
+
"version": "1.1.2",
|
| 685 |
+
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
| 686 |
+
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
| 687 |
+
"dev": true,
|
| 688 |
+
"license": "MIT",
|
| 689 |
+
"funding": {
|
| 690 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 691 |
+
}
|
| 692 |
+
},
|
| 693 |
+
"node_modules/glob-parent": {
|
| 694 |
+
"version": "6.0.2",
|
| 695 |
+
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",
|
| 696 |
+
"integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==",
|
| 697 |
+
"dev": true,
|
| 698 |
+
"license": "ISC",
|
| 699 |
+
"dependencies": {
|
| 700 |
+
"is-glob": "^4.0.3"
|
| 701 |
+
},
|
| 702 |
+
"engines": {
|
| 703 |
+
"node": ">=10.13.0"
|
| 704 |
+
}
|
| 705 |
+
},
|
| 706 |
+
"node_modules/graceful-fs": {
|
| 707 |
+
"version": "4.2.11",
|
| 708 |
+
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
| 709 |
+
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
| 710 |
+
"license": "ISC"
|
| 711 |
+
},
|
| 712 |
+
"node_modules/hasown": {
|
| 713 |
+
"version": "2.0.4",
|
| 714 |
+
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
|
| 715 |
+
"integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
|
| 716 |
+
"dev": true,
|
| 717 |
+
"license": "MIT",
|
| 718 |
+
"dependencies": {
|
| 719 |
+
"function-bind": "^1.1.2"
|
| 720 |
+
},
|
| 721 |
+
"engines": {
|
| 722 |
+
"node": ">= 0.4"
|
| 723 |
+
}
|
| 724 |
+
},
|
| 725 |
+
"node_modules/is-binary-path": {
|
| 726 |
+
"version": "2.1.0",
|
| 727 |
+
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
|
| 728 |
+
"integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==",
|
| 729 |
+
"dev": true,
|
| 730 |
+
"license": "MIT",
|
| 731 |
+
"dependencies": {
|
| 732 |
+
"binary-extensions": "^2.0.0"
|
| 733 |
+
},
|
| 734 |
+
"engines": {
|
| 735 |
+
"node": ">=8"
|
| 736 |
+
}
|
| 737 |
+
},
|
| 738 |
+
"node_modules/is-core-module": {
|
| 739 |
+
"version": "2.18.0",
|
| 740 |
+
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.18.0.tgz",
|
| 741 |
+
"integrity": "sha512-qyax9fgaKOEC4qK8WZn7Q4IcoZC9RC1O1fFxRcRTq/oMMkWT/uXpqpXa12kzWR409zAt1drYN9N9BO26UmBCmw==",
|
| 742 |
+
"dev": true,
|
| 743 |
+
"license": "MIT",
|
| 744 |
+
"dependencies": {
|
| 745 |
+
"hasown": "^2.0.4"
|
| 746 |
+
},
|
| 747 |
+
"engines": {
|
| 748 |
+
"node": ">= 0.4"
|
| 749 |
+
},
|
| 750 |
+
"funding": {
|
| 751 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 752 |
+
}
|
| 753 |
+
},
|
| 754 |
+
"node_modules/is-extglob": {
|
| 755 |
+
"version": "2.1.1",
|
| 756 |
+
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
| 757 |
+
"integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
|
| 758 |
+
"dev": true,
|
| 759 |
+
"license": "MIT",
|
| 760 |
+
"engines": {
|
| 761 |
+
"node": ">=0.10.0"
|
| 762 |
+
}
|
| 763 |
+
},
|
| 764 |
+
"node_modules/is-glob": {
|
| 765 |
+
"version": "4.0.3",
|
| 766 |
+
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
| 767 |
+
"integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
|
| 768 |
+
"dev": true,
|
| 769 |
+
"license": "MIT",
|
| 770 |
+
"dependencies": {
|
| 771 |
+
"is-extglob": "^2.1.1"
|
| 772 |
+
},
|
| 773 |
+
"engines": {
|
| 774 |
+
"node": ">=0.10.0"
|
| 775 |
+
}
|
| 776 |
+
},
|
| 777 |
+
"node_modules/is-number": {
|
| 778 |
+
"version": "7.0.0",
|
| 779 |
+
"resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
|
| 780 |
+
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
|
| 781 |
+
"dev": true,
|
| 782 |
+
"license": "MIT",
|
| 783 |
+
"engines": {
|
| 784 |
+
"node": ">=0.12.0"
|
| 785 |
+
}
|
| 786 |
+
},
|
| 787 |
+
"node_modules/jiti": {
|
| 788 |
+
"version": "1.21.7",
|
| 789 |
+
"resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.7.tgz",
|
| 790 |
+
"integrity": "sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A==",
|
| 791 |
+
"dev": true,
|
| 792 |
+
"license": "MIT",
|
| 793 |
+
"bin": {
|
| 794 |
+
"jiti": "bin/jiti.js"
|
| 795 |
+
}
|
| 796 |
+
},
|
| 797 |
+
"node_modules/js-tokens": {
|
| 798 |
+
"version": "4.0.0",
|
| 799 |
+
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
| 800 |
+
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
|
| 801 |
+
"license": "MIT"
|
| 802 |
+
},
|
| 803 |
+
"node_modules/lilconfig": {
|
| 804 |
+
"version": "3.1.5",
|
| 805 |
+
"resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.5.tgz",
|
| 806 |
+
"integrity": "sha512-aRAOI9Ia43ygL4o1EOmC/sc/0OFxrm7qcQngiIyWaqVnSnz932ybJ07zyCcgMNGSDP8Yxaf88Xj1zHEXmvQ4SA==",
|
| 807 |
+
"dev": true,
|
| 808 |
+
"license": "MIT",
|
| 809 |
+
"engines": {
|
| 810 |
+
"node": ">=14"
|
| 811 |
+
},
|
| 812 |
+
"funding": {
|
| 813 |
+
"url": "https://github.com/sponsors/antonk52"
|
| 814 |
+
}
|
| 815 |
+
},
|
| 816 |
+
"node_modules/lines-and-columns": {
|
| 817 |
+
"version": "1.2.4",
|
| 818 |
+
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
|
| 819 |
+
"integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==",
|
| 820 |
+
"dev": true,
|
| 821 |
+
"license": "MIT"
|
| 822 |
+
},
|
| 823 |
+
"node_modules/loose-envify": {
|
| 824 |
+
"version": "1.4.0",
|
| 825 |
+
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
| 826 |
+
"integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
|
| 827 |
+
"license": "MIT",
|
| 828 |
+
"dependencies": {
|
| 829 |
+
"js-tokens": "^3.0.0 || ^4.0.0"
|
| 830 |
+
},
|
| 831 |
+
"bin": {
|
| 832 |
+
"loose-envify": "cli.js"
|
| 833 |
+
}
|
| 834 |
+
},
|
| 835 |
+
"node_modules/lucide-react": {
|
| 836 |
+
"version": "0.454.0",
|
| 837 |
+
"resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.454.0.tgz",
|
| 838 |
+
"integrity": "sha512-hw7zMDwykCLnEzgncEEjHeA6+45aeEzRYuKHuyRSOPkhko+J3ySGjGIzu+mmMfDFG1vazHepMaYFYHbTFAZAAQ==",
|
| 839 |
+
"license": "ISC",
|
| 840 |
+
"peerDependencies": {
|
| 841 |
+
"react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0-rc"
|
| 842 |
+
}
|
| 843 |
+
},
|
| 844 |
+
"node_modules/merge2": {
|
| 845 |
+
"version": "1.4.1",
|
| 846 |
+
"resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz",
|
| 847 |
+
"integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==",
|
| 848 |
+
"dev": true,
|
| 849 |
+
"license": "MIT",
|
| 850 |
+
"engines": {
|
| 851 |
+
"node": ">= 8"
|
| 852 |
+
}
|
| 853 |
+
},
|
| 854 |
+
"node_modules/micromatch": {
|
| 855 |
+
"version": "4.0.8",
|
| 856 |
+
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz",
|
| 857 |
+
"integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==",
|
| 858 |
+
"dev": true,
|
| 859 |
+
"license": "MIT",
|
| 860 |
+
"dependencies": {
|
| 861 |
+
"braces": "^3.0.3",
|
| 862 |
+
"picomatch": "^2.3.1"
|
| 863 |
+
},
|
| 864 |
+
"engines": {
|
| 865 |
+
"node": ">=8.6"
|
| 866 |
+
}
|
| 867 |
+
},
|
| 868 |
+
"node_modules/mz": {
|
| 869 |
+
"version": "2.7.0",
|
| 870 |
+
"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
|
| 871 |
+
"integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==",
|
| 872 |
+
"dev": true,
|
| 873 |
+
"license": "MIT",
|
| 874 |
+
"dependencies": {
|
| 875 |
+
"any-promise": "^1.0.0",
|
| 876 |
+
"object-assign": "^4.0.1",
|
| 877 |
+
"thenify-all": "^1.0.0"
|
| 878 |
+
}
|
| 879 |
+
},
|
| 880 |
+
"node_modules/nanoid": {
|
| 881 |
+
"version": "3.3.20",
|
| 882 |
+
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz",
|
| 883 |
+
"integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==",
|
| 884 |
+
"funding": [
|
| 885 |
+
{
|
| 886 |
+
"type": "github",
|
| 887 |
+
"url": "https://github.com/sponsors/ai"
|
| 888 |
+
}
|
| 889 |
+
],
|
| 890 |
+
"license": "MIT",
|
| 891 |
+
"bin": {
|
| 892 |
+
"nanoid": "bin/nanoid.cjs"
|
| 893 |
+
},
|
| 894 |
+
"engines": {
|
| 895 |
+
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
|
| 896 |
+
}
|
| 897 |
+
},
|
| 898 |
+
"node_modules/next": {
|
| 899 |
+
"version": "14.2.16",
|
| 900 |
+
"resolved": "https://registry.npmjs.org/next/-/next-14.2.16.tgz",
|
| 901 |
+
"integrity": "sha512-LcO7WnFu6lYSvCzZoo1dB+IO0xXz5uEv52HF1IUN0IqVTUIZGHuuR10I5efiLadGt+4oZqTcNZyVVEem/TM5nA==",
|
| 902 |
+
"deprecated": "This version has a security vulnerability. Please upgrade to a patched version. See https://nextjs.org/blog/security-update-2025-12-11 for more details.",
|
| 903 |
+
"license": "MIT",
|
| 904 |
+
"dependencies": {
|
| 905 |
+
"@next/env": "14.2.16",
|
| 906 |
+
"@swc/helpers": "0.5.5",
|
| 907 |
+
"busboy": "1.6.0",
|
| 908 |
+
"caniuse-lite": "^1.0.30001579",
|
| 909 |
+
"graceful-fs": "^4.2.11",
|
| 910 |
+
"postcss": "8.4.31",
|
| 911 |
+
"styled-jsx": "5.1.1"
|
| 912 |
+
},
|
| 913 |
+
"bin": {
|
| 914 |
+
"next": "dist/bin/next"
|
| 915 |
+
},
|
| 916 |
+
"engines": {
|
| 917 |
+
"node": ">=18.17.0"
|
| 918 |
+
},
|
| 919 |
+
"optionalDependencies": {
|
| 920 |
+
"@next/swc-darwin-arm64": "14.2.16",
|
| 921 |
+
"@next/swc-darwin-x64": "14.2.16",
|
| 922 |
+
"@next/swc-linux-arm64-gnu": "14.2.16",
|
| 923 |
+
"@next/swc-linux-arm64-musl": "14.2.16",
|
| 924 |
+
"@next/swc-linux-x64-gnu": "14.2.16",
|
| 925 |
+
"@next/swc-linux-x64-musl": "14.2.16",
|
| 926 |
+
"@next/swc-win32-arm64-msvc": "14.2.16",
|
| 927 |
+
"@next/swc-win32-ia32-msvc": "14.2.16",
|
| 928 |
+
"@next/swc-win32-x64-msvc": "14.2.16"
|
| 929 |
+
},
|
| 930 |
+
"peerDependencies": {
|
| 931 |
+
"@opentelemetry/api": "^1.1.0",
|
| 932 |
+
"@playwright/test": "^1.41.2",
|
| 933 |
+
"react": "^18.2.0",
|
| 934 |
+
"react-dom": "^18.2.0",
|
| 935 |
+
"sass": "^1.3.0"
|
| 936 |
+
},
|
| 937 |
+
"peerDependenciesMeta": {
|
| 938 |
+
"@opentelemetry/api": {
|
| 939 |
+
"optional": true
|
| 940 |
+
},
|
| 941 |
+
"@playwright/test": {
|
| 942 |
+
"optional": true
|
| 943 |
+
},
|
| 944 |
+
"sass": {
|
| 945 |
+
"optional": true
|
| 946 |
+
}
|
| 947 |
+
}
|
| 948 |
+
},
|
| 949 |
+
"node_modules/next/node_modules/postcss": {
|
| 950 |
+
"version": "8.4.31",
|
| 951 |
+
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
|
| 952 |
+
"integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==",
|
| 953 |
+
"funding": [
|
| 954 |
+
{
|
| 955 |
+
"type": "opencollective",
|
| 956 |
+
"url": "https://opencollective.com/postcss/"
|
| 957 |
+
},
|
| 958 |
+
{
|
| 959 |
+
"type": "tidelift",
|
| 960 |
+
"url": "https://tidelift.com/funding/github/npm/postcss"
|
| 961 |
+
},
|
| 962 |
+
{
|
| 963 |
+
"type": "github",
|
| 964 |
+
"url": "https://github.com/sponsors/ai"
|
| 965 |
+
}
|
| 966 |
+
],
|
| 967 |
+
"license": "MIT",
|
| 968 |
+
"dependencies": {
|
| 969 |
+
"nanoid": "^3.3.6",
|
| 970 |
+
"picocolors": "^1.0.0",
|
| 971 |
+
"source-map-js": "^1.0.2"
|
| 972 |
+
},
|
| 973 |
+
"engines": {
|
| 974 |
+
"node": "^10 || ^12 || >=14"
|
| 975 |
+
}
|
| 976 |
+
},
|
| 977 |
+
"node_modules/node-releases": {
|
| 978 |
+
"version": "2.0.63",
|
| 979 |
+
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.63.tgz",
|
| 980 |
+
"integrity": "sha512-6li2QanLsAXpIH2R6j77MzRyvOyrvdTqlKtO4CgBdHGNvN99ZZfyxszHc5o5+IZBWD5u6Hzwg83JoGXmqZNG9Q==",
|
| 981 |
+
"dev": true,
|
| 982 |
+
"license": "MIT",
|
| 983 |
+
"engines": {
|
| 984 |
+
"node": ">=18"
|
| 985 |
+
}
|
| 986 |
+
},
|
| 987 |
+
"node_modules/normalize-path": {
|
| 988 |
+
"version": "3.0.0",
|
| 989 |
+
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
|
| 990 |
+
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
|
| 991 |
+
"dev": true,
|
| 992 |
+
"license": "MIT",
|
| 993 |
+
"engines": {
|
| 994 |
+
"node": ">=0.10.0"
|
| 995 |
+
}
|
| 996 |
+
},
|
| 997 |
+
"node_modules/object-assign": {
|
| 998 |
+
"version": "4.1.1",
|
| 999 |
+
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
| 1000 |
+
"integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
|
| 1001 |
+
"dev": true,
|
| 1002 |
+
"license": "MIT",
|
| 1003 |
+
"engines": {
|
| 1004 |
+
"node": ">=0.10.0"
|
| 1005 |
+
}
|
| 1006 |
+
},
|
| 1007 |
+
"node_modules/object-hash": {
|
| 1008 |
+
"version": "3.0.0",
|
| 1009 |
+
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
|
| 1010 |
+
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
|
| 1011 |
+
"dev": true,
|
| 1012 |
+
"license": "MIT",
|
| 1013 |
+
"engines": {
|
| 1014 |
+
"node": ">= 6"
|
| 1015 |
+
}
|
| 1016 |
+
},
|
| 1017 |
+
"node_modules/path-parse": {
|
| 1018 |
+
"version": "1.0.7",
|
| 1019 |
+
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
|
| 1020 |
+
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
|
| 1021 |
+
"dev": true,
|
| 1022 |
+
"license": "MIT"
|
| 1023 |
+
},
|
| 1024 |
+
"node_modules/picocolors": {
|
| 1025 |
+
"version": "1.1.1",
|
| 1026 |
+
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
|
| 1027 |
+
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
|
| 1028 |
+
"license": "ISC"
|
| 1029 |
+
},
|
| 1030 |
+
"node_modules/picomatch": {
|
| 1031 |
+
"version": "2.3.2",
|
| 1032 |
+
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz",
|
| 1033 |
+
"integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==",
|
| 1034 |
+
"dev": true,
|
| 1035 |
+
"license": "MIT",
|
| 1036 |
+
"engines": {
|
| 1037 |
+
"node": ">=8.6"
|
| 1038 |
+
},
|
| 1039 |
+
"funding": {
|
| 1040 |
+
"url": "https://github.com/sponsors/jonschlinkert"
|
| 1041 |
+
}
|
| 1042 |
+
},
|
| 1043 |
+
"node_modules/pirates": {
|
| 1044 |
+
"version": "4.0.7",
|
| 1045 |
+
"resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.7.tgz",
|
| 1046 |
+
"integrity": "sha512-TfySrs/5nm8fQJDcBDuUng3VOUKsd7S+zqvbOTiGXHfxX4wK31ard+hoNuvkicM/2YFzlpDgABOevKSsB4G/FA==",
|
| 1047 |
+
"dev": true,
|
| 1048 |
+
"license": "MIT",
|
| 1049 |
+
"engines": {
|
| 1050 |
+
"node": ">= 6"
|
| 1051 |
+
}
|
| 1052 |
+
},
|
| 1053 |
+
"node_modules/postcss": {
|
| 1054 |
+
"version": "8.5.32",
|
| 1055 |
+
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz",
|
| 1056 |
+
"integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==",
|
| 1057 |
+
"dev": true,
|
| 1058 |
+
"funding": [
|
| 1059 |
+
{
|
| 1060 |
+
"type": "opencollective",
|
| 1061 |
+
"url": "https://opencollective.com/postcss/"
|
| 1062 |
+
},
|
| 1063 |
+
{
|
| 1064 |
+
"type": "tidelift",
|
| 1065 |
+
"url": "https://tidelift.com/funding/github/npm/postcss"
|
| 1066 |
+
},
|
| 1067 |
+
{
|
| 1068 |
+
"type": "github",
|
| 1069 |
+
"url": "https://github.com/sponsors/ai"
|
| 1070 |
+
}
|
| 1071 |
+
],
|
| 1072 |
+
"license": "MIT",
|
| 1073 |
+
"dependencies": {
|
| 1074 |
+
"nanoid": "^3.3.20",
|
| 1075 |
+
"picocolors": "^1.1.1",
|
| 1076 |
+
"source-map-js": "^1.2.2"
|
| 1077 |
+
},
|
| 1078 |
+
"engines": {
|
| 1079 |
+
"node": "^10 || ^12 || >=14"
|
| 1080 |
+
}
|
| 1081 |
+
},
|
| 1082 |
+
"node_modules/postcss-import": {
|
| 1083 |
+
"version": "15.1.0",
|
| 1084 |
+
"resolved": "https://registry.npmjs.org/postcss-import/-/postcss-import-15.1.0.tgz",
|
| 1085 |
+
"integrity": "sha512-hpr+J05B2FVYUAXHeK1YyI267J/dDDhMU6B6civm8hSY1jYJnBXxzKDKDswzJmtLHryrjhnDjqqp/49t8FALew==",
|
| 1086 |
+
"dev": true,
|
| 1087 |
+
"license": "MIT",
|
| 1088 |
+
"dependencies": {
|
| 1089 |
+
"postcss-value-parser": "^4.0.0",
|
| 1090 |
+
"read-cache": "^1.0.0",
|
| 1091 |
+
"resolve": "^1.1.7"
|
| 1092 |
+
},
|
| 1093 |
+
"engines": {
|
| 1094 |
+
"node": ">=14.0.0"
|
| 1095 |
+
},
|
| 1096 |
+
"peerDependencies": {
|
| 1097 |
+
"postcss": "^8.0.0"
|
| 1098 |
+
}
|
| 1099 |
+
},
|
| 1100 |
+
"node_modules/postcss-js": {
|
| 1101 |
+
"version": "4.1.0",
|
| 1102 |
+
"resolved": "https://registry.npmjs.org/postcss-js/-/postcss-js-4.1.0.tgz",
|
| 1103 |
+
"integrity": "sha512-oIAOTqgIo7q2EOwbhb8UalYePMvYoIeRY2YKntdpFQXNosSu3vLrniGgmH9OKs/qAkfoj5oB3le/7mINW1LCfw==",
|
| 1104 |
+
"dev": true,
|
| 1105 |
+
"funding": [
|
| 1106 |
+
{
|
| 1107 |
+
"type": "opencollective",
|
| 1108 |
+
"url": "https://opencollective.com/postcss/"
|
| 1109 |
+
},
|
| 1110 |
+
{
|
| 1111 |
+
"type": "github",
|
| 1112 |
+
"url": "https://github.com/sponsors/ai"
|
| 1113 |
+
}
|
| 1114 |
+
],
|
| 1115 |
+
"license": "MIT",
|
| 1116 |
+
"dependencies": {
|
| 1117 |
+
"camelcase-css": "^2.0.1"
|
| 1118 |
+
},
|
| 1119 |
+
"engines": {
|
| 1120 |
+
"node": "^12 || ^14 || >= 16"
|
| 1121 |
+
},
|
| 1122 |
+
"peerDependencies": {
|
| 1123 |
+
"postcss": "^8.4.21"
|
| 1124 |
+
}
|
| 1125 |
+
},
|
| 1126 |
+
"node_modules/postcss-load-config": {
|
| 1127 |
+
"version": "6.0.1",
|
| 1128 |
+
"resolved": "https://registry.npmjs.org/postcss-load-config/-/postcss-load-config-6.0.1.tgz",
|
| 1129 |
+
"integrity": "sha512-oPtTM4oerL+UXmx+93ytZVN82RrlY/wPUV8IeDxFrzIjXOLF1pN+EmKPLbubvKHT2HC20xXsCAH2Z+CKV6Oz/g==",
|
| 1130 |
+
"dev": true,
|
| 1131 |
+
"funding": [
|
| 1132 |
+
{
|
| 1133 |
+
"type": "opencollective",
|
| 1134 |
+
"url": "https://opencollective.com/postcss/"
|
| 1135 |
+
},
|
| 1136 |
+
{
|
| 1137 |
+
"type": "github",
|
| 1138 |
+
"url": "https://github.com/sponsors/ai"
|
| 1139 |
+
}
|
| 1140 |
+
],
|
| 1141 |
+
"license": "MIT",
|
| 1142 |
+
"dependencies": {
|
| 1143 |
+
"lilconfig": "^3.1.1"
|
| 1144 |
+
},
|
| 1145 |
+
"engines": {
|
| 1146 |
+
"node": ">= 18"
|
| 1147 |
+
},
|
| 1148 |
+
"peerDependencies": {
|
| 1149 |
+
"jiti": ">=1.21.0",
|
| 1150 |
+
"postcss": ">=8.0.9",
|
| 1151 |
+
"tsx": "^4.8.1",
|
| 1152 |
+
"yaml": "^2.4.2"
|
| 1153 |
+
},
|
| 1154 |
+
"peerDependenciesMeta": {
|
| 1155 |
+
"jiti": {
|
| 1156 |
+
"optional": true
|
| 1157 |
+
},
|
| 1158 |
+
"postcss": {
|
| 1159 |
+
"optional": true
|
| 1160 |
+
},
|
| 1161 |
+
"tsx": {
|
| 1162 |
+
"optional": true
|
| 1163 |
+
},
|
| 1164 |
+
"yaml": {
|
| 1165 |
+
"optional": true
|
| 1166 |
+
}
|
| 1167 |
+
}
|
| 1168 |
+
},
|
| 1169 |
+
"node_modules/postcss-nested": {
|
| 1170 |
+
"version": "6.2.0",
|
| 1171 |
+
"resolved": "https://registry.npmjs.org/postcss-nested/-/postcss-nested-6.2.0.tgz",
|
| 1172 |
+
"integrity": "sha512-HQbt28KulC5AJzG+cZtj9kvKB93CFCdLvog1WFLf1D+xmMvPGlBstkpTEZfK5+AN9hfJocyBFCNiqyS48bpgzQ==",
|
| 1173 |
+
"dev": true,
|
| 1174 |
+
"funding": [
|
| 1175 |
+
{
|
| 1176 |
+
"type": "opencollective",
|
| 1177 |
+
"url": "https://opencollective.com/postcss/"
|
| 1178 |
+
},
|
| 1179 |
+
{
|
| 1180 |
+
"type": "github",
|
| 1181 |
+
"url": "https://github.com/sponsors/ai"
|
| 1182 |
+
}
|
| 1183 |
+
],
|
| 1184 |
+
"license": "MIT",
|
| 1185 |
+
"dependencies": {
|
| 1186 |
+
"postcss-selector-parser": "^6.1.1"
|
| 1187 |
+
},
|
| 1188 |
+
"engines": {
|
| 1189 |
+
"node": ">=12.0"
|
| 1190 |
+
},
|
| 1191 |
+
"peerDependencies": {
|
| 1192 |
+
"postcss": "^8.2.14"
|
| 1193 |
+
}
|
| 1194 |
+
},
|
| 1195 |
+
"node_modules/postcss-selector-parser": {
|
| 1196 |
+
"version": "6.1.6",
|
| 1197 |
+
"resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-6.1.6.tgz",
|
| 1198 |
+
"integrity": "sha512-BK87/Qgti3DIcgS2PaCVoteFIkjIFvCJBizZDIVSjdlFNg4Jv+SRqbN2JONb/qQUH4ZFqfXYF+izg15W2HVRvA==",
|
| 1199 |
+
"dev": true,
|
| 1200 |
+
"license": "MIT",
|
| 1201 |
+
"dependencies": {
|
| 1202 |
+
"util-deprecate": "^1.0.2"
|
| 1203 |
+
},
|
| 1204 |
+
"engines": {
|
| 1205 |
+
"node": ">=4"
|
| 1206 |
+
}
|
| 1207 |
+
},
|
| 1208 |
+
"node_modules/postcss-value-parser": {
|
| 1209 |
+
"version": "4.2.0",
|
| 1210 |
+
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
|
| 1211 |
+
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==",
|
| 1212 |
+
"dev": true,
|
| 1213 |
+
"license": "MIT"
|
| 1214 |
+
},
|
| 1215 |
+
"node_modules/queue-microtask": {
|
| 1216 |
+
"version": "1.2.3",
|
| 1217 |
+
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
|
| 1218 |
+
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==",
|
| 1219 |
+
"dev": true,
|
| 1220 |
+
"funding": [
|
| 1221 |
+
{
|
| 1222 |
+
"type": "github",
|
| 1223 |
+
"url": "https://github.com/sponsors/feross"
|
| 1224 |
+
},
|
| 1225 |
+
{
|
| 1226 |
+
"type": "patreon",
|
| 1227 |
+
"url": "https://www.patreon.com/feross"
|
| 1228 |
+
},
|
| 1229 |
+
{
|
| 1230 |
+
"type": "consulting",
|
| 1231 |
+
"url": "https://feross.org/support"
|
| 1232 |
+
}
|
| 1233 |
+
],
|
| 1234 |
+
"license": "MIT"
|
| 1235 |
+
},
|
| 1236 |
+
"node_modules/react": {
|
| 1237 |
+
"version": "18.3.1",
|
| 1238 |
+
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
|
| 1239 |
+
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
|
| 1240 |
+
"license": "MIT",
|
| 1241 |
+
"dependencies": {
|
| 1242 |
+
"loose-envify": "^1.1.0"
|
| 1243 |
+
},
|
| 1244 |
+
"engines": {
|
| 1245 |
+
"node": ">=0.10.0"
|
| 1246 |
+
}
|
| 1247 |
+
},
|
| 1248 |
+
"node_modules/react-dom": {
|
| 1249 |
+
"version": "18.3.1",
|
| 1250 |
+
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
|
| 1251 |
+
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
|
| 1252 |
+
"license": "MIT",
|
| 1253 |
+
"dependencies": {
|
| 1254 |
+
"loose-envify": "^1.1.0",
|
| 1255 |
+
"scheduler": "^0.23.2"
|
| 1256 |
+
},
|
| 1257 |
+
"peerDependencies": {
|
| 1258 |
+
"react": "^18.3.1"
|
| 1259 |
+
}
|
| 1260 |
+
},
|
| 1261 |
+
"node_modules/read-cache": {
|
| 1262 |
+
"version": "1.0.2",
|
| 1263 |
+
"resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.2.tgz",
|
| 1264 |
+
"integrity": "sha512-/peqiBB/n07gQGLsWaHho3WfvUyRscw0gYTsEFMhrIe/nWLkYaf5SbKYjGYqtRV3aPwykJgF2VEMo1ac4bnsGA==",
|
| 1265 |
+
"dev": true,
|
| 1266 |
+
"license": "MIT"
|
| 1267 |
+
},
|
| 1268 |
+
"node_modules/readdirp": {
|
| 1269 |
+
"version": "3.6.0",
|
| 1270 |
+
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
|
| 1271 |
+
"integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==",
|
| 1272 |
+
"dev": true,
|
| 1273 |
+
"license": "MIT",
|
| 1274 |
+
"dependencies": {
|
| 1275 |
+
"picomatch": "^2.2.1"
|
| 1276 |
+
},
|
| 1277 |
+
"engines": {
|
| 1278 |
+
"node": ">=8.10.0"
|
| 1279 |
+
}
|
| 1280 |
+
},
|
| 1281 |
+
"node_modules/resolve": {
|
| 1282 |
+
"version": "1.22.14",
|
| 1283 |
+
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.14.tgz",
|
| 1284 |
+
"integrity": "sha512-1ZjYvR9sbkiwC5+9QHetqW5HmA2pHRMaoupD01t2HlYnV/vydC2zPwLixhsMieSWVZt0JJRg5LVIk0Ow1D/TrA==",
|
| 1285 |
+
"dev": true,
|
| 1286 |
+
"license": "MIT",
|
| 1287 |
+
"dependencies": {
|
| 1288 |
+
"es-errors": "^1.3.0",
|
| 1289 |
+
"is-core-module": "^2.18.0",
|
| 1290 |
+
"path-parse": "^1.0.7",
|
| 1291 |
+
"supports-preserve-symlinks-flag": "^1.0.0"
|
| 1292 |
+
},
|
| 1293 |
+
"bin": {
|
| 1294 |
+
"resolve": "bin/resolve"
|
| 1295 |
+
},
|
| 1296 |
+
"engines": {
|
| 1297 |
+
"node": ">= 0.4"
|
| 1298 |
+
},
|
| 1299 |
+
"funding": {
|
| 1300 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1301 |
+
}
|
| 1302 |
+
},
|
| 1303 |
+
"node_modules/reusify": {
|
| 1304 |
+
"version": "1.1.0",
|
| 1305 |
+
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz",
|
| 1306 |
+
"integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==",
|
| 1307 |
+
"dev": true,
|
| 1308 |
+
"license": "MIT",
|
| 1309 |
+
"engines": {
|
| 1310 |
+
"iojs": ">=1.0.0",
|
| 1311 |
+
"node": ">=0.10.0"
|
| 1312 |
+
}
|
| 1313 |
+
},
|
| 1314 |
+
"node_modules/run-parallel": {
|
| 1315 |
+
"version": "1.2.0",
|
| 1316 |
+
"resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz",
|
| 1317 |
+
"integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==",
|
| 1318 |
+
"dev": true,
|
| 1319 |
+
"funding": [
|
| 1320 |
+
{
|
| 1321 |
+
"type": "github",
|
| 1322 |
+
"url": "https://github.com/sponsors/feross"
|
| 1323 |
+
},
|
| 1324 |
+
{
|
| 1325 |
+
"type": "patreon",
|
| 1326 |
+
"url": "https://www.patreon.com/feross"
|
| 1327 |
+
},
|
| 1328 |
+
{
|
| 1329 |
+
"type": "consulting",
|
| 1330 |
+
"url": "https://feross.org/support"
|
| 1331 |
+
}
|
| 1332 |
+
],
|
| 1333 |
+
"license": "MIT",
|
| 1334 |
+
"dependencies": {
|
| 1335 |
+
"queue-microtask": "^1.2.2"
|
| 1336 |
+
}
|
| 1337 |
+
},
|
| 1338 |
+
"node_modules/scheduler": {
|
| 1339 |
+
"version": "0.23.2",
|
| 1340 |
+
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",
|
| 1341 |
+
"integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",
|
| 1342 |
+
"license": "MIT",
|
| 1343 |
+
"dependencies": {
|
| 1344 |
+
"loose-envify": "^1.1.0"
|
| 1345 |
+
}
|
| 1346 |
+
},
|
| 1347 |
+
"node_modules/source-map-js": {
|
| 1348 |
+
"version": "1.2.2",
|
| 1349 |
+
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz",
|
| 1350 |
+
"integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==",
|
| 1351 |
+
"license": "BSD-3-Clause",
|
| 1352 |
+
"engines": {
|
| 1353 |
+
"node": ">=0.10.0"
|
| 1354 |
+
}
|
| 1355 |
+
},
|
| 1356 |
+
"node_modules/streamsearch": {
|
| 1357 |
+
"version": "1.1.0",
|
| 1358 |
+
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz",
|
| 1359 |
+
"integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==",
|
| 1360 |
+
"engines": {
|
| 1361 |
+
"node": ">=10.0.0"
|
| 1362 |
+
}
|
| 1363 |
+
},
|
| 1364 |
+
"node_modules/styled-jsx": {
|
| 1365 |
+
"version": "5.1.1",
|
| 1366 |
+
"resolved": "https://registry.npmjs.org/styled-jsx/-/styled-jsx-5.1.1.tgz",
|
| 1367 |
+
"integrity": "sha512-pW7uC1l4mBZ8ugbiZrcIsiIvVx1UmTfw7UkC3Um2tmfUq9Bhk8IiyEIPl6F8agHgjzku6j0xQEZbfA5uSgSaCw==",
|
| 1368 |
+
"license": "MIT",
|
| 1369 |
+
"dependencies": {
|
| 1370 |
+
"client-only": "0.0.1"
|
| 1371 |
+
},
|
| 1372 |
+
"engines": {
|
| 1373 |
+
"node": ">= 12.0.0"
|
| 1374 |
+
},
|
| 1375 |
+
"peerDependencies": {
|
| 1376 |
+
"react": ">= 16.8.0 || 17.x.x || ^18.0.0-0"
|
| 1377 |
+
},
|
| 1378 |
+
"peerDependenciesMeta": {
|
| 1379 |
+
"@babel/core": {
|
| 1380 |
+
"optional": true
|
| 1381 |
+
},
|
| 1382 |
+
"babel-plugin-macros": {
|
| 1383 |
+
"optional": true
|
| 1384 |
+
}
|
| 1385 |
+
}
|
| 1386 |
+
},
|
| 1387 |
+
"node_modules/sucrase": {
|
| 1388 |
+
"version": "3.35.1",
|
| 1389 |
+
"resolved": "https://registry.npmjs.org/sucrase/-/sucrase-3.35.1.tgz",
|
| 1390 |
+
"integrity": "sha512-DhuTmvZWux4H1UOnWMB3sk0sbaCVOoQZjv8u1rDoTV0HTdGem9hkAZtl4JZy8P2z4Bg0nT+YMeOFyVr4zcG5Tw==",
|
| 1391 |
+
"dev": true,
|
| 1392 |
+
"license": "MIT",
|
| 1393 |
+
"dependencies": {
|
| 1394 |
+
"@jridgewell/gen-mapping": "^0.3.2",
|
| 1395 |
+
"commander": "^4.0.0",
|
| 1396 |
+
"lines-and-columns": "^1.1.6",
|
| 1397 |
+
"mz": "^2.7.0",
|
| 1398 |
+
"pirates": "^4.0.1",
|
| 1399 |
+
"tinyglobby": "^0.2.11",
|
| 1400 |
+
"ts-interface-checker": "^0.1.9"
|
| 1401 |
+
},
|
| 1402 |
+
"bin": {
|
| 1403 |
+
"sucrase": "bin/sucrase",
|
| 1404 |
+
"sucrase-node": "bin/sucrase-node"
|
| 1405 |
+
},
|
| 1406 |
+
"engines": {
|
| 1407 |
+
"node": ">=16 || 14 >=14.17"
|
| 1408 |
+
}
|
| 1409 |
+
},
|
| 1410 |
+
"node_modules/supports-preserve-symlinks-flag": {
|
| 1411 |
+
"version": "1.0.0",
|
| 1412 |
+
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
|
| 1413 |
+
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
|
| 1414 |
+
"dev": true,
|
| 1415 |
+
"license": "MIT",
|
| 1416 |
+
"engines": {
|
| 1417 |
+
"node": ">= 0.4"
|
| 1418 |
+
},
|
| 1419 |
+
"funding": {
|
| 1420 |
+
"url": "https://github.com/sponsors/ljharb"
|
| 1421 |
+
}
|
| 1422 |
+
},
|
| 1423 |
+
"node_modules/tailwindcss": {
|
| 1424 |
+
"version": "3.4.19",
|
| 1425 |
+
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.19.tgz",
|
| 1426 |
+
"integrity": "sha512-3ofp+LL8E+pK/JuPLPggVAIaEuhvIz4qNcf3nA1Xn2o/7fb7s/TYpHhwGDv1ZU3PkBluUVaF8PyCHcm48cKLWQ==",
|
| 1427 |
+
"dev": true,
|
| 1428 |
+
"license": "MIT",
|
| 1429 |
+
"dependencies": {
|
| 1430 |
+
"@alloc/quick-lru": "^5.2.0",
|
| 1431 |
+
"arg": "^5.0.2",
|
| 1432 |
+
"chokidar": "^3.6.0",
|
| 1433 |
+
"didyoumean": "^1.2.2",
|
| 1434 |
+
"dlv": "^1.1.3",
|
| 1435 |
+
"fast-glob": "^3.3.2",
|
| 1436 |
+
"glob-parent": "^6.0.2",
|
| 1437 |
+
"is-glob": "^4.0.3",
|
| 1438 |
+
"jiti": "^1.21.7",
|
| 1439 |
+
"lilconfig": "^3.1.3",
|
| 1440 |
+
"micromatch": "^4.0.8",
|
| 1441 |
+
"normalize-path": "^3.0.0",
|
| 1442 |
+
"object-hash": "^3.0.0",
|
| 1443 |
+
"picocolors": "^1.1.1",
|
| 1444 |
+
"postcss": "^8.4.47",
|
| 1445 |
+
"postcss-import": "^15.1.0",
|
| 1446 |
+
"postcss-js": "^4.0.1",
|
| 1447 |
+
"postcss-load-config": "^4.0.2 || ^5.0 || ^6.0",
|
| 1448 |
+
"postcss-nested": "^6.2.0",
|
| 1449 |
+
"postcss-selector-parser": "^6.1.2",
|
| 1450 |
+
"resolve": "^1.22.8",
|
| 1451 |
+
"sucrase": "^3.35.0"
|
| 1452 |
+
},
|
| 1453 |
+
"bin": {
|
| 1454 |
+
"tailwind": "lib/cli.js",
|
| 1455 |
+
"tailwindcss": "lib/cli.js"
|
| 1456 |
+
},
|
| 1457 |
+
"engines": {
|
| 1458 |
+
"node": ">=14.0.0"
|
| 1459 |
+
}
|
| 1460 |
+
},
|
| 1461 |
+
"node_modules/thenify": {
|
| 1462 |
+
"version": "3.3.1",
|
| 1463 |
+
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
|
| 1464 |
+
"integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==",
|
| 1465 |
+
"dev": true,
|
| 1466 |
+
"license": "MIT",
|
| 1467 |
+
"dependencies": {
|
| 1468 |
+
"any-promise": "^1.0.0"
|
| 1469 |
+
}
|
| 1470 |
+
},
|
| 1471 |
+
"node_modules/thenify-all": {
|
| 1472 |
+
"version": "1.6.0",
|
| 1473 |
+
"resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz",
|
| 1474 |
+
"integrity": "sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==",
|
| 1475 |
+
"dev": true,
|
| 1476 |
+
"license": "MIT",
|
| 1477 |
+
"dependencies": {
|
| 1478 |
+
"thenify": ">= 3.1.0 < 4"
|
| 1479 |
+
},
|
| 1480 |
+
"engines": {
|
| 1481 |
+
"node": ">=0.8"
|
| 1482 |
+
}
|
| 1483 |
+
},
|
| 1484 |
+
"node_modules/tinyglobby": {
|
| 1485 |
+
"version": "0.2.17",
|
| 1486 |
+
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",
|
| 1487 |
+
"integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==",
|
| 1488 |
+
"dev": true,
|
| 1489 |
+
"license": "MIT",
|
| 1490 |
+
"dependencies": {
|
| 1491 |
+
"fdir": "^6.5.0",
|
| 1492 |
+
"picomatch": "^4.0.4"
|
| 1493 |
+
},
|
| 1494 |
+
"engines": {
|
| 1495 |
+
"node": ">=12.0.0"
|
| 1496 |
+
},
|
| 1497 |
+
"funding": {
|
| 1498 |
+
"url": "https://github.com/sponsors/SuperchupuDev"
|
| 1499 |
+
}
|
| 1500 |
+
},
|
| 1501 |
+
"node_modules/tinyglobby/node_modules/fdir": {
|
| 1502 |
+
"version": "6.5.0",
|
| 1503 |
+
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
|
| 1504 |
+
"integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==",
|
| 1505 |
+
"dev": true,
|
| 1506 |
+
"license": "MIT",
|
| 1507 |
+
"engines": {
|
| 1508 |
+
"node": ">=12.0.0"
|
| 1509 |
+
},
|
| 1510 |
+
"peerDependencies": {
|
| 1511 |
+
"picomatch": "^3 || ^4"
|
| 1512 |
+
},
|
| 1513 |
+
"peerDependenciesMeta": {
|
| 1514 |
+
"picomatch": {
|
| 1515 |
+
"optional": true
|
| 1516 |
+
}
|
| 1517 |
+
}
|
| 1518 |
+
},
|
| 1519 |
+
"node_modules/tinyglobby/node_modules/picomatch": {
|
| 1520 |
+
"version": "4.0.7",
|
| 1521 |
+
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz",
|
| 1522 |
+
"integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==",
|
| 1523 |
+
"dev": true,
|
| 1524 |
+
"license": "MIT",
|
| 1525 |
+
"engines": {
|
| 1526 |
+
"node": ">=12"
|
| 1527 |
+
},
|
| 1528 |
+
"funding": {
|
| 1529 |
+
"url": "https://github.com/sponsors/jonschlinkert"
|
| 1530 |
+
}
|
| 1531 |
+
},
|
| 1532 |
+
"node_modules/to-regex-range": {
|
| 1533 |
+
"version": "5.0.1",
|
| 1534 |
+
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
|
| 1535 |
+
"integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==",
|
| 1536 |
+
"dev": true,
|
| 1537 |
+
"license": "MIT",
|
| 1538 |
+
"dependencies": {
|
| 1539 |
+
"is-number": "^7.0.0"
|
| 1540 |
+
},
|
| 1541 |
+
"engines": {
|
| 1542 |
+
"node": ">=8.0"
|
| 1543 |
+
}
|
| 1544 |
+
},
|
| 1545 |
+
"node_modules/ts-interface-checker": {
|
| 1546 |
+
"version": "0.1.13",
|
| 1547 |
+
"resolved": "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz",
|
| 1548 |
+
"integrity": "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==",
|
| 1549 |
+
"dev": true,
|
| 1550 |
+
"license": "Apache-2.0"
|
| 1551 |
+
},
|
| 1552 |
+
"node_modules/tslib": {
|
| 1553 |
+
"version": "2.9.1",
|
| 1554 |
+
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
|
| 1555 |
+
"integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
|
| 1556 |
+
"license": "0BSD"
|
| 1557 |
+
},
|
| 1558 |
+
"node_modules/typescript": {
|
| 1559 |
+
"version": "5.9.3",
|
| 1560 |
+
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
| 1561 |
+
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
| 1562 |
+
"dev": true,
|
| 1563 |
+
"license": "Apache-2.0",
|
| 1564 |
+
"bin": {
|
| 1565 |
+
"tsc": "bin/tsc",
|
| 1566 |
+
"tsserver": "bin/tsserver"
|
| 1567 |
+
},
|
| 1568 |
+
"engines": {
|
| 1569 |
+
"node": ">=14.17"
|
| 1570 |
+
}
|
| 1571 |
+
},
|
| 1572 |
+
"node_modules/undici-types": {
|
| 1573 |
+
"version": "6.21.0",
|
| 1574 |
+
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
|
| 1575 |
+
"integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
|
| 1576 |
+
"dev": true,
|
| 1577 |
+
"license": "MIT"
|
| 1578 |
+
},
|
| 1579 |
+
"node_modules/update-browserslist-db": {
|
| 1580 |
+
"version": "1.3.4",
|
| 1581 |
+
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.3.4.tgz",
|
| 1582 |
+
"integrity": "sha512-t8wonIOdQyOjtPd2VktlBu6QjTVTks6v8bSi7kd0r2Vll8TK1JYDZtRRdbmCHOAMphkZgrzK+L+vXK4pyZ8t4A==",
|
| 1583 |
+
"dev": true,
|
| 1584 |
+
"funding": [
|
| 1585 |
+
{
|
| 1586 |
+
"type": "opencollective",
|
| 1587 |
+
"url": "https://opencollective.com/browserslist"
|
| 1588 |
+
},
|
| 1589 |
+
{
|
| 1590 |
+
"type": "tidelift",
|
| 1591 |
+
"url": "https://tidelift.com/funding/github/npm/browserslist"
|
| 1592 |
+
},
|
| 1593 |
+
{
|
| 1594 |
+
"type": "github",
|
| 1595 |
+
"url": "https://github.com/sponsors/ai"
|
| 1596 |
+
}
|
| 1597 |
+
],
|
| 1598 |
+
"license": "MIT",
|
| 1599 |
+
"dependencies": {
|
| 1600 |
+
"escalade": "^3.2.0",
|
| 1601 |
+
"picocolors": "^1.1.1"
|
| 1602 |
+
},
|
| 1603 |
+
"bin": {
|
| 1604 |
+
"update-browserslist-db": "cli.js"
|
| 1605 |
+
},
|
| 1606 |
+
"peerDependencies": {
|
| 1607 |
+
"browserslist": ">= 4.21.0"
|
| 1608 |
+
}
|
| 1609 |
+
},
|
| 1610 |
+
"node_modules/util-deprecate": {
|
| 1611 |
+
"version": "1.0.2",
|
| 1612 |
+
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
| 1613 |
+
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
|
| 1614 |
+
"dev": true,
|
| 1615 |
+
"license": "MIT"
|
| 1616 |
+
}
|
| 1617 |
+
}
|
| 1618 |
+
}
|
frontend/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "xetcloud-nextjs",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"private": true,
|
| 5 |
+
"scripts": {
|
| 6 |
+
"dev": "next dev -p 3000",
|
| 7 |
+
"build": "next build",
|
| 8 |
+
"start": "next start -p 3000"
|
| 9 |
+
},
|
| 10 |
+
"dependencies": {
|
| 11 |
+
"lucide-react": "^0.454.0",
|
| 12 |
+
"next": "14.2.16",
|
| 13 |
+
"react": "^18.3.1",
|
| 14 |
+
"react-dom": "^18.3.1"
|
| 15 |
+
},
|
| 16 |
+
"devDependencies": {
|
| 17 |
+
"@types/node": "^20.17.0",
|
| 18 |
+
"@types/react": "^18.3.12",
|
| 19 |
+
"@types/react-dom": "^18.3.1",
|
| 20 |
+
"autoprefixer": "^10.4.20",
|
| 21 |
+
"postcss": "^8.4.47",
|
| 22 |
+
"tailwindcss": "^3.4.14",
|
| 23 |
+
"typescript": "^5.6.3"
|
| 24 |
+
}
|
| 25 |
+
}
|
frontend/postcss.config.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module.exports = {
|
| 2 |
+
plugins: {
|
| 3 |
+
tailwindcss: {},
|
| 4 |
+
autoprefixer: {},
|
| 5 |
+
},
|
| 6 |
+
};
|
frontend/src/app/activity/layout.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata } from "next";
|
| 2 |
+
|
| 3 |
+
export const metadata: Metadata = {
|
| 4 |
+
title: "Nhật ký Hoạt động & Kiểm toán Bảo mật — Upload ThTuanIT",
|
| 5 |
+
description:
|
| 6 |
+
"Theo dõi lịch sử xác thực, tải tệp, đổi tên đường dẫn và cập nhật quyền hạn RBAC theo thời gian thực trên Upload ThTuanIT.",
|
| 7 |
+
alternates: {
|
| 8 |
+
canonical: "/activity",
|
| 9 |
+
},
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
export default function ActivityLayout({ children }: { children: React.ReactNode }) {
|
| 13 |
+
return <>{children}</>;
|
| 14 |
+
}
|
frontend/src/app/activity/page.tsx
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Activity } from "lucide-react";
|
| 5 |
+
import { useCloud } from "@/context/CloudContext";
|
| 6 |
+
import { WorkspaceShell } from "@/components/WorkspaceShell";
|
| 7 |
+
|
| 8 |
+
export default function ActivityPage() {
|
| 9 |
+
const { auditLogs } = useCloud();
|
| 10 |
+
|
| 11 |
+
return (
|
| 12 |
+
<WorkspaceShell>
|
| 13 |
+
<div className="p-6 space-y-6 max-w-[1200px]">
|
| 14 |
+
<div className="glass rounded-3xl p-6 border border-white/10">
|
| 15 |
+
<h1 className="text-lg font-bold text-white mb-1 flex items-center gap-2">
|
| 16 |
+
<Activity className="w-5 h-5 text-indigo-400" /> Nhật ký Hoạt động Phiên làm việc (/activity)
|
| 17 |
+
</h1>
|
| 18 |
+
<p className="text-xs text-slate-400 mb-5">
|
| 19 |
+
Theo dõi toàn bộ thao tác xác thực, tải tệp, chỉnh sửa đường dẫn và phân quyền trong thời gian thực.
|
| 20 |
+
</p>
|
| 21 |
+
|
| 22 |
+
<div className="space-y-2.5">
|
| 23 |
+
{auditLogs.map((log) => (
|
| 24 |
+
<div
|
| 25 |
+
key={log.id}
|
| 26 |
+
className="p-3.5 rounded-2xl bg-slate-900/80 border border-white/5 flex items-center justify-between gap-4 text-xs"
|
| 27 |
+
>
|
| 28 |
+
<div className="flex items-center gap-3">
|
| 29 |
+
<span
|
| 30 |
+
className={`w-2 h-2 rounded-full ${
|
| 31 |
+
log.status === "success"
|
| 32 |
+
? "bg-emerald-400"
|
| 33 |
+
: log.status === "warn"
|
| 34 |
+
? "bg-rose-400"
|
| 35 |
+
: "bg-indigo-400"
|
| 36 |
+
}`}
|
| 37 |
+
/>
|
| 38 |
+
<span className="font-mono text-slate-400">{log.time}</span>
|
| 39 |
+
<span className="px-2 py-0.5 rounded bg-white/5 font-mono text-slate-300">@{log.actor}</span>
|
| 40 |
+
<span className="font-semibold text-white">{log.action}</span>
|
| 41 |
+
</div>
|
| 42 |
+
<span className="font-mono text-indigo-300 truncate max-w-xs">{log.target}</span>
|
| 43 |
+
</div>
|
| 44 |
+
))}
|
| 45 |
+
</div>
|
| 46 |
+
</div>
|
| 47 |
+
</div>
|
| 48 |
+
</WorkspaceShell>
|
| 49 |
+
);
|
| 50 |
+
}
|
frontend/src/app/admin/layout.tsx
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata } from "next";
|
| 2 |
+
|
| 3 |
+
export const metadata: Metadata = {
|
| 4 |
+
title: "Quản trị Người dùng & Phân quyền RBAC — Upload ThTuanIT",
|
| 5 |
+
description:
|
| 6 |
+
"Bảng điều khiển dành cho Quản trị viên để cấp hoặc thu hồi quyền Upload, Rename, Delete và quản lý tài khoản người dùng trên Upload ThTuanIT.",
|
| 7 |
+
robots: {
|
| 8 |
+
index: false,
|
| 9 |
+
follow: false,
|
| 10 |
+
},
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
export default function AdminLayout({ children }: { children: React.ReactNode }) {
|
| 14 |
+
return <>{children}</>;
|
| 15 |
+
}
|
frontend/src/app/admin/page.tsx
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useEffect } from "react";
|
| 4 |
+
import Link from "next/link";
|
| 5 |
+
import { UserPlus, Edit3, Trash2, Shield, Lock } from "lucide-react";
|
| 6 |
+
import { useCloud } from "@/context/CloudContext";
|
| 7 |
+
import { WorkspaceShell } from "@/components/WorkspaceShell";
|
| 8 |
+
|
| 9 |
+
function PermissionToggle({
|
| 10 |
+
checked,
|
| 11 |
+
disabled,
|
| 12 |
+
onChange,
|
| 13 |
+
}: {
|
| 14 |
+
checked: boolean;
|
| 15 |
+
disabled?: boolean;
|
| 16 |
+
onChange: () => void;
|
| 17 |
+
}) {
|
| 18 |
+
return (
|
| 19 |
+
<button
|
| 20 |
+
type="button"
|
| 21 |
+
disabled={disabled}
|
| 22 |
+
onClick={onChange}
|
| 23 |
+
className={`w-10 h-5 rounded-full transition relative inline-flex items-center p-0.5 ${
|
| 24 |
+
checked ? "bg-indigo-600" : "bg-slate-800 border border-white/10"
|
| 25 |
+
} ${disabled ? "opacity-60 cursor-not-allowed" : "cursor-pointer"}`}
|
| 26 |
+
>
|
| 27 |
+
<span
|
| 28 |
+
className={`w-4 h-4 rounded-full bg-white transition transform ${
|
| 29 |
+
checked ? "translate-x-5" : "translate-x-0"
|
| 30 |
+
}`}
|
| 31 |
+
/>
|
| 32 |
+
</button>
|
| 33 |
+
);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
export default function AdminPage() {
|
| 37 |
+
const {
|
| 38 |
+
token,
|
| 39 |
+
currentUser,
|
| 40 |
+
isAdmin,
|
| 41 |
+
usersList,
|
| 42 |
+
loadUsersList,
|
| 43 |
+
setEditingUser,
|
| 44 |
+
handleQuickTogglePermission,
|
| 45 |
+
handleDeleteUser,
|
| 46 |
+
} = useCloud();
|
| 47 |
+
|
| 48 |
+
useEffect(() => {
|
| 49 |
+
if (isAdmin && token) {
|
| 50 |
+
loadUsersList(token);
|
| 51 |
+
}
|
| 52 |
+
}, [isAdmin, token]);
|
| 53 |
+
|
| 54 |
+
return (
|
| 55 |
+
<WorkspaceShell>
|
| 56 |
+
{currentUser && !isAdmin ? (
|
| 57 |
+
<div className="p-8 max-w-lg mx-auto text-center space-y-4 my-auto">
|
| 58 |
+
<div className="w-14 h-14 mx-auto rounded-2xl bg-rose-500/15 border border-rose-500/30 flex items-center justify-center text-rose-400">
|
| 59 |
+
<Lock className="w-7 h-7" />
|
| 60 |
+
</div>
|
| 61 |
+
<h1 className="text-xl font-extrabold text-white">Khu vực giới hạn cho Quản trị viên (Admin)</h1>
|
| 62 |
+
<p className="text-xs text-slate-400 leading-relaxed">
|
| 63 |
+
Tài khoản hiện tại của bạn (<code className="text-indigo-300">@{currentUser.username}</code>) là tài khoản
|
| 64 |
+
Thành viên. Vui lòng đăng nhập bằng tài khoản <code className="text-amber-300">admin</code> để quản lý phân
|
| 65 |
+
quyền.
|
| 66 |
+
</p>
|
| 67 |
+
<Link
|
| 68 |
+
href="/dashboard"
|
| 69 |
+
className="inline-flex px-5 py-2.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white transition"
|
| 70 |
+
>
|
| 71 |
+
Quay về Tổng quan (/dashboard)
|
| 72 |
+
</Link>
|
| 73 |
+
</div>
|
| 74 |
+
) : (
|
| 75 |
+
<div className="p-6 space-y-6 max-w-[1400px]">
|
| 76 |
+
<div className="glass-panel rounded-3xl p-6 sm:p-8 flex flex-wrap items-center justify-between gap-4 border border-amber-500/30">
|
| 77 |
+
<div>
|
| 78 |
+
<span className="px-2.5 py-0.5 rounded-full text-[10px] font-mono font-bold uppercase bg-amber-500/20 text-amber-300 border border-amber-500/30">
|
| 79 |
+
IAM & Role-Based Access Control • /admin
|
| 80 |
+
</span>
|
| 81 |
+
<h1 className="text-xl sm:text-2xl font-extrabold text-white mt-1 flex items-center gap-2">
|
| 82 |
+
<Shield className="w-6 h-6 text-amber-400" />
|
| 83 |
+
<span>Quản trị Người dùng & Phân quyền Hệ thống</span>
|
| 84 |
+
</h1>
|
| 85 |
+
<p className="text-xs sm:text-sm text-slate-300 mt-1">
|
| 86 |
+
Chỉnh sửa trực tiếp quyền <code className="text-amber-300">Tải lên</code>,{" "}
|
| 87 |
+
<code className="text-amber-300">Đổi tên/Sửa</code>,{" "}
|
| 88 |
+
<code className="text-amber-300">Xóa file</code> hoặc nâng quyền Admin cho bất kỳ tài khoản nào.
|
| 89 |
+
</p>
|
| 90 |
+
</div>
|
| 91 |
+
|
| 92 |
+
<button
|
| 93 |
+
onClick={() =>
|
| 94 |
+
setEditingUser({
|
| 95 |
+
isNew: true,
|
| 96 |
+
username: "",
|
| 97 |
+
display_name: "",
|
| 98 |
+
role: "user",
|
| 99 |
+
password: "",
|
| 100 |
+
permissions: { can_upload: true, can_rename: false, can_delete: false },
|
| 101 |
+
active: true,
|
| 102 |
+
})
|
| 103 |
+
}
|
| 104 |
+
className="flex items-center gap-2 px-5 py-3 rounded-2xl bg-amber-500 hover:bg-amber-400 text-slate-950 font-bold text-xs sm:text-sm shadow-lg shadow-amber-500/25 transition"
|
| 105 |
+
>
|
| 106 |
+
<UserPlus className="w-4 h-4" />
|
| 107 |
+
<span>Tạo tài khoản mới</span>
|
| 108 |
+
</button>
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
<div className="glass rounded-3xl overflow-hidden border border-white/10">
|
| 112 |
+
<div className="overflow-x-auto">
|
| 113 |
+
<table className="w-full text-left border-collapse">
|
| 114 |
+
<thead>
|
| 115 |
+
<tr className="border-b border-white/10 text-[11px] font-semibold uppercase tracking-wider text-slate-400 bg-slate-900/70">
|
| 116 |
+
<th className="py-4 px-5">Thành viên</th>
|
| 117 |
+
<th className="py-4 px-4">Vai trò</th>
|
| 118 |
+
<th className="py-4 px-4 text-center">Quyền Upload</th>
|
| 119 |
+
<th className="py-4 px-4 text-center">Quyền Sửa/Đổi tên</th>
|
| 120 |
+
<th className="py-4 px-4 text-center">Quyền Xóa file</th>
|
| 121 |
+
<th className="py-4 px-4 text-center">Trạng thái</th>
|
| 122 |
+
<th className="py-4 px-5 text-right">Thao tác</th>
|
| 123 |
+
</tr>
|
| 124 |
+
</thead>
|
| 125 |
+
<tbody className="divide-y divide-white/5 text-sm">
|
| 126 |
+
{usersList.map((u) => {
|
| 127 |
+
const isRootAdmin = u.username === "admin";
|
| 128 |
+
return (
|
| 129 |
+
<tr key={u.username} className="hover:bg-white/5 transition">
|
| 130 |
+
<td className="py-4 px-5">
|
| 131 |
+
<div className="flex items-center gap-3">
|
| 132 |
+
<div
|
| 133 |
+
className={`w-9 h-9 rounded-xl flex items-center justify-center font-bold text-xs ${
|
| 134 |
+
u.role === "admin"
|
| 135 |
+
? "bg-amber-500/20 text-amber-300 border border-amber-500/30"
|
| 136 |
+
: "bg-indigo-500/20 text-indigo-300 border border-indigo-500/30"
|
| 137 |
+
}`}
|
| 138 |
+
>
|
| 139 |
+
{u.display_name.charAt(0).toUpperCase()}
|
| 140 |
+
</div>
|
| 141 |
+
<div>
|
| 142 |
+
<p className="font-semibold text-white">{u.display_name}</p>
|
| 143 |
+
<p className="text-xs font-mono text-slate-400">@{u.username}</p>
|
| 144 |
+
</div>
|
| 145 |
+
</div>
|
| 146 |
+
</td>
|
| 147 |
+
|
| 148 |
+
<td className="py-4 px-4">
|
| 149 |
+
<button
|
| 150 |
+
disabled={isRootAdmin}
|
| 151 |
+
onClick={() => handleQuickTogglePermission(u, "role")}
|
| 152 |
+
className={`px-2.5 py-1 rounded-lg text-xs font-mono font-bold uppercase transition ${
|
| 153 |
+
u.role === "admin"
|
| 154 |
+
? "bg-amber-500/20 text-amber-300 border border-amber-500/40"
|
| 155 |
+
: "bg-slate-800 text-slate-300 border border-white/10 hover:border-indigo-400"
|
| 156 |
+
} ${isRootAdmin ? "opacity-80 cursor-not-allowed" : "cursor-pointer"}`}
|
| 157 |
+
>
|
| 158 |
+
{u.role}
|
| 159 |
+
</button>
|
| 160 |
+
</td>
|
| 161 |
+
|
| 162 |
+
<td className="py-4 px-4 text-center">
|
| 163 |
+
<PermissionToggle
|
| 164 |
+
checked={u.role === "admin" || u.permissions.can_upload}
|
| 165 |
+
disabled={u.role === "admin"}
|
| 166 |
+
onChange={() => handleQuickTogglePermission(u, "can_upload")}
|
| 167 |
+
/>
|
| 168 |
+
</td>
|
| 169 |
+
|
| 170 |
+
<td className="py-4 px-4 text-center">
|
| 171 |
+
<PermissionToggle
|
| 172 |
+
checked={u.role === "admin" || u.permissions.can_rename}
|
| 173 |
+
disabled={u.role === "admin"}
|
| 174 |
+
onChange={() => handleQuickTogglePermission(u, "can_rename")}
|
| 175 |
+
/>
|
| 176 |
+
</td>
|
| 177 |
+
|
| 178 |
+
<td className="py-4 px-4 text-center">
|
| 179 |
+
<PermissionToggle
|
| 180 |
+
checked={u.role === "admin" || u.permissions.can_delete}
|
| 181 |
+
disabled={u.role === "admin"}
|
| 182 |
+
onChange={() => handleQuickTogglePermission(u, "can_delete")}
|
| 183 |
+
/>
|
| 184 |
+
</td>
|
| 185 |
+
|
| 186 |
+
<td className="py-4 px-4 text-center">
|
| 187 |
+
<button
|
| 188 |
+
disabled={isRootAdmin}
|
| 189 |
+
onClick={() => handleQuickTogglePermission(u, "active")}
|
| 190 |
+
className={`px-2.5 py-1 rounded-full text-[11px] font-semibold transition ${
|
| 191 |
+
u.active
|
| 192 |
+
? "bg-emerald-500/15 text-emerald-300 border border-emerald-500/30"
|
| 193 |
+
: "bg-rose-500/15 text-rose-300 border border-rose-500/30"
|
| 194 |
+
}`}
|
| 195 |
+
>
|
| 196 |
+
{u.active ? "Hoạt động" : "Đã khóa"}
|
| 197 |
+
</button>
|
| 198 |
+
</td>
|
| 199 |
+
|
| 200 |
+
<td className="py-4 px-5 text-right">
|
| 201 |
+
<div className="inline-flex items-center gap-1.5">
|
| 202 |
+
<button
|
| 203 |
+
onClick={() =>
|
| 204 |
+
setEditingUser({
|
| 205 |
+
isNew: false,
|
| 206 |
+
username: u.username,
|
| 207 |
+
display_name: u.display_name,
|
| 208 |
+
role: u.role,
|
| 209 |
+
password: "",
|
| 210 |
+
permissions: { ...u.permissions },
|
| 211 |
+
active: u.active,
|
| 212 |
+
})
|
| 213 |
+
}
|
| 214 |
+
className="px-3 py-1.5 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-medium text-slate-200 flex items-center gap-1.5"
|
| 215 |
+
>
|
| 216 |
+
<Edit3 className="w-3.5 h-3.5 text-amber-400" />
|
| 217 |
+
<span>Chỉnh sửa</span>
|
| 218 |
+
</button>
|
| 219 |
+
{!isRootAdmin && (
|
| 220 |
+
<button
|
| 221 |
+
onClick={() => handleDeleteUser(u.username)}
|
| 222 |
+
className="p-1.5 rounded-xl bg-rose-500/15 hover:bg-rose-500/30 text-rose-400"
|
| 223 |
+
>
|
| 224 |
+
<Trash2 className="w-4 h-4" />
|
| 225 |
+
</button>
|
| 226 |
+
)}
|
| 227 |
+
</div>
|
| 228 |
+
</td>
|
| 229 |
+
</tr>
|
| 230 |
+
);
|
| 231 |
+
})}
|
| 232 |
+
</tbody>
|
| 233 |
+
</table>
|
| 234 |
+
</div>
|
| 235 |
+
</div>
|
| 236 |
+
</div>
|
| 237 |
+
)}
|
| 238 |
+
</WorkspaceShell>
|
| 239 |
+
);
|
| 240 |
+
}
|
frontend/src/app/dashboard/layout.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata } from "next";
|
| 2 |
+
|
| 3 |
+
export const metadata: Metadata = {
|
| 4 |
+
title: "Bảng điều khiển Tổng quan — Upload ThTuanIT",
|
| 5 |
+
description:
|
| 6 |
+
"Theo dõi dung lượng lưu trữ trên Upload ThTuanIT, danh sách tệp tải lên gần đây và ma trận quyền hạn RBAC cá nhân.",
|
| 7 |
+
alternates: {
|
| 8 |
+
canonical: "/dashboard",
|
| 9 |
+
},
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
|
| 13 |
+
return <>{children}</>;
|
| 14 |
+
}
|
frontend/src/app/dashboard/page.tsx
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import Link from "next/link";
|
| 5 |
+
import {
|
| 6 |
+
Sparkles,
|
| 7 |
+
Folder,
|
| 8 |
+
Shield,
|
| 9 |
+
HardDrive,
|
| 10 |
+
Layers,
|
| 11 |
+
Server,
|
| 12 |
+
Clock,
|
| 13 |
+
ChevronRight,
|
| 14 |
+
Film,
|
| 15 |
+
Image as ImageIcon,
|
| 16 |
+
Archive,
|
| 17 |
+
FileCode2,
|
| 18 |
+
Eye,
|
| 19 |
+
Download,
|
| 20 |
+
} from "lucide-react";
|
| 21 |
+
import { useCloud } from "@/context/CloudContext";
|
| 22 |
+
import { formatBytes } from "@/lib/api";
|
| 23 |
+
import { WorkspaceShell } from "@/components/WorkspaceShell";
|
| 24 |
+
|
| 25 |
+
export default function DashboardPage() {
|
| 26 |
+
const {
|
| 27 |
+
currentUser,
|
| 28 |
+
bucketName,
|
| 29 |
+
hfVersion,
|
| 30 |
+
healthOk,
|
| 31 |
+
isAdmin,
|
| 32 |
+
canUpload,
|
| 33 |
+
canRename,
|
| 34 |
+
canDelete,
|
| 35 |
+
files,
|
| 36 |
+
stats,
|
| 37 |
+
setPreviewFile,
|
| 38 |
+
triggerDownload,
|
| 39 |
+
} = useCloud();
|
| 40 |
+
|
| 41 |
+
return (
|
| 42 |
+
<WorkspaceShell>
|
| 43 |
+
{currentUser && (
|
| 44 |
+
<div className="p-6 space-y-6 max-w-[1500px]">
|
| 45 |
+
{/* Welcome Banner */}
|
| 46 |
+
<div className="glass-panel rounded-3xl p-6 sm:p-8 border border-white/15 flex flex-col lg:flex-row lg:items-center justify-between gap-6">
|
| 47 |
+
<div className="space-y-2">
|
| 48 |
+
<div className="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-indigo-500/15 border border-indigo-500/30 text-xs font-mono text-indigo-300">
|
| 49 |
+
<Sparkles className="w-3.5 h-3.5 text-amber-400" />
|
| 50 |
+
<span>Upload ThTuanIT Dashboard • /dashboard</span>
|
| 51 |
+
</div>
|
| 52 |
+
<h1 className="text-2xl sm:text-3xl font-extrabold text-white">
|
| 53 |
+
Xin chào, {currentUser.display_name}!
|
| 54 |
+
</h1>
|
| 55 |
+
<p className="text-xs sm:text-sm text-slate-300 max-w-2xl">
|
| 56 |
+
Bạn đang truy cập hệ thống lưu trữ đám mây <code className="text-indigo-300 font-mono">Upload ThTuanIT</code> với quyền{" "}
|
| 57 |
+
<b className={isAdmin ? "text-amber-300" : "text-indigo-300"}>
|
| 58 |
+
{isAdmin
|
| 59 |
+
? "Quản trị viên hệ thống (Xem & Quản lý toàn bộ Kho lưu trữ)"
|
| 60 |
+
: `Thành viên (@${currentUser.username} - Chỉ hiển thị tệp của bạn)`}
|
| 61 |
+
</b>
|
| 62 |
+
.
|
| 63 |
+
</p>
|
| 64 |
+
</div>
|
| 65 |
+
|
| 66 |
+
<div className="flex flex-wrap items-center gap-3">
|
| 67 |
+
<Link
|
| 68 |
+
href="/explorer"
|
| 69 |
+
className="px-5 py-3 rounded-2xl bg-white/10 hover:bg-white/15 border border-white/15 text-xs font-bold text-white transition flex items-center gap-2"
|
| 70 |
+
>
|
| 71 |
+
<Folder className="w-4 h-4 text-indigo-400" />
|
| 72 |
+
<span>Mở Trình duyệt Tệp (/explorer)</span>
|
| 73 |
+
</Link>
|
| 74 |
+
{isAdmin && (
|
| 75 |
+
<Link
|
| 76 |
+
href="/admin"
|
| 77 |
+
className="px-5 py-3 rounded-2xl bg-amber-500 hover:bg-amber-400 text-slate-950 font-bold text-xs shadow-lg shadow-amber-500/25 transition flex items-center gap-2"
|
| 78 |
+
>
|
| 79 |
+
<Shield className="w-4 h-4" />
|
| 80 |
+
<span>Phân quyền Người dùng (/admin)</span>
|
| 81 |
+
</Link>
|
| 82 |
+
)}
|
| 83 |
+
</div>
|
| 84 |
+
</div>
|
| 85 |
+
|
| 86 |
+
{/* 4 KPI Stat Cards */}
|
| 87 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4">
|
| 88 |
+
<div className="glass-card rounded-2xl p-5">
|
| 89 |
+
<div className="flex items-center justify-between text-xs text-slate-400 mb-2">
|
| 90 |
+
<span>{isAdmin ? "TỔNG DUNG LƯỢNG BUCKET" : "DUNG LƯỢNG CỦA BẠN"}</span>
|
| 91 |
+
<HardDrive className="w-4 h-4 text-indigo-400" />
|
| 92 |
+
</div>
|
| 93 |
+
<p className="text-2xl font-extrabold text-white font-mono">{formatBytes(stats.totalSize)}</p>
|
| 94 |
+
<p className="text-[11px] text-emerald-400 mt-1 font-mono">Hạn mức: 10 GiB / request</p>
|
| 95 |
+
</div>
|
| 96 |
+
|
| 97 |
+
<div className="glass-card rounded-2xl p-5">
|
| 98 |
+
<div className="flex items-center justify-between text-xs text-slate-400 mb-2">
|
| 99 |
+
<span>{isAdmin ? "TỔNG SỐ TỆP TOÀN BUCKET" : "SỐ TỆP ĐÃ TẢI LÊN"}</span>
|
| 100 |
+
<Layers className="w-4 h-4 text-rose-400" />
|
| 101 |
+
</div>
|
| 102 |
+
<p className="text-2xl font-extrabold text-white font-mono">{files.length}</p>
|
| 103 |
+
<p className="text-[11px] text-slate-400 mt-1 font-mono">
|
| 104 |
+
{stats.counts.video} video • {stats.counts.archive} nén • {stats.counts.doc} khác
|
| 105 |
+
</p>
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
<div className="glass-card rounded-2xl p-5">
|
| 109 |
+
<div className="flex items-center justify-between text-xs text-slate-400 mb-2">
|
| 110 |
+
<span>TRẠNG THÁI HẠ TẦNG</span>
|
| 111 |
+
<Server className="w-4 h-4 text-emerald-400" />
|
| 112 |
+
</div>
|
| 113 |
+
<p className="text-2xl font-extrabold text-emerald-400 font-mono">
|
| 114 |
+
{healthOk ? "99.9% Online" : "Offline"}
|
| 115 |
+
</p>
|
| 116 |
+
<p className="text-[11px] text-slate-400 mt-1 font-mono">Upload ThTuanIT Core v{hfVersion}</p>
|
| 117 |
+
</div>
|
| 118 |
+
|
| 119 |
+
<div className="glass-card rounded-2xl p-5">
|
| 120 |
+
<div className="flex items-center justify-between text-xs text-slate-400 mb-2">
|
| 121 |
+
<span>PHẠM VI DỮ LIỆU ({currentUser.role.toUpperCase()})</span>
|
| 122 |
+
<Shield className="w-4 h-4 text-amber-400" />
|
| 123 |
+
</div>
|
| 124 |
+
<p className="text-xl font-extrabold text-amber-300 font-mono">
|
| 125 |
+
{isAdmin ? "Toàn bộ Bucket" : `Cá nhân (@${currentUser.username})`}
|
| 126 |
+
</p>
|
| 127 |
+
<p className="text-[11px] text-slate-400 mt-1 font-mono">
|
| 128 |
+
{isAdmin
|
| 129 |
+
? "Admin xem & quản lý tệp của mọi thành viên"
|
| 130 |
+
: "Chỉ hiển thị các tệp do chính bạn tải lên"}
|
| 131 |
+
</p>
|
| 132 |
+
</div>
|
| 133 |
+
</div>
|
| 134 |
+
|
| 135 |
+
{/* Recent Files & Quick Access */}
|
| 136 |
+
<div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
|
| 137 |
+
<div className="lg:col-span-8 glass rounded-3xl p-6 border border-white/10">
|
| 138 |
+
<div className="flex items-center justify-between mb-4">
|
| 139 |
+
<h2 className="text-sm font-bold uppercase tracking-wider text-slate-300 flex items-center gap-2">
|
| 140 |
+
<Clock className="w-4 h-4 text-indigo-400" />{" "}
|
| 141 |
+
{isAdmin ? "Tệp tin gần đây trên toàn Bucket" : `Tệp tin gần đây của @${currentUser.username}`}
|
| 142 |
+
</h2>
|
| 143 |
+
<Link
|
| 144 |
+
href="/explorer"
|
| 145 |
+
className="text-xs text-indigo-400 hover:text-indigo-300 font-semibold flex items-center gap-1"
|
| 146 |
+
>
|
| 147 |
+
<span>Xem tất cả</span>
|
| 148 |
+
<ChevronRight className="w-3.5 h-3.5" />
|
| 149 |
+
</Link>
|
| 150 |
+
</div>
|
| 151 |
+
|
| 152 |
+
<div className="divide-y divide-white/5">
|
| 153 |
+
{files.slice(0, 6).map((file) => (
|
| 154 |
+
<div
|
| 155 |
+
key={file.path}
|
| 156 |
+
className="py-3 flex items-center justify-between gap-4 hover:bg-white/5 px-3 rounded-xl transition"
|
| 157 |
+
>
|
| 158 |
+
<div
|
| 159 |
+
onClick={() => setPreviewFile(file)}
|
| 160 |
+
className="flex items-center gap-3 min-w-0 cursor-pointer"
|
| 161 |
+
>
|
| 162 |
+
<div className="w-9 h-9 rounded-xl bg-indigo-500/15 border border-indigo-500/30 flex items-center justify-center shrink-0">
|
| 163 |
+
{file.category === "video" ? (
|
| 164 |
+
<Film className="w-4 h-4 text-rose-400" />
|
| 165 |
+
) : file.category === "image" ? (
|
| 166 |
+
<ImageIcon className="w-4 h-4 text-indigo-400" />
|
| 167 |
+
) : file.category === "archive" ? (
|
| 168 |
+
<Archive className="w-4 h-4 text-amber-400" />
|
| 169 |
+
) : (
|
| 170 |
+
<FileCode2 className="w-4 h-4 text-emerald-400" />
|
| 171 |
+
)}
|
| 172 |
+
</div>
|
| 173 |
+
<div className="min-w-0">
|
| 174 |
+
<div className="flex items-center gap-2">
|
| 175 |
+
<p className="text-sm font-semibold text-white truncate">{file.name}</p>
|
| 176 |
+
<span className="px-1.5 py-0.5 rounded text-[10px] font-mono bg-indigo-500/15 text-indigo-300 border border-indigo-500/30 shrink-0">
|
| 177 |
+
@{file.owner}
|
| 178 |
+
</span>
|
| 179 |
+
</div>
|
| 180 |
+
<p className="text-xs font-mono text-slate-400 truncate">
|
| 181 |
+
{formatBytes(file.size)} • {file.updatedAt || "Root"}
|
| 182 |
+
</p>
|
| 183 |
+
</div>
|
| 184 |
+
</div>
|
| 185 |
+
|
| 186 |
+
<div className="flex items-center gap-1.5 shrink-0">
|
| 187 |
+
<button
|
| 188 |
+
onClick={() => setPreviewFile(file)}
|
| 189 |
+
className="p-2 rounded-lg bg-white/5 hover:bg-white/10 text-slate-300"
|
| 190 |
+
title="Xem trước"
|
| 191 |
+
>
|
| 192 |
+
<Eye className="w-4 h-4" />
|
| 193 |
+
</button>
|
| 194 |
+
<button
|
| 195 |
+
onClick={() => triggerDownload(file)}
|
| 196 |
+
className="p-2 rounded-lg bg-indigo-500/15 hover:bg-indigo-500/25 text-indigo-300"
|
| 197 |
+
title="Tải về"
|
| 198 |
+
>
|
| 199 |
+
<Download className="w-4 h-4" />
|
| 200 |
+
</button>
|
| 201 |
+
</div>
|
| 202 |
+
</div>
|
| 203 |
+
))}
|
| 204 |
+
{files.length === 0 && (
|
| 205 |
+
<p className="py-10 text-center text-xs text-slate-400">
|
| 206 |
+
Chưa có tệp tin nào trong không gian lưu trữ của bạn.
|
| 207 |
+
</p>
|
| 208 |
+
)}
|
| 209 |
+
</div>
|
| 210 |
+
</div>
|
| 211 |
+
|
| 212 |
+
{/* Right Column: User Permission Matrix Card */}
|
| 213 |
+
<div className="lg:col-span-4 glass rounded-3xl p-6 border border-white/10 flex flex-col justify-between space-y-4">
|
| 214 |
+
<div>
|
| 215 |
+
<h2 className="text-sm font-bold uppercase tracking-wider text-slate-300 mb-4 flex items-center gap-2">
|
| 216 |
+
<Shield className="w-4 h-4 text-amber-400" /> Ma trận Quyền hiện tại
|
| 217 |
+
</h2>
|
| 218 |
+
<div className="space-y-2.5 text-xs">
|
| 219 |
+
{[
|
| 220 |
+
{ label: "Xem & Phát trực tuyến Media", allowed: true },
|
| 221 |
+
{ label: "Tải tệp tin từ Bucket về máy", allowed: true },
|
| 222 |
+
{ label: "Tải tệp mới lên Bucket (Upload)", allowed: canUpload },
|
| 223 |
+
{ label: "Đổi tên / Di chuyển đường dẫn tệp", allowed: canRename },
|
| 224 |
+
{ label: "Xóa vĩnh viễn tệp khỏi Bucket", allowed: canDelete },
|
| 225 |
+
{ label: "Quản trị người dùng & Phân quyền", allowed: isAdmin },
|
| 226 |
+
].map((row, idx) => (
|
| 227 |
+
<div
|
| 228 |
+
key={idx}
|
| 229 |
+
className="flex items-center justify-between p-2.5 rounded-xl bg-slate-900/80 border border-white/5"
|
| 230 |
+
>
|
| 231 |
+
<span className={row.allowed ? "text-slate-200" : "text-slate-500"}>{row.label}</span>
|
| 232 |
+
{row.allowed ? (
|
| 233 |
+
<span className="px-2 py-0.5 rounded bg-emerald-500/15 text-emerald-300 font-mono text-[10px]">
|
| 234 |
+
ALLOWED
|
| 235 |
+
</span>
|
| 236 |
+
) : (
|
| 237 |
+
<span className="px-2 py-0.5 rounded bg-rose-500/15 text-rose-300 font-mono text-[10px]">
|
| 238 |
+
DENIED
|
| 239 |
+
</span>
|
| 240 |
+
)}
|
| 241 |
+
</div>
|
| 242 |
+
))}
|
| 243 |
+
</div>
|
| 244 |
+
</div>
|
| 245 |
+
|
| 246 |
+
{isAdmin && (
|
| 247 |
+
<Link
|
| 248 |
+
href="/admin"
|
| 249 |
+
className="w-full py-2.5 rounded-xl bg-amber-500/20 hover:bg-amber-500/30 border border-amber-500/40 text-amber-300 text-xs font-bold text-center transition block"
|
| 250 |
+
>
|
| 251 |
+
Chỉnh sửa quyền của các User (/admin) →
|
| 252 |
+
</Link>
|
| 253 |
+
)}
|
| 254 |
+
</div>
|
| 255 |
+
</div>
|
| 256 |
+
</div>
|
| 257 |
+
)}
|
| 258 |
+
</WorkspaceShell>
|
| 259 |
+
);
|
| 260 |
+
}
|
frontend/src/app/developers/layout.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata } from "next";
|
| 2 |
+
|
| 3 |
+
export const metadata: Metadata = {
|
| 4 |
+
title: "Tài liệu Tích hợp REST API & CLI — Upload ThTuanIT",
|
| 5 |
+
description:
|
| 6 |
+
"Hướng dẫn tích hợp RESTful API, Bearer Token HMAC-SHA256 và X-API-Key để tải lên, liệt kê, đổi tên và tải xuống tệp từ Upload ThTuanIT.",
|
| 7 |
+
alternates: {
|
| 8 |
+
canonical: "/developers",
|
| 9 |
+
},
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
export default function DevelopersLayout({ children }: { children: React.ReactNode }) {
|
| 13 |
+
return <>{children}</>;
|
| 14 |
+
}
|
frontend/src/app/developers/page.tsx
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Copy } from "lucide-react";
|
| 5 |
+
import { useCloud } from "@/context/CloudContext";
|
| 6 |
+
import { WorkspaceShell } from "@/components/WorkspaceShell";
|
| 7 |
+
import { NavbarPublic } from "@/components/NavbarPublic";
|
| 8 |
+
|
| 9 |
+
export default function DevelopersPage() {
|
| 10 |
+
const { token, currentUser, notify } = useCloud();
|
| 11 |
+
const sampleToken = token ? `${token.slice(0, 28)}...` : "<YOUR_BEARER_TOKEN>";
|
| 12 |
+
|
| 13 |
+
const content = (
|
| 14 |
+
<div className="p-6 space-y-6 max-w-[1300px] mx-auto">
|
| 15 |
+
<div className="glass-panel rounded-3xl p-6 sm:p-8 border border-indigo-500/30">
|
| 16 |
+
<span className="px-2.5 py-0.5 rounded-full text-[10px] font-mono font-bold uppercase bg-indigo-500/20 text-indigo-300 border border-indigo-500/30">
|
| 17 |
+
Developer Hub • /developers
|
| 18 |
+
</span>
|
| 19 |
+
<h1 className="text-2xl font-extrabold text-white mt-1">Tích hợp REST API & Bearer Token</h1>
|
| 20 |
+
<p className="text-xs sm:text-sm text-slate-300 mt-1">
|
| 21 |
+
Sử dụng Session Token hiện tại của bạn hoặc <code className="text-indigo-300">X-API-Key</code> để tự động hóa
|
| 22 |
+
việc tải lên, liệt kê và tải xuống tệp từ terminal hoặc ứng dụng CI/CD bên ngoài.
|
| 23 |
+
</p>
|
| 24 |
+
|
| 25 |
+
{token && (
|
| 26 |
+
<div className="mt-4 p-4 rounded-2xl bg-slate-950/90 border border-white/10 flex items-center justify-between gap-4">
|
| 27 |
+
<div className="min-w-0">
|
| 28 |
+
<p className="text-[11px] font-mono text-slate-400">BEARER TOKEN CỦA BẠN (Hiệu lực 7 ngày)</p>
|
| 29 |
+
<p className="text-xs font-mono text-emerald-300 truncate mt-0.5">{token}</p>
|
| 30 |
+
</div>
|
| 31 |
+
<button
|
| 32 |
+
onClick={() => {
|
| 33 |
+
navigator.clipboard.writeText(token);
|
| 34 |
+
notify("Đã sao chép Bearer Token!", "success");
|
| 35 |
+
}}
|
| 36 |
+
className="px-3.5 py-2 rounded-xl bg-white/10 hover:bg-white/15 text-xs font-semibold text-white shrink-0 flex items-center gap-1.5"
|
| 37 |
+
>
|
| 38 |
+
<Copy className="w-3.5 h-3.5" /> Sao chép Token
|
| 39 |
+
</button>
|
| 40 |
+
</div>
|
| 41 |
+
)}
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
| 45 |
+
{[
|
| 46 |
+
{
|
| 47 |
+
title: "1. Liệt kê danh sách tệp (theo quyền User/Admin)",
|
| 48 |
+
method: "GET /api/files",
|
| 49 |
+
code: `curl -s "http://localhost:8080/api/files" \\\n -H "Authorization: Bearer ${sampleToken}"`,
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
title: "2. Tải tệp mới lên Upload ThTuanIT (Turbo Upload)",
|
| 53 |
+
method: "POST /api/upload",
|
| 54 |
+
code: `curl -X POST "http://localhost:8080/api/upload" \\\n -H "Authorization: Bearer ${sampleToken}" \\\n -F "path=media/video.mp4" \\\n -F "file=@./video.mp4"`,
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
title: "3. Đổi tên / Di chuyển đường dẫn tệp (Zero-Copy Hash)",
|
| 58 |
+
method: "PUT /api/files",
|
| 59 |
+
code: `curl -X PUT "http://localhost:8080/api/files" \\\n -H "Authorization: Bearer ${sampleToken}" \\\n -H "Content-Type: application/json" \\\n -d '{"old_path":"media/video.mp4","new_path":"archive/video-2026.mp4"}'`,
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
title: "4. Tải tệp xuống hoặc Streaming HTTP Range",
|
| 63 |
+
method: "GET /api/download",
|
| 64 |
+
code: `curl -L "http://localhost:8080/api/download?path=111.mp4" \\\n -H "Authorization: Bearer ${sampleToken}" \\\n -o 111.mp4`,
|
| 65 |
+
},
|
| 66 |
+
].map((snip, idx) => (
|
| 67 |
+
<article key={idx} className="glass rounded-3xl p-5 border border-white/10 flex flex-col justify-between">
|
| 68 |
+
<div>
|
| 69 |
+
<div className="flex items-center justify-between mb-3">
|
| 70 |
+
<h2 className="text-sm font-bold text-white">{snip.title}</h2>
|
| 71 |
+
<span className="px-2 py-0.5 rounded text-[10px] font-mono bg-indigo-500/20 text-indigo-300 border border-indigo-500/30">
|
| 72 |
+
{snip.method}
|
| 73 |
+
</span>
|
| 74 |
+
</div>
|
| 75 |
+
<pre className="p-4 rounded-2xl bg-slate-950/90 border border-white/5 text-xs font-mono text-slate-300 overflow-x-auto">
|
| 76 |
+
{snip.code}
|
| 77 |
+
</pre>
|
| 78 |
+
</div>
|
| 79 |
+
</article>
|
| 80 |
+
))}
|
| 81 |
+
</div>
|
| 82 |
+
</div>
|
| 83 |
+
);
|
| 84 |
+
|
| 85 |
+
if (!currentUser) {
|
| 86 |
+
return (
|
| 87 |
+
<div className="min-h-screen flex flex-col bg-grid-pattern">
|
| 88 |
+
<NavbarPublic />
|
| 89 |
+
<main className="flex-1 py-6">{content}</main>
|
| 90 |
+
</div>
|
| 91 |
+
);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
return <WorkspaceShell>{content}</WorkspaceShell>;
|
| 95 |
+
}
|
frontend/src/app/explorer/layout.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata } from "next";
|
| 2 |
+
|
| 3 |
+
export const metadata: Metadata = {
|
| 4 |
+
title: "Trình duyệt Tệp Đám mây — Upload ThTuanIT",
|
| 5 |
+
description:
|
| 6 |
+
"Duyệt thư mục, tải tệp lớn tới 10 GiB với Turbo Parallel Upload, đổi tên tệp tức thì và phát trực tuyến Video trên Upload ThTuanIT.",
|
| 7 |
+
alternates: {
|
| 8 |
+
canonical: "/explorer",
|
| 9 |
+
},
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
export default function ExplorerLayout({ children }: { children: React.ReactNode }) {
|
| 13 |
+
return <>{children}</>;
|
| 14 |
+
}
|
frontend/src/app/explorer/page.tsx
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useMemo } from "react";
|
| 4 |
+
import {
|
| 5 |
+
HardDrive,
|
| 6 |
+
ChevronRight,
|
| 7 |
+
Shield,
|
| 8 |
+
LayoutGrid,
|
| 9 |
+
List,
|
| 10 |
+
Folder,
|
| 11 |
+
Film,
|
| 12 |
+
Image as ImageIcon,
|
| 13 |
+
Archive,
|
| 14 |
+
FileCode2,
|
| 15 |
+
Eye,
|
| 16 |
+
Download,
|
| 17 |
+
Edit3,
|
| 18 |
+
Trash2,
|
| 19 |
+
UploadCloud,
|
| 20 |
+
Share2,
|
| 21 |
+
} from "lucide-react";
|
| 22 |
+
import { useCloud } from "@/context/CloudContext";
|
| 23 |
+
import { formatBytes } from "@/lib/api";
|
| 24 |
+
import { FileNode } from "@/types/cloud";
|
| 25 |
+
import { WorkspaceShell } from "@/components/WorkspaceShell";
|
| 26 |
+
import { FileInspectorDrawer } from "@/components/FileInspectorDrawer";
|
| 27 |
+
|
| 28 |
+
export default function ExplorerPage() {
|
| 29 |
+
const {
|
| 30 |
+
currentUser,
|
| 31 |
+
bucketName,
|
| 32 |
+
isAdmin,
|
| 33 |
+
canUpload,
|
| 34 |
+
canRename,
|
| 35 |
+
canDelete,
|
| 36 |
+
files,
|
| 37 |
+
currentFolder,
|
| 38 |
+
setCurrentFolder,
|
| 39 |
+
categoryFilter,
|
| 40 |
+
setCategoryFilter,
|
| 41 |
+
searchQuery,
|
| 42 |
+
sortBy,
|
| 43 |
+
setSortBy,
|
| 44 |
+
viewMode,
|
| 45 |
+
setViewMode,
|
| 46 |
+
inspectedFile,
|
| 47 |
+
setInspectedFile,
|
| 48 |
+
setPreviewFile,
|
| 49 |
+
triggerDownload,
|
| 50 |
+
sharesMap,
|
| 51 |
+
setShareTarget,
|
| 52 |
+
setRenameTarget,
|
| 53 |
+
setNewPathInput,
|
| 54 |
+
handleDeleteFile,
|
| 55 |
+
setUploadTargetFolder,
|
| 56 |
+
setUploadModalOpen,
|
| 57 |
+
} = useCloud();
|
| 58 |
+
|
| 59 |
+
const folderParts = useMemo(
|
| 60 |
+
() => (currentFolder ? currentFolder.split("/").filter(Boolean) : []),
|
| 61 |
+
[currentFolder]
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
const { subfolders, visibleFiles } = useMemo(() => {
|
| 65 |
+
const subs = new Map<string, { name: string; count: number; size: number }>();
|
| 66 |
+
const list: FileNode[] = [];
|
| 67 |
+
const q = searchQuery.trim().toLowerCase();
|
| 68 |
+
|
| 69 |
+
files.forEach((f) => {
|
| 70 |
+
if (categoryFilter !== "all" && f.category !== categoryFilter) return;
|
| 71 |
+
if (q) {
|
| 72 |
+
if (f.path.toLowerCase().includes(q)) list.push(f);
|
| 73 |
+
return;
|
| 74 |
+
}
|
| 75 |
+
if (categoryFilter !== "all") {
|
| 76 |
+
list.push(f);
|
| 77 |
+
return;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
if (currentFolder === "") {
|
| 81 |
+
if (f.folder === "") {
|
| 82 |
+
list.push(f);
|
| 83 |
+
} else {
|
| 84 |
+
const top = f.folder.split("/")[0];
|
| 85 |
+
const cur = subs.get(top) || { name: top, count: 0, size: 0 };
|
| 86 |
+
cur.count++;
|
| 87 |
+
cur.size += f.size || 0;
|
| 88 |
+
subs.set(top, cur);
|
| 89 |
+
}
|
| 90 |
+
} else if (f.folder === currentFolder) {
|
| 91 |
+
list.push(f);
|
| 92 |
+
} else if (f.folder.startsWith(currentFolder + "/")) {
|
| 93 |
+
const rest = f.folder.slice(currentFolder.length + 1);
|
| 94 |
+
const nextName = rest.split("/")[0];
|
| 95 |
+
const fullPath = `${currentFolder}/${nextName}`;
|
| 96 |
+
const cur = subs.get(fullPath) || { name: nextName, count: 0, size: 0 };
|
| 97 |
+
cur.count++;
|
| 98 |
+
cur.size += f.size || 0;
|
| 99 |
+
subs.set(fullPath, cur);
|
| 100 |
+
}
|
| 101 |
+
});
|
| 102 |
+
|
| 103 |
+
list.sort((a, b) => {
|
| 104 |
+
if (sortBy === "size_desc") return b.size - a.size;
|
| 105 |
+
if (sortBy === "size_asc") return a.size - b.size;
|
| 106 |
+
if (sortBy === "name_asc") return a.name.localeCompare(b.name);
|
| 107 |
+
return (b.updatedAt || "").localeCompare(a.updatedAt || "");
|
| 108 |
+
});
|
| 109 |
+
|
| 110 |
+
return { subfolders: Array.from(subs.entries()), visibleFiles: list };
|
| 111 |
+
}, [files, currentFolder, categoryFilter, searchQuery, sortBy]);
|
| 112 |
+
|
| 113 |
+
return (
|
| 114 |
+
<WorkspaceShell>
|
| 115 |
+
{currentUser && (
|
| 116 |
+
<div className="p-6 flex-1 flex gap-6 max-w-[1600px]">
|
| 117 |
+
<div className="flex-1 flex flex-col space-y-4 min-w-0">
|
| 118 |
+
{/* Explorer Breadcrumb & Sort Bar */}
|
| 119 |
+
<div className="glass rounded-2xl p-3.5 sm:px-5 flex flex-wrap items-center justify-between gap-3">
|
| 120 |
+
<div className="flex items-center gap-1.5 text-sm overflow-x-auto py-1">
|
| 121 |
+
<button
|
| 122 |
+
onClick={() => {
|
| 123 |
+
setCurrentFolder("");
|
| 124 |
+
setCategoryFilter("all");
|
| 125 |
+
}}
|
| 126 |
+
className={`flex items-center gap-1.5 px-2.5 py-1 rounded-lg transition ${
|
| 127 |
+
folderParts.length === 0 && categoryFilter === "all"
|
| 128 |
+
? "bg-indigo-500/20 text-indigo-300 font-semibold"
|
| 129 |
+
: "text-slate-400 hover:text-white"
|
| 130 |
+
}`}
|
| 131 |
+
>
|
| 132 |
+
<HardDrive className="w-3.5 h-3.5" />
|
| 133 |
+
<span>{bucketName}</span>
|
| 134 |
+
</button>
|
| 135 |
+
{categoryFilter !== "all" && (
|
| 136 |
+
<>
|
| 137 |
+
<ChevronRight className="w-3.5 h-3.5 text-slate-600 shrink-0" />
|
| 138 |
+
<span className="px-2.5 py-1 rounded-lg bg-indigo-500/20 text-indigo-300 text-xs font-semibold uppercase">
|
| 139 |
+
Lọc: {categoryFilter}
|
| 140 |
+
</span>
|
| 141 |
+
</>
|
| 142 |
+
)}
|
| 143 |
+
{folderParts.map((part, idx) => {
|
| 144 |
+
const full = folderParts.slice(0, idx + 1).join("/");
|
| 145 |
+
const isLast = idx === folderParts.length - 1;
|
| 146 |
+
return (
|
| 147 |
+
<React.Fragment key={full}>
|
| 148 |
+
<ChevronRight className="w-3.5 h-3.5 text-slate-600 shrink-0" />
|
| 149 |
+
<button
|
| 150 |
+
onClick={() => setCurrentFolder(full)}
|
| 151 |
+
className={`px-2.5 py-1 rounded-lg transition truncate max-w-[160px] ${
|
| 152 |
+
isLast ? "bg-indigo-500/20 text-indigo-300 font-semibold" : "text-slate-400 hover:text-white"
|
| 153 |
+
}`}
|
| 154 |
+
>
|
| 155 |
+
{part}
|
| 156 |
+
</button>
|
| 157 |
+
</React.Fragment>
|
| 158 |
+
);
|
| 159 |
+
})}
|
| 160 |
+
</div>
|
| 161 |
+
|
| 162 |
+
<div className="flex items-center gap-2.5 ml-auto">
|
| 163 |
+
<span
|
| 164 |
+
className={`hidden sm:inline-flex items-center gap-1.5 px-2.5 py-1 rounded-xl text-[11px] font-mono border ${
|
| 165 |
+
isAdmin
|
| 166 |
+
? "bg-amber-500/15 text-amber-300 border-amber-500/30"
|
| 167 |
+
: "bg-emerald-500/15 text-emerald-300 border-emerald-500/30"
|
| 168 |
+
}`}
|
| 169 |
+
>
|
| 170 |
+
<Shield className="w-3.5 h-3.5" />
|
| 171 |
+
{isAdmin ? "Admin: Xem toàn bộ Bucket" : `Cá nhân: Chỉ tệp của @${currentUser.username}`}
|
| 172 |
+
</span>
|
| 173 |
+
|
| 174 |
+
<select
|
| 175 |
+
value={sortBy}
|
| 176 |
+
onChange={(e) => setSortBy(e.target.value as any)}
|
| 177 |
+
className="bg-slate-900/90 border border-white/10 rounded-xl px-3 py-1.5 text-xs text-slate-200 focus:outline-none"
|
| 178 |
+
>
|
| 179 |
+
<option value="date_desc">Mới nhất trước</option>
|
| 180 |
+
<option value="size_desc">Dung lượng giảm dần</option>
|
| 181 |
+
<option value="size_asc">Dung lượng tăng dần</option>
|
| 182 |
+
<option value="name_asc">Tên A → Z</option>
|
| 183 |
+
</select>
|
| 184 |
+
|
| 185 |
+
<div className="flex items-center bg-slate-900/90 p-1 rounded-xl border border-white/10">
|
| 186 |
+
<button
|
| 187 |
+
onClick={() => setViewMode("grid")}
|
| 188 |
+
className={`p-1.5 rounded-lg transition ${
|
| 189 |
+
viewMode === "grid" ? "bg-indigo-600 text-white" : "text-slate-400 hover:text-white"
|
| 190 |
+
}`}
|
| 191 |
+
>
|
| 192 |
+
<LayoutGrid className="w-4 h-4" />
|
| 193 |
+
</button>
|
| 194 |
+
<button
|
| 195 |
+
onClick={() => setViewMode("list")}
|
| 196 |
+
className={`p-1.5 rounded-lg transition ${
|
| 197 |
+
viewMode === "list" ? "bg-indigo-600 text-white" : "text-slate-400 hover:text-white"
|
| 198 |
+
}`}
|
| 199 |
+
>
|
| 200 |
+
<List className="w-4 h-4" />
|
| 201 |
+
</button>
|
| 202 |
+
</div>
|
| 203 |
+
</div>
|
| 204 |
+
</div>
|
| 205 |
+
|
| 206 |
+
{/* Files & Folders Container */}
|
| 207 |
+
<div className="glass rounded-3xl p-5 flex-1 min-h-[500px] flex flex-col justify-between">
|
| 208 |
+
<div className="space-y-6">
|
| 209 |
+
{/* Subfolders */}
|
| 210 |
+
{subfolders.length > 0 && (
|
| 211 |
+
<div>
|
| 212 |
+
<h2 className="text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3">
|
| 213 |
+
Thư mục ({subfolders.length})
|
| 214 |
+
</h2>
|
| 215 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4 gap-3.5">
|
| 216 |
+
{subfolders.map(([folderPath, info]) => (
|
| 217 |
+
<div
|
| 218 |
+
key={folderPath}
|
| 219 |
+
onClick={() => setCurrentFolder(folderPath)}
|
| 220 |
+
className="glass-card rounded-2xl p-4 cursor-pointer flex items-center gap-3.5 group"
|
| 221 |
+
>
|
| 222 |
+
<div className="w-11 h-11 rounded-xl bg-amber-500/15 border border-amber-500/30 flex items-center justify-center text-amber-400">
|
| 223 |
+
<Folder className="w-5 h-5" />
|
| 224 |
+
</div>
|
| 225 |
+
<div className="min-w-0 flex-1">
|
| 226 |
+
<p className="text-sm font-semibold text-slate-100 truncate group-hover:text-amber-300">
|
| 227 |
+
{info.name}
|
| 228 |
+
</p>
|
| 229 |
+
<p className="text-xs text-slate-400 font-mono">
|
| 230 |
+
{info.count} tệp • {formatBytes(info.size)}
|
| 231 |
+
</p>
|
| 232 |
+
</div>
|
| 233 |
+
<ChevronRight className="w-4 h-4 text-slate-500" />
|
| 234 |
+
</div>
|
| 235 |
+
))}
|
| 236 |
+
</div>
|
| 237 |
+
</div>
|
| 238 |
+
)}
|
| 239 |
+
|
| 240 |
+
{/* Files */}
|
| 241 |
+
{visibleFiles.length > 0 ? (
|
| 242 |
+
<div>
|
| 243 |
+
<h2 className="text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3">
|
| 244 |
+
Tệp tin ({visibleFiles.length})
|
| 245 |
+
</h2>
|
| 246 |
+
{viewMode === "grid" ? (
|
| 247 |
+
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4">
|
| 248 |
+
{visibleFiles.map((file) => {
|
| 249 |
+
const selected = inspectedFile?.path === file.path;
|
| 250 |
+
return (
|
| 251 |
+
<div
|
| 252 |
+
key={file.path}
|
| 253 |
+
onClick={() => setInspectedFile(file)}
|
| 254 |
+
className={`glass-card rounded-2xl p-4 flex flex-col justify-between cursor-pointer group ${
|
| 255 |
+
selected ? "ring-2 ring-indigo-500 border-indigo-500/60" : ""
|
| 256 |
+
}`}
|
| 257 |
+
>
|
| 258 |
+
<div>
|
| 259 |
+
<div className="flex items-start justify-between gap-3 mb-3">
|
| 260 |
+
<div className="w-11 h-11 rounded-xl bg-indigo-500/15 border border-indigo-500/30 flex items-center justify-center">
|
| 261 |
+
{file.category === "video" ? (
|
| 262 |
+
<Film className="w-5 h-5 text-rose-400" />
|
| 263 |
+
) : file.category === "image" ? (
|
| 264 |
+
<ImageIcon className="w-5 h-5 text-indigo-400" />
|
| 265 |
+
) : file.category === "archive" ? (
|
| 266 |
+
<Archive className="w-5 h-5 text-amber-400" />
|
| 267 |
+
) : (
|
| 268 |
+
<FileCode2 className="w-5 h-5 text-emerald-400" />
|
| 269 |
+
)}
|
| 270 |
+
</div>
|
| 271 |
+
<div className="flex items-center gap-1.5">
|
| 272 |
+
{sharesMap[file.path]?.enabled && (
|
| 273 |
+
<button
|
| 274 |
+
onClick={(e) => {
|
| 275 |
+
e.stopPropagation();
|
| 276 |
+
setShareTarget(file);
|
| 277 |
+
}}
|
| 278 |
+
className="px-2 py-0.5 rounded-md text-[10px] font-mono font-bold bg-emerald-500/20 text-emerald-300 border border-emerald-500/40 flex items-center gap-1"
|
| 279 |
+
title="Đang bật chia sẻ qua Link"
|
| 280 |
+
>
|
| 281 |
+
<Share2 className="w-2.5 h-2.5" />
|
| 282 |
+
<span>
|
| 283 |
+
{(sharesMap[file.path]?.requests || []).filter((r) => r.status === "pending")
|
| 284 |
+
.length > 0
|
| 285 |
+
? `${
|
| 286 |
+
(sharesMap[file.path]?.requests || []).filter(
|
| 287 |
+
(r) => r.status === "pending"
|
| 288 |
+
).length
|
| 289 |
+
} chờ duyệt`
|
| 290 |
+
: "Đang Share"}
|
| 291 |
+
</span>
|
| 292 |
+
</button>
|
| 293 |
+
)}
|
| 294 |
+
<span className="px-2 py-0.5 rounded-md text-[10px] font-mono font-semibold bg-white/5 text-slate-300 border border-white/10 uppercase">
|
| 295 |
+
{file.ext || "FILE"}
|
| 296 |
+
</span>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
<h3 className="text-sm font-semibold text-slate-100 truncate group-hover:text-indigo-300">
|
| 300 |
+
{file.name}
|
| 301 |
+
</h3>
|
| 302 |
+
<div className="flex items-center justify-between gap-2 mt-1">
|
| 303 |
+
<p className="text-[11px] text-slate-400 font-mono truncate">
|
| 304 |
+
{file.folder ? `📁 ${file.folder}` : "Root"}
|
| 305 |
+
</p>
|
| 306 |
+
<span className="px-1.5 py-0.5 rounded text-[10px] font-mono bg-indigo-500/15 text-indigo-300 border border-indigo-500/30 shrink-0">
|
| 307 |
+
@{file.owner}
|
| 308 |
+
</span>
|
| 309 |
+
</div>
|
| 310 |
+
</div>
|
| 311 |
+
|
| 312 |
+
<div
|
| 313 |
+
onClick={(e) => e.stopPropagation()}
|
| 314 |
+
className="mt-4 pt-3 border-t border-white/5 flex items-center justify-between text-xs text-slate-400"
|
| 315 |
+
>
|
| 316 |
+
<span className="font-mono text-[11px] text-slate-200 font-medium">
|
| 317 |
+
{formatBytes(file.size)}
|
| 318 |
+
</span>
|
| 319 |
+
<div className="flex items-center gap-1">
|
| 320 |
+
<button
|
| 321 |
+
onClick={() => setShareTarget(file)}
|
| 322 |
+
className={`p-1.5 rounded-lg transition ${
|
| 323 |
+
sharesMap[file.path]?.enabled
|
| 324 |
+
? "bg-emerald-500/20 text-emerald-300 hover:bg-emerald-500/30"
|
| 325 |
+
: "hover:bg-emerald-500/20 text-emerald-400"
|
| 326 |
+
}`}
|
| 327 |
+
title="Chia sẻ nhanh qua Link"
|
| 328 |
+
>
|
| 329 |
+
<Share2 className="w-3.5 h-3.5" />
|
| 330 |
+
</button>
|
| 331 |
+
<button
|
| 332 |
+
onClick={() => setPreviewFile(file)}
|
| 333 |
+
className="p-1.5 rounded-lg hover:bg-white/10 text-slate-300"
|
| 334 |
+
title="Phát / Xem trước"
|
| 335 |
+
>
|
| 336 |
+
<Eye className="w-3.5 h-3.5" />
|
| 337 |
+
</button>
|
| 338 |
+
<button
|
| 339 |
+
onClick={() => triggerDownload(file)}
|
| 340 |
+
className="p-1.5 rounded-lg hover:bg-indigo-500/20 text-indigo-400"
|
| 341 |
+
title="Tải xuống"
|
| 342 |
+
>
|
| 343 |
+
<Download className="w-3.5 h-3.5" />
|
| 344 |
+
</button>
|
| 345 |
+
{canRename && (
|
| 346 |
+
<button
|
| 347 |
+
onClick={() => {
|
| 348 |
+
setRenameTarget(file);
|
| 349 |
+
setNewPathInput(file.path);
|
| 350 |
+
}}
|
| 351 |
+
className="p-1.5 rounded-lg hover:bg-amber-500/20 text-amber-400"
|
| 352 |
+
title="Đổi tên / Di chuyển"
|
| 353 |
+
>
|
| 354 |
+
<Edit3 className="w-3.5 h-3.5" />
|
| 355 |
+
</button>
|
| 356 |
+
)}
|
| 357 |
+
{canDelete && (
|
| 358 |
+
<button
|
| 359 |
+
onClick={() => handleDeleteFile(file)}
|
| 360 |
+
className="p-1.5 rounded-lg hover:bg-rose-500/20 text-rose-400"
|
| 361 |
+
title="Xóa tệp"
|
| 362 |
+
>
|
| 363 |
+
<Trash2 className="w-3.5 h-3.5" />
|
| 364 |
+
</button>
|
| 365 |
+
)}
|
| 366 |
+
</div>
|
| 367 |
+
</div>
|
| 368 |
+
</div>
|
| 369 |
+
);
|
| 370 |
+
})}
|
| 371 |
+
</div>
|
| 372 |
+
) : (
|
| 373 |
+
<div className="overflow-x-auto rounded-2xl border border-white/10">
|
| 374 |
+
<table className="w-full text-left border-collapse">
|
| 375 |
+
<thead>
|
| 376 |
+
<tr className="border-b border-white/10 text-[11px] font-semibold uppercase tracking-wider text-slate-400 bg-slate-900/60">
|
| 377 |
+
<th className="py-3 px-4">Tên tệp</th>
|
| 378 |
+
<th className="py-3 px-4">Người tải lên</th>
|
| 379 |
+
<th className="py-3 px-4 hidden md:table-cell">Thư mục</th>
|
| 380 |
+
<th className="py-3 px-4">Kích thước</th>
|
| 381 |
+
<th className="py-3 px-4 hidden sm:table-cell">Cập nhật</th>
|
| 382 |
+
<th className="py-3 px-4 text-right">Thao tác</th>
|
| 383 |
+
</tr>
|
| 384 |
+
</thead>
|
| 385 |
+
<tbody className="divide-y divide-white/5 text-sm">
|
| 386 |
+
{visibleFiles.map((file) => (
|
| 387 |
+
<tr
|
| 388 |
+
key={file.path}
|
| 389 |
+
onClick={() => setInspectedFile(file)}
|
| 390 |
+
className="hover:bg-white/5 transition cursor-pointer"
|
| 391 |
+
>
|
| 392 |
+
<td className="py-3 px-4 font-medium text-slate-100">{file.name}</td>
|
| 393 |
+
<td className="py-3 px-4">
|
| 394 |
+
<span className="px-2 py-0.5 rounded text-xs font-mono bg-indigo-500/15 text-indigo-300 border border-indigo-500/30">
|
| 395 |
+
@{file.owner}
|
| 396 |
+
</span>
|
| 397 |
+
</td>
|
| 398 |
+
<td className="py-3 px-4 hidden md:table-cell font-mono text-xs text-slate-400">
|
| 399 |
+
{file.folder || "/"}
|
| 400 |
+
</td>
|
| 401 |
+
<td className="py-3 px-4 font-mono text-xs text-slate-200">
|
| 402 |
+
{formatBytes(file.size)}
|
| 403 |
+
</td>
|
| 404 |
+
<td className="py-3 px-4 hidden sm:table-cell font-mono text-xs text-slate-400">
|
| 405 |
+
{file.updatedAt || "—"}
|
| 406 |
+
</td>
|
| 407 |
+
<td onClick={(e) => e.stopPropagation()} className="py-3 px-4 text-right">
|
| 408 |
+
<div className="inline-flex items-center gap-1">
|
| 409 |
+
<button
|
| 410 |
+
onClick={() => setShareTarget(file)}
|
| 411 |
+
className={`p-1.5 rounded-lg transition ${
|
| 412 |
+
sharesMap[file.path]?.enabled
|
| 413 |
+
? "bg-emerald-500/20 text-emerald-300 hover:bg-emerald-500/30"
|
| 414 |
+
: "hover:bg-emerald-500/20 text-emerald-400"
|
| 415 |
+
}`}
|
| 416 |
+
title="Chia sẻ nhanh qua Link"
|
| 417 |
+
>
|
| 418 |
+
<Share2 className="w-4 h-4" />
|
| 419 |
+
</button>
|
| 420 |
+
<button
|
| 421 |
+
onClick={() => setPreviewFile(file)}
|
| 422 |
+
className="p-1.5 rounded-lg hover:bg-white/10 text-slate-300"
|
| 423 |
+
>
|
| 424 |
+
<Eye className="w-4 h-4" />
|
| 425 |
+
</button>
|
| 426 |
+
<button
|
| 427 |
+
onClick={() => triggerDownload(file)}
|
| 428 |
+
className="p-1.5 rounded-lg hover:bg-indigo-500/20 text-indigo-400"
|
| 429 |
+
>
|
| 430 |
+
<Download className="w-4 h-4" />
|
| 431 |
+
</button>
|
| 432 |
+
{canRename && (
|
| 433 |
+
<button
|
| 434 |
+
onClick={() => {
|
| 435 |
+
setRenameTarget(file);
|
| 436 |
+
setNewPathInput(file.path);
|
| 437 |
+
}}
|
| 438 |
+
className="p-1.5 rounded-lg hover:bg-amber-500/20 text-amber-400"
|
| 439 |
+
>
|
| 440 |
+
<Edit3 className="w-4 h-4" />
|
| 441 |
+
</button>
|
| 442 |
+
)}
|
| 443 |
+
{canDelete && (
|
| 444 |
+
<button
|
| 445 |
+
onClick={() => handleDeleteFile(file)}
|
| 446 |
+
className="p-1.5 rounded-lg hover:bg-rose-500/20 text-rose-400"
|
| 447 |
+
>
|
| 448 |
+
<Trash2 className="w-4 h-4" />
|
| 449 |
+
</button>
|
| 450 |
+
)}
|
| 451 |
+
</div>
|
| 452 |
+
</td>
|
| 453 |
+
</tr>
|
| 454 |
+
))}
|
| 455 |
+
</tbody>
|
| 456 |
+
</table>
|
| 457 |
+
</div>
|
| 458 |
+
)}
|
| 459 |
+
</div>
|
| 460 |
+
) : (
|
| 461 |
+
subfolders.length === 0 && (
|
| 462 |
+
<div className="py-16 text-center space-y-3">
|
| 463 |
+
<p className="text-sm font-semibold text-slate-300">
|
| 464 |
+
{isAdmin
|
| 465 |
+
? "Không có tệp tin nào khớp với bộ lọc hiện tại."
|
| 466 |
+
: `Bạn (@${currentUser.username}) chưa tải lên tệp tin nào trong thư mục này.`}
|
| 467 |
+
</p>
|
| 468 |
+
{!isAdmin && (
|
| 469 |
+
<p className="text-xs text-slate-400 max-w-md mx-auto">
|
| 470 |
+
Chế độ bảo mật cá nhân đang bật: Mỗi thành viên chỉ nhìn thấy và quản lý các tệp do chính
|
| 471 |
+
mình tải lên.
|
| 472 |
+
</p>
|
| 473 |
+
)}
|
| 474 |
+
{canUpload && (
|
| 475 |
+
<button
|
| 476 |
+
onClick={() => {
|
| 477 |
+
setUploadTargetFolder(currentFolder);
|
| 478 |
+
setUploadModalOpen(true);
|
| 479 |
+
}}
|
| 480 |
+
className="inline-flex items-center gap-2 px-4 py-2 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white transition"
|
| 481 |
+
>
|
| 482 |
+
<UploadCloud className="w-4 h-4" />
|
| 483 |
+
<span>Tải tệp đầu tiên của bạn lên</span>
|
| 484 |
+
</button>
|
| 485 |
+
)}
|
| 486 |
+
</div>
|
| 487 |
+
)
|
| 488 |
+
)}
|
| 489 |
+
</div>
|
| 490 |
+
|
| 491 |
+
<div className="mt-6 pt-3 border-t border-white/5 flex items-center justify-between text-[11px] text-slate-400 font-mono">
|
| 492 |
+
<span>
|
| 493 |
+
Hiển thị {subfolders.length} thư mục, {visibleFiles.length} tệp tin
|
| 494 |
+
</span>
|
| 495 |
+
<span>Nhấn vào 1 tệp để mở bảng Chi tiết bên phải</span>
|
| 496 |
+
</div>
|
| 497 |
+
</div>
|
| 498 |
+
</div>
|
| 499 |
+
|
| 500 |
+
<FileInspectorDrawer />
|
| 501 |
+
</div>
|
| 502 |
+
)}
|
| 503 |
+
</WorkspaceShell>
|
| 504 |
+
);
|
| 505 |
+
}
|
frontend/src/app/globals.css
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@tailwind base;
|
| 2 |
+
@tailwind components;
|
| 3 |
+
@tailwind utilities;
|
| 4 |
+
|
| 5 |
+
:root {
|
| 6 |
+
color-scheme: dark;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
body {
|
| 10 |
+
background-color: #03050c;
|
| 11 |
+
color: #f8fafc;
|
| 12 |
+
overflow-x: hidden;
|
| 13 |
+
background-image:
|
| 14 |
+
radial-gradient(circle at 12% 8%, rgba(99, 102, 241, 0.14) 0px, transparent 40%),
|
| 15 |
+
radial-gradient(circle at 88% 12%, rgba(139, 92, 246, 0.12) 0px, transparent 42%),
|
| 16 |
+
radial-gradient(circle at 50% 90%, rgba(16, 185, 129, 0.08) 0px, transparent 48%);
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
/* Subtle engineering grid pattern */
|
| 20 |
+
.bg-grid-pattern {
|
| 21 |
+
background-size: 40px 40px;
|
| 22 |
+
background-image:
|
| 23 |
+
linear-gradient(to right, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
|
| 24 |
+
linear-gradient(to bottom, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
.glass {
|
| 28 |
+
background: rgba(10, 14, 26, 0.72);
|
| 29 |
+
backdrop-filter: blur(24px);
|
| 30 |
+
-webkit-backdrop-filter: blur(24px);
|
| 31 |
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
.glass-panel {
|
| 35 |
+
background: linear-gradient(180deg, rgba(17, 24, 39, 0.75) 0%, rgba(10, 14, 26, 0.88) 100%);
|
| 36 |
+
backdrop-filter: blur(20px);
|
| 37 |
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
| 38 |
+
box-shadow: 0 20px 50px -15px rgba(0, 0, 0, 0.7);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
.glass-card {
|
| 42 |
+
background: linear-gradient(145deg, rgba(30, 41, 59, 0.42), rgba(15, 23, 42, 0.72));
|
| 43 |
+
backdrop-filter: blur(16px);
|
| 44 |
+
border: 1px solid rgba(255, 255, 255, 0.07);
|
| 45 |
+
transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
.glass-card:hover {
|
| 49 |
+
border-color: rgba(99, 102, 241, 0.45);
|
| 50 |
+
transform: translateY(-2px);
|
| 51 |
+
box-shadow: 0 14px 34px -10px rgba(0, 0, 0, 0.65), 0 0 24px -6px rgba(99, 102, 241, 0.22);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.glow-indigo {
|
| 55 |
+
box-shadow: 0 0 40px -10px rgba(99, 102, 241, 0.45);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
::-webkit-scrollbar {
|
| 59 |
+
width: 6px;
|
| 60 |
+
height: 6px;
|
| 61 |
+
}
|
| 62 |
+
::-webkit-scrollbar-track {
|
| 63 |
+
background: #03050c;
|
| 64 |
+
}
|
| 65 |
+
::-webkit-scrollbar-thumb {
|
| 66 |
+
background: #1e293b;
|
| 67 |
+
border-radius: 9999px;
|
| 68 |
+
}
|
| 69 |
+
::-webkit-scrollbar-thumb:hover {
|
| 70 |
+
background: #475569;
|
| 71 |
+
}
|
frontend/src/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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata, Viewport } from "next";
|
| 2 |
+
import { Inter, JetBrains_Mono } from "next/font/google";
|
| 3 |
+
import { CloudProvider } from "@/context/CloudContext";
|
| 4 |
+
import "./globals.css";
|
| 5 |
+
|
| 6 |
+
const inter = Inter({
|
| 7 |
+
subsets: ["latin", "vietnamese"],
|
| 8 |
+
variable: "--font-inter",
|
| 9 |
+
display: "swap",
|
| 10 |
+
});
|
| 11 |
+
const mono = JetBrains_Mono({
|
| 12 |
+
subsets: ["latin"],
|
| 13 |
+
variable: "--font-mono",
|
| 14 |
+
display: "swap",
|
| 15 |
+
});
|
| 16 |
+
|
| 17 |
+
export const viewport: Viewport = {
|
| 18 |
+
themeColor: "#03050c",
|
| 19 |
+
width: "device-width",
|
| 20 |
+
initialScale: 1,
|
| 21 |
+
};
|
| 22 |
+
|
| 23 |
+
export const metadata: Metadata = {
|
| 24 |
+
metadataBase: new URL("http://localhost:3000"),
|
| 25 |
+
title: {
|
| 26 |
+
default: "Upload ThTuanIT — Nền tảng Lưu trữ & Tải tệp Đám mây Siêu Tốc",
|
| 27 |
+
template: "%s | Upload ThTuanIT",
|
| 28 |
+
},
|
| 29 |
+
description:
|
| 30 |
+
"Upload ThTuanIT là nền tảng lưu trữ đám mây thế hệ mới hỗ trợ Turbo Parallel Upload tới 10 GiB/file, cô lập không gian tệp cá nhân theo từng thành viên, phát trực tuyến Video 4K HTTP Range và Quản trị Phân quyền RBAC chuyên nghiệp.",
|
| 31 |
+
keywords: [
|
| 32 |
+
"Upload ThTuanIT",
|
| 33 |
+
"ThTuanIT",
|
| 34 |
+
"ThTuanIT Cloud",
|
| 35 |
+
"Lưu trữ đám mây Upload ThTuanIT",
|
| 36 |
+
"Upload file tốc độ cao",
|
| 37 |
+
"Chia sẻ tệp tin lớn 10GB",
|
| 38 |
+
"Phân quyền RBAC",
|
| 39 |
+
"Cloud Object Storage Việt Nam",
|
| 40 |
+
],
|
| 41 |
+
authors: [{ name: "ThTuanIT" }],
|
| 42 |
+
creator: "ThTuanIT",
|
| 43 |
+
publisher: "Upload ThTuanIT",
|
| 44 |
+
robots: {
|
| 45 |
+
index: true,
|
| 46 |
+
follow: true,
|
| 47 |
+
googleBot: {
|
| 48 |
+
index: true,
|
| 49 |
+
follow: true,
|
| 50 |
+
"max-video-preview": -1,
|
| 51 |
+
"max-image-preview": "large",
|
| 52 |
+
"max-snippet": -1,
|
| 53 |
+
},
|
| 54 |
+
},
|
| 55 |
+
alternates: {
|
| 56 |
+
canonical: "/",
|
| 57 |
+
},
|
| 58 |
+
openGraph: {
|
| 59 |
+
type: "website",
|
| 60 |
+
locale: "vi_VN",
|
| 61 |
+
url: "http://localhost:3000",
|
| 62 |
+
siteName: "Upload ThTuanIT",
|
| 63 |
+
title: "Upload ThTuanIT — Hạ tầng Lưu trữ & Chia sẻ Tệp Đám mây Siêu Tốc",
|
| 64 |
+
description:
|
| 65 |
+
"Tải lên song song (Turbo Parallel Upload) tới 10 GiB/tệp, cô lập dữ liệu cá nhân, phát trực tuyến Video 4K và quản trị phân quyền Admin/User toàn diện cùng Upload ThTuanIT.",
|
| 66 |
+
},
|
| 67 |
+
twitter: {
|
| 68 |
+
card: "summary_large_image",
|
| 69 |
+
title: "Upload ThTuanIT — Cloud Object Storage & Turbo Upload",
|
| 70 |
+
description:
|
| 71 |
+
"Hạ tầng lưu trữ đám mây tốc độ cao Upload ThTuanIT với Turbo Upload Engine, RBAC IAM & Media Streaming.",
|
| 72 |
+
},
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
export default function RootLayout({
|
| 76 |
+
children,
|
| 77 |
+
}: Readonly<{
|
| 78 |
+
children: React.ReactNode;
|
| 79 |
+
}>) {
|
| 80 |
+
const jsonLd = {
|
| 81 |
+
"@context": "https://schema.org",
|
| 82 |
+
"@graph": [
|
| 83 |
+
{
|
| 84 |
+
"@type": "SoftwareApplication",
|
| 85 |
+
name: "Upload ThTuanIT",
|
| 86 |
+
applicationCategory: "CloudStorageApplication",
|
| 87 |
+
operatingSystem: "Web, Windows, Linux, macOS",
|
| 88 |
+
offers: {
|
| 89 |
+
"@type": "Offer",
|
| 90 |
+
price: "0",
|
| 91 |
+
priceCurrency: "VND",
|
| 92 |
+
},
|
| 93 |
+
description:
|
| 94 |
+
"Upload ThTuanIT là hệ thống lưu trữ và chia sẻ tệp đám mây tốc độ cao, tích hợp phân quyền người dùng RBAC, cô lập tệp cá nhân và công nghệ Turbo Parallel Upload.",
|
| 95 |
+
featureList: [
|
| 96 |
+
"Turbo Parallel & Batch Upload siêu tốc độ qua Dual-Lane Worker Pool",
|
| 97 |
+
"Zero-Copy Server-Side Rename đổi tên tệp lớn tức thì",
|
| 98 |
+
"Cô lập không gian lưu trữ cá nhân cho từng User và chế độ toàn quyền cho Admin",
|
| 99 |
+
"Phân quyền chi tiết Admin & User (RBAC)",
|
| 100 |
+
"HTTP 206 Partial Content Video Streaming mượt mà",
|
| 101 |
+
],
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"@type": "Organization",
|
| 105 |
+
name: "Upload ThTuanIT",
|
| 106 |
+
url: "http://localhost:3000",
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"@type": "WebSite",
|
| 110 |
+
name: "Upload ThTuanIT",
|
| 111 |
+
url: "http://localhost:3000",
|
| 112 |
+
},
|
| 113 |
+
{
|
| 114 |
+
"@type": "BreadcrumbList",
|
| 115 |
+
itemListElement: [
|
| 116 |
+
{
|
| 117 |
+
"@type": "ListItem",
|
| 118 |
+
position: 1,
|
| 119 |
+
name: "Trang chủ Upload ThTuanIT",
|
| 120 |
+
item: "http://localhost:3000/",
|
| 121 |
+
},
|
| 122 |
+
{
|
| 123 |
+
"@type": "ListItem",
|
| 124 |
+
position: 2,
|
| 125 |
+
name: "Bảng điều khiển Upload ThTuanIT",
|
| 126 |
+
item: "http://localhost:3000/dashboard",
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"@type": "ListItem",
|
| 130 |
+
position: 3,
|
| 131 |
+
name: "Trình duyệt Tệp Upload ThTuanIT",
|
| 132 |
+
item: "http://localhost:3000/explorer",
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"@type": "ListItem",
|
| 136 |
+
position: 4,
|
| 137 |
+
name: "Tài liệu API Upload ThTuanIT",
|
| 138 |
+
item: "http://localhost:3000/developers",
|
| 139 |
+
},
|
| 140 |
+
],
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"@type": "FAQPage",
|
| 144 |
+
mainEntity: [
|
| 145 |
+
{
|
| 146 |
+
"@type": "Question",
|
| 147 |
+
name: "Công nghệ Turbo Upload của Upload ThTuanIT giúp tăng tốc độ tải lên như thế nào?",
|
| 148 |
+
acceptedAnswer: {
|
| 149 |
+
"@type": "Answer",
|
| 150 |
+
text: "Upload ThTuanIT duy trì kiến trúc Dual-Lane Persistent Worker Pool tốc độ cao và gom nhiều tệp vào một phiên đồng bộ duy nhất (Batch Commit), giúp triệt tiêu độ trễ khởi tạo và tối đa hóa băng thông đường truyền.",
|
| 151 |
+
},
|
| 152 |
+
},
|
| 153 |
+
{
|
| 154 |
+
"@type": "Question",
|
| 155 |
+
name: "Cơ chế bảo mật tệp cá nhân và phân quyền Admin trên Upload ThTuanIT hoạt động ra sao?",
|
| 156 |
+
acceptedAnswer: {
|
| 157 |
+
"@type": "Answer",
|
| 158 |
+
text: "Trên Upload ThTuanIT, mỗi thành viên (User) chỉ nhìn thấy và tải xuống các tệp tin do chính mình tải lên. Quản trị viên (Admin) có quyền giám sát toàn bộ kho lưu trữ và bật/tắt quyền Upload, Rename, Delete theo thời gian thực.",
|
| 159 |
+
},
|
| 160 |
+
},
|
| 161 |
+
],
|
| 162 |
+
},
|
| 163 |
+
],
|
| 164 |
+
};
|
| 165 |
+
|
| 166 |
+
return (
|
| 167 |
+
<html lang="vi" className="dark scroll-smooth">
|
| 168 |
+
<head>
|
| 169 |
+
<script
|
| 170 |
+
type="application/ld+json"
|
| 171 |
+
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
|
| 172 |
+
/>
|
| 173 |
+
</head>
|
| 174 |
+
<body
|
| 175 |
+
className={`${inter.variable} ${mono.variable} font-sans min-h-screen antialiased selection:bg-indigo-500 selection:text-white`}
|
| 176 |
+
>
|
| 177 |
+
<CloudProvider>{children}</CloudProvider>
|
| 178 |
+
</body>
|
| 179 |
+
</html>
|
| 180 |
+
);
|
| 181 |
+
}
|
frontend/src/app/login/layout.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata } from "next";
|
| 2 |
+
|
| 3 |
+
export const metadata: Metadata = {
|
| 4 |
+
title: "Đăng nhập Hệ thống — Upload ThTuanIT",
|
| 5 |
+
description:
|
| 6 |
+
"Đăng nhập vào cổng lưu trữ đám mây Upload ThTuanIT để quản lý tệp tin cá nhân hoặc truy cập bảng điều khiển Admin.",
|
| 7 |
+
alternates: {
|
| 8 |
+
canonical: "/login",
|
| 9 |
+
},
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
export default function LoginLayout({ children }: { children: React.ReactNode }) {
|
| 13 |
+
return <>{children}</>;
|
| 14 |
+
}
|
frontend/src/app/login/page.tsx
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import Link from "next/link";
|
| 5 |
+
import { useRouter } from "next/navigation";
|
| 6 |
+
import { ChevronLeft, ArrowRight, KeyRound, Lock, ShieldCheck } from "lucide-react";
|
| 7 |
+
import { useCloud } from "@/context/CloudContext";
|
| 8 |
+
import { NavbarPublic } from "@/components/NavbarPublic";
|
| 9 |
+
|
| 10 |
+
export default function LoginPage() {
|
| 11 |
+
const router = useRouter();
|
| 12 |
+
const { loginWithCredentials } = useCloud();
|
| 13 |
+
const [username, setUsername] = useState("");
|
| 14 |
+
const [password, setPassword] = useState("");
|
| 15 |
+
const [submitting, setSubmitting] = useState(false);
|
| 16 |
+
|
| 17 |
+
async function onSubmit(e: React.FormEvent) {
|
| 18 |
+
e.preventDefault();
|
| 19 |
+
setSubmitting(true);
|
| 20 |
+
const ok = await loginWithCredentials(username, password);
|
| 21 |
+
setSubmitting(false);
|
| 22 |
+
if (ok) {
|
| 23 |
+
router.push("/dashboard");
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
return (
|
| 28 |
+
<div className="min-h-screen flex flex-col bg-grid-pattern">
|
| 29 |
+
<NavbarPublic />
|
| 30 |
+
<main className="flex-1 flex items-center justify-center p-4 sm:p-8">
|
| 31 |
+
<div className="w-full max-w-4xl grid grid-cols-1 lg:grid-cols-12 glass-panel rounded-3xl overflow-hidden border border-white/15">
|
| 32 |
+
{/* Left Security Info */}
|
| 33 |
+
<div className="lg:col-span-5 p-8 bg-gradient-to-br from-indigo-950/90 via-slate-900 to-slate-950 flex flex-col justify-between border-b lg:border-b-0 lg:border-r border-white/10">
|
| 34 |
+
<div>
|
| 35 |
+
<Link
|
| 36 |
+
href="/"
|
| 37 |
+
className="inline-flex items-center gap-1.5 text-xs text-slate-400 hover:text-white mb-6 transition"
|
| 38 |
+
>
|
| 39 |
+
<ChevronLeft className="w-4 h-4" /> Quay lại trang chủ
|
| 40 |
+
</Link>
|
| 41 |
+
<h1 className="text-2xl font-extrabold text-white mb-2">Đăng nhập Upload ThTuanIT</h1>
|
| 42 |
+
<p className="text-xs text-slate-300 leading-relaxed mb-6">
|
| 43 |
+
Nhập thông tin tài khoản của bạn để truy cập không gian lưu trữ đám mây cá nhân và quản lý tệp tin tốc
|
| 44 |
+
độ cao.
|
| 45 |
+
</p>
|
| 46 |
+
|
| 47 |
+
<div className="p-4 rounded-2xl bg-indigo-500/10 border border-indigo-500/25 space-y-2.5 text-xs text-slate-300">
|
| 48 |
+
<p className="font-bold text-indigo-300 flex items-center gap-1.5">
|
| 49 |
+
<ShieldCheck className="w-4 h-4 text-emerald-400" /> Bảo mật & Quyền riêng tư
|
| 50 |
+
</p>
|
| 51 |
+
<ul className="space-y-1.5 list-disc list-inside text-slate-300">
|
| 52 |
+
<li>Xác thực phiên bằng chữ ký số HMAC-SHA256</li>
|
| 53 |
+
<li>Không gian lưu trữ tệp tách biệt theo từng tài khoản</li>
|
| 54 |
+
<li>Tự động chống ghi đè khi tải tệp trùng tên</li>
|
| 55 |
+
</ul>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
<div className="pt-6 border-t border-white/10 text-[11px] text-slate-400 font-mono flex items-center justify-between">
|
| 60 |
+
<span className="flex items-center gap-1">
|
| 61 |
+
<Lock className="w-3.5 h-3.5 text-indigo-400" /> HMAC-SHA256
|
| 62 |
+
</span>
|
| 63 |
+
<span>Upload ThTuanIT</span>
|
| 64 |
+
</div>
|
| 65 |
+
</div>
|
| 66 |
+
|
| 67 |
+
{/* Right Form */}
|
| 68 |
+
<div className="lg:col-span-7 p-8 sm:p-10 flex flex-col justify-center">
|
| 69 |
+
<div className="flex items-center gap-2 p-1 rounded-2xl bg-slate-900 border border-white/10 mb-6">
|
| 70 |
+
<Link
|
| 71 |
+
href="/login"
|
| 72 |
+
className="flex-1 py-2.5 rounded-xl text-xs font-bold text-center bg-indigo-600 text-white shadow-lg shadow-indigo-600/30"
|
| 73 |
+
>
|
| 74 |
+
Đăng nhập hệ thống
|
| 75 |
+
</Link>
|
| 76 |
+
<Link
|
| 77 |
+
href="/register"
|
| 78 |
+
className="flex-1 py-2.5 rounded-xl text-xs font-bold text-center text-slate-400 hover:text-white transition"
|
| 79 |
+
>
|
| 80 |
+
Đăng ký thành viên
|
| 81 |
+
</Link>
|
| 82 |
+
</div>
|
| 83 |
+
|
| 84 |
+
<form onSubmit={onSubmit} className="space-y-4">
|
| 85 |
+
<div>
|
| 86 |
+
<label className="block text-xs font-semibold text-slate-300 mb-1.5">Tên đăng nhập (Username)</label>
|
| 87 |
+
<input
|
| 88 |
+
type="text"
|
| 89 |
+
required
|
| 90 |
+
value={username}
|
| 91 |
+
onChange={(e) => setUsername(e.target.value)}
|
| 92 |
+
placeholder="Nhập tên đăng nhập của bạn..."
|
| 93 |
+
className="w-full bg-slate-900/90 border border-white/15 focus:border-indigo-500 rounded-xl px-4 py-3 text-sm text-white font-mono focus:outline-none"
|
| 94 |
+
/>
|
| 95 |
+
</div>
|
| 96 |
+
|
| 97 |
+
<div>
|
| 98 |
+
<label className="block text-xs font-semibold text-slate-300 mb-1.5">Mật khẩu bảo mật</label>
|
| 99 |
+
<input
|
| 100 |
+
type="password"
|
| 101 |
+
required
|
| 102 |
+
value={password}
|
| 103 |
+
onChange={(e) => setPassword(e.target.value)}
|
| 104 |
+
placeholder="••••••••"
|
| 105 |
+
className="w-full bg-slate-900/90 border border-white/15 focus:border-indigo-500 rounded-xl px-4 py-3 text-sm text-white font-mono focus:outline-none"
|
| 106 |
+
/>
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
<button
|
| 110 |
+
type="submit"
|
| 111 |
+
disabled={submitting}
|
| 112 |
+
className="w-full py-3.5 rounded-xl bg-gradient-to-r from-indigo-600 via-violet-600 to-indigo-600 hover:from-indigo-500 hover:to-violet-500 font-bold text-sm text-white shadow-xl shadow-indigo-600/30 transition flex items-center justify-center gap-2 disabled:opacity-50"
|
| 113 |
+
>
|
| 114 |
+
<KeyRound className="w-4 h-4" />
|
| 115 |
+
<span>{submitting ? "Đang xác thực..." : "Đăng nhập vào Upload ThTuanIT"}</span>
|
| 116 |
+
<ArrowRight className="w-4 h-4" />
|
| 117 |
+
</button>
|
| 118 |
+
</form>
|
| 119 |
+
</div>
|
| 120 |
+
</div>
|
| 121 |
+
</main>
|
| 122 |
+
</div>
|
| 123 |
+
);
|
| 124 |
+
}
|
frontend/src/app/page.tsx
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import Link from "next/link";
|
| 5 |
+
import {
|
| 6 |
+
Sparkles,
|
| 7 |
+
Shield,
|
| 8 |
+
ArrowRight,
|
| 9 |
+
Zap,
|
| 10 |
+
Code2,
|
| 11 |
+
LayoutGrid,
|
| 12 |
+
Folder,
|
| 13 |
+
CloudUpload,
|
| 14 |
+
Lock,
|
| 15 |
+
Film,
|
| 16 |
+
HardDrive,
|
| 17 |
+
} from "lucide-react";
|
| 18 |
+
import { useCloud } from "@/context/CloudContext";
|
| 19 |
+
import { NavbarPublic } from "@/components/NavbarPublic";
|
| 20 |
+
|
| 21 |
+
export default function LandingPage() {
|
| 22 |
+
const { currentUser } = useCloud();
|
| 23 |
+
|
| 24 |
+
return (
|
| 25 |
+
<div className="min-h-screen flex flex-col bg-grid-pattern">
|
| 26 |
+
<NavbarPublic />
|
| 27 |
+
|
| 28 |
+
<main className="flex-1">
|
| 29 |
+
{/* HERO SECTION */}
|
| 30 |
+
<section className="max-w-7xl mx-auto px-4 sm:px-8 pt-16 pb-20 lg:pt-24 lg:pb-28 grid grid-cols-1 lg:grid-cols-12 gap-12 items-center">
|
| 31 |
+
<div className="lg:col-span-7 space-y-6">
|
| 32 |
+
<div className="inline-flex items-center gap-2.5 px-3.5 py-1.5 rounded-full glass border border-indigo-500/30 text-xs font-medium text-indigo-300">
|
| 33 |
+
<Sparkles className="w-3.5 h-3.5 text-amber-400" />
|
| 34 |
+
<span>Upload ThTuanIT • Hạ tầng Lưu trữ & Truyền tải Tệp Đám mây Thế hệ mới</span>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<h1 className="text-4xl sm:text-5xl lg:text-6xl font-extrabold tracking-tight text-white leading-[1.12]">
|
| 38 |
+
Nền tảng{" "}
|
| 39 |
+
<span className="bg-gradient-to-r from-indigo-400 via-purple-300 to-amber-300 bg-clip-text text-transparent">
|
| 40 |
+
Upload ThTuanIT
|
| 41 |
+
</span>{" "}
|
| 42 |
+
siêu tốc độ cho mọi dữ liệu lớn.
|
| 43 |
+
</h1>
|
| 44 |
+
|
| 45 |
+
<p className="text-base sm:text-lg text-slate-300 leading-relaxed max-w-2xl">
|
| 46 |
+
Lưu trữ, quản lý và chia sẻ tệp tin dung lượng lớn lên tới <b>10 GiB/file</b> trên hạ tầng đám mây{" "}
|
| 47 |
+
<b className="text-indigo-300">Upload ThTuanIT</b>. Tích hợp sẵn công nghệ truyền tải đa luồng{" "}
|
| 48 |
+
<b>Turbo Parallel Engine</b>, cô lập không gian lưu trữ cá nhân theo từng thành viên, kiểm soát quyền hạn
|
| 49 |
+
chi tiết (RBAC) và phát trực tuyến Video 4K mượt mà.
|
| 50 |
+
</p>
|
| 51 |
+
|
| 52 |
+
<div className="flex flex-wrap items-center gap-4 pt-2">
|
| 53 |
+
{currentUser ? (
|
| 54 |
+
<>
|
| 55 |
+
<Link
|
| 56 |
+
href="/dashboard"
|
| 57 |
+
className="px-6 py-3.5 rounded-2xl bg-gradient-to-r from-indigo-600 to-violet-600 hover:from-indigo-500 hover:to-violet-500 text-white font-bold text-sm shadow-xl shadow-indigo-600/30 transition flex items-center gap-2.5"
|
| 58 |
+
>
|
| 59 |
+
<LayoutGrid className="w-4 h-4 text-amber-300" />
|
| 60 |
+
<span>Mở Bảng điều khiển (/dashboard)</span>
|
| 61 |
+
<ArrowRight className="w-4 h-4" />
|
| 62 |
+
</Link>
|
| 63 |
+
<Link
|
| 64 |
+
href="/explorer"
|
| 65 |
+
className="px-6 py-3.5 rounded-2xl glass hover:bg-white/10 text-slate-200 font-semibold text-sm border border-white/15 transition flex items-center gap-2"
|
| 66 |
+
>
|
| 67 |
+
<Folder className="w-4 h-4 text-indigo-400" />
|
| 68 |
+
<span>Trình duyệt Tệp (/explorer)</span>
|
| 69 |
+
</Link>
|
| 70 |
+
</>
|
| 71 |
+
) : (
|
| 72 |
+
<>
|
| 73 |
+
<Link
|
| 74 |
+
href="/login"
|
| 75 |
+
className="px-6 py-3.5 rounded-2xl bg-gradient-to-r from-indigo-600 to-violet-600 hover:from-indigo-500 hover:to-violet-500 text-white font-bold text-sm shadow-xl shadow-indigo-600/30 transition flex items-center gap-2.5"
|
| 76 |
+
>
|
| 77 |
+
<CloudUpload className="w-4 h-4 text-amber-300" />
|
| 78 |
+
<span>Đăng nhập để Tải tệp lên</span>
|
| 79 |
+
<ArrowRight className="w-4 h-4" />
|
| 80 |
+
</Link>
|
| 81 |
+
|
| 82 |
+
<Link
|
| 83 |
+
href="/register"
|
| 84 |
+
className="px-6 py-3.5 rounded-2xl glass hover:bg-white/10 text-slate-200 font-semibold text-sm border border-white/15 transition flex items-center gap-2"
|
| 85 |
+
>
|
| 86 |
+
<span>Tạo tài khoản miễn phí</span>
|
| 87 |
+
</Link>
|
| 88 |
+
</>
|
| 89 |
+
)}
|
| 90 |
+
</div>
|
| 91 |
+
|
| 92 |
+
{/* Trust Metrics Bar */}
|
| 93 |
+
<div className="pt-8 grid grid-cols-3 gap-6 border-t border-white/10 max-w-lg">
|
| 94 |
+
<div>
|
| 95 |
+
<p className="text-2xl font-extrabold text-white font-mono">10 GiB</p>
|
| 96 |
+
<p className="text-xs text-slate-400 mt-0.5">Kích thước tối đa / tệp</p>
|
| 97 |
+
</div>
|
| 98 |
+
<div>
|
| 99 |
+
<p className="text-2xl font-extrabold text-emerald-400 font-mono">Dual-Lane</p>
|
| 100 |
+
<p className="text-xs text-slate-400 mt-0.5">Turbo Upload không nghẽn</p>
|
| 101 |
+
</div>
|
| 102 |
+
<div>
|
| 103 |
+
<p className="text-2xl font-extrabold text-amber-400 font-mono">RBAC</p>
|
| 104 |
+
<p className="text-xs text-slate-400 mt-0.5">B��o mật không gian riêng</p>
|
| 105 |
+
</div>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
|
| 109 |
+
{/* Right System Architecture Showcase Card */}
|
| 110 |
+
<div className="lg:col-span-5">
|
| 111 |
+
<div className="glass-panel rounded-3xl p-6 border border-white/15 relative overflow-hidden glow-indigo">
|
| 112 |
+
<div className="flex items-center justify-between pb-4 mb-5 border-b border-white/10">
|
| 113 |
+
<div className="flex items-center gap-2">
|
| 114 |
+
<span className="w-3 h-3 rounded-full bg-rose-500/80" />
|
| 115 |
+
<span className="w-3 h-3 rounded-full bg-amber-500/80" />
|
| 116 |
+
<span className="w-3 h-3 rounded-full bg-emerald-500/80" />
|
| 117 |
+
<span className="ml-2 text-xs font-mono text-slate-400">thtuanit://cloud/engine</span>
|
| 118 |
+
</div>
|
| 119 |
+
<span className="px-2.5 py-0.5 rounded-md text-[10px] font-mono bg-emerald-500/15 text-emerald-300 border border-emerald-500/30">
|
| 120 |
+
UPLOAD THTUANIT
|
| 121 |
+
</span>
|
| 122 |
+
</div>
|
| 123 |
+
|
| 124 |
+
<div className="space-y-3.5">
|
| 125 |
+
<div className="p-4 rounded-2xl bg-slate-900/90 border border-indigo-500/30 flex items-start gap-3.5">
|
| 126 |
+
<div className="w-10 h-10 rounded-xl bg-indigo-500/15 border border-indigo-500/30 flex items-center justify-center text-indigo-400 shrink-0">
|
| 127 |
+
<Zap className="w-5 h-5" />
|
| 128 |
+
</div>
|
| 129 |
+
<div>
|
| 130 |
+
<h2 className="text-xs font-bold uppercase tracking-wider text-indigo-300">
|
| 131 |
+
Turbo Parallel Upload (4 Luồng)
|
| 132 |
+
</h2>
|
| 133 |
+
<p className="text-xs text-slate-300 mt-1 leading-relaxed">
|
| 134 |
+
Truyền tải đồng thời nhiều tệp dung lượng lớn tới 10 GiB với bộ đệm streaming 4 MiB và tự động
|
| 135 |
+
đổi tên chống ghi đè thông minh.
|
| 136 |
+
</p>
|
| 137 |
+
</div>
|
| 138 |
+
</div>
|
| 139 |
+
|
| 140 |
+
<div className="p-4 rounded-2xl bg-slate-900/80 border border-white/10 flex items-start gap-3.5">
|
| 141 |
+
<div className="w-10 h-10 rounded-xl bg-emerald-500/15 border border-emerald-500/30 flex items-center justify-center text-emerald-400 shrink-0">
|
| 142 |
+
<Lock className="w-5 h-5" />
|
| 143 |
+
</div>
|
| 144 |
+
<div>
|
| 145 |
+
<h2 className="text-xs font-bold uppercase tracking-wider text-emerald-300">
|
| 146 |
+
Không gian Lưu trữ Cá nhân Biệt lập
|
| 147 |
+
</h2>
|
| 148 |
+
<p className="text-xs text-slate-400 mt-1 leading-relaxed">
|
| 149 |
+
Mỗi tài khoản sở hữu phân vùng lưu trữ riêng biệt, chỉ hiển thị và cho phép thao tác trên những
|
| 150 |
+
tệp do chính bạn tải lên.
|
| 151 |
+
</p>
|
| 152 |
+
</div>
|
| 153 |
+
</div>
|
| 154 |
+
|
| 155 |
+
<div className="p-4 rounded-2xl bg-slate-900/80 border border-white/10 flex items-start gap-3.5">
|
| 156 |
+
<div className="w-10 h-10 rounded-xl bg-rose-500/15 border border-rose-500/30 flex items-center justify-center text-rose-400 shrink-0">
|
| 157 |
+
<Film className="w-5 h-5" />
|
| 158 |
+
</div>
|
| 159 |
+
<div>
|
| 160 |
+
<h2 className="text-xs font-bold uppercase tracking-wider text-rose-300">
|
| 161 |
+
Phát trực tuyến Video HTTP Range
|
| 162 |
+
</h2>
|
| 163 |
+
<p className="text-xs text-slate-400 mt-1 leading-relaxed">
|
| 164 |
+
Xem trực tiếp video độ phân giải cao ngay trên trình duyệt với khả năng tua mượt mà không cần chờ
|
| 165 |
+
tải toàn bộ tệp.
|
| 166 |
+
</p>
|
| 167 |
+
</div>
|
| 168 |
+
</div>
|
| 169 |
+
</div>
|
| 170 |
+
</div>
|
| 171 |
+
</div>
|
| 172 |
+
</section>
|
| 173 |
+
|
| 174 |
+
{/* FEATURE BENTO GRID */}
|
| 175 |
+
<section id="architecture" className="max-w-7xl mx-auto px-4 sm:px-8 py-16 border-t border-white/10">
|
| 176 |
+
<div className="text-center max-w-2xl mx-auto mb-12">
|
| 177 |
+
<h2 className="text-2xl sm:text-3xl font-extrabold text-white">
|
| 178 |
+
Tại sao chọn nền tảng lưu trữ đám mây Upload ThTuanIT?
|
| 179 |
+
</h2>
|
| 180 |
+
<p className="text-sm text-slate-400 mt-2">
|
| 181 |
+
Thiết kế tối ưu cho tốc độ truyền tải tệp lớn, bảo mật phân quyền nhiều lớp và trải nghiệm quản lý tệp
|
| 182 |
+
trực quan.
|
| 183 |
+
</p>
|
| 184 |
+
</div>
|
| 185 |
+
|
| 186 |
+
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
| 187 |
+
<article className="glass-card rounded-3xl p-6 space-y-3">
|
| 188 |
+
<div className="w-12 h-12 rounded-2xl bg-indigo-500/15 border border-indigo-500/30 flex items-center justify-center text-indigo-400">
|
| 189 |
+
<Zap className="w-6 h-6" />
|
| 190 |
+
</div>
|
| 191 |
+
<h3 className="text-base font-bold text-white">Công nghệ Turbo Upload ThTuanIT</h3>
|
| 192 |
+
<p className="text-xs text-slate-400 leading-relaxed">
|
| 193 |
+
Tách biệt luồng xử lý siêu dữ liệu (<code className="text-indigo-300">metaQueue</code>) và luồng truyền
|
| 194 |
+
tải tệp nặng (<code className="text-indigo-300">xferQueue</code>), đảm bảo duyệt tệp tức thì trong 3ms
|
| 195 |
+
ngay cả khi đang tải lên tệp 10 GiB.
|
| 196 |
+
</p>
|
| 197 |
+
</article>
|
| 198 |
+
|
| 199 |
+
<article id="rbac" className="glass-card rounded-3xl p-6 space-y-3">
|
| 200 |
+
<div className="w-12 h-12 rounded-2xl bg-amber-500/15 border border-amber-500/30 flex items-center justify-center text-amber-400">
|
| 201 |
+
<Shield className="w-6 h-6" />
|
| 202 |
+
</div>
|
| 203 |
+
<h3 className="text-base font-bold text-white">Cô lập Tệp Cá nhân & RBAC</h3>
|
| 204 |
+
<p className="text-xs text-slate-400 leading-relaxed">
|
| 205 |
+
Người dùng chỉ xem được tệp đã tải lên của chính mình. Quản trị viên có thể giám sát kho lưu trữ và
|
| 206 |
+
cấp/thu hồi từng quyền <code className="text-amber-300">Upload</code>,{" "}
|
| 207 |
+
<code className="text-amber-300">Rename</code>, <code className="text-amber-300">Delete</code> theo thời
|
| 208 |
+
gian thực.
|
| 209 |
+
</p>
|
| 210 |
+
</article>
|
| 211 |
+
|
| 212 |
+
<article className="glass-card rounded-3xl p-6 space-y-3">
|
| 213 |
+
<div className="w-12 h-12 rounded-2xl bg-emerald-500/15 border border-emerald-500/30 flex items-center justify-center text-emerald-400">
|
| 214 |
+
<Code2 className="w-6 h-6" />
|
| 215 |
+
</div>
|
| 216 |
+
<h3 className="text-base font-bold text-white">Đường dẫn Rõ ràng & REST API</h3>
|
| 217 |
+
<p className="text-xs text-slate-400 leading-relaxed">
|
| 218 |
+
Hệ thống phân tách rõ các định tuyến <code className="text-emerald-300">/dashboard</code>,{" "}
|
| 219 |
+
<code className="text-emerald-300">/explorer</code>, <code className="text-emerald-300">/admin</code>,{" "}
|
| 220 |
+
<code className="text-emerald-300">/developers</code> và <code className="text-emerald-300">/activity</code>.
|
| 221 |
+
</p>
|
| 222 |
+
</article>
|
| 223 |
+
</div>
|
| 224 |
+
</section>
|
| 225 |
+
|
| 226 |
+
{/* SEO FAQ & BENCHMARK SECTION */}
|
| 227 |
+
<section id="faq" className="max-w-7xl mx-auto px-4 sm:px-8 py-16 border-t border-white/10">
|
| 228 |
+
<div className="grid grid-cols-1 lg:grid-cols-12 gap-10">
|
| 229 |
+
<div className="lg:col-span-5 space-y-3">
|
| 230 |
+
<span className="px-2.5 py-1 rounded-full text-[10px] font-mono font-bold uppercase bg-indigo-500/20 text-indigo-300 border border-indigo-500/30">
|
| 231 |
+
Câu hỏi thường gặp
|
| 232 |
+
</span>
|
| 233 |
+
<h2 className="text-2xl sm:text-3xl font-extrabold text-white">
|
| 234 |
+
Giải đáp về nền tảng Upload ThTuanIT
|
| 235 |
+
</h2>
|
| 236 |
+
<p className="text-xs sm:text-sm text-slate-400 leading-relaxed">
|
| 237 |
+
Tìm hiểu cách Upload ThTuanIT tối ưu tốc độ tải lên, bảo vệ quyền riêng tư tệp tin của từng thành viên
|
| 238 |
+
và tự động chống ghi đè tệp trùng tên.
|
| 239 |
+
</p>
|
| 240 |
+
</div>
|
| 241 |
+
|
| 242 |
+
<div className="lg:col-span-7 space-y-4">
|
| 243 |
+
<article className="glass rounded-2xl p-5 border border-white/10">
|
| 244 |
+
<h3 className="text-sm font-bold text-white mb-1.5">
|
| 245 |
+
1. Công nghệ Turbo Parallel & Batch Upload trên Upload ThTuanIT hoạt động như thế nào?
|
| 246 |
+
</h3>
|
| 247 |
+
<p className="text-xs text-slate-300 leading-relaxed">
|
| 248 |
+
Upload ThTuanIT duy trì hệ thống <b>Dual-Lane Worker Pool</b> luôn sẵn sàng trong RAM và truyền luồng
|
| 249 |
+
dữ liệu trực tiếp qua bộ đệm 4 MiB, hỗ trợ tải lên song song 4 luồng hoặc gom nhiều tệp trong một lần
|
| 250 |
+
đồng bộ duy nhất.
|
| 251 |
+
</p>
|
| 252 |
+
</article>
|
| 253 |
+
|
| 254 |
+
<article className="glass rounded-2xl p-5 border border-white/10">
|
| 255 |
+
<h3 className="text-sm font-bold text-white mb-1.5">
|
| 256 |
+
2. Tải lên tệp trùng tên nhưng khác nội dung có bị mất tệp cũ không?
|
| 257 |
+
</h3>
|
| 258 |
+
<p className="text-xs text-slate-300 leading-relaxed">
|
| 259 |
+
Không. Mỗi tài khoản có phân vùng lưu trữ riêng biệt. Nếu bạn tải lên tệp trùng tên với tệp đã có của
|
| 260 |
+
mình, hệ thống tự động đánh số thứ tự (<code className="text-amber-300">tenfile (1).ext</code>,{" "}
|
| 261 |
+
<code className="text-amber-300">tenfile (2).ext</code>) để giữ nguyên vẹn mọi phiên bản.
|
| 262 |
+
</p>
|
| 263 |
+
</article>
|
| 264 |
+
|
| 265 |
+
<article className="glass rounded-2xl p-5 border border-white/10">
|
| 266 |
+
<h3 className="text-sm font-bold text-white mb-1.5">
|
| 267 |
+
3. Quyền riêng tư tệp của từng người dùng trên Upload ThTuanIT được bảo vệ ra sao?
|
| 268 |
+
</h3>
|
| 269 |
+
<p className="text-xs text-slate-300 leading-relaxed">
|
| 270 |
+
Mỗi tệp tải lên được gắn định danh chủ sở hữu (<code className="text-emerald-300">@username</code>).
|
| 271 |
+
Người dùng thông thường chỉ xem và tải được tệp của mình.
|
| 272 |
+
</p>
|
| 273 |
+
</article>
|
| 274 |
+
</div>
|
| 275 |
+
</div>
|
| 276 |
+
</section>
|
| 277 |
+
</main>
|
| 278 |
+
|
| 279 |
+
{/* SEO FOOTER WITH SITEMAP LINKS */}
|
| 280 |
+
<footer className="border-t border-white/10 glass py-10">
|
| 281 |
+
<div className="max-w-7xl mx-auto px-4 sm:px-8 flex flex-col sm:flex-row items-center justify-between gap-6 text-xs text-slate-400">
|
| 282 |
+
<div>
|
| 283 |
+
<p className="font-bold text-white">Upload ThTuanIT — Nền tảng Lưu trữ Đám mây Siêu Tốc</p>
|
| 284 |
+
<p className="mt-1">© {new Date().getFullYear()} Upload ThTuanIT • Bảo mật RBAC & Turbo Cloud Storage</p>
|
| 285 |
+
</div>
|
| 286 |
+
<nav aria-label="Liên kết trang" className="flex flex-wrap items-center gap-5 font-medium">
|
| 287 |
+
<Link href="/" className="hover:text-white transition">
|
| 288 |
+
Trang chủ
|
| 289 |
+
</Link>
|
| 290 |
+
<Link href="/dashboard" className="hover:text-white transition">
|
| 291 |
+
Tổng quan (/dashboard)
|
| 292 |
+
</Link>
|
| 293 |
+
<Link href="/explorer" className="hover:text-white transition">
|
| 294 |
+
Trình duyệt Tệp (/explorer)
|
| 295 |
+
</Link>
|
| 296 |
+
<Link href="/developers" className="hover:text-white transition">
|
| 297 |
+
REST API (/developers)
|
| 298 |
+
</Link>
|
| 299 |
+
<Link href="/login" className="hover:text-white transition">
|
| 300 |
+
Đăng nhập (/login)
|
| 301 |
+
</Link>
|
| 302 |
+
<Link href="/register" className="hover:text-white transition">
|
| 303 |
+
Đăng ký (/register)
|
| 304 |
+
</Link>
|
| 305 |
+
</nav>
|
| 306 |
+
</div>
|
| 307 |
+
</footer>
|
| 308 |
+
</div>
|
| 309 |
+
);
|
| 310 |
+
}
|
frontend/src/app/register/layout.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Metadata } from "next";
|
| 2 |
+
|
| 3 |
+
export const metadata: Metadata = {
|
| 4 |
+
title: "Đăng ký Tài khoản Đám mây — Upload ThTuanIT",
|
| 5 |
+
description:
|
| 6 |
+
"Tạo tài khoản miễn phí trên Upload ThTuanIT với không gian lưu trữ tệp cá nhân riêng biệt và tốc độ tải lên siêu tốc.",
|
| 7 |
+
alternates: {
|
| 8 |
+
canonical: "/register",
|
| 9 |
+
},
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
export default function RegisterLayout({ children }: { children: React.ReactNode }) {
|
| 13 |
+
return <>{children}</>;
|
| 14 |
+
}
|
frontend/src/app/register/page.tsx
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import Link from "next/link";
|
| 5 |
+
import { useRouter } from "next/navigation";
|
| 6 |
+
import { ChevronLeft, ArrowRight, UserPlus, Shield } from "lucide-react";
|
| 7 |
+
import { useCloud } from "@/context/CloudContext";
|
| 8 |
+
import { NavbarPublic } from "@/components/NavbarPublic";
|
| 9 |
+
|
| 10 |
+
export default function RegisterPage() {
|
| 11 |
+
const router = useRouter();
|
| 12 |
+
const { bucketName, registerAccount } = useCloud();
|
| 13 |
+
const [username, setUsername] = useState("");
|
| 14 |
+
const [displayName, setDisplayName] = useState("");
|
| 15 |
+
const [password, setPassword] = useState("");
|
| 16 |
+
const [submitting, setSubmitting] = useState(false);
|
| 17 |
+
|
| 18 |
+
async function onSubmit(e: React.FormEvent) {
|
| 19 |
+
e.preventDefault();
|
| 20 |
+
setSubmitting(true);
|
| 21 |
+
const ok = await registerAccount(username, displayName, password);
|
| 22 |
+
setSubmitting(false);
|
| 23 |
+
if (ok) {
|
| 24 |
+
router.push("/dashboard");
|
| 25 |
+
}
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
return (
|
| 29 |
+
<div className="min-h-screen flex flex-col bg-grid-pattern">
|
| 30 |
+
<NavbarPublic />
|
| 31 |
+
<main className="flex-1 flex items-center justify-center p-4 sm:p-8">
|
| 32 |
+
<div className="w-full max-w-4xl grid grid-cols-1 lg:grid-cols-12 glass-panel rounded-3xl overflow-hidden border border-white/15">
|
| 33 |
+
<div className="lg:col-span-5 p-8 bg-gradient-to-br from-indigo-950/90 via-slate-900 to-slate-950 flex flex-col justify-between border-b lg:border-b-0 lg:border-r border-white/10">
|
| 34 |
+
<div>
|
| 35 |
+
<Link
|
| 36 |
+
href="/"
|
| 37 |
+
className="inline-flex items-center gap-1.5 text-xs text-slate-400 hover:text-white mb-6 transition"
|
| 38 |
+
>
|
| 39 |
+
<ChevronLeft className="w-4 h-4" /> Quay lại trang chủ
|
| 40 |
+
</Link>
|
| 41 |
+
<h1 className="text-2xl font-extrabold text-white mb-2">Tạo tài khoản mới</h1>
|
| 42 |
+
<p className="text-xs text-slate-300 leading-relaxed mb-6">
|
| 43 |
+
Mỗi tài khoản thành viên mới sẽ được cấp không gian lưu trữ cá nhân riêng biệt: chỉ bạn và Quản trị
|
| 44 |
+
viên mới có thể nhìn thấy các tệp bạn tải lên.
|
| 45 |
+
</p>
|
| 46 |
+
<div className="p-4 rounded-2xl bg-emerald-500/10 border border-emerald-500/25 space-y-2 text-xs text-emerald-200">
|
| 47 |
+
<p className="font-bold flex items-center gap-1.5">
|
| 48 |
+
<Shield className="w-4 h-4 text-emerald-400" /> Quyền mặc định khi đăng ký:
|
| 49 |
+
</p>
|
| 50 |
+
<ul className="space-y-1 text-slate-300 list-disc list-inside">
|
| 51 |
+
<li>Tải tệp lên Bucket (tối đa 10 GiB/file)</li>
|
| 52 |
+
<li>Chỉ hiển thị tệp do chính bạn tải lên</li>
|
| 53 |
+
<li>Xem trực tuyến Video & Tải tệp về máy</li>
|
| 54 |
+
</ul>
|
| 55 |
+
</div>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
<div className="pt-6 border-t border-white/10 text-[11px] text-slate-400 font-mono flex justify-between">
|
| 59 |
+
<span>Isolated Workspace</span>
|
| 60 |
+
<span>Bucket: {bucketName}</span>
|
| 61 |
+
</div>
|
| 62 |
+
</div>
|
| 63 |
+
|
| 64 |
+
<div className="lg:col-span-7 p-8 sm:p-10 flex flex-col justify-center">
|
| 65 |
+
<div className="flex items-center gap-2 p-1 rounded-2xl bg-slate-900 border border-white/10 mb-6">
|
| 66 |
+
<Link
|
| 67 |
+
href="/login"
|
| 68 |
+
className="flex-1 py-2.5 rounded-xl text-xs font-bold text-center text-slate-400 hover:text-white transition"
|
| 69 |
+
>
|
| 70 |
+
Đăng nhập hệ thống
|
| 71 |
+
</Link>
|
| 72 |
+
<Link
|
| 73 |
+
href="/register"
|
| 74 |
+
className="flex-1 py-2.5 rounded-xl text-xs font-bold text-center bg-indigo-600 text-white shadow-lg shadow-indigo-600/30"
|
| 75 |
+
>
|
| 76 |
+
Đăng ký thành viên
|
| 77 |
+
</Link>
|
| 78 |
+
</div>
|
| 79 |
+
|
| 80 |
+
<form onSubmit={onSubmit} className="space-y-4">
|
| 81 |
+
<div>
|
| 82 |
+
<label className="block text-xs font-semibold text-slate-300 mb-1.5">Tên đăng nhập (Username)</label>
|
| 83 |
+
<input
|
| 84 |
+
type="text"
|
| 85 |
+
required
|
| 86 |
+
value={username}
|
| 87 |
+
onChange={(e) => setUsername(e.target.value)}
|
| 88 |
+
placeholder="Ví dụ: minhtuan"
|
| 89 |
+
className="w-full bg-slate-900/90 border border-white/15 focus:border-indigo-500 rounded-xl px-4 py-3 text-sm text-white font-mono focus:outline-none"
|
| 90 |
+
/>
|
| 91 |
+
</div>
|
| 92 |
+
|
| 93 |
+
<div>
|
| 94 |
+
<label className="block text-xs font-semibold text-slate-300 mb-1.5">Họ và tên hiển thị</label>
|
| 95 |
+
<input
|
| 96 |
+
type="text"
|
| 97 |
+
required
|
| 98 |
+
value={displayName}
|
| 99 |
+
onChange={(e) => setDisplayName(e.target.value)}
|
| 100 |
+
placeholder="Ví dụ: Trần Minh Tuấn"
|
| 101 |
+
className="w-full bg-slate-900/90 border border-white/15 focus:border-indigo-500 rounded-xl px-4 py-3 text-sm text-white focus:outline-none"
|
| 102 |
+
/>
|
| 103 |
+
</div>
|
| 104 |
+
|
| 105 |
+
<div>
|
| 106 |
+
<label className="block text-xs font-semibold text-slate-300 mb-1.5">Mật khẩu bảo mật (tối thiểu 4 ký tự)</label>
|
| 107 |
+
<input
|
| 108 |
+
type="password"
|
| 109 |
+
required
|
| 110 |
+
value={password}
|
| 111 |
+
onChange={(e) => setPassword(e.target.value)}
|
| 112 |
+
placeholder="••••••••"
|
| 113 |
+
className="w-full bg-slate-900/90 border border-white/15 focus:border-indigo-500 rounded-xl px-4 py-3 text-sm text-white font-mono focus:outline-none"
|
| 114 |
+
/>
|
| 115 |
+
</div>
|
| 116 |
+
|
| 117 |
+
<button
|
| 118 |
+
type="submit"
|
| 119 |
+
disabled={submitting}
|
| 120 |
+
className="w-full py-3.5 rounded-xl bg-gradient-to-r from-indigo-600 via-violet-600 to-indigo-600 hover:from-indigo-500 hover:to-violet-500 font-bold text-sm text-white shadow-xl shadow-indigo-600/30 transition flex items-center justify-center gap-2 disabled:opacity-50"
|
| 121 |
+
>
|
| 122 |
+
<UserPlus className="w-4 h-4" />
|
| 123 |
+
<span>{submitting ? "Đang khởi tạo..." : "Hoàn tất Đăng ký"}</span>
|
| 124 |
+
<ArrowRight className="w-4 h-4" />
|
| 125 |
+
</button>
|
| 126 |
+
</form>
|
| 127 |
+
</div>
|
| 128 |
+
</div>
|
| 129 |
+
</main>
|
| 130 |
+
</div>
|
| 131 |
+
);
|
| 132 |
+
}
|
frontend/src/app/robots.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { MetadataRoute } from "next";
|
| 2 |
+
|
| 3 |
+
export default function robots(): MetadataRoute.Robots {
|
| 4 |
+
return {
|
| 5 |
+
rules: {
|
| 6 |
+
userAgent: "*",
|
| 7 |
+
allow: ["/", "/login", "/register", "/developers", "/explorer", "/dashboard"],
|
| 8 |
+
disallow: ["/api/admin/", "/admin"],
|
| 9 |
+
},
|
| 10 |
+
sitemap: "http://localhost:3000/sitemap.xml",
|
| 11 |
+
};
|
| 12 |
+
}
|
frontend/src/app/share/page.tsx
ADDED
|
@@ -0,0 +1,427 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { Suspense, useEffect, useState, useCallback } from "react";
|
| 4 |
+
import Link from "next/link";
|
| 5 |
+
import { useSearchParams } from "next/navigation";
|
| 6 |
+
import {
|
| 7 |
+
CloudUpload,
|
| 8 |
+
Download,
|
| 9 |
+
Lock,
|
| 10 |
+
Clock,
|
| 11 |
+
CheckCircle2,
|
| 12 |
+
AlertTriangle,
|
| 13 |
+
Share2,
|
| 14 |
+
Send,
|
| 15 |
+
Film,
|
| 16 |
+
Image as ImageIcon,
|
| 17 |
+
Archive,
|
| 18 |
+
FileCode2,
|
| 19 |
+
Copy,
|
| 20 |
+
Check,
|
| 21 |
+
RefreshCw,
|
| 22 |
+
} from "lucide-react";
|
| 23 |
+
import {
|
| 24 |
+
apiFetch,
|
| 25 |
+
formatBytes,
|
| 26 |
+
detectCategory,
|
| 27 |
+
buildPublicShareDownloadUrl,
|
| 28 |
+
buildFrontendShareUrl,
|
| 29 |
+
} from "@/lib/api";
|
| 30 |
+
|
| 31 |
+
interface PublicShareInfo {
|
| 32 |
+
id: string;
|
| 33 |
+
file_name: string;
|
| 34 |
+
size: number;
|
| 35 |
+
owner: string;
|
| 36 |
+
enabled: boolean;
|
| 37 |
+
require_approval: boolean;
|
| 38 |
+
created_at: string;
|
| 39 |
+
updated_at: string;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function getOrCreateVisitorToken(): string {
|
| 43 |
+
if (typeof window === "undefined") return "";
|
| 44 |
+
let tk = localStorage.getItem("thtuanit_visitor_token") || "";
|
| 45 |
+
if (!tk) {
|
| 46 |
+
tk = "vt_" + Math.random().toString(36).slice(2, 10) + Date.now().toString(36);
|
| 47 |
+
localStorage.setItem("thtuanit_visitor_token", tk);
|
| 48 |
+
}
|
| 49 |
+
return tk;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
function ShareViewerContent() {
|
| 53 |
+
const searchParams = useSearchParams();
|
| 54 |
+
const shareId = (searchParams.get("id") || "").trim();
|
| 55 |
+
|
| 56 |
+
const [visitorToken, setVisitorToken] = useState<string>("");
|
| 57 |
+
const [loading, setLoading] = useState<boolean>(true);
|
| 58 |
+
const [errorMsg, setErrorMsg] = useState<string>("");
|
| 59 |
+
const [share, setShare] = useState<PublicShareInfo | null>(null);
|
| 60 |
+
const [accessGranted, setAccessGranted] = useState<boolean>(false);
|
| 61 |
+
const [requestStatus, setRequestStatus] = useState<"none" | "pending" | "approved" | "rejected" | "disabled">("none");
|
| 62 |
+
|
| 63 |
+
const [visitorName, setVisitorName] = useState<string>("");
|
| 64 |
+
const [note, setNote] = useState<string>("");
|
| 65 |
+
const [submittingRequest, setSubmittingRequest] = useState<boolean>(false);
|
| 66 |
+
const [copied, setCopied] = useState<boolean>(false);
|
| 67 |
+
|
| 68 |
+
const fetchShareStatus = useCallback(
|
| 69 |
+
async (vToken: string, silent = false) => {
|
| 70 |
+
if (!shareId) {
|
| 71 |
+
setErrorMsg("Thiếu mã liên kết chia sẻ (id).");
|
| 72 |
+
setLoading(false);
|
| 73 |
+
return;
|
| 74 |
+
}
|
| 75 |
+
if (!silent) setLoading(true);
|
| 76 |
+
try {
|
| 77 |
+
const authToken = typeof window !== "undefined" ? localStorage.getItem("xet_auth_token") || "" : "";
|
| 78 |
+
const headers: Record<string, string> = {};
|
| 79 |
+
if (authToken) headers["Authorization"] = `Bearer ${authToken}`;
|
| 80 |
+
|
| 81 |
+
const res = await apiFetch(
|
| 82 |
+
`/api/public/share?id=${encodeURIComponent(shareId)}&visitor_token=${encodeURIComponent(vToken)}`,
|
| 83 |
+
{ headers }
|
| 84 |
+
);
|
| 85 |
+
const data = await res.json();
|
| 86 |
+
if (!res.ok) {
|
| 87 |
+
setShare(null);
|
| 88 |
+
setAccessGranted(false);
|
| 89 |
+
setRequestStatus("disabled");
|
| 90 |
+
setErrorMsg(data.detail || data.error || "Liên kết chia sẻ đã bị tắt hoặc không tồn tại.");
|
| 91 |
+
} else {
|
| 92 |
+
setErrorMsg("");
|
| 93 |
+
setShare(data.share);
|
| 94 |
+
setAccessGranted(Boolean(data.access_granted));
|
| 95 |
+
setRequestStatus(data.request_status || "none");
|
| 96 |
+
if (data.visitor_name && !visitorName) {
|
| 97 |
+
setVisitorName(data.visitor_name);
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
} catch {
|
| 101 |
+
if (!silent) {
|
| 102 |
+
setErrorMsg("Không thể kết nối tới máy chủ Upload ThTuanIT.");
|
| 103 |
+
}
|
| 104 |
+
} finally {
|
| 105 |
+
if (!silent) setLoading(false);
|
| 106 |
+
}
|
| 107 |
+
},
|
| 108 |
+
[shareId, visitorName]
|
| 109 |
+
);
|
| 110 |
+
|
| 111 |
+
useEffect(() => {
|
| 112 |
+
const vToken = getOrCreateVisitorToken();
|
| 113 |
+
const savedName = typeof window !== "undefined" ? localStorage.getItem("thtuanit_visitor_name") || "" : "";
|
| 114 |
+
if (savedName) setVisitorName(savedName);
|
| 115 |
+
setVisitorToken(vToken);
|
| 116 |
+
fetchShareStatus(vToken, false);
|
| 117 |
+
}, [fetchShareStatus]);
|
| 118 |
+
|
| 119 |
+
// Poll every 3 seconds while waiting for owner approval
|
| 120 |
+
useEffect(() => {
|
| 121 |
+
if (!shareId || !visitorToken) return;
|
| 122 |
+
if (requestStatus !== "pending" && accessGranted) return;
|
| 123 |
+
const timer = setInterval(() => {
|
| 124 |
+
fetchShareStatus(visitorToken, true);
|
| 125 |
+
}, 3000);
|
| 126 |
+
return () => clearInterval(timer);
|
| 127 |
+
}, [shareId, visitorToken, requestStatus, accessGranted, fetchShareStatus]);
|
| 128 |
+
|
| 129 |
+
async function handleRequestAccess(e: React.FormEvent) {
|
| 130 |
+
e.preventDefault();
|
| 131 |
+
if (!shareId || !visitorName.trim()) return;
|
| 132 |
+
setSubmittingRequest(true);
|
| 133 |
+
try {
|
| 134 |
+
if (typeof window !== "undefined") {
|
| 135 |
+
localStorage.setItem("thtuanit_visitor_name", visitorName.trim());
|
| 136 |
+
}
|
| 137 |
+
const res = await apiFetch("/api/public/share/request", {
|
| 138 |
+
method: "POST",
|
| 139 |
+
headers: { "Content-Type": "application/json" },
|
| 140 |
+
body: JSON.stringify({
|
| 141 |
+
share_id: shareId,
|
| 142 |
+
visitor_token: visitorToken,
|
| 143 |
+
visitor_name: visitorName.trim(),
|
| 144 |
+
note: note.trim(),
|
| 145 |
+
}),
|
| 146 |
+
});
|
| 147 |
+
const data = await res.json();
|
| 148 |
+
if (!res.ok) {
|
| 149 |
+
setErrorMsg(data.detail || data.error || "Không thể gửi yêu cầu truy cập.");
|
| 150 |
+
} else {
|
| 151 |
+
setRequestStatus(data.request_status || "pending");
|
| 152 |
+
}
|
| 153 |
+
} catch {
|
| 154 |
+
setErrorMsg("Lỗi kết nối khi gửi yêu cầu.");
|
| 155 |
+
} finally {
|
| 156 |
+
setSubmittingRequest(false);
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
function handleCopyLink() {
|
| 161 |
+
if (!shareId) return;
|
| 162 |
+
const url = buildFrontendShareUrl(shareId);
|
| 163 |
+
navigator.clipboard.writeText(url);
|
| 164 |
+
setCopied(true);
|
| 165 |
+
setTimeout(() => setCopied(false), 2500);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
const category = share ? detectCategory(share.file_name) : "doc";
|
| 169 |
+
const inlineUrl = share ? buildPublicShareDownloadUrl(share.id, visitorToken, true) : "";
|
| 170 |
+
const downloadUrl = share ? buildPublicShareDownloadUrl(share.id, visitorToken, false) : "";
|
| 171 |
+
|
| 172 |
+
return (
|
| 173 |
+
<div className="min-h-screen bg-grid-pattern flex flex-col justify-between">
|
| 174 |
+
{/* Top Navbar */}
|
| 175 |
+
<header className="glass border-b border-white/10 px-6 py-4">
|
| 176 |
+
<div className="max-w-5xl mx-auto flex items-center justify-between">
|
| 177 |
+
<Link href="/" className="flex items-center gap-3">
|
| 178 |
+
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-indigo-500 via-purple-500 to-amber-500 p-[1px]">
|
| 179 |
+
<div className="w-full h-full bg-slate-950 rounded-[11px] flex items-center justify-center text-indigo-400">
|
| 180 |
+
<CloudUpload className="w-5 h-5" />
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
<div>
|
| 184 |
+
<div className="flex items-center gap-2">
|
| 185 |
+
<span className="font-bold text-base text-white">Upload ThTuanIT</span>
|
| 186 |
+
<span className="text-[10px] font-mono px-2 py-0.5 rounded-full bg-emerald-500/20 text-emerald-300 border border-emerald-500/30">
|
| 187 |
+
QUICK SHARE
|
| 188 |
+
</span>
|
| 189 |
+
</div>
|
| 190 |
+
<p className="text-xs text-slate-400">Trình xem & Chia sẻ tệp tin bảo mật</p>
|
| 191 |
+
</div>
|
| 192 |
+
</Link>
|
| 193 |
+
|
| 194 |
+
<div className="flex items-center gap-2.5">
|
| 195 |
+
{share && (
|
| 196 |
+
<button
|
| 197 |
+
onClick={handleCopyLink}
|
| 198 |
+
className="px-3.5 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs font-semibold text-slate-200 flex items-center gap-1.5 transition"
|
| 199 |
+
>
|
| 200 |
+
{copied ? <Check className="w-3.5 h-3.5 text-emerald-400" /> : <Copy className="w-3.5 h-3.5" />}
|
| 201 |
+
<span>{copied ? "Đã chép Link" : "Sao chép Link"}</span>
|
| 202 |
+
</button>
|
| 203 |
+
)}
|
| 204 |
+
<Link
|
| 205 |
+
href="/explorer"
|
| 206 |
+
className="px-4 py-2 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white transition"
|
| 207 |
+
>
|
| 208 |
+
Mở Kho lưu trữ của bạn
|
| 209 |
+
</Link>
|
| 210 |
+
</div>
|
| 211 |
+
</div>
|
| 212 |
+
</header>
|
| 213 |
+
|
| 214 |
+
{/* Main Content */}
|
| 215 |
+
<main className="flex-1 flex items-center justify-center p-6">
|
| 216 |
+
{loading ? (
|
| 217 |
+
<div className="glass-panel rounded-3xl p-10 max-w-md w-full text-center space-y-3 border border-white/10">
|
| 218 |
+
<RefreshCw className="w-8 h-8 text-indigo-400 animate-spin mx-auto" />
|
| 219 |
+
<p className="text-sm font-bold text-white">Đang kiểm tra quyền truy cập liên kết chia sẻ...</p>
|
| 220 |
+
</div>
|
| 221 |
+
) : errorMsg || !share ? (
|
| 222 |
+
<div className="glass-panel rounded-3xl p-8 max-w-md w-full text-center space-y-4 border border-rose-500/30">
|
| 223 |
+
<div className="w-14 h-14 mx-auto rounded-2xl bg-rose-500/15 border border-rose-500/30 flex items-center justify-center text-rose-400">
|
| 224 |
+
<AlertTriangle className="w-7 h-7" />
|
| 225 |
+
</div>
|
| 226 |
+
<h1 className="text-lg font-extrabold text-white">Liên kết chia sẻ không khả dụng</h1>
|
| 227 |
+
<p className="text-xs text-slate-300 leading-relaxed">
|
| 228 |
+
{errorMsg || "Chủ sở hữu đã tắt chia sẻ tệp tin này hoặc đường dẫn không tồn tại."}
|
| 229 |
+
</p>
|
| 230 |
+
<div className="pt-2">
|
| 231 |
+
<Link
|
| 232 |
+
href="/"
|
| 233 |
+
className="inline-flex items-center gap-2 px-5 py-2.5 rounded-xl bg-white/10 hover:bg-white/15 text-xs font-bold text-white transition"
|
| 234 |
+
>
|
| 235 |
+
Về trang chủ Upload ThTuanIT
|
| 236 |
+
</Link>
|
| 237 |
+
</div>
|
| 238 |
+
</div>
|
| 239 |
+
) : !accessGranted ? (
|
| 240 |
+
/* REQUIRE APPROVAL SCREEN */
|
| 241 |
+
<div className="glass-panel rounded-3xl p-8 max-w-lg w-full border border-indigo-500/30 space-y-6">
|
| 242 |
+
<div className="flex items-center gap-4 p-4 rounded-2xl bg-slate-900/90 border border-white/10">
|
| 243 |
+
<div className="w-12 h-12 rounded-2xl bg-indigo-500/20 border border-indigo-500/40 flex items-center justify-center shrink-0">
|
| 244 |
+
{category === "video" ? (
|
| 245 |
+
<Film className="w-6 h-6 text-rose-400" />
|
| 246 |
+
) : category === "image" ? (
|
| 247 |
+
<ImageIcon className="w-6 h-6 text-indigo-400" />
|
| 248 |
+
) : category === "archive" ? (
|
| 249 |
+
<Archive className="w-6 h-6 text-amber-400" />
|
| 250 |
+
) : (
|
| 251 |
+
<FileCode2 className="w-6 h-6 text-emerald-400" />
|
| 252 |
+
)}
|
| 253 |
+
</div>
|
| 254 |
+
<div className="min-w-0 flex-1">
|
| 255 |
+
<h1 className="text-base font-bold text-white truncate">{share.file_name}</h1>
|
| 256 |
+
<p className="text-xs text-slate-400 font-mono mt-0.5">
|
| 257 |
+
{formatBytes(share.size)} • Chia sẻ bởi <span className="text-indigo-300">@{share.owner}</span>
|
| 258 |
+
</p>
|
| 259 |
+
</div>
|
| 260 |
+
</div>
|
| 261 |
+
|
| 262 |
+
{requestStatus === "pending" ? (
|
| 263 |
+
<div className="p-6 rounded-2xl bg-amber-500/10 border border-amber-500/30 text-center space-y-3">
|
| 264 |
+
<div className="w-12 h-12 mx-auto rounded-2xl bg-amber-500/20 border border-amber-500/40 flex items-center justify-center text-amber-300">
|
| 265 |
+
<Clock className="w-6 h-6 animate-pulse" />
|
| 266 |
+
</div>
|
| 267 |
+
<h2 className="text-sm font-bold text-amber-200">
|
| 268 |
+
Đang chờ @{share.owner} cho phép xem tệp...
|
| 269 |
+
</h2>
|
| 270 |
+
<p className="text-xs text-slate-300 leading-relaxed">
|
| 271 |
+
Yêu cầu của bạn (<b>{visitorName}</b>) đã được gửi tới chủ sở hữu tệp. Trang này sẽ{" "}
|
| 272 |
+
<b>tự động mở tệp ngay lập tức</b> khi chủ tệp nhấn <b>“Cho phép”</b>.
|
| 273 |
+
</p>
|
| 274 |
+
<div className="pt-2">
|
| 275 |
+
<button
|
| 276 |
+
type="button"
|
| 277 |
+
onClick={() => fetchShareStatus(visitorToken, false)}
|
| 278 |
+
className="inline-flex items-center gap-1.5 px-4 py-2 rounded-xl bg-white/10 hover:bg-white/15 text-xs font-semibold text-white transition"
|
| 279 |
+
>
|
| 280 |
+
<RefreshCw className="w-3.5 h-3.5" /> Kiểm tra ngay
|
| 281 |
+
</button>
|
| 282 |
+
</div>
|
| 283 |
+
</div>
|
| 284 |
+
) : (
|
| 285 |
+
<form onSubmit={handleRequestAccess} className="space-y-4">
|
| 286 |
+
<div className="p-4 rounded-2xl bg-indigo-500/10 border border-indigo-500/30 flex items-start gap-3">
|
| 287 |
+
<Lock className="w-5 h-5 text-indigo-400 shrink-0 mt-0.5" />
|
| 288 |
+
<div className="text-xs text-slate-300 leading-relaxed">
|
| 289 |
+
{requestStatus === "rejected" ? (
|
| 290 |
+
<span className="text-rose-300 font-semibold">
|
| 291 |
+
Yêu cầu trước đó đã bị từ chối hoặc thu hồi. Bạn có thể gửi lại yêu cầu xin phép bên dưới.
|
| 292 |
+
</span>
|
| 293 |
+
) : (
|
| 294 |
+
<span>
|
| 295 |
+
Chủ sở hữu tệp (<b>@{share.owner}</b>) yêu cầu xác nhận trước khi xem. Vui lòng nhập tên của bạn
|
| 296 |
+
để gửi yêu cầu cho phép xem và tải tệp.
|
| 297 |
+
</span>
|
| 298 |
+
)}
|
| 299 |
+
</div>
|
| 300 |
+
</div>
|
| 301 |
+
|
| 302 |
+
<div>
|
| 303 |
+
<label className="block text-xs font-semibold text-slate-200 mb-1.5">
|
| 304 |
+
Tên của bạn (để chủ tệp biết ai đang xin xem) *
|
| 305 |
+
</label>
|
| 306 |
+
<input
|
| 307 |
+
type="text"
|
| 308 |
+
required
|
| 309 |
+
value={visitorName}
|
| 310 |
+
onChange={(e) => setVisitorName(e.target.value)}
|
| 311 |
+
placeholder="Ví dụ: Nguyễn Văn A / Tuấn..."
|
| 312 |
+
className="w-full bg-slate-900 border border-white/15 focus:border-indigo-500 rounded-xl px-4 py-2.5 text-sm text-white focus:outline-none"
|
| 313 |
+
/>
|
| 314 |
+
</div>
|
| 315 |
+
|
| 316 |
+
<div>
|
| 317 |
+
<label className="block text-xs font-semibold text-slate-300 mb-1.5">
|
| 318 |
+
Lời nhắn gửi chủ tệp (tùy chọn)
|
| 319 |
+
</label>
|
| 320 |
+
<input
|
| 321 |
+
type="text"
|
| 322 |
+
value={note}
|
| 323 |
+
onChange={(e) => setNote(e.target.value)}
|
| 324 |
+
placeholder="Ví dụ: Cho mình xin quyền xem file này nhé!"
|
| 325 |
+
className="w-full bg-slate-900 border border-white/15 focus:border-indigo-500 rounded-xl px-4 py-2.5 text-sm text-white focus:outline-none"
|
| 326 |
+
/>
|
| 327 |
+
</div>
|
| 328 |
+
|
| 329 |
+
<button
|
| 330 |
+
type="submit"
|
| 331 |
+
disabled={submittingRequest}
|
| 332 |
+
className="w-full py-3 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 hover:from-indigo-500 hover:to-violet-500 text-xs font-bold text-white shadow-lg shadow-indigo-600/30 flex items-center justify-center gap-2 transition"
|
| 333 |
+
>
|
| 334 |
+
<Send className="w-4 h-4" />
|
| 335 |
+
<span>{submittingRequest ? "Đang gửi yêu cầu..." : "Hỏi xin phép xem & tải tệp"}</span>
|
| 336 |
+
</button>
|
| 337 |
+
</form>
|
| 338 |
+
)}
|
| 339 |
+
</div>
|
| 340 |
+
) : (
|
| 341 |
+
/* ACCESS GRANTED -> FULL PREVIEW & DOWNLOAD */
|
| 342 |
+
<div className="glass-panel rounded-3xl overflow-hidden border border-white/15 max-w-4xl w-full flex flex-col">
|
| 343 |
+
<div className="px-6 py-4 border-b border-white/10 flex flex-wrap items-center justify-between gap-4">
|
| 344 |
+
<div className="min-w-0">
|
| 345 |
+
<div className="flex items-center gap-2">
|
| 346 |
+
<h1 className="text-base sm:text-lg font-extrabold text-white truncate">{share.file_name}</h1>
|
| 347 |
+
<span className="px-2 py-0.5 rounded-full text-[10px] font-mono bg-emerald-500/20 text-emerald-300 border border-emerald-500/30 flex items-center gap-1 shrink-0">
|
| 348 |
+
<CheckCircle2 className="w-3 h-3" /> Đã cấp quyền xem
|
| 349 |
+
</span>
|
| 350 |
+
</div>
|
| 351 |
+
<p className="text-xs text-slate-400 font-mono mt-0.5">
|
| 352 |
+
Kích thước: {formatBytes(share.size)} • Chia sẻ bởi @{share.owner} • Cập nhật: {share.updated_at}
|
| 353 |
+
</p>
|
| 354 |
+
</div>
|
| 355 |
+
|
| 356 |
+
<div className="flex items-center gap-2.5">
|
| 357 |
+
<a
|
| 358 |
+
href={downloadUrl}
|
| 359 |
+
download={share.file_name}
|
| 360 |
+
className="px-5 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 hover:from-indigo-500 hover:to-violet-500 text-xs font-bold text-white shadow-lg shadow-indigo-600/30 flex items-center gap-2 transition"
|
| 361 |
+
>
|
| 362 |
+
<Download className="w-4 h-4" />
|
| 363 |
+
<span>Tải tệp xuống ({formatBytes(share.size)})</span>
|
| 364 |
+
</a>
|
| 365 |
+
</div>
|
| 366 |
+
</div>
|
| 367 |
+
|
| 368 |
+
<div className="p-6 bg-slate-950/80 min-h-[380px] flex items-center justify-center">
|
| 369 |
+
{category === "video" ? (
|
| 370 |
+
<video
|
| 371 |
+
controls
|
| 372 |
+
autoPlay
|
| 373 |
+
src={inlineUrl}
|
| 374 |
+
className="max-h-[68vh] w-full rounded-2xl bg-black border border-white/10 shadow-2xl"
|
| 375 |
+
/>
|
| 376 |
+
) : category === "image" ? (
|
| 377 |
+
<img
|
| 378 |
+
src={inlineUrl}
|
| 379 |
+
alt={share.file_name}
|
| 380 |
+
className="max-h-[68vh] rounded-2xl object-contain border border-white/10 shadow-2xl"
|
| 381 |
+
/>
|
| 382 |
+
) : (
|
| 383 |
+
<div className="text-center py-12 space-y-4 max-w-md">
|
| 384 |
+
<div className="w-16 h-16 mx-auto rounded-2xl bg-indigo-500/15 border border-indigo-500/30 flex items-center justify-center text-indigo-400">
|
| 385 |
+
<Share2 className="w-8 h-8" />
|
| 386 |
+
</div>
|
| 387 |
+
<div className="space-y-1">
|
| 388 |
+
<h2 className="text-base font-bold text-white break-all">{share.file_name}</h2>
|
| 389 |
+
<p className="text-xs text-slate-400 font-mono">
|
| 390 |
+
Dung lượng: {formatBytes(share.size)} • Người chia sẻ: @{share.owner}
|
| 391 |
+
</p>
|
| 392 |
+
</div>
|
| 393 |
+
<a
|
| 394 |
+
href={downloadUrl}
|
| 395 |
+
download={share.file_name}
|
| 396 |
+
className="inline-flex items-center gap-2 px-6 py-3 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white shadow-lg shadow-indigo-600/30 transition"
|
| 397 |
+
>
|
| 398 |
+
<Download className="w-4 h-4" />
|
| 399 |
+
<span>Tải tệp tin về máy ngay</span>
|
| 400 |
+
</a>
|
| 401 |
+
</div>
|
| 402 |
+
)}
|
| 403 |
+
</div>
|
| 404 |
+
</div>
|
| 405 |
+
)}
|
| 406 |
+
</main>
|
| 407 |
+
|
| 408 |
+
<footer className="py-4 text-center text-xs text-slate-500 font-mono border-t border-white/5">
|
| 409 |
+
Upload ThTuanIT • Hệ thống Chia sẻ Tệp tin Nhanh & Kiểm soát Quyền Truy cập
|
| 410 |
+
</footer>
|
| 411 |
+
</div>
|
| 412 |
+
);
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
export default function SharePage() {
|
| 416 |
+
return (
|
| 417 |
+
<Suspense
|
| 418 |
+
fallback={
|
| 419 |
+
<div className="min-h-screen flex items-center justify-center bg-grid-pattern text-white text-sm">
|
| 420 |
+
Đang tải liên kết chia sẻ Upload ThTuanIT...
|
| 421 |
+
</div>
|
| 422 |
+
}
|
| 423 |
+
>
|
| 424 |
+
<ShareViewerContent />
|
| 425 |
+
</Suspense>
|
| 426 |
+
);
|
| 427 |
+
}
|
frontend/src/app/sitemap.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { MetadataRoute } from "next";
|
| 2 |
+
|
| 3 |
+
export default function sitemap(): MetadataRoute.Sitemap {
|
| 4 |
+
const now = new Date();
|
| 5 |
+
return [
|
| 6 |
+
{
|
| 7 |
+
url: "http://localhost:3000/",
|
| 8 |
+
lastModified: now,
|
| 9 |
+
changeFrequency: "daily",
|
| 10 |
+
priority: 1.0,
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
url: "http://localhost:3000/dashboard",
|
| 14 |
+
lastModified: now,
|
| 15 |
+
changeFrequency: "daily",
|
| 16 |
+
priority: 0.9,
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
url: "http://localhost:3000/explorer",
|
| 20 |
+
lastModified: now,
|
| 21 |
+
changeFrequency: "daily",
|
| 22 |
+
priority: 0.9,
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
url: "http://localhost:3000/developers",
|
| 26 |
+
lastModified: now,
|
| 27 |
+
changeFrequency: "weekly",
|
| 28 |
+
priority: 0.85,
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
url: "http://localhost:3000/login",
|
| 32 |
+
lastModified: now,
|
| 33 |
+
changeFrequency: "monthly",
|
| 34 |
+
priority: 0.8,
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
url: "http://localhost:3000/register",
|
| 38 |
+
lastModified: now,
|
| 39 |
+
changeFrequency: "monthly",
|
| 40 |
+
priority: 0.8,
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
url: "http://localhost:3000/activity",
|
| 44 |
+
lastModified: now,
|
| 45 |
+
changeFrequency: "daily",
|
| 46 |
+
priority: 0.7,
|
| 47 |
+
},
|
| 48 |
+
];
|
| 49 |
+
}
|
frontend/src/components/FileInspectorDrawer.tsx
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import { Info, X, Eye, Download, Edit3, Trash2, Share2 } from "lucide-react";
|
| 5 |
+
import { useCloud } from "@/context/CloudContext";
|
| 6 |
+
import { formatBytes } from "@/lib/api";
|
| 7 |
+
|
| 8 |
+
export function FileInspectorDrawer() {
|
| 9 |
+
const {
|
| 10 |
+
inspectedFile,
|
| 11 |
+
setInspectedFile,
|
| 12 |
+
getDownloadUrl,
|
| 13 |
+
setPreviewFile,
|
| 14 |
+
triggerDownload,
|
| 15 |
+
sharesMap,
|
| 16 |
+
setShareTarget,
|
| 17 |
+
canRename,
|
| 18 |
+
canDelete,
|
| 19 |
+
setRenameTarget,
|
| 20 |
+
setNewPathInput,
|
| 21 |
+
handleDeleteFile,
|
| 22 |
+
} = useCloud();
|
| 23 |
+
|
| 24 |
+
if (!inspectedFile) return null;
|
| 25 |
+
|
| 26 |
+
const fileShare = sharesMap[inspectedFile.path];
|
| 27 |
+
const pendingCount =
|
| 28 |
+
fileShare?.enabled && Array.isArray(fileShare.requests)
|
| 29 |
+
? fileShare.requests.filter((r) => r.status === "pending").length
|
| 30 |
+
: 0;
|
| 31 |
+
|
| 32 |
+
return (
|
| 33 |
+
<aside className="w-80 shrink-0 glass rounded-3xl p-5 border border-white/10 flex flex-col justify-between h-fit sticky top-24">
|
| 34 |
+
<div className="space-y-4">
|
| 35 |
+
<div className="flex items-center justify-between border-b border-white/10 pb-3">
|
| 36 |
+
<span className="text-xs font-bold uppercase tracking-wider text-indigo-300 flex items-center gap-1.5">
|
| 37 |
+
<Info className="w-4 h-4" /> Chi tiết Tệp tin
|
| 38 |
+
</span>
|
| 39 |
+
<button
|
| 40 |
+
onClick={() => setInspectedFile(null)}
|
| 41 |
+
className="p-1 rounded-lg hover:bg-white/10 text-slate-400"
|
| 42 |
+
>
|
| 43 |
+
<X className="w-4 h-4" />
|
| 44 |
+
</button>
|
| 45 |
+
</div>
|
| 46 |
+
|
| 47 |
+
{/* Mini Media Thumbnail if video or image */}
|
| 48 |
+
{inspectedFile.category === "video" ? (
|
| 49 |
+
<video
|
| 50 |
+
controls
|
| 51 |
+
src={getDownloadUrl(inspectedFile.path, true)}
|
| 52 |
+
className="w-full rounded-2xl bg-black border border-white/10 max-h-44"
|
| 53 |
+
/>
|
| 54 |
+
) : inspectedFile.category === "image" ? (
|
| 55 |
+
<img
|
| 56 |
+
src={getDownloadUrl(inspectedFile.path, true)}
|
| 57 |
+
alt={inspectedFile.name}
|
| 58 |
+
className="w-full rounded-2xl object-cover max-h-44 border border-white/10"
|
| 59 |
+
/>
|
| 60 |
+
) : null}
|
| 61 |
+
|
| 62 |
+
<div>
|
| 63 |
+
<h4 className="text-sm font-bold text-white break-all">{inspectedFile.name}</h4>
|
| 64 |
+
<p className="text-xs font-mono text-slate-400 mt-1 break-all">
|
| 65 |
+
cloud://thtuanit/{inspectedFile.path}
|
| 66 |
+
</p>
|
| 67 |
+
</div>
|
| 68 |
+
|
| 69 |
+
<div className="p-3.5 rounded-2xl bg-slate-900/90 border border-white/5 space-y-2 text-xs font-mono">
|
| 70 |
+
<div className="flex justify-between">
|
| 71 |
+
<span className="text-slate-400">Người sở hữu:</span>
|
| 72 |
+
<span className="text-indigo-300 font-bold">@{inspectedFile.owner}</span>
|
| 73 |
+
</div>
|
| 74 |
+
<div className="flex justify-between">
|
| 75 |
+
<span className="text-slate-400">Dung lượng:</span>
|
| 76 |
+
<span className="text-white">{formatBytes(inspectedFile.size)}</span>
|
| 77 |
+
</div>
|
| 78 |
+
<div className="flex justify-between">
|
| 79 |
+
<span className="text-slate-400">Bytes:</span>
|
| 80 |
+
<span className="text-slate-300">{inspectedFile.size.toLocaleString()}</span>
|
| 81 |
+
</div>
|
| 82 |
+
<div className="flex justify-between">
|
| 83 |
+
<span className="text-slate-400">Cập nhật:</span>
|
| 84 |
+
<span className="text-slate-300">{inspectedFile.updatedAt || "N/A"}</span>
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
|
| 88 |
+
<div className="space-y-2 pt-2">
|
| 89 |
+
<button
|
| 90 |
+
onClick={() => setShareTarget(inspectedFile)}
|
| 91 |
+
className="w-full py-2.5 rounded-xl bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-500 hover:to-teal-500 text-xs font-bold text-white flex items-center justify-center gap-2 transition shadow-lg shadow-emerald-600/20"
|
| 92 |
+
>
|
| 93 |
+
<Share2 className="w-4 h-4" />
|
| 94 |
+
<span>
|
| 95 |
+
{fileShare?.enabled
|
| 96 |
+
? pendingCount > 0
|
| 97 |
+
? `Quản lý Link Share (${pendingCount} chờ duyệt)`
|
| 98 |
+
: "Đang chia sẻ • Quản lý Link"
|
| 99 |
+
: "Chia sẻ nhanh qua Link"}
|
| 100 |
+
</span>
|
| 101 |
+
</button>
|
| 102 |
+
<button
|
| 103 |
+
onClick={() => setPreviewFile(inspectedFile)}
|
| 104 |
+
className="w-full py-2.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white flex items-center justify-center gap-2 transition"
|
| 105 |
+
>
|
| 106 |
+
<Eye className="w-4 h-4" /> Mở Trình phát Toàn màn hình
|
| 107 |
+
</button>
|
| 108 |
+
<button
|
| 109 |
+
onClick={() => triggerDownload(inspectedFile)}
|
| 110 |
+
className="w-full py-2.5 rounded-xl bg-white/10 hover:bg-white/15 text-xs font-semibold text-slate-200 flex items-center justify-center gap-2 transition"
|
| 111 |
+
>
|
| 112 |
+
<Download className="w-4 h-4" /> Tải tệp về máy
|
| 113 |
+
</button>
|
| 114 |
+
{canRename && (
|
| 115 |
+
<button
|
| 116 |
+
onClick={() => {
|
| 117 |
+
setRenameTarget(inspectedFile);
|
| 118 |
+
setNewPathInput(inspectedFile.path);
|
| 119 |
+
}}
|
| 120 |
+
className="w-full py-2.5 rounded-xl bg-amber-500/15 hover:bg-amber-500/25 border border-amber-500/30 text-xs font-semibold text-amber-300 flex items-center justify-center gap-2 transition"
|
| 121 |
+
>
|
| 122 |
+
<Edit3 className="w-4 h-4" /> Đổi tên / Di chuyển
|
| 123 |
+
</button>
|
| 124 |
+
)}
|
| 125 |
+
{canDelete && (
|
| 126 |
+
<button
|
| 127 |
+
onClick={() => handleDeleteFile(inspectedFile)}
|
| 128 |
+
className="w-full py-2.5 rounded-xl bg-rose-500/15 hover:bg-rose-500/25 border border-rose-500/30 text-xs font-semibold text-rose-300 flex items-center justify-center gap-2 transition"
|
| 129 |
+
>
|
| 130 |
+
<Trash2 className="w-4 h-4" /> Xóa khỏi Kho lưu trữ
|
| 131 |
+
</button>
|
| 132 |
+
)}
|
| 133 |
+
</div>
|
| 134 |
+
</div>
|
| 135 |
+
</aside>
|
| 136 |
+
);
|
| 137 |
+
}
|
frontend/src/components/GlobalModals.tsx
ADDED
|
@@ -0,0 +1,769 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState, useEffect } from "react";
|
| 4 |
+
import {
|
| 5 |
+
UploadCloud,
|
| 6 |
+
X,
|
| 7 |
+
Edit3,
|
| 8 |
+
Shield,
|
| 9 |
+
Download,
|
| 10 |
+
CheckCircle2,
|
| 11 |
+
AlertTriangle,
|
| 12 |
+
Sparkles,
|
| 13 |
+
Share2,
|
| 14 |
+
Copy,
|
| 15 |
+
Check,
|
| 16 |
+
Lock,
|
| 17 |
+
Unlock,
|
| 18 |
+
Power,
|
| 19 |
+
RefreshCw,
|
| 20 |
+
ExternalLink,
|
| 21 |
+
UserCheck,
|
| 22 |
+
UserX,
|
| 23 |
+
Clock,
|
| 24 |
+
} from "lucide-react";
|
| 25 |
+
import { useCloud } from "@/context/CloudContext";
|
| 26 |
+
import { formatBytes, buildFrontendShareUrl } from "@/lib/api";
|
| 27 |
+
import { ToastMsg } from "@/types/cloud";
|
| 28 |
+
|
| 29 |
+
export function GlobalModals() {
|
| 30 |
+
const {
|
| 31 |
+
uploadModalOpen,
|
| 32 |
+
setUploadModalOpen,
|
| 33 |
+
uploadTargetFolder,
|
| 34 |
+
setUploadTargetFolder,
|
| 35 |
+
selectedFiles,
|
| 36 |
+
setSelectedFiles,
|
| 37 |
+
startBatchUpload,
|
| 38 |
+
renameTarget,
|
| 39 |
+
setRenameTarget,
|
| 40 |
+
newPathInput,
|
| 41 |
+
setNewPathInput,
|
| 42 |
+
renaming,
|
| 43 |
+
handleRenameSubmit,
|
| 44 |
+
editingUser,
|
| 45 |
+
setEditingUser,
|
| 46 |
+
handleSaveUser,
|
| 47 |
+
previewFile,
|
| 48 |
+
setPreviewFile,
|
| 49 |
+
getDownloadUrl,
|
| 50 |
+
triggerDownload,
|
| 51 |
+
sharesMap,
|
| 52 |
+
shareTarget,
|
| 53 |
+
setShareTarget,
|
| 54 |
+
upsertFileShare,
|
| 55 |
+
respondShareRequest,
|
| 56 |
+
notify,
|
| 57 |
+
toasts,
|
| 58 |
+
} = useCloud();
|
| 59 |
+
|
| 60 |
+
const [draftRequireApproval, setDraftRequireApproval] = useState<boolean>(true);
|
| 61 |
+
const [savingShare, setSavingShare] = useState<boolean>(false);
|
| 62 |
+
const [copiedShareLink, setCopiedShareLink] = useState<boolean>(false);
|
| 63 |
+
|
| 64 |
+
const activeShare = shareTarget ? sharesMap[shareTarget.path] : undefined;
|
| 65 |
+
|
| 66 |
+
useEffect(() => {
|
| 67 |
+
if (shareTarget) {
|
| 68 |
+
const sh = sharesMap[shareTarget.path];
|
| 69 |
+
setDraftRequireApproval(sh ? sh.require_approval : true);
|
| 70 |
+
setCopiedShareLink(false);
|
| 71 |
+
}
|
| 72 |
+
}, [shareTarget, sharesMap]);
|
| 73 |
+
|
| 74 |
+
async function handleEnableShare() {
|
| 75 |
+
if (!shareTarget) return;
|
| 76 |
+
setSavingShare(true);
|
| 77 |
+
await upsertFileShare(shareTarget.path, shareTarget.size, true, draftRequireApproval, false);
|
| 78 |
+
setSavingShare(false);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
async function handleDisableShare() {
|
| 82 |
+
if (!shareTarget || !activeShare) return;
|
| 83 |
+
setSavingShare(true);
|
| 84 |
+
await upsertFileShare(shareTarget.path, shareTarget.size, false, activeShare.require_approval, false);
|
| 85 |
+
setSavingShare(false);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
async function handleToggleRequireApproval(nextVal: boolean) {
|
| 89 |
+
if (!shareTarget || !activeShare) return;
|
| 90 |
+
setDraftRequireApproval(nextVal);
|
| 91 |
+
setSavingShare(true);
|
| 92 |
+
await upsertFileShare(shareTarget.path, shareTarget.size, activeShare.enabled, nextVal, false);
|
| 93 |
+
setSavingShare(false);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
async function handleRegenerateShareLink() {
|
| 97 |
+
if (!shareTarget || !activeShare) return;
|
| 98 |
+
if (!confirm("Đổi mã liên kết mới sẽ vô hiệu hóa liên kết cũ và xóa danh sách đã cấp quyền trước đó. Tiếp tục?")) {
|
| 99 |
+
return;
|
| 100 |
+
}
|
| 101 |
+
setSavingShare(true);
|
| 102 |
+
await upsertFileShare(shareTarget.path, shareTarget.size, true, activeShare.require_approval, true);
|
| 103 |
+
setSavingShare(false);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
function handleCopyShareUrl(shareId: string) {
|
| 107 |
+
const url = buildFrontendShareUrl(shareId);
|
| 108 |
+
navigator.clipboard.writeText(url);
|
| 109 |
+
setCopiedShareLink(true);
|
| 110 |
+
notify("Đã sao chép liên kết chia sẻ!", "success", url);
|
| 111 |
+
setTimeout(() => setCopiedShareLink(false), 2500);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
return (
|
| 115 |
+
<>
|
| 116 |
+
{/* 1. UPLOAD MODAL */}
|
| 117 |
+
{uploadModalOpen && (
|
| 118 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-sm p-4">
|
| 119 |
+
<div className="glass-panel w-full max-w-lg rounded-3xl p-6 border border-white/15">
|
| 120 |
+
<div className="flex items-center justify-between mb-4">
|
| 121 |
+
<h3 className="text-base font-bold text-white flex items-center gap-2">
|
| 122 |
+
<UploadCloud className="w-5 h-5 text-indigo-400" />
|
| 123 |
+
<span>Tải tệp lên Upload ThTuanIT</span>
|
| 124 |
+
</h3>
|
| 125 |
+
<button onClick={() => setUploadModalOpen(false)} className="p-1.5 rounded-xl bg-white/5 text-slate-400">
|
| 126 |
+
<X className="w-4 h-4" />
|
| 127 |
+
</button>
|
| 128 |
+
</div>
|
| 129 |
+
|
| 130 |
+
<div className="space-y-4">
|
| 131 |
+
<div>
|
| 132 |
+
<label className="block text-xs font-medium text-slate-300 mb-1">Thư mục đích (tùy chọn)</label>
|
| 133 |
+
<input
|
| 134 |
+
type="text"
|
| 135 |
+
value={uploadTargetFolder}
|
| 136 |
+
onChange={(e) => setUploadTargetFolder(e.target.value)}
|
| 137 |
+
placeholder="Ví dụ: videos/2026 hoặc để trống lưu ở gốc"
|
| 138 |
+
className="w-full bg-slate-900 border border-white/10 rounded-xl px-3.5 py-2.5 text-sm text-white font-mono focus:outline-none"
|
| 139 |
+
/>
|
| 140 |
+
</div>
|
| 141 |
+
|
| 142 |
+
<label className="flex flex-col items-center justify-center p-8 border-2 border-dashed border-white/15 hover:border-indigo-500 rounded-2xl bg-slate-900/50 cursor-pointer transition">
|
| 143 |
+
<input
|
| 144 |
+
type="file"
|
| 145 |
+
multiple
|
| 146 |
+
className="hidden"
|
| 147 |
+
onChange={(e) => setSelectedFiles(Array.from(e.target.files || []))}
|
| 148 |
+
/>
|
| 149 |
+
<UploadCloud className="w-10 h-10 text-indigo-400 mb-2" />
|
| 150 |
+
<span className="text-sm font-medium text-slate-200">Nhấn để chọn nhiều tệp hoặc kéo thả</span>
|
| 151 |
+
<span className="text-xs text-slate-400 mt-1">Tối đa 10 GiB mỗi tệp qua Upload ThTuanIT Turbo Engine</span>
|
| 152 |
+
</label>
|
| 153 |
+
|
| 154 |
+
{selectedFiles.length > 0 && (
|
| 155 |
+
<div className="max-h-36 overflow-y-auto space-y-1.5">
|
| 156 |
+
{selectedFiles.map((f, i) => (
|
| 157 |
+
<div
|
| 158 |
+
key={i}
|
| 159 |
+
className="flex justify-between text-xs px-3 py-2 rounded-xl bg-slate-900 border border-white/10"
|
| 160 |
+
>
|
| 161 |
+
<span className="truncate text-slate-200">{f.name}</span>
|
| 162 |
+
<span className="font-mono text-slate-400 ml-2">{formatBytes(f.size)}</span>
|
| 163 |
+
</div>
|
| 164 |
+
))}
|
| 165 |
+
</div>
|
| 166 |
+
)}
|
| 167 |
+
|
| 168 |
+
<div className="flex justify-end gap-2 pt-2">
|
| 169 |
+
<button
|
| 170 |
+
onClick={() => setUploadModalOpen(false)}
|
| 171 |
+
className="px-4 py-2 rounded-xl bg-white/5 text-xs text-slate-300"
|
| 172 |
+
>
|
| 173 |
+
Hủy
|
| 174 |
+
</button>
|
| 175 |
+
<button
|
| 176 |
+
onClick={startBatchUpload}
|
| 177 |
+
className="px-5 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 text-xs font-bold text-white"
|
| 178 |
+
>
|
| 179 |
+
Bắt đầu tải lên ({selectedFiles.length})
|
| 180 |
+
</button>
|
| 181 |
+
</div>
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
</div>
|
| 185 |
+
)}
|
| 186 |
+
|
| 187 |
+
{/* 2. RENAME / MOVE FILE MODAL */}
|
| 188 |
+
{renameTarget && (
|
| 189 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-sm p-4">
|
| 190 |
+
<div className="glass-panel w-full max-w-md rounded-3xl p-6 border border-white/15">
|
| 191 |
+
<div className="flex items-center justify-between mb-4">
|
| 192 |
+
<h3 className="text-base font-bold text-white flex items-center gap-2">
|
| 193 |
+
<Edit3 className="w-5 h-5 text-amber-400" />
|
| 194 |
+
<span>Đổi tên / Di chuyển Tệp tin</span>
|
| 195 |
+
</h3>
|
| 196 |
+
<button onClick={() => setRenameTarget(null)} className="p-1.5 rounded-xl bg-white/5 text-slate-400">
|
| 197 |
+
<X className="w-4 h-4" />
|
| 198 |
+
</button>
|
| 199 |
+
</div>
|
| 200 |
+
|
| 201 |
+
<form onSubmit={handleRenameSubmit} className="space-y-4">
|
| 202 |
+
<div>
|
| 203 |
+
<label className="block text-xs text-slate-400 mb-1">Đường dẫn hiện tại</label>
|
| 204 |
+
<p className="text-xs font-mono text-slate-300 bg-slate-900/70 px-3 py-2 rounded-xl border border-white/5">
|
| 205 |
+
{renameTarget.path}
|
| 206 |
+
</p>
|
| 207 |
+
</div>
|
| 208 |
+
<div>
|
| 209 |
+
<label className="block text-xs font-medium text-slate-200 mb-1">Đường dẫn / Tên mới</label>
|
| 210 |
+
<input
|
| 211 |
+
type="text"
|
| 212 |
+
required
|
| 213 |
+
value={newPathInput}
|
| 214 |
+
onChange={(e) => setNewPathInput(e.target.value)}
|
| 215 |
+
className="w-full bg-slate-900 border border-white/15 focus:border-amber-400 rounded-xl px-3.5 py-2.5 text-sm text-white font-mono focus:outline-none"
|
| 216 |
+
/>
|
| 217 |
+
</div>
|
| 218 |
+
<div className="flex justify-end gap-2">
|
| 219 |
+
<button
|
| 220 |
+
type="button"
|
| 221 |
+
onClick={() => setRenameTarget(null)}
|
| 222 |
+
className="px-4 py-2 rounded-xl bg-white/5 text-xs text-slate-300"
|
| 223 |
+
>
|
| 224 |
+
Hủy
|
| 225 |
+
</button>
|
| 226 |
+
<button
|
| 227 |
+
type="submit"
|
| 228 |
+
disabled={renaming}
|
| 229 |
+
className="px-5 py-2 rounded-xl bg-amber-500 hover:bg-amber-400 text-slate-950 font-bold text-xs"
|
| 230 |
+
>
|
| 231 |
+
{renaming ? "Đang đồng bộ..." : "Lưu thay đổi"}
|
| 232 |
+
</button>
|
| 233 |
+
</div>
|
| 234 |
+
</form>
|
| 235 |
+
</div>
|
| 236 |
+
</div>
|
| 237 |
+
)}
|
| 238 |
+
|
| 239 |
+
{/* 3. QUICK SHARE MODAL (CHIA SẺ NHANH & PHÊ DUYỆT QUYỀN XEM) */}
|
| 240 |
+
{shareTarget && (
|
| 241 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-md p-4">
|
| 242 |
+
<div className="glass-panel w-full max-w-xl rounded-3xl p-6 border border-indigo-500/30 space-y-5 max-h-[90vh] overflow-y-auto">
|
| 243 |
+
<div className="flex items-center justify-between border-b border-white/10 pb-4">
|
| 244 |
+
<div className="flex items-center gap-3 min-w-0">
|
| 245 |
+
<div className="w-10 h-10 rounded-2xl bg-indigo-500/20 border border-indigo-500/40 flex items-center justify-center text-indigo-300 shrink-0">
|
| 246 |
+
<Share2 className="w-5 h-5" />
|
| 247 |
+
</div>
|
| 248 |
+
<div className="min-w-0">
|
| 249 |
+
<h3 className="text-base font-bold text-white truncate">Chia sẻ nhanh: {shareTarget.name}</h3>
|
| 250 |
+
<p className="text-xs text-slate-400 font-mono truncate">
|
| 251 |
+
{formatBytes(shareTarget.size)} • Chủ sở hữu: @{shareTarget.owner}
|
| 252 |
+
</p>
|
| 253 |
+
</div>
|
| 254 |
+
</div>
|
| 255 |
+
<button
|
| 256 |
+
onClick={() => setShareTarget(null)}
|
| 257 |
+
className="p-1.5 rounded-xl bg-white/5 hover:bg-white/10 text-slate-400 hover:text-white"
|
| 258 |
+
>
|
| 259 |
+
<X className="w-4 h-4" />
|
| 260 |
+
</button>
|
| 261 |
+
</div>
|
| 262 |
+
|
| 263 |
+
{/* IF NOT YET ENABLED -> CONFIRMATION TO ALLOW SHARING */}
|
| 264 |
+
{!activeShare || !activeShare.enabled ? (
|
| 265 |
+
<div className="space-y-4">
|
| 266 |
+
<div className="p-4 rounded-2xl bg-amber-500/10 border border-amber-500/30 space-y-2">
|
| 267 |
+
<div className="flex items-center gap-2 text-amber-300 font-bold text-xs uppercase tracking-wider">
|
| 268 |
+
<Lock className="w-4 h-4" />
|
| 269 |
+
<span>Xác nhận cho phép chia sẻ tệp tin</span>
|
| 270 |
+
</div>
|
| 271 |
+
<p className="text-xs text-slate-300 leading-relaxed">
|
| 272 |
+
Tệp <b>{shareTarget.name}</b> hiện đang ở chế độ <b>Riêng tư</b>. Bạn có muốn tạo liên kết chia sẻ
|
| 273 |
+
để gửi cho mọi người xem được tệp này không? Bạn có thể <b>tắt chia sẻ bất cứ lúc nào</b>.
|
| 274 |
+
</p>
|
| 275 |
+
</div>
|
| 276 |
+
|
| 277 |
+
<div className="space-y-2.5">
|
| 278 |
+
<p className="text-xs font-bold text-slate-200 uppercase tracking-wider">
|
| 279 |
+
Chọn chế độ kiểm soát người xem:
|
| 280 |
+
</p>
|
| 281 |
+
|
| 282 |
+
<label
|
| 283 |
+
onClick={() => setDraftRequireApproval(true)}
|
| 284 |
+
className={`flex items-start gap-3 p-3.5 rounded-2xl border cursor-pointer transition ${
|
| 285 |
+
draftRequireApproval
|
| 286 |
+
? "bg-indigo-500/15 border-indigo-500/50 text-white"
|
| 287 |
+
: "bg-slate-900/70 border-white/10 text-slate-400 hover:border-white/20"
|
| 288 |
+
}`}
|
| 289 |
+
>
|
| 290 |
+
<input
|
| 291 |
+
type="radio"
|
| 292 |
+
checked={draftRequireApproval}
|
| 293 |
+
onChange={() => setDraftRequireApproval(true)}
|
| 294 |
+
className="mt-1 accent-indigo-500"
|
| 295 |
+
/>
|
| 296 |
+
<div className="text-xs space-y-1">
|
| 297 |
+
<p className="font-bold text-slate-100 flex items-center gap-1.5">
|
| 298 |
+
<Lock className="w-3.5 h-3.5 text-indigo-400" />
|
| 299 |
+
<span>Phải hỏi xin phép khi truy cập (Khuyên dùng)</span>
|
| 300 |
+
</p>
|
| 301 |
+
<p className="text-slate-400 leading-relaxed">
|
| 302 |
+
Người có link khi mở phải gửi yêu cầu và <b>chờ bạn bấm "Cho phép"</b> mới được xem
|
| 303 |
+
trước hoặc tải tệp xuống.
|
| 304 |
+
</p>
|
| 305 |
+
</div>
|
| 306 |
+
</label>
|
| 307 |
+
|
| 308 |
+
<label
|
| 309 |
+
onClick={() => setDraftRequireApproval(false)}
|
| 310 |
+
className={`flex items-start gap-3 p-3.5 rounded-2xl border cursor-pointer transition ${
|
| 311 |
+
!draftRequireApproval
|
| 312 |
+
? "bg-emerald-500/15 border-emerald-500/50 text-white"
|
| 313 |
+
: "bg-slate-900/70 border-white/10 text-slate-400 hover:border-white/20"
|
| 314 |
+
}`}
|
| 315 |
+
>
|
| 316 |
+
<input
|
| 317 |
+
type="radio"
|
| 318 |
+
checked={!draftRequireApproval}
|
| 319 |
+
onChange={() => setDraftRequireApproval(false)}
|
| 320 |
+
className="mt-1 accent-emerald-500"
|
| 321 |
+
/>
|
| 322 |
+
<div className="text-xs space-y-1">
|
| 323 |
+
<p className="font-bold text-slate-100 flex items-center gap-1.5">
|
| 324 |
+
<Unlock className="w-3.5 h-3.5 text-emerald-400" />
|
| 325 |
+
<span>Chia sẻ nhanh trực tiếp qua Link</span>
|
| 326 |
+
</p>
|
| 327 |
+
<p className="text-slate-400 leading-relaxed">
|
| 328 |
+
Bất kỳ ai nhận được liên kết chia sẻ này đều có thể xem và tải tệp ngay lập tức cho đến khi bạn
|
| 329 |
+
tắt liên kết.
|
| 330 |
+
</p>
|
| 331 |
+
</div>
|
| 332 |
+
</label>
|
| 333 |
+
</div>
|
| 334 |
+
|
| 335 |
+
<div className="flex items-center justify-end gap-2.5 pt-2">
|
| 336 |
+
<button
|
| 337 |
+
type="button"
|
| 338 |
+
onClick={() => setShareTarget(null)}
|
| 339 |
+
className="px-4 py-2.5 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-semibold text-slate-300"
|
| 340 |
+
>
|
| 341 |
+
Không chia sẻ
|
| 342 |
+
</button>
|
| 343 |
+
<button
|
| 344 |
+
type="button"
|
| 345 |
+
disabled={savingShare}
|
| 346 |
+
onClick={handleEnableShare}
|
| 347 |
+
className="px-5 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 hover:from-indigo-500 hover:to-violet-500 text-xs font-bold text-white shadow-lg shadow-indigo-600/30 flex items-center gap-2"
|
| 348 |
+
>
|
| 349 |
+
<Share2 className="w-4 h-4" />
|
| 350 |
+
<span>{savingShare ? "Đang tạo liên kết..." : "Cho phép & Bật Link Chia sẻ"}</span>
|
| 351 |
+
</button>
|
| 352 |
+
</div>
|
| 353 |
+
</div>
|
| 354 |
+
) : (
|
| 355 |
+
/* WHEN SHARE IS ACTIVE (ENABLED) */
|
| 356 |
+
<div className="space-y-5">
|
| 357 |
+
{/* Status Banner & Quick OFF Button */}
|
| 358 |
+
<div className="p-4 rounded-2xl bg-emerald-500/10 border border-emerald-500/30 flex flex-wrap items-center justify-between gap-3">
|
| 359 |
+
<div className="flex items-center gap-2.5">
|
| 360 |
+
<span className="w-2.5 h-2.5 rounded-full bg-emerald-400 animate-pulse" />
|
| 361 |
+
<div>
|
| 362 |
+
<p className="text-xs font-bold text-emerald-300">Liên kết chia sẻ đang BẬT</p>
|
| 363 |
+
<p className="text-[11px] text-slate-300">
|
| 364 |
+
{activeShare.require_approval
|
| 365 |
+
? "Chế độ: Người xem phải hỏi xin phép và được bạn duyệt"
|
| 366 |
+
: "Chế độ: Ai có link đều xem & tải được ngay"}
|
| 367 |
+
</p>
|
| 368 |
+
</div>
|
| 369 |
+
</div>
|
| 370 |
+
<button
|
| 371 |
+
type="button"
|
| 372 |
+
disabled={savingShare}
|
| 373 |
+
onClick={handleDisableShare}
|
| 374 |
+
className="px-3.5 py-2 rounded-xl bg-rose-500/20 hover:bg-rose-500/30 border border-rose-500/40 text-xs font-bold text-rose-300 flex items-center gap-1.5 transition"
|
| 375 |
+
>
|
| 376 |
+
<Power className="w-3.5 h-3.5" />
|
| 377 |
+
<span>Tắt chia sẻ ngay</span>
|
| 378 |
+
</button>
|
| 379 |
+
</div>
|
| 380 |
+
|
| 381 |
+
{/* Share URL Box */}
|
| 382 |
+
<div className="space-y-2">
|
| 383 |
+
<div className="flex items-center justify-between">
|
| 384 |
+
<label className="text-xs font-bold text-slate-300">
|
| 385 |
+
Liên kết gửi cho mọi người:
|
| 386 |
+
</label>
|
| 387 |
+
<button
|
| 388 |
+
type="button"
|
| 389 |
+
onClick={handleRegenerateShareLink}
|
| 390 |
+
className="text-[11px] text-indigo-300 hover:text-indigo-200 flex items-center gap-1 font-mono"
|
| 391 |
+
>
|
| 392 |
+
<RefreshCw className="w-3 h-3" /> Đổi mã link mới
|
| 393 |
+
</button>
|
| 394 |
+
</div>
|
| 395 |
+
<div className="flex items-center gap-2">
|
| 396 |
+
<input
|
| 397 |
+
type="text"
|
| 398 |
+
readOnly
|
| 399 |
+
value={buildFrontendShareUrl(activeShare.id)}
|
| 400 |
+
className="flex-1 bg-slate-950 border border-white/15 rounded-xl px-3.5 py-2.5 text-xs font-mono text-indigo-200 focus:outline-none"
|
| 401 |
+
/>
|
| 402 |
+
<button
|
| 403 |
+
type="button"
|
| 404 |
+
onClick={() => handleCopyShareUrl(activeShare.id)}
|
| 405 |
+
className="px-4 py-2.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white flex items-center gap-1.5 shrink-0 transition"
|
| 406 |
+
>
|
| 407 |
+
{copiedShareLink ? <Check className="w-4 h-4 text-emerald-300" /> : <Copy className="w-4 h-4" />}
|
| 408 |
+
<span>{copiedShareLink ? "Đã chép" : "Sao chép"}</span>
|
| 409 |
+
</button>
|
| 410 |
+
<a
|
| 411 |
+
href={buildFrontendShareUrl(activeShare.id)}
|
| 412 |
+
target="_blank"
|
| 413 |
+
rel="noopener noreferrer"
|
| 414 |
+
className="p-2.5 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-slate-300 hover:text-white"
|
| 415 |
+
title="Mở trang chia sẻ trong tab mới"
|
| 416 |
+
>
|
| 417 |
+
<ExternalLink className="w-4 h-4" />
|
| 418 |
+
</a>
|
| 419 |
+
</div>
|
| 420 |
+
</div>
|
| 421 |
+
|
| 422 |
+
{/* Toggle Require Approval */}
|
| 423 |
+
<div className="p-3.5 rounded-2xl bg-slate-900/90 border border-white/10 flex items-center justify-between gap-4">
|
| 424 |
+
<div className="space-y-0.5">
|
| 425 |
+
<p className="text-xs font-bold text-white flex items-center gap-1.5">
|
| 426 |
+
{activeShare.require_approval ? (
|
| 427 |
+
<Lock className="w-3.5 h-3.5 text-amber-400" />
|
| 428 |
+
) : (
|
| 429 |
+
<Unlock className="w-3.5 h-3.5 text-emerald-400" />
|
| 430 |
+
)}
|
| 431 |
+
<span>Bắt buộc hỏi xin phép trước khi xem tệp</span>
|
| 432 |
+
</p>
|
| 433 |
+
<p className="text-[11px] text-slate-400">
|
| 434 |
+
Khi bật, người mở link phải gửi yêu cầu và chờ bạn nhấn "Cho phép" bên dưới.
|
| 435 |
+
</p>
|
| 436 |
+
</div>
|
| 437 |
+
<button
|
| 438 |
+
type="button"
|
| 439 |
+
disabled={savingShare}
|
| 440 |
+
onClick={() => handleToggleRequireApproval(!activeShare.require_approval)}
|
| 441 |
+
className={`px-3.5 py-1.5 rounded-xl text-xs font-bold border transition shrink-0 ${
|
| 442 |
+
activeShare.require_approval
|
| 443 |
+
? "bg-amber-500/20 text-amber-300 border-amber-500/40"
|
| 444 |
+
: "bg-white/5 text-slate-400 border-white/10 hover:text-white"
|
| 445 |
+
}`}
|
| 446 |
+
>
|
| 447 |
+
{activeShare.require_approval ? "Đang BẬT hỏi phép" : "Đang TẮT hỏi phép"}
|
| 448 |
+
</button>
|
| 449 |
+
</div>
|
| 450 |
+
|
| 451 |
+
{/* Access Requests List */}
|
| 452 |
+
<div className="space-y-2.5 pt-1 border-t border-white/10">
|
| 453 |
+
<div className="flex items-center justify-between">
|
| 454 |
+
<h4 className="text-xs font-bold uppercase tracking-wider text-slate-300">
|
| 455 |
+
Danh sách người xin quyền xem ({activeShare.requests?.length || 0})
|
| 456 |
+
</h4>
|
| 457 |
+
<span className="text-[11px] font-mono text-slate-400">Tự động cập nhật</span>
|
| 458 |
+
</div>
|
| 459 |
+
|
| 460 |
+
{!activeShare.requests || activeShare.requests.length === 0 ? (
|
| 461 |
+
<div className="p-5 rounded-2xl bg-slate-950/60 border border-white/5 text-center text-xs text-slate-400">
|
| 462 |
+
Chưa có yêu cầu xin quyền xem nào cho liên kết này.
|
| 463 |
+
</div>
|
| 464 |
+
) : (
|
| 465 |
+
<div className="space-y-2 max-h-56 overflow-y-auto pr-1">
|
| 466 |
+
{activeShare.requests.map((req) => (
|
| 467 |
+
<div
|
| 468 |
+
key={req.request_id}
|
| 469 |
+
className="p-3 rounded-2xl bg-slate-900/90 border border-white/10 flex flex-wrap items-center justify-between gap-3"
|
| 470 |
+
>
|
| 471 |
+
<div className="min-w-0 flex-1">
|
| 472 |
+
<div className="flex items-center gap-2">
|
| 473 |
+
<span className="text-xs font-bold text-white truncate">{req.visitor_name}</span>
|
| 474 |
+
{req.status === "pending" && (
|
| 475 |
+
<span className="px-2 py-0.5 rounded-full text-[10px] font-mono bg-amber-500/20 text-amber-300 border border-amber-500/30 flex items-center gap-1">
|
| 476 |
+
<Clock className="w-3 h-3" /> Chờ cho phép
|
| 477 |
+
</span>
|
| 478 |
+
)}
|
| 479 |
+
{req.status === "approved" && (
|
| 480 |
+
<span className="px-2 py-0.5 rounded-full text-[10px] font-mono bg-emerald-500/20 text-emerald-300 border border-emerald-500/30">
|
| 481 |
+
✓ Đã cho phép
|
| 482 |
+
</span>
|
| 483 |
+
)}
|
| 484 |
+
{req.status === "rejected" && (
|
| 485 |
+
<span className="px-2 py-0.5 rounded-full text-[10px] font-mono bg-rose-500/20 text-rose-300 border border-rose-500/30">
|
| 486 |
+
✕ Đã từ chối
|
| 487 |
+
</span>
|
| 488 |
+
)}
|
| 489 |
+
</div>
|
| 490 |
+
{req.note && <p className="text-xs text-slate-300 mt-0.5 italic">“{req.note}”</p>}
|
| 491 |
+
<p className="text-[10px] font-mono text-slate-500 mt-0.5">{req.requested_at}</p>
|
| 492 |
+
</div>
|
| 493 |
+
|
| 494 |
+
<div className="flex items-center gap-1.5">
|
| 495 |
+
{req.status !== "approved" && (
|
| 496 |
+
<button
|
| 497 |
+
type="button"
|
| 498 |
+
onClick={() => respondShareRequest(activeShare.id, req.request_id, "approved")}
|
| 499 |
+
className="px-3 py-1.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-xs font-bold text-white flex items-center gap-1 transition"
|
| 500 |
+
>
|
| 501 |
+
<UserCheck className="w-3.5 h-3.5" />
|
| 502 |
+
<span>Cho phép</span>
|
| 503 |
+
</button>
|
| 504 |
+
)}
|
| 505 |
+
{req.status !== "rejected" && (
|
| 506 |
+
<button
|
| 507 |
+
type="button"
|
| 508 |
+
onClick={() => respondShareRequest(activeShare.id, req.request_id, "rejected")}
|
| 509 |
+
className="px-3 py-1.5 rounded-xl bg-rose-500/20 hover:bg-rose-500/30 border border-rose-500/30 text-xs font-semibold text-rose-300 flex items-center gap-1 transition"
|
| 510 |
+
>
|
| 511 |
+
<UserX className="w-3.5 h-3.5" />
|
| 512 |
+
<span>{req.status === "approved" ? "Thu hồi" : "Từ chối"}</span>
|
| 513 |
+
</button>
|
| 514 |
+
)}
|
| 515 |
+
</div>
|
| 516 |
+
</div>
|
| 517 |
+
))}
|
| 518 |
+
</div>
|
| 519 |
+
)}
|
| 520 |
+
</div>
|
| 521 |
+
</div>
|
| 522 |
+
)}
|
| 523 |
+
</div>
|
| 524 |
+
</div>
|
| 525 |
+
)}
|
| 526 |
+
|
| 527 |
+
{/* 4. ADMIN EDIT / CREATE USER MODAL */}
|
| 528 |
+
{editingUser && (
|
| 529 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-sm p-4">
|
| 530 |
+
<div className="glass-panel w-full max-w-md rounded-3xl p-6 border border-amber-500/30">
|
| 531 |
+
<div className="flex items-center justify-between mb-4">
|
| 532 |
+
<h3 className="text-base font-bold text-white flex items-center gap-2">
|
| 533 |
+
<Shield className="w-5 h-5 text-amber-400" />
|
| 534 |
+
<span>{editingUser.isNew ? "Thêm người dùng mới" : `Chỉnh sửa @${editingUser.username}`}</span>
|
| 535 |
+
</h3>
|
| 536 |
+
<button onClick={() => setEditingUser(null)} className="p-1.5 rounded-xl bg-white/5 text-slate-400">
|
| 537 |
+
<X className="w-4 h-4" />
|
| 538 |
+
</button>
|
| 539 |
+
</div>
|
| 540 |
+
|
| 541 |
+
<form onSubmit={handleSaveUser} className="space-y-4">
|
| 542 |
+
<div>
|
| 543 |
+
<label className="block text-xs font-medium text-slate-300 mb-1">Tên đăng nhập (Username)</label>
|
| 544 |
+
<input
|
| 545 |
+
type="text"
|
| 546 |
+
required
|
| 547 |
+
disabled={!editingUser.isNew}
|
| 548 |
+
value={editingUser.username}
|
| 549 |
+
onChange={(e) => setEditingUser({ ...editingUser, username: e.target.value })}
|
| 550 |
+
className="w-full bg-slate-900 border border-white/15 rounded-xl px-3.5 py-2 text-sm text-white font-mono disabled:opacity-60"
|
| 551 |
+
/>
|
| 552 |
+
</div>
|
| 553 |
+
|
| 554 |
+
<div>
|
| 555 |
+
<label className="block text-xs font-medium text-slate-300 mb-1">Tên hiển thị</label>
|
| 556 |
+
<input
|
| 557 |
+
type="text"
|
| 558 |
+
required
|
| 559 |
+
value={editingUser.display_name}
|
| 560 |
+
onChange={(e) => setEditingUser({ ...editingUser, display_name: e.target.value })}
|
| 561 |
+
className="w-full bg-slate-900 border border-white/15 rounded-xl px-3.5 py-2 text-sm text-white"
|
| 562 |
+
/>
|
| 563 |
+
</div>
|
| 564 |
+
|
| 565 |
+
<div className="grid grid-cols-2 gap-3">
|
| 566 |
+
<div>
|
| 567 |
+
<label className="block text-xs font-medium text-slate-300 mb-1">Vai trò (Role)</label>
|
| 568 |
+
<select
|
| 569 |
+
value={editingUser.role}
|
| 570 |
+
disabled={editingUser.username === "admin"}
|
| 571 |
+
onChange={(e) => setEditingUser({ ...editingUser, role: e.target.value as "admin" | "user" })}
|
| 572 |
+
className="w-full bg-slate-900 border border-white/15 rounded-xl px-3 py-2 text-sm text-white"
|
| 573 |
+
>
|
| 574 |
+
<option value="user">User (Thành viên)</option>
|
| 575 |
+
<option value="admin">Admin (Quản trị viên)</option>
|
| 576 |
+
</select>
|
| 577 |
+
</div>
|
| 578 |
+
|
| 579 |
+
<div>
|
| 580 |
+
<label className="block text-xs font-medium text-slate-300 mb-1">
|
| 581 |
+
{editingUser.isNew ? "Mật khẩu *" : "Đặt mật khẩu mới"}
|
| 582 |
+
</label>
|
| 583 |
+
<input
|
| 584 |
+
type="password"
|
| 585 |
+
required={editingUser.isNew}
|
| 586 |
+
value={editingUser.password}
|
| 587 |
+
onChange={(e) => setEditingUser({ ...editingUser, password: e.target.value })}
|
| 588 |
+
placeholder="••••••••"
|
| 589 |
+
className="w-full bg-slate-900 border border-white/15 rounded-xl px-3.5 py-2 text-sm text-white font-mono"
|
| 590 |
+
/>
|
| 591 |
+
</div>
|
| 592 |
+
</div>
|
| 593 |
+
|
| 594 |
+
{editingUser.role !== "admin" && (
|
| 595 |
+
<div className="p-3.5 rounded-2xl bg-slate-900/90 border border-white/10 space-y-2.5">
|
| 596 |
+
<p className="text-xs font-semibold text-slate-300">Quyền hạn chi tiết:</p>
|
| 597 |
+
<label className="flex items-center justify-between text-xs text-slate-300 cursor-pointer">
|
| 598 |
+
<span>Cho phép tải tệp lên (Upload)</span>
|
| 599 |
+
<input
|
| 600 |
+
type="checkbox"
|
| 601 |
+
checked={editingUser.permissions.can_upload}
|
| 602 |
+
onChange={(e) =>
|
| 603 |
+
setEditingUser({
|
| 604 |
+
...editingUser,
|
| 605 |
+
permissions: { ...editingUser.permissions, can_upload: e.target.checked },
|
| 606 |
+
})
|
| 607 |
+
}
|
| 608 |
+
className="rounded accent-indigo-500"
|
| 609 |
+
/>
|
| 610 |
+
</label>
|
| 611 |
+
<label className="flex items-center justify-between text-xs text-slate-300 cursor-pointer">
|
| 612 |
+
<span>Cho phép đổi tên / di chuyển tệp (Rename)</span>
|
| 613 |
+
<input
|
| 614 |
+
type="checkbox"
|
| 615 |
+
checked={editingUser.permissions.can_rename}
|
| 616 |
+
onChange={(e) =>
|
| 617 |
+
setEditingUser({
|
| 618 |
+
...editingUser,
|
| 619 |
+
permissions: { ...editingUser.permissions, can_rename: e.target.checked },
|
| 620 |
+
})
|
| 621 |
+
}
|
| 622 |
+
className="rounded accent-indigo-500"
|
| 623 |
+
/>
|
| 624 |
+
</label>
|
| 625 |
+
<label className="flex items-center justify-between text-xs text-slate-300 cursor-pointer">
|
| 626 |
+
<span>Cho phép xóa tệp tin khỏi Bucket (Delete)</span>
|
| 627 |
+
<input
|
| 628 |
+
type="checkbox"
|
| 629 |
+
checked={editingUser.permissions.can_delete}
|
| 630 |
+
onChange={(e) =>
|
| 631 |
+
setEditingUser({
|
| 632 |
+
...editingUser,
|
| 633 |
+
permissions: { ...editingUser.permissions, can_delete: e.target.checked },
|
| 634 |
+
})
|
| 635 |
+
}
|
| 636 |
+
className="rounded accent-indigo-500"
|
| 637 |
+
/>
|
| 638 |
+
</label>
|
| 639 |
+
</div>
|
| 640 |
+
)}
|
| 641 |
+
|
| 642 |
+
<div className="flex justify-end gap-2 pt-2">
|
| 643 |
+
<button
|
| 644 |
+
type="button"
|
| 645 |
+
onClick={() => setEditingUser(null)}
|
| 646 |
+
className="px-4 py-2 rounded-xl bg-white/5 text-xs text-slate-300"
|
| 647 |
+
>
|
| 648 |
+
Hủy
|
| 649 |
+
</button>
|
| 650 |
+
<button
|
| 651 |
+
type="submit"
|
| 652 |
+
className="px-5 py-2 rounded-xl bg-amber-500 hover:bg-amber-400 text-slate-950 font-bold text-xs"
|
| 653 |
+
>
|
| 654 |
+
Lưu cấu hình
|
| 655 |
+
</button>
|
| 656 |
+
</div>
|
| 657 |
+
</form>
|
| 658 |
+
</div>
|
| 659 |
+
</div>
|
| 660 |
+
)}
|
| 661 |
+
|
| 662 |
+
{/* 5. FULLSCREEN MEDIA PREVIEW MODAL */}
|
| 663 |
+
{previewFile && (
|
| 664 |
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/85 backdrop-blur-md p-4">
|
| 665 |
+
<div className="glass-panel w-full max-w-4xl rounded-3xl overflow-hidden border border-white/15 flex flex-col max-h-[90vh]">
|
| 666 |
+
<div className="px-6 py-4 border-b border-white/10 flex items-center justify-between gap-4">
|
| 667 |
+
<div className="min-w-0">
|
| 668 |
+
<div className="flex items-center gap-2">
|
| 669 |
+
<h3 className="text-base font-bold text-white truncate">{previewFile.name}</h3>
|
| 670 |
+
<span className="px-2 py-0.5 rounded text-[10px] font-mono bg-indigo-500/20 text-indigo-300 border border-indigo-500/30">
|
| 671 |
+
@{previewFile.owner}
|
| 672 |
+
</span>
|
| 673 |
+
</div>
|
| 674 |
+
<p className="text-xs text-slate-400 font-mono truncate">
|
| 675 |
+
{formatBytes(previewFile.size)} • cloud://thtuanit/{previewFile.path}
|
| 676 |
+
</p>
|
| 677 |
+
</div>
|
| 678 |
+
<div className="flex items-center gap-2">
|
| 679 |
+
<button
|
| 680 |
+
onClick={() => {
|
| 681 |
+
const target = previewFile;
|
| 682 |
+
setPreviewFile(null);
|
| 683 |
+
setShareTarget(target);
|
| 684 |
+
}}
|
| 685 |
+
className="px-3.5 py-1.5 rounded-xl bg-emerald-600/20 hover:bg-emerald-600/30 border border-emerald-500/40 text-xs font-semibold text-emerald-300 flex items-center gap-1.5"
|
| 686 |
+
>
|
| 687 |
+
<Share2 className="w-3.5 h-3.5" /> Chia sẻ nhanh
|
| 688 |
+
</button>
|
| 689 |
+
<button
|
| 690 |
+
onClick={() => triggerDownload(previewFile)}
|
| 691 |
+
className="px-3.5 py-1.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-semibold text-white flex items-center gap-1.5"
|
| 692 |
+
>
|
| 693 |
+
<Download className="w-3.5 h-3.5" /> Tải xuống
|
| 694 |
+
</button>
|
| 695 |
+
<button
|
| 696 |
+
onClick={() => setPreviewFile(null)}
|
| 697 |
+
className="p-1.5 rounded-xl bg-white/5 hover:bg-white/10 text-slate-300"
|
| 698 |
+
>
|
| 699 |
+
<X className="w-4 h-4" />
|
| 700 |
+
</button>
|
| 701 |
+
</div>
|
| 702 |
+
</div>
|
| 703 |
+
<div className="p-6 flex-1 overflow-auto flex items-center justify-center bg-slate-950/80 min-h-[340px]">
|
| 704 |
+
{previewFile.category === "video" ? (
|
| 705 |
+
<video
|
| 706 |
+
controls
|
| 707 |
+
autoPlay
|
| 708 |
+
src={getDownloadUrl(previewFile.path, true)}
|
| 709 |
+
className="max-h-[68vh] w-full rounded-2xl bg-black shadow-2xl"
|
| 710 |
+
/>
|
| 711 |
+
) : previewFile.category === "image" ? (
|
| 712 |
+
<img
|
| 713 |
+
src={getDownloadUrl(previewFile.path, true)}
|
| 714 |
+
alt={previewFile.name}
|
| 715 |
+
className="max-h-[68vh] rounded-2xl object-contain"
|
| 716 |
+
/>
|
| 717 |
+
) : (
|
| 718 |
+
<div className="text-center py-10">
|
| 719 |
+
<p className="text-sm text-slate-300 mb-4">
|
| 720 |
+
Tệp <b>{previewFile.name}</b> ({formatBytes(previewFile.size)}) sẵn sàng để tải về máy.
|
| 721 |
+
</p>
|
| 722 |
+
<button
|
| 723 |
+
onClick={() => triggerDownload(previewFile)}
|
| 724 |
+
className="px-6 py-3 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white"
|
| 725 |
+
>
|
| 726 |
+
Tải tệp tin về máy ngay
|
| 727 |
+
</button>
|
| 728 |
+
</div>
|
| 729 |
+
)}
|
| 730 |
+
</div>
|
| 731 |
+
</div>
|
| 732 |
+
</div>
|
| 733 |
+
)}
|
| 734 |
+
|
| 735 |
+
<ToastStack toasts={toasts} />
|
| 736 |
+
</>
|
| 737 |
+
);
|
| 738 |
+
}
|
| 739 |
+
|
| 740 |
+
export function ToastStack({ toasts }: { toasts: ToastMsg[] }) {
|
| 741 |
+
return (
|
| 742 |
+
<div className="fixed bottom-5 right-5 z-50 flex flex-col gap-2.5 max-w-sm w-full pointer-events-none">
|
| 743 |
+
{toasts.map((t) => (
|
| 744 |
+
<div
|
| 745 |
+
key={t.id}
|
| 746 |
+
className={`pointer-events-auto glass px-4 py-3 rounded-2xl border shadow-xl flex items-start gap-3 ${
|
| 747 |
+
t.type === "success"
|
| 748 |
+
? "border-emerald-500/40 text-emerald-200"
|
| 749 |
+
: t.type === "error"
|
| 750 |
+
? "border-rose-500/40 text-rose-200"
|
| 751 |
+
: "border-indigo-500/40 text-slate-200"
|
| 752 |
+
}`}
|
| 753 |
+
>
|
| 754 |
+
{t.type === "success" ? (
|
| 755 |
+
<CheckCircle2 className="w-5 h-5 text-emerald-400 shrink-0 mt-0.5" />
|
| 756 |
+
) : t.type === "error" ? (
|
| 757 |
+
<AlertTriangle className="w-5 h-5 text-rose-400 shrink-0 mt-0.5" />
|
| 758 |
+
) : (
|
| 759 |
+
<Sparkles className="w-5 h-5 text-indigo-400 shrink-0 mt-0.5" />
|
| 760 |
+
)}
|
| 761 |
+
<div className="min-w-0 flex-1">
|
| 762 |
+
<p className="text-xs font-semibold">{t.title}</p>
|
| 763 |
+
{t.detail && <p className="text-[11px] opacity-80 font-mono truncate mt-0.5">{t.detail}</p>}
|
| 764 |
+
</div>
|
| 765 |
+
</div>
|
| 766 |
+
))}
|
| 767 |
+
</div>
|
| 768 |
+
);
|
| 769 |
+
}
|
frontend/src/components/NavbarPublic.tsx
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React from "react";
|
| 4 |
+
import Link from "next/link";
|
| 5 |
+
import { ArrowRight, LayoutGrid, CloudUpload } from "lucide-react";
|
| 6 |
+
import { useCloud } from "@/context/CloudContext";
|
| 7 |
+
import { ToastStack } from "@/components/GlobalModals";
|
| 8 |
+
|
| 9 |
+
export function NavbarPublic() {
|
| 10 |
+
const { healthOk, currentUser, toasts } = useCloud();
|
| 11 |
+
|
| 12 |
+
return (
|
| 13 |
+
<>
|
| 14 |
+
<header className="sticky top-0 z-40 glass border-b border-white/10">
|
| 15 |
+
<div className="max-w-7xl mx-auto px-4 sm:px-8 h-20 flex items-center justify-between">
|
| 16 |
+
<Link href="/" className="flex items-center gap-3.5 group">
|
| 17 |
+
<div className="w-11 h-11 rounded-2xl bg-gradient-to-br from-indigo-500 via-purple-500 to-amber-500 p-[1px] shadow-lg shadow-indigo-500/25 group-hover:scale-105 transition">
|
| 18 |
+
<div className="w-full h-full bg-slate-950 rounded-[15px] flex items-center justify-center text-indigo-400">
|
| 19 |
+
<CloudUpload className="w-6 h-6" />
|
| 20 |
+
</div>
|
| 21 |
+
</div>
|
| 22 |
+
<div>
|
| 23 |
+
<div className="flex items-center gap-2">
|
| 24 |
+
<span className="font-extrabold text-lg tracking-tight text-white">Upload ThTuanIT</span>
|
| 25 |
+
<span className="text-[10px] font-mono font-bold uppercase px-2 py-0.5 rounded-full bg-indigo-500/20 text-indigo-300 border border-indigo-500/30">
|
| 26 |
+
Cloud Pro
|
| 27 |
+
</span>
|
| 28 |
+
</div>
|
| 29 |
+
<p className="text-[11px] text-slate-400 font-mono">Nền tảng Lưu trữ & Chia sẻ Tệp Siêu Tốc</p>
|
| 30 |
+
</div>
|
| 31 |
+
</Link>
|
| 32 |
+
|
| 33 |
+
<nav aria-label="Điều hướng chính" className="hidden md:flex items-center gap-7 text-sm font-medium text-slate-300">
|
| 34 |
+
<Link href="/#architecture" className="hover:text-white transition">
|
| 35 |
+
Công nghệ Turbo
|
| 36 |
+
</Link>
|
| 37 |
+
<Link href="/#rbac" className="hover:text-white transition">
|
| 38 |
+
Phân quyền RBAC
|
| 39 |
+
</Link>
|
| 40 |
+
<Link href="/#faq" className="hover:text-white transition">
|
| 41 |
+
Câu hỏi thường gặp
|
| 42 |
+
</Link>
|
| 43 |
+
<Link href="/developers" className="hover:text-white transition">
|
| 44 |
+
Tài liệu API
|
| 45 |
+
</Link>
|
| 46 |
+
<div className="flex items-center gap-2 px-3 py-1 rounded-full bg-emerald-500/10 border border-emerald-500/25 text-xs font-mono text-emerald-300">
|
| 47 |
+
<span className={`w-2 h-2 rounded-full ${healthOk ? "bg-emerald-400 animate-pulse" : "bg-rose-500"}`} />
|
| 48 |
+
<span>ThTuanIT Storage</span>
|
| 49 |
+
</div>
|
| 50 |
+
</nav>
|
| 51 |
+
|
| 52 |
+
<div className="flex items-center gap-3">
|
| 53 |
+
{currentUser ? (
|
| 54 |
+
<Link
|
| 55 |
+
href="/dashboard"
|
| 56 |
+
className="px-5 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600 via-violet-600 to-indigo-600 hover:from-indigo-500 hover:to-violet-500 text-xs sm:text-sm font-semibold text-white shadow-lg shadow-indigo-600/30 transition flex items-center gap-2"
|
| 57 |
+
>
|
| 58 |
+
<LayoutGrid className="w-4 h-4" />
|
| 59 |
+
<span>Vào Workspace (@{currentUser.username})</span>
|
| 60 |
+
</Link>
|
| 61 |
+
) : (
|
| 62 |
+
<>
|
| 63 |
+
<Link
|
| 64 |
+
href="/login"
|
| 65 |
+
className="px-4 py-2.5 rounded-xl text-xs sm:text-sm font-semibold text-slate-200 hover:text-white hover:bg-white/5 transition"
|
| 66 |
+
>
|
| 67 |
+
Đăng nhập
|
| 68 |
+
</Link>
|
| 69 |
+
<Link
|
| 70 |
+
href="/register"
|
| 71 |
+
className="px-5 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600 via-violet-600 to-indigo-600 hover:from-indigo-500 hover:to-violet-500 text-xs sm:text-sm font-semibold text-white shadow-lg shadow-indigo-600/30 transition flex items-center gap-2"
|
| 72 |
+
>
|
| 73 |
+
<span>Đăng ký miễn phí</span>
|
| 74 |
+
<ArrowRight className="w-4 h-4" />
|
| 75 |
+
</Link>
|
| 76 |
+
</>
|
| 77 |
+
)}
|
| 78 |
+
</div>
|
| 79 |
+
</div>
|
| 80 |
+
</header>
|
| 81 |
+
<ToastStack toasts={toasts} />
|
| 82 |
+
</>
|
| 83 |
+
);
|
| 84 |
+
}
|
frontend/src/components/WorkspaceShell.tsx
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { useState } from "react";
|
| 4 |
+
import Link from "next/link";
|
| 5 |
+
import { usePathname, useRouter } from "next/navigation";
|
| 6 |
+
import {
|
| 7 |
+
CloudUpload,
|
| 8 |
+
UploadCloud,
|
| 9 |
+
Search,
|
| 10 |
+
RefreshCw,
|
| 11 |
+
Folder,
|
| 12 |
+
Film,
|
| 13 |
+
Image as ImageIcon,
|
| 14 |
+
Archive,
|
| 15 |
+
FileCode2,
|
| 16 |
+
Shield,
|
| 17 |
+
LogOut,
|
| 18 |
+
BarChart3,
|
| 19 |
+
Terminal,
|
| 20 |
+
Activity,
|
| 21 |
+
X,
|
| 22 |
+
Lock,
|
| 23 |
+
ArrowRight,
|
| 24 |
+
Share2,
|
| 25 |
+
} from "lucide-react";
|
| 26 |
+
import { useCloud } from "@/context/CloudContext";
|
| 27 |
+
import { formatBytes } from "@/lib/api";
|
| 28 |
+
import { GlobalModals } from "@/components/GlobalModals";
|
| 29 |
+
|
| 30 |
+
export function WorkspaceShell({ children }: { children: React.ReactNode }) {
|
| 31 |
+
const pathname = usePathname();
|
| 32 |
+
const router = useRouter();
|
| 33 |
+
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
|
| 34 |
+
const [isDraggingOver, setIsDraggingOver] = useState(false);
|
| 35 |
+
|
| 36 |
+
const {
|
| 37 |
+
token,
|
| 38 |
+
currentUser,
|
| 39 |
+
authLoading,
|
| 40 |
+
healthOk,
|
| 41 |
+
isAdmin,
|
| 42 |
+
canUpload,
|
| 43 |
+
files,
|
| 44 |
+
loadingFiles,
|
| 45 |
+
currentFolder,
|
| 46 |
+
categoryFilter,
|
| 47 |
+
setCategoryFilter,
|
| 48 |
+
searchQuery,
|
| 49 |
+
setSearchQuery,
|
| 50 |
+
stats,
|
| 51 |
+
loadFiles,
|
| 52 |
+
setUploadModalOpen,
|
| 53 |
+
setUploadTargetFolder,
|
| 54 |
+
setSelectedFiles,
|
| 55 |
+
uploadQueue,
|
| 56 |
+
sharesMap,
|
| 57 |
+
pendingRequestsCount,
|
| 58 |
+
setShareTarget,
|
| 59 |
+
usersList,
|
| 60 |
+
handleLogout,
|
| 61 |
+
notify,
|
| 62 |
+
} = useCloud();
|
| 63 |
+
|
| 64 |
+
if (authLoading) {
|
| 65 |
+
return (
|
| 66 |
+
<div className="min-h-screen flex items-center justify-center bg-grid-pattern">
|
| 67 |
+
<div className="glass-panel rounded-3xl p-10 flex flex-col items-center gap-4 border border-white/10">
|
| 68 |
+
<div className="w-14 h-14 rounded-2xl bg-gradient-to-br from-indigo-500 via-purple-500 to-amber-500 p-[1px] animate-pulse">
|
| 69 |
+
<div className="w-full h-full bg-slate-950 rounded-[15px] flex items-center justify-center">
|
| 70 |
+
<CloudUpload className="w-7 h-7 text-indigo-400" />
|
| 71 |
+
</div>
|
| 72 |
+
</div>
|
| 73 |
+
<div className="text-center">
|
| 74 |
+
<p className="text-sm font-bold text-white tracking-wide">UPLOAD THTUANIT</p>
|
| 75 |
+
<p className="text-xs text-slate-400 font-mono mt-1">Đang đồng bộ phiên làm việc bảo mật...</p>
|
| 76 |
+
</div>
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
if (!currentUser) {
|
| 83 |
+
return (
|
| 84 |
+
<div className="min-h-screen flex items-center justify-center bg-grid-pattern p-6">
|
| 85 |
+
<div className="glass-panel max-w-md w-full rounded-3xl p-8 border border-white/15 text-center space-y-4">
|
| 86 |
+
<div className="w-14 h-14 mx-auto rounded-2xl bg-indigo-500/15 border border-indigo-500/30 flex items-center justify-center text-indigo-400">
|
| 87 |
+
<Lock className="w-7 h-7" />
|
| 88 |
+
</div>
|
| 89 |
+
<h1 className="text-xl font-extrabold text-white">Yêu cầu xác thực Upload ThTuanIT</h1>
|
| 90 |
+
<p className="text-xs text-slate-300 leading-relaxed">
|
| 91 |
+
Vui lòng đăng nhập vào tài khoản Upload ThTuanIT của bạn để truy cập dữ liệu cá nhân hoặc bảng điều khiển Admin.
|
| 92 |
+
</p>
|
| 93 |
+
<div className="flex items-center justify-center gap-3 pt-2">
|
| 94 |
+
<Link
|
| 95 |
+
href="/"
|
| 96 |
+
className="px-4 py-2.5 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-semibold text-slate-300 transition"
|
| 97 |
+
>
|
| 98 |
+
Về trang chủ
|
| 99 |
+
</Link>
|
| 100 |
+
<Link
|
| 101 |
+
href="/login"
|
| 102 |
+
className="px-5 py-2.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-bold text-white shadow-lg shadow-indigo-600/30 transition flex items-center gap-1.5"
|
| 103 |
+
>
|
| 104 |
+
<span>Đăng nhập ngay</span>
|
| 105 |
+
<ArrowRight className="w-4 h-4" />
|
| 106 |
+
</Link>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
const navItems = [
|
| 114 |
+
{ href: "/dashboard", label: "Tổng quan hệ thống", icon: <BarChart3 className="w-4 h-4" /> },
|
| 115 |
+
{ href: "/explorer", label: "Trình duyệt đám mây", icon: <Folder className="w-4 h-4" />, badge: files.length },
|
| 116 |
+
...(isAdmin
|
| 117 |
+
? [
|
| 118 |
+
{
|
| 119 |
+
href: "/admin",
|
| 120 |
+
label: "Quản trị & Phân quyền",
|
| 121 |
+
icon: <Shield className="w-4 h-4 text-amber-400" />,
|
| 122 |
+
badge: usersList.length || undefined,
|
| 123 |
+
},
|
| 124 |
+
]
|
| 125 |
+
: []),
|
| 126 |
+
{ href: "/developers", label: "Tích hợp API & CLI", icon: <Terminal className="w-4 h-4" /> },
|
| 127 |
+
{ href: "/activity", label: "Nhật ký hoạt động", icon: <Activity className="w-4 h-4" /> },
|
| 128 |
+
];
|
| 129 |
+
|
| 130 |
+
return (
|
| 131 |
+
<div
|
| 132 |
+
className="min-h-screen flex bg-grid-pattern relative"
|
| 133 |
+
onDragOver={(e) => {
|
| 134 |
+
e.preventDefault();
|
| 135 |
+
if (canUpload) setIsDraggingOver(true);
|
| 136 |
+
}}
|
| 137 |
+
onDragLeave={(e) => {
|
| 138 |
+
if (e.currentTarget.contains(e.relatedTarget as Node)) return;
|
| 139 |
+
setIsDraggingOver(false);
|
| 140 |
+
}}
|
| 141 |
+
onDrop={(e) => {
|
| 142 |
+
e.preventDefault();
|
| 143 |
+
setIsDraggingOver(false);
|
| 144 |
+
if (!canUpload) {
|
| 145 |
+
notify("Tài khoản của bạn không có quyền tải tệp lên", "error");
|
| 146 |
+
return;
|
| 147 |
+
}
|
| 148 |
+
const dropped = Array.from(e.dataTransfer.files || []);
|
| 149 |
+
if (dropped.length > 0) {
|
| 150 |
+
setSelectedFiles(dropped);
|
| 151 |
+
setUploadTargetFolder(currentFolder);
|
| 152 |
+
setUploadModalOpen(true);
|
| 153 |
+
}
|
| 154 |
+
}}
|
| 155 |
+
>
|
| 156 |
+
{/* DRAG & DROP OVERLAY */}
|
| 157 |
+
{isDraggingOver && (
|
| 158 |
+
<div className="fixed inset-0 z-50 bg-indigo-950/80 backdrop-blur-md border-4 border-dashed border-indigo-400 m-4 rounded-3xl flex flex-col items-center justify-center pointer-events-none">
|
| 159 |
+
<UploadCloud className="w-16 h-16 text-indigo-300 animate-bounce mb-3" />
|
| 160 |
+
<h3 className="text-2xl font-extrabold text-white">Thả tệp vào đây để tải lên Upload ThTuanIT</h3>
|
| 161 |
+
<p className="text-sm text-indigo-200 font-mono mt-1">
|
| 162 |
+
Thư mục đích: {currentFolder ? `/${currentFolder}` : "/ (Root)"}
|
| 163 |
+
</p>
|
| 164 |
+
</div>
|
| 165 |
+
)}
|
| 166 |
+
|
| 167 |
+
{/* LEFT SIDEBAR NAVIGATION */}
|
| 168 |
+
<aside
|
| 169 |
+
className={`${
|
| 170 |
+
sidebarCollapsed ? "w-20" : "w-72"
|
| 171 |
+
} glass border-r border-white/10 flex flex-col justify-between shrink-0 sticky top-0 h-screen z-30 transition-all duration-200`}
|
| 172 |
+
>
|
| 173 |
+
<div className="p-4 space-y-6 overflow-y-auto">
|
| 174 |
+
{/* Brand Logo */}
|
| 175 |
+
<div className="flex items-center justify-between px-2 pt-1">
|
| 176 |
+
<Link href="/" className="flex items-center gap-3 overflow-hidden">
|
| 177 |
+
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-indigo-500 via-purple-500 to-amber-500 p-[1px] shrink-0">
|
| 178 |
+
<div className="w-full h-full bg-slate-950 rounded-[11px] flex items-center justify-center text-indigo-400">
|
| 179 |
+
<CloudUpload className="w-5 h-5" />
|
| 180 |
+
</div>
|
| 181 |
+
</div>
|
| 182 |
+
{!sidebarCollapsed && (
|
| 183 |
+
<div className="min-w-0">
|
| 184 |
+
<div className="flex items-center gap-1.5">
|
| 185 |
+
<span className="font-bold text-sm text-white truncate">Upload ThTuanIT</span>
|
| 186 |
+
<span className="text-[9px] font-mono px-1.5 py-0.5 rounded bg-indigo-500/20 text-indigo-300 border border-indigo-500/30">
|
| 187 |
+
PRO
|
| 188 |
+
</span>
|
| 189 |
+
</div>
|
| 190 |
+
<p className="text-[11px] text-slate-400 font-mono truncate">ThTuanIT Cloud Storage</p>
|
| 191 |
+
</div>
|
| 192 |
+
)}
|
| 193 |
+
</Link>
|
| 194 |
+
<button
|
| 195 |
+
onClick={() => setSidebarCollapsed(!sidebarCollapsed)}
|
| 196 |
+
className="p-1.5 rounded-lg bg-white/5 hover:bg-white/10 text-slate-400 hover:text-white"
|
| 197 |
+
title="Thu gọn / Mở rộng thanh bên"
|
| 198 |
+
>
|
| 199 |
+
<BarChart3 className="w-4 h-4 rotate-90" />
|
| 200 |
+
</button>
|
| 201 |
+
</div>
|
| 202 |
+
|
| 203 |
+
{/* Primary Upload CTA */}
|
| 204 |
+
<div>
|
| 205 |
+
{canUpload ? (
|
| 206 |
+
<button
|
| 207 |
+
onClick={() => {
|
| 208 |
+
setUploadTargetFolder(currentFolder);
|
| 209 |
+
setUploadModalOpen(true);
|
| 210 |
+
}}
|
| 211 |
+
className="w-full py-3 px-4 rounded-2xl bg-gradient-to-r from-indigo-600 via-violet-600 to-indigo-600 hover:from-indigo-500 hover:to-violet-500 font-bold text-xs text-white shadow-lg shadow-indigo-600/30 transition flex items-center justify-center gap-2"
|
| 212 |
+
>
|
| 213 |
+
<UploadCloud className="w-4 h-4 shrink-0" />
|
| 214 |
+
{!sidebarCollapsed && <span>Tải tệp lên Cloud</span>}
|
| 215 |
+
</button>
|
| 216 |
+
) : (
|
| 217 |
+
!sidebarCollapsed && (
|
| 218 |
+
<div className="p-3 rounded-2xl bg-rose-500/10 border border-rose-500/20 flex items-center gap-2 text-xs text-rose-300">
|
| 219 |
+
<Lock className="w-4 h-4 shrink-0" />
|
| 220 |
+
<span>Quyền tải lên đang tắt</span>
|
| 221 |
+
</div>
|
| 222 |
+
)
|
| 223 |
+
)}
|
| 224 |
+
</div>
|
| 225 |
+
|
| 226 |
+
{/* Primary Route Links */}
|
| 227 |
+
<nav aria-label="Menu Workspace" className="space-y-1">
|
| 228 |
+
{!sidebarCollapsed && (
|
| 229 |
+
<p className="px-3 text-[10px] font-bold uppercase tracking-wider text-slate-400 mb-2">
|
| 230 |
+
Không gian làm việc
|
| 231 |
+
</p>
|
| 232 |
+
)}
|
| 233 |
+
{navItems.map((item) => {
|
| 234 |
+
const active = pathname === item.href || pathname.startsWith(item.href + "/");
|
| 235 |
+
return (
|
| 236 |
+
<Link
|
| 237 |
+
key={item.href}
|
| 238 |
+
href={item.href}
|
| 239 |
+
className={`w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-xs font-semibold transition ${
|
| 240 |
+
active
|
| 241 |
+
? "bg-indigo-500/20 text-white border border-indigo-500/40 shadow-sm"
|
| 242 |
+
: "text-slate-400 hover:bg-white/5 hover:text-slate-200"
|
| 243 |
+
}`}
|
| 244 |
+
>
|
| 245 |
+
<div className="flex items-center gap-3">
|
| 246 |
+
{item.icon}
|
| 247 |
+
{!sidebarCollapsed && <span>{item.label}</span>}
|
| 248 |
+
</div>
|
| 249 |
+
{!sidebarCollapsed && item.badge !== undefined && (
|
| 250 |
+
<span className="text-[10px] font-mono px-2 py-0.5 rounded-full bg-white/10 text-slate-300">
|
| 251 |
+
{item.badge}
|
| 252 |
+
</span>
|
| 253 |
+
)}
|
| 254 |
+
</Link>
|
| 255 |
+
);
|
| 256 |
+
})}
|
| 257 |
+
</nav>
|
| 258 |
+
|
| 259 |
+
{/* Quick Category Filter (Redirects to /explorer) */}
|
| 260 |
+
{!sidebarCollapsed && (
|
| 261 |
+
<div className="space-y-1 pt-2 border-t border-white/10">
|
| 262 |
+
<p className="px-3 text-[10px] font-bold uppercase tracking-wider text-slate-400 mb-2">
|
| 263 |
+
Phân loại thông minh
|
| 264 |
+
</p>
|
| 265 |
+
{[
|
| 266 |
+
{ id: "video", label: "Video & Streaming", icon: <Film className="w-4 h-4 text-rose-400" />, count: stats.counts.video },
|
| 267 |
+
{ id: "image", label: "Hình ảnh & Đồ họa", icon: <ImageIcon className="w-4 h-4 text-indigo-400" />, count: stats.counts.image },
|
| 268 |
+
{ id: "archive", label: "Gói nén & Dataset", icon: <Archive className="w-4 h-4 text-amber-400" />, count: stats.counts.archive },
|
| 269 |
+
{ id: "doc", label: "Tài liệu & Mã nguồn", icon: <FileCode2 className="w-4 h-4 text-emerald-400" />, count: stats.counts.doc },
|
| 270 |
+
].map((cat) => (
|
| 271 |
+
<button
|
| 272 |
+
key={cat.id}
|
| 273 |
+
onClick={() => {
|
| 274 |
+
setCategoryFilter(cat.id as any);
|
| 275 |
+
if (pathname !== "/explorer") {
|
| 276 |
+
router.push("/explorer");
|
| 277 |
+
}
|
| 278 |
+
}}
|
| 279 |
+
className={`w-full flex items-center justify-between px-3 py-2 rounded-xl text-xs transition ${
|
| 280 |
+
pathname === "/explorer" && categoryFilter === cat.id
|
| 281 |
+
? "bg-white/10 text-white font-semibold"
|
| 282 |
+
: "text-slate-400 hover:bg-white/5 hover:text-slate-200"
|
| 283 |
+
}`}
|
| 284 |
+
>
|
| 285 |
+
<div className="flex items-center gap-2.5">
|
| 286 |
+
{cat.icon}
|
| 287 |
+
<span>{cat.label}</span>
|
| 288 |
+
</div>
|
| 289 |
+
<span className="text-[11px] font-mono text-slate-400">{cat.count}</span>
|
| 290 |
+
</button>
|
| 291 |
+
))}
|
| 292 |
+
</div>
|
| 293 |
+
)}
|
| 294 |
+
</div>
|
| 295 |
+
|
| 296 |
+
{/* Bottom Storage Widget & User Card */}
|
| 297 |
+
<div className="p-4 border-t border-white/10 space-y-3 bg-slate-950/50">
|
| 298 |
+
{!sidebarCollapsed && (
|
| 299 |
+
<div className="p-3.5 rounded-2xl bg-slate-900/90 border border-white/10">
|
| 300 |
+
<div className="flex items-center justify-between text-xs mb-1.5">
|
| 301 |
+
<span className="text-slate-400 font-medium">
|
| 302 |
+
{isAdmin ? "Tổng dung lượng Kho lưu trữ" : `Dung lượng của @${currentUser.username}`}
|
| 303 |
+
</span>
|
| 304 |
+
<span className="font-mono font-bold text-indigo-300">{formatBytes(stats.totalSize)}</span>
|
| 305 |
+
</div>
|
| 306 |
+
<div className="w-full h-1.5 bg-slate-800 rounded-full overflow-hidden flex">
|
| 307 |
+
<div style={{ width: `${Math.min((stats.sizes.video / (stats.totalSize || 1)) * 100, 100)}%` }} className="bg-rose-500 h-full" />
|
| 308 |
+
<div style={{ width: `${Math.min((stats.sizes.archive / (stats.totalSize || 1)) * 100, 100)}%` }} className="bg-amber-400 h-full" />
|
| 309 |
+
<div style={{ width: `${Math.min((stats.sizes.image / (stats.totalSize || 1)) * 100, 100)}%` }} className="bg-indigo-400 h-full" />
|
| 310 |
+
</div>
|
| 311 |
+
</div>
|
| 312 |
+
)}
|
| 313 |
+
|
| 314 |
+
{/* Current User Profile Card */}
|
| 315 |
+
<div className="flex items-center justify-between gap-2 p-2 rounded-2xl bg-white/5 border border-white/10">
|
| 316 |
+
<div className="flex items-center gap-2.5 min-w-0">
|
| 317 |
+
<div
|
| 318 |
+
className={`w-9 h-9 rounded-xl flex items-center justify-center font-bold text-xs shrink-0 ${
|
| 319 |
+
isAdmin
|
| 320 |
+
? "bg-amber-500/20 text-amber-300 border border-amber-500/40"
|
| 321 |
+
: "bg-indigo-500/20 text-indigo-300 border border-indigo-500/40"
|
| 322 |
+
}`}
|
| 323 |
+
>
|
| 324 |
+
{currentUser.display_name.charAt(0).toUpperCase()}
|
| 325 |
+
</div>
|
| 326 |
+
{!sidebarCollapsed && (
|
| 327 |
+
<div className="min-w-0">
|
| 328 |
+
<p className="text-xs font-bold text-white truncate">{currentUser.display_name}</p>
|
| 329 |
+
<p className="text-[10px] font-mono text-slate-400 truncate">
|
| 330 |
+
@{currentUser.username} • {isAdmin ? "ADMIN" : "USER"}
|
| 331 |
+
</p>
|
| 332 |
+
</div>
|
| 333 |
+
)}
|
| 334 |
+
</div>
|
| 335 |
+
<button
|
| 336 |
+
onClick={handleLogout}
|
| 337 |
+
title="Đăng xuất"
|
| 338 |
+
className="p-2 rounded-xl bg-rose-500/10 hover:bg-rose-500/20 text-rose-300 transition shrink-0"
|
| 339 |
+
>
|
| 340 |
+
<LogOut className="w-4 h-4" />
|
| 341 |
+
</button>
|
| 342 |
+
</div>
|
| 343 |
+
</div>
|
| 344 |
+
</aside>
|
| 345 |
+
|
| 346 |
+
{/* MAIN CONTENT AREA */}
|
| 347 |
+
<div className="flex-1 flex flex-col min-w-0">
|
| 348 |
+
{/* TOP HEADER BAR */}
|
| 349 |
+
<header className="sticky top-0 z-20 h-16 glass border-b border-white/10 px-6 flex items-center justify-between gap-4">
|
| 350 |
+
<div className="flex items-center gap-3 flex-1 max-w-xl">
|
| 351 |
+
<div className="relative w-full">
|
| 352 |
+
<Search className="w-4 h-4 text-slate-400 absolute left-3.5 top-1/2 -translate-y-1/2" />
|
| 353 |
+
<input
|
| 354 |
+
type="text"
|
| 355 |
+
value={searchQuery}
|
| 356 |
+
onChange={(e) => {
|
| 357 |
+
setSearchQuery(e.target.value);
|
| 358 |
+
if (pathname !== "/explorer") router.push("/explorer");
|
| 359 |
+
}}
|
| 360 |
+
placeholder="Tìm kiếm tệp tin trên Upload ThTuanIT..."
|
| 361 |
+
className="w-full bg-slate-900/80 border border-white/10 focus:border-indigo-500 rounded-xl pl-10 pr-8 py-2 text-xs sm:text-sm text-slate-100 placeholder-slate-500 focus:outline-none transition"
|
| 362 |
+
/>
|
| 363 |
+
{searchQuery && (
|
| 364 |
+
<button
|
| 365 |
+
onClick={() => setSearchQuery("")}
|
| 366 |
+
className="absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-white"
|
| 367 |
+
>
|
| 368 |
+
<X className="w-4 h-4" />
|
| 369 |
+
</button>
|
| 370 |
+
)}
|
| 371 |
+
</div>
|
| 372 |
+
</div>
|
| 373 |
+
|
| 374 |
+
<div className="flex items-center gap-3">
|
| 375 |
+
{pendingRequestsCount > 0 && (
|
| 376 |
+
<button
|
| 377 |
+
onClick={() => {
|
| 378 |
+
const firstPendingShare = Object.values(sharesMap).find(
|
| 379 |
+
(sh) => sh.enabled && sh.requests?.some((r) => r.status === "pending")
|
| 380 |
+
);
|
| 381 |
+
if (firstPendingShare) {
|
| 382 |
+
const targetFile = files.find((f) => f.path === firstPendingShare.path);
|
| 383 |
+
if (targetFile) setShareTarget(targetFile);
|
| 384 |
+
}
|
| 385 |
+
}}
|
| 386 |
+
className="flex items-center gap-2 px-3.5 py-2 rounded-xl bg-amber-500/20 hover:bg-amber-500/30 border border-amber-500/40 text-xs font-bold text-amber-300 animate-pulse transition"
|
| 387 |
+
>
|
| 388 |
+
<Share2 className="w-3.5 h-3.5" />
|
| 389 |
+
<span>{pendingRequestsCount} yêu cầu xin xem tệp</span>
|
| 390 |
+
</button>
|
| 391 |
+
)}
|
| 392 |
+
|
| 393 |
+
<div className="hidden sm:flex items-center gap-2 px-3 py-1.5 rounded-xl bg-slate-900/90 border border-white/10 text-xs font-mono">
|
| 394 |
+
<span className={`w-2 h-2 rounded-full ${healthOk ? "bg-emerald-400" : "bg-rose-500"}`} />
|
| 395 |
+
<span className="text-slate-300">cloud://thtuanit/storage</span>
|
| 396 |
+
</div>
|
| 397 |
+
|
| 398 |
+
<button
|
| 399 |
+
onClick={() => loadFiles(token, true)}
|
| 400 |
+
disabled={loadingFiles}
|
| 401 |
+
className="flex items-center gap-2 px-3.5 py-2 rounded-xl bg-white/5 hover:bg-white/10 border border-white/10 text-xs font-semibold text-slate-200 transition"
|
| 402 |
+
>
|
| 403 |
+
<RefreshCw className={`w-3.5 h-3.5 ${loadingFiles ? "animate-spin text-indigo-400" : ""}`} />
|
| 404 |
+
<span className="hidden md:inline">Đồng bộ</span>
|
| 405 |
+
</button>
|
| 406 |
+
</div>
|
| 407 |
+
</header>
|
| 408 |
+
|
| 409 |
+
{/* TURBO UPLOAD PROGRESS HUD */}
|
| 410 |
+
{uploadQueue.length > 0 && (
|
| 411 |
+
<div className="mx-6 mt-4 glass-panel rounded-2xl p-4 border border-indigo-500/40 space-y-2.5">
|
| 412 |
+
<div className="flex items-center justify-between text-xs">
|
| 413 |
+
<span className="font-bold text-indigo-300 flex items-center gap-2">
|
| 414 |
+
<UploadCloud className="w-4 h-4 animate-bounce" />
|
| 415 |
+
<span>Upload ThTuanIT Turbo Parallel (4 luồng đồng thời)...</span>
|
| 416 |
+
</span>
|
| 417 |
+
<span className="font-mono text-slate-400">
|
| 418 |
+
{uploadQueue.filter((q) => q.status === "done").length}/{uploadQueue.length} hoàn tất
|
| 419 |
+
</span>
|
| 420 |
+
</div>
|
| 421 |
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
|
| 422 |
+
{uploadQueue.map((item) => (
|
| 423 |
+
<div key={item.id} className="bg-slate-900/90 rounded-xl p-2.5 border border-white/10">
|
| 424 |
+
<div className="flex justify-between text-xs mb-1 gap-2">
|
| 425 |
+
<span className="font-mono text-slate-200 truncate">{item.path}</span>
|
| 426 |
+
<span className="font-mono text-indigo-300 shrink-0">
|
| 427 |
+
{item.status === "syncing"
|
| 428 |
+
? "Đang đồng bộ Cloud..."
|
| 429 |
+
: item.status === "done"
|
| 430 |
+
? "✓ Hoàn tất"
|
| 431 |
+
: item.status === "error"
|
| 432 |
+
? "✕ Lỗi"
|
| 433 |
+
: `${item.progress}% • ${item.speedMBps || ""}${
|
| 434 |
+
item.etaSec ? ` (${item.etaSec}s)` : ""
|
| 435 |
+
}`}
|
| 436 |
+
</span>
|
| 437 |
+
</div>
|
| 438 |
+
<div className="w-full h-1.5 bg-slate-800 rounded-full overflow-hidden">
|
| 439 |
+
<div
|
| 440 |
+
style={{ width: `${item.progress}%` }}
|
| 441 |
+
className={`h-full transition-all ${
|
| 442 |
+
item.status === "error"
|
| 443 |
+
? "bg-rose-500"
|
| 444 |
+
: item.status === "done"
|
| 445 |
+
? "bg-emerald-400"
|
| 446 |
+
: "bg-indigo-500"
|
| 447 |
+
}`}
|
| 448 |
+
/>
|
| 449 |
+
</div>
|
| 450 |
+
</div>
|
| 451 |
+
))}
|
| 452 |
+
</div>
|
| 453 |
+
</div>
|
| 454 |
+
)}
|
| 455 |
+
|
| 456 |
+
{/* ROUTE PAGE CONTENT */}
|
| 457 |
+
<main className="flex-1 flex flex-col">{children}</main>
|
| 458 |
+
</div>
|
| 459 |
+
|
| 460 |
+
<GlobalModals />
|
| 461 |
+
</div>
|
| 462 |
+
);
|
| 463 |
+
}
|
frontend/src/context/CloudContext.tsx
ADDED
|
@@ -0,0 +1,889 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client";
|
| 2 |
+
|
| 3 |
+
import React, { createContext, useContext, useState, useEffect, useMemo } from "react";
|
| 4 |
+
import { useRouter } from "next/navigation";
|
| 5 |
+
import {
|
| 6 |
+
UserProfile,
|
| 7 |
+
FileNode,
|
| 8 |
+
ToastMsg,
|
| 9 |
+
UploadProgressItem,
|
| 10 |
+
AuditLogEntry,
|
| 11 |
+
EditingUserForm,
|
| 12 |
+
PermissionSet,
|
| 13 |
+
ShareLink,
|
| 14 |
+
} from "@/types/cloud";
|
| 15 |
+
import { apiFetch, getBackendOrigin, formatBytes, normalizeFile, buildDownloadUrl } from "@/lib/api";
|
| 16 |
+
|
| 17 |
+
interface CloudContextValue {
|
| 18 |
+
// Auth & System
|
| 19 |
+
token: string;
|
| 20 |
+
currentUser: UserProfile | null;
|
| 21 |
+
authLoading: boolean;
|
| 22 |
+
bucketName: string;
|
| 23 |
+
hfVersion: string;
|
| 24 |
+
healthOk: boolean;
|
| 25 |
+
isAdmin: boolean;
|
| 26 |
+
canUpload: boolean;
|
| 27 |
+
canDelete: boolean;
|
| 28 |
+
canRename: boolean;
|
| 29 |
+
loginWithCredentials: (username: string, password: string) => Promise<boolean>;
|
| 30 |
+
registerAccount: (username: string, displayName: string, password: string) => Promise<boolean>;
|
| 31 |
+
handleLogout: () => Promise<void>;
|
| 32 |
+
|
| 33 |
+
// Files & Explorer Filters
|
| 34 |
+
files: FileNode[];
|
| 35 |
+
loadingFiles: boolean;
|
| 36 |
+
currentFolder: string;
|
| 37 |
+
setCurrentFolder: (folder: string) => void;
|
| 38 |
+
categoryFilter: "all" | "video" | "image" | "archive" | "doc";
|
| 39 |
+
setCategoryFilter: (cat: "all" | "video" | "image" | "archive" | "doc") => void;
|
| 40 |
+
searchQuery: string;
|
| 41 |
+
setSearchQuery: (q: string) => void;
|
| 42 |
+
sortBy: "date_desc" | "size_desc" | "size_asc" | "name_asc";
|
| 43 |
+
setSortBy: (s: "date_desc" | "size_desc" | "size_asc" | "name_asc") => void;
|
| 44 |
+
viewMode: "grid" | "list";
|
| 45 |
+
setViewMode: (m: "grid" | "list") => void;
|
| 46 |
+
inspectedFile: FileNode | null;
|
| 47 |
+
setInspectedFile: (f: FileNode | null) => void;
|
| 48 |
+
stats: {
|
| 49 |
+
totalSize: number;
|
| 50 |
+
counts: { video: number; image: number; archive: number; doc: number };
|
| 51 |
+
sizes: { video: number; image: number; archive: number; doc: number };
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
// File Actions
|
| 55 |
+
loadFiles: (tk?: string, showToast?: boolean) => Promise<void>;
|
| 56 |
+
getDownloadUrl: (path: string, inline?: boolean) => string;
|
| 57 |
+
triggerDownload: (file: FileNode) => void;
|
| 58 |
+
handleDeleteFile: (file: FileNode) => Promise<void>;
|
| 59 |
+
handleRenameSubmit: (e: React.FormEvent) => Promise<void>;
|
| 60 |
+
|
| 61 |
+
// Modals & Upload Queue
|
| 62 |
+
uploadModalOpen: boolean;
|
| 63 |
+
setUploadModalOpen: (open: boolean) => void;
|
| 64 |
+
uploadTargetFolder: string;
|
| 65 |
+
setUploadTargetFolder: (folder: string) => void;
|
| 66 |
+
selectedFiles: File[];
|
| 67 |
+
setSelectedFiles: (files: File[]) => void;
|
| 68 |
+
uploadQueue: UploadProgressItem[];
|
| 69 |
+
startBatchUpload: () => Promise<void>;
|
| 70 |
+
previewFile: FileNode | null;
|
| 71 |
+
setPreviewFile: (f: FileNode | null) => void;
|
| 72 |
+
renameTarget: FileNode | null;
|
| 73 |
+
setRenameTarget: (f: FileNode | null) => void;
|
| 74 |
+
newPathInput: string;
|
| 75 |
+
setNewPathInput: (p: string) => void;
|
| 76 |
+
renaming: boolean;
|
| 77 |
+
|
| 78 |
+
// Quick Share
|
| 79 |
+
sharesMap: Record<string, ShareLink>;
|
| 80 |
+
pendingRequestsCount: number;
|
| 81 |
+
shareTarget: FileNode | null;
|
| 82 |
+
setShareTarget: (f: FileNode | null) => void;
|
| 83 |
+
loadShares: (tk?: string) => Promise<void>;
|
| 84 |
+
upsertFileShare: (
|
| 85 |
+
path: string,
|
| 86 |
+
size: number,
|
| 87 |
+
enabled: boolean,
|
| 88 |
+
requireApproval: boolean,
|
| 89 |
+
regenerate?: boolean
|
| 90 |
+
) => Promise<ShareLink | null>;
|
| 91 |
+
respondShareRequest: (
|
| 92 |
+
shareId: string,
|
| 93 |
+
requestId: string,
|
| 94 |
+
status: "approved" | "rejected"
|
| 95 |
+
) => Promise<ShareLink | null>;
|
| 96 |
+
|
| 97 |
+
// Admin RBAC
|
| 98 |
+
usersList: UserProfile[];
|
| 99 |
+
loadingUsers: boolean;
|
| 100 |
+
editingUser: EditingUserForm | null;
|
| 101 |
+
setEditingUser: (u: EditingUserForm | null) => void;
|
| 102 |
+
loadUsersList: (tk?: string) => Promise<void>;
|
| 103 |
+
handleSaveUser: (e: React.FormEvent) => Promise<void>;
|
| 104 |
+
handleQuickTogglePermission: (u: UserProfile, field: keyof PermissionSet | "role" | "active") => Promise<void>;
|
| 105 |
+
handleDeleteUser: (username: string) => Promise<void>;
|
| 106 |
+
|
| 107 |
+
// Logs & Notifications
|
| 108 |
+
auditLogs: AuditLogEntry[];
|
| 109 |
+
toasts: ToastMsg[];
|
| 110 |
+
notify: (title: string, type?: "success" | "error" | "info", detail?: string) => void;
|
| 111 |
+
pushLog: (action: string, target: string, status?: "success" | "warn" | "info") => void;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
const CloudContext = createContext<CloudContextValue | null>(null);
|
| 115 |
+
|
| 116 |
+
export function CloudProvider({ children }: { children: React.ReactNode }) {
|
| 117 |
+
const router = useRouter();
|
| 118 |
+
|
| 119 |
+
// --- AUTH & SYSTEM STATE ---
|
| 120 |
+
const [token, setToken] = useState<string>("");
|
| 121 |
+
const [currentUser, setCurrentUser] = useState<UserProfile | null>(null);
|
| 122 |
+
const [authLoading, setAuthLoading] = useState<boolean>(true);
|
| 123 |
+
const [bucketName, setBucketName] = useState("Upload ThTuanIT");
|
| 124 |
+
const [hfVersion, setHfVersion] = useState("2.4.0");
|
| 125 |
+
const [healthOk, setHealthOk] = useState(true);
|
| 126 |
+
|
| 127 |
+
// --- FILES & EXPLORER STATE ---
|
| 128 |
+
const [files, setFiles] = useState<FileNode[]>([]);
|
| 129 |
+
const [loadingFiles, setLoadingFiles] = useState(false);
|
| 130 |
+
const [currentFolder, setCurrentFolder] = useState("");
|
| 131 |
+
const [categoryFilter, setCategoryFilter] = useState<"all" | "video" | "image" | "archive" | "doc">("all");
|
| 132 |
+
const [searchQuery, setSearchQuery] = useState("");
|
| 133 |
+
const [sortBy, setSortBy] = useState<"date_desc" | "size_desc" | "size_asc" | "name_asc">("date_desc");
|
| 134 |
+
const [viewMode, setViewMode] = useState<"grid" | "list">("grid");
|
| 135 |
+
const [inspectedFile, setInspectedFile] = useState<FileNode | null>(null);
|
| 136 |
+
|
| 137 |
+
// --- MODALS & UPLOAD STATE ---
|
| 138 |
+
const [uploadModalOpen, setUploadModalOpen] = useState(false);
|
| 139 |
+
const [uploadTargetFolder, setUploadTargetFolder] = useState("");
|
| 140 |
+
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
| 141 |
+
const [uploadQueue, setUploadQueue] = useState<UploadProgressItem[]>([]);
|
| 142 |
+
const [previewFile, setPreviewFile] = useState<FileNode | null>(null);
|
| 143 |
+
const [renameTarget, setRenameTarget] = useState<FileNode | null>(null);
|
| 144 |
+
const [newPathInput, setNewPathInput] = useState("");
|
| 145 |
+
const [renaming, setRenaming] = useState(false);
|
| 146 |
+
|
| 147 |
+
// --- QUICK SHARE STATE ---
|
| 148 |
+
const [sharesMap, setSharesMap] = useState<Record<string, ShareLink>>({});
|
| 149 |
+
const [shareTarget, setShareTarget] = useState<FileNode | null>(null);
|
| 150 |
+
|
| 151 |
+
// --- ADMIN USERS STATE ---
|
| 152 |
+
const [usersList, setUsersList] = useState<UserProfile[]>([]);
|
| 153 |
+
const [loadingUsers, setLoadingUsers] = useState(false);
|
| 154 |
+
const [editingUser, setEditingUser] = useState<EditingUserForm | null>(null);
|
| 155 |
+
|
| 156 |
+
// --- LOGS & TOASTS ---
|
| 157 |
+
const [auditLogs, setAuditLogs] = useState<AuditLogEntry[]>([
|
| 158 |
+
{
|
| 159 |
+
id: "init-1",
|
| 160 |
+
time: new Date().toLocaleTimeString("vi-VN"),
|
| 161 |
+
actor: "system",
|
| 162 |
+
action: "Khởi tạo kết nối Upload ThTuanIT Turbo Engine",
|
| 163 |
+
target: "cloud://thtuanit/storage",
|
| 164 |
+
status: "info",
|
| 165 |
+
},
|
| 166 |
+
]);
|
| 167 |
+
const [toasts, setToasts] = useState<ToastMsg[]>([]);
|
| 168 |
+
|
| 169 |
+
const pushLog = (action: string, target: string, status: "success" | "warn" | "info" = "info") => {
|
| 170 |
+
setAuditLogs((prev) => [
|
| 171 |
+
{
|
| 172 |
+
id: `${Date.now()}-${Math.random()}`,
|
| 173 |
+
time: new Date().toLocaleTimeString("vi-VN"),
|
| 174 |
+
actor: currentUser?.username || "system",
|
| 175 |
+
action,
|
| 176 |
+
target,
|
| 177 |
+
status,
|
| 178 |
+
},
|
| 179 |
+
...prev.slice(0, 49),
|
| 180 |
+
]);
|
| 181 |
+
};
|
| 182 |
+
|
| 183 |
+
const notify = (title: string, type: "success" | "error" | "info" = "info", detail?: string) => {
|
| 184 |
+
const id = Date.now() + Math.random();
|
| 185 |
+
setToasts((prev) => [...prev, { id, title, type, detail }]);
|
| 186 |
+
setTimeout(() => {
|
| 187 |
+
setToasts((prev) => prev.filter((t) => t.id !== id));
|
| 188 |
+
}, 4200);
|
| 189 |
+
};
|
| 190 |
+
|
| 191 |
+
useEffect(() => {
|
| 192 |
+
const savedToken = localStorage.getItem("xet_auth_token") || "";
|
| 193 |
+
setToken(savedToken);
|
| 194 |
+
checkHealth();
|
| 195 |
+
fetchCurrentUser(savedToken);
|
| 196 |
+
}, []);
|
| 197 |
+
|
| 198 |
+
async function checkHealth() {
|
| 199 |
+
try {
|
| 200 |
+
const res = await apiFetch("/health");
|
| 201 |
+
const data = await res.json();
|
| 202 |
+
setHealthOk(Boolean(data.ok));
|
| 203 |
+
if (data.version) setHfVersion(data.version);
|
| 204 |
+
} catch {
|
| 205 |
+
setHealthOk(false);
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
async function fetchCurrentUser(tk: string) {
|
| 210 |
+
setAuthLoading(true);
|
| 211 |
+
try {
|
| 212 |
+
const headers: Record<string, string> = {};
|
| 213 |
+
if (tk) headers["Authorization"] = `Bearer ${tk}`;
|
| 214 |
+
const res = await apiFetch("/api/auth/me", { headers });
|
| 215 |
+
if (res.ok) {
|
| 216 |
+
const data = await res.json();
|
| 217 |
+
setCurrentUser(data.user);
|
| 218 |
+
loadFiles(tk);
|
| 219 |
+
loadShares(tk);
|
| 220 |
+
if (data.user.role === "admin") {
|
| 221 |
+
loadUsersList(tk);
|
| 222 |
+
}
|
| 223 |
+
} else {
|
| 224 |
+
setCurrentUser(null);
|
| 225 |
+
}
|
| 226 |
+
} catch {
|
| 227 |
+
setCurrentUser(null);
|
| 228 |
+
} finally {
|
| 229 |
+
setAuthLoading(false);
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
async function loginWithCredentials(username: string, password: string): Promise<boolean> {
|
| 234 |
+
try {
|
| 235 |
+
const res = await apiFetch("/api/auth/login", {
|
| 236 |
+
method: "POST",
|
| 237 |
+
headers: { "Content-Type": "application/json" },
|
| 238 |
+
body: JSON.stringify({ username, password }),
|
| 239 |
+
});
|
| 240 |
+
const data = await res.json();
|
| 241 |
+
if (!res.ok) {
|
| 242 |
+
throw new Error(data.detail || data.error || "Đăng nhập thất bại");
|
| 243 |
+
}
|
| 244 |
+
localStorage.setItem("xet_auth_token", data.token);
|
| 245 |
+
setToken(data.token);
|
| 246 |
+
setCurrentUser(data.user);
|
| 247 |
+
pushLog("Đăng nhập hệ thống", `@${data.user.username} (${data.user.role})`, "success");
|
| 248 |
+
notify(`Chào mừng ${data.user.display_name}!`, "success", `Vai trò: ${data.user.role.toUpperCase()}`);
|
| 249 |
+
await loadFiles(data.token);
|
| 250 |
+
await loadShares(data.token);
|
| 251 |
+
if (data.user.role === "admin") {
|
| 252 |
+
loadUsersList(data.token);
|
| 253 |
+
}
|
| 254 |
+
return true;
|
| 255 |
+
} catch (err: any) {
|
| 256 |
+
notify("Đăng nhập không thành công", "error", err.message);
|
| 257 |
+
return false;
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
async function registerAccount(username: string, displayName: string, password: string): Promise<boolean> {
|
| 262 |
+
try {
|
| 263 |
+
const res = await apiFetch("/api/auth/register", {
|
| 264 |
+
method: "POST",
|
| 265 |
+
headers: { "Content-Type": "application/json" },
|
| 266 |
+
body: JSON.stringify({ username, display_name: displayName || username, password }),
|
| 267 |
+
});
|
| 268 |
+
const data = await res.json();
|
| 269 |
+
if (!res.ok) {
|
| 270 |
+
throw new Error(data.detail || data.error || "Đăng ký thất bại");
|
| 271 |
+
}
|
| 272 |
+
localStorage.setItem("xet_auth_token", data.token);
|
| 273 |
+
setToken(data.token);
|
| 274 |
+
setCurrentUser(data.user);
|
| 275 |
+
pushLog("Đ��ng ký tài khoản mới", `@${data.user.username}`, "success");
|
| 276 |
+
notify("Đăng ký tài khoản thành công!", "success", `@${data.user.username}`);
|
| 277 |
+
await loadFiles(data.token);
|
| 278 |
+
await loadShares(data.token);
|
| 279 |
+
return true;
|
| 280 |
+
} catch (err: any) {
|
| 281 |
+
notify("Đăng ký không thành công", "error", err.message);
|
| 282 |
+
return false;
|
| 283 |
+
}
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
async function handleLogout() {
|
| 287 |
+
await apiFetch("/api/auth/logout", { method: "POST" }).catch(() => {});
|
| 288 |
+
localStorage.removeItem("xet_auth_token");
|
| 289 |
+
setToken("");
|
| 290 |
+
setCurrentUser(null);
|
| 291 |
+
setFiles([]);
|
| 292 |
+
notify("Đã đăng xuất khỏi phiên làm việc", "info");
|
| 293 |
+
router.push("/login");
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
async function loadFiles(tk = token, showToast = false) {
|
| 297 |
+
setLoadingFiles(true);
|
| 298 |
+
try {
|
| 299 |
+
const res = await apiFetch("/api/files", {
|
| 300 |
+
headers: tk ? { Authorization: `Bearer ${tk}` } : {},
|
| 301 |
+
});
|
| 302 |
+
const data = await res.json();
|
| 303 |
+
if (!res.ok) throw new Error(data.detail || data.error || "Không thể tải danh sách tệp");
|
| 304 |
+
const list: FileNode[] = Array.isArray(data.items)
|
| 305 |
+
? data.items.map(normalizeFile)
|
| 306 |
+
: Array.isArray(data.entries)
|
| 307 |
+
? data.entries.map((p: string) => normalizeFile({ path: p, size: 0 }))
|
| 308 |
+
: [];
|
| 309 |
+
setFiles(list);
|
| 310 |
+
loadShares(tk);
|
| 311 |
+
if (showToast) {
|
| 312 |
+
notify("Đã đồng bộ dữ liệu Upload ThTuanIT", "success", `${list.length} tệp tin hiện có`);
|
| 313 |
+
pushLog("Đồng bộ danh sách tệp", `${list.length} files`, "info");
|
| 314 |
+
}
|
| 315 |
+
} catch (err: any) {
|
| 316 |
+
notify("Lỗi tải danh sách tệp", "error", err.message);
|
| 317 |
+
} finally {
|
| 318 |
+
setLoadingFiles(false);
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
|
| 322 |
+
function getDownloadUrl(path: string, inline = false) {
|
| 323 |
+
return buildDownloadUrl(path, token, inline);
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
function triggerDownload(file: FileNode) {
|
| 327 |
+
notify("Đang tải tệp xuống từ Upload ThTuanIT...", "info", file.path);
|
| 328 |
+
pushLog("Tải tệp xuống", file.path, "info");
|
| 329 |
+
const a = document.createElement("a");
|
| 330 |
+
a.href = getDownloadUrl(file.path, false);
|
| 331 |
+
a.download = file.name;
|
| 332 |
+
document.body.appendChild(a);
|
| 333 |
+
a.click();
|
| 334 |
+
a.remove();
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
async function handleDeleteFile(file: FileNode) {
|
| 338 |
+
if (!confirm(`Bạn có chắc chắn muốn xóa vĩnh viễn tệp "${file.path}" khỏi Upload ThTuanIT?`)) return;
|
| 339 |
+
try {
|
| 340 |
+
notify("Đang xóa tệp khỏi kho lưu trữ Upload ThTuanIT...", "info", file.path);
|
| 341 |
+
const res = await apiFetch(`/api/files?path=${encodeURIComponent(file.path)}`, {
|
| 342 |
+
method: "DELETE",
|
| 343 |
+
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
| 344 |
+
});
|
| 345 |
+
const data = await res.json();
|
| 346 |
+
if (!res.ok) throw new Error(data.detail || data.error || "Xóa thất bại");
|
| 347 |
+
notify("Đã xóa tệp thành công", "success", file.path);
|
| 348 |
+
pushLog("Xóa tệp khỏi Bucket", file.path, "warn");
|
| 349 |
+
if (previewFile?.path === file.path) setPreviewFile(null);
|
| 350 |
+
if (inspectedFile?.path === file.path) setInspectedFile(null);
|
| 351 |
+
loadFiles(token, false);
|
| 352 |
+
} catch (err: any) {
|
| 353 |
+
notify("Không thể xóa tệp", "error", err.message);
|
| 354 |
+
}
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
async function handleRenameSubmit(e: React.FormEvent) {
|
| 358 |
+
e.preventDefault();
|
| 359 |
+
if (!renameTarget || !newPathInput.trim()) return;
|
| 360 |
+
setRenaming(true);
|
| 361 |
+
try {
|
| 362 |
+
const res = await apiFetch("/api/files", {
|
| 363 |
+
method: "PUT",
|
| 364 |
+
headers: {
|
| 365 |
+
"Content-Type": "application/json",
|
| 366 |
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
| 367 |
+
},
|
| 368 |
+
body: JSON.stringify({
|
| 369 |
+
old_path: renameTarget.path,
|
| 370 |
+
new_path: newPathInput.trim(),
|
| 371 |
+
}),
|
| 372 |
+
});
|
| 373 |
+
const data = await res.json();
|
| 374 |
+
if (!res.ok) throw new Error(data.detail || data.error || "Đổi tên tệp thất bại");
|
| 375 |
+
notify("Đã đổi tên / di chuyển tệp thành công!", "success", `${renameTarget.path} → ${newPathInput.trim()}`);
|
| 376 |
+
pushLog("Đổi tên / Di chuyển tệp", `${renameTarget.path} → ${newPathInput.trim()}`, "success");
|
| 377 |
+
setRenameTarget(null);
|
| 378 |
+
setInspectedFile(null);
|
| 379 |
+
loadFiles(token, false);
|
| 380 |
+
} catch (err: any) {
|
| 381 |
+
notify("Lỗi khi đổi tên tệp", "error", err.message);
|
| 382 |
+
} finally {
|
| 383 |
+
setRenaming(false);
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
// --- TURBO UPLOAD ENGINE ---
|
| 388 |
+
async function startBatchUpload() {
|
| 389 |
+
if (selectedFiles.length === 0) {
|
| 390 |
+
notify("Vui lòng chọn ít nhất 1 tệp tin", "error");
|
| 391 |
+
return;
|
| 392 |
+
}
|
| 393 |
+
const cleanFolder = uploadTargetFolder.trim().replace(/^\/+|\/+$/g, "");
|
| 394 |
+
const batch = [...selectedFiles];
|
| 395 |
+
setUploadModalOpen(false);
|
| 396 |
+
setSelectedFiles([]);
|
| 397 |
+
|
| 398 |
+
const initialQueue: UploadProgressItem[] = batch.map((f, idx) => ({
|
| 399 |
+
id: `${Date.now()}-${idx}`,
|
| 400 |
+
path: cleanFolder ? `${cleanFolder}/${f.name}` : f.name,
|
| 401 |
+
progress: 0,
|
| 402 |
+
speedMBps: "0.0 MB/s",
|
| 403 |
+
etaSec: 0,
|
| 404 |
+
status: "uploading",
|
| 405 |
+
}));
|
| 406 |
+
setUploadQueue(initialQueue);
|
| 407 |
+
|
| 408 |
+
const totalBatchBytes = batch.reduce((acc, f) => acc + f.size, 0);
|
| 409 |
+
if (batch.length > 1 && totalBatchBytes <= 512 * 1024 * 1024) {
|
| 410 |
+
try {
|
| 411 |
+
await uploadBatchSingleCommitXHR(batch, cleanFolder, (pct, speedStr, eta) => {
|
| 412 |
+
setUploadQueue((prev) =>
|
| 413 |
+
prev.map((q) => ({
|
| 414 |
+
...q,
|
| 415 |
+
progress: pct,
|
| 416 |
+
speedMBps: speedStr,
|
| 417 |
+
etaSec: eta,
|
| 418 |
+
status: pct >= 100 ? "syncing" : "uploading",
|
| 419 |
+
}))
|
| 420 |
+
);
|
| 421 |
+
});
|
| 422 |
+
setUploadQueue((prev) => prev.map((q) => ({ ...q, progress: 100, status: "done" })));
|
| 423 |
+
pushLog("Turbo Batch Upload", `${batch.length} files (${formatBytes(totalBatchBytes)})`, "success");
|
| 424 |
+
notify(`Turbo Batch: Đã tải lên ${batch.length} tệp trong 1 lần commit!`, "success");
|
| 425 |
+
await loadFiles(token, false);
|
| 426 |
+
setTimeout(() => setUploadQueue([]), 4000);
|
| 427 |
+
return;
|
| 428 |
+
} catch (err) {
|
| 429 |
+
console.warn("Batch commit fallback:", err);
|
| 430 |
+
}
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
const CONCURRENCY = 4;
|
| 434 |
+
let cursor = 0;
|
| 435 |
+
let okCount = 0;
|
| 436 |
+
|
| 437 |
+
async function worker() {
|
| 438 |
+
while (cursor < batch.length) {
|
| 439 |
+
const i = cursor++;
|
| 440 |
+
const file = batch[i];
|
| 441 |
+
const item = initialQueue[i];
|
| 442 |
+
try {
|
| 443 |
+
await uploadSingleXHR(file, item.path, (pct, speedStr, eta) => {
|
| 444 |
+
setUploadQueue((prev) =>
|
| 445 |
+
prev.map((q) =>
|
| 446 |
+
q.id === item.id
|
| 447 |
+
? {
|
| 448 |
+
...q,
|
| 449 |
+
progress: pct,
|
| 450 |
+
speedMBps: speedStr,
|
| 451 |
+
etaSec: eta,
|
| 452 |
+
status: pct >= 100 ? "syncing" : "uploading",
|
| 453 |
+
}
|
| 454 |
+
: q
|
| 455 |
+
)
|
| 456 |
+
);
|
| 457 |
+
});
|
| 458 |
+
okCount++;
|
| 459 |
+
pushLog("Tải tệp lên Bucket", `${item.path} (${formatBytes(file.size)})`, "success");
|
| 460 |
+
setUploadQueue((prev) =>
|
| 461 |
+
prev.map((q) => (q.id === item.id ? { ...q, progress: 100, status: "done" } : q))
|
| 462 |
+
);
|
| 463 |
+
} catch (err: any) {
|
| 464 |
+
setUploadQueue((prev) => prev.map((q) => (q.id === item.id ? { ...q, status: "error" } : q)));
|
| 465 |
+
notify(`Lỗi tải lên ${file.name}`, "error", err.message);
|
| 466 |
+
}
|
| 467 |
+
}
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
await Promise.all(Array.from({ length: Math.min(CONCURRENCY, batch.length) }, () => worker()));
|
| 471 |
+
|
| 472 |
+
if (okCount > 0) {
|
| 473 |
+
notify(`Turbo Upload hoàn tất ${okCount}/${batch.length} tệp!`, "success");
|
| 474 |
+
await loadFiles(token, false);
|
| 475 |
+
}
|
| 476 |
+
setTimeout(() => setUploadQueue([]), 4500);
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
function uploadBatchSingleCommitXHR(
|
| 480 |
+
batchFiles: File[],
|
| 481 |
+
folder: string,
|
| 482 |
+
onProgress: (pct: number, speedMBps: string, etaSec: number) => void
|
| 483 |
+
) {
|
| 484 |
+
return new Promise((resolve, reject) => {
|
| 485 |
+
const xhr = new XMLHttpRequest();
|
| 486 |
+
const form = new FormData();
|
| 487 |
+
if (folder) form.append("folder", folder);
|
| 488 |
+
batchFiles.forEach((f) => form.append("files", f));
|
| 489 |
+
const startedAt = performance.now();
|
| 490 |
+
|
| 491 |
+
xhr.upload.onprogress = (ev) => {
|
| 492 |
+
if (ev.lengthComputable) {
|
| 493 |
+
const pct = Math.round((ev.loaded / ev.total) * 100);
|
| 494 |
+
const elapsedSec = Math.max((performance.now() - startedAt) / 1000, 0.1);
|
| 495 |
+
const bps = ev.loaded / elapsedSec;
|
| 496 |
+
const speedMBps = (bps / (1024 * 1024)).toFixed(1) + " MB/s";
|
| 497 |
+
const etaSec = bps > 0 ? Math.ceil((ev.total - ev.loaded) / bps) : 0;
|
| 498 |
+
onProgress(pct, speedMBps, etaSec);
|
| 499 |
+
}
|
| 500 |
+
};
|
| 501 |
+
xhr.onload = () => {
|
| 502 |
+
try {
|
| 503 |
+
const data = JSON.parse(xhr.responseText || "{}");
|
| 504 |
+
if (xhr.status >= 200 && xhr.status < 300) resolve(data);
|
| 505 |
+
else reject(new Error(data.detail || data.error || `HTTP ${xhr.status}`));
|
| 506 |
+
} catch {
|
| 507 |
+
reject(new Error(`HTTP ${xhr.status}`));
|
| 508 |
+
}
|
| 509 |
+
};
|
| 510 |
+
xhr.onerror = () => reject(new Error("Lỗi kết nối mạng"));
|
| 511 |
+
xhr.open("POST", `${getBackendOrigin()}/api/upload/batch`);
|
| 512 |
+
if (token) xhr.setRequestHeader("Authorization", `Bearer ${token}`);
|
| 513 |
+
xhr.send(form);
|
| 514 |
+
});
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
function uploadSingleXHR(
|
| 518 |
+
file: File,
|
| 519 |
+
remotePath: string,
|
| 520 |
+
onProgress: (pct: number, speedMBps: string, etaSec: number) => void
|
| 521 |
+
) {
|
| 522 |
+
return new Promise((resolve, reject) => {
|
| 523 |
+
const xhr = new XMLHttpRequest();
|
| 524 |
+
const form = new FormData();
|
| 525 |
+
form.append("path", remotePath);
|
| 526 |
+
form.append("file", file);
|
| 527 |
+
const startedAt = performance.now();
|
| 528 |
+
|
| 529 |
+
xhr.upload.onprogress = (ev) => {
|
| 530 |
+
if (ev.lengthComputable) {
|
| 531 |
+
const pct = Math.round((ev.loaded / ev.total) * 100);
|
| 532 |
+
const elapsedSec = Math.max((performance.now() - startedAt) / 1000, 0.1);
|
| 533 |
+
const bps = ev.loaded / elapsedSec;
|
| 534 |
+
const speedMBps = (bps / (1024 * 1024)).toFixed(1) + " MB/s";
|
| 535 |
+
const etaSec = bps > 0 ? Math.ceil((ev.total - ev.loaded) / bps) : 0;
|
| 536 |
+
onProgress(pct, speedMBps, etaSec);
|
| 537 |
+
}
|
| 538 |
+
};
|
| 539 |
+
xhr.onload = () => {
|
| 540 |
+
try {
|
| 541 |
+
const data = JSON.parse(xhr.responseText || "{}");
|
| 542 |
+
if (xhr.status >= 200 && xhr.status < 300) resolve(data);
|
| 543 |
+
else reject(new Error(data.detail || data.error || `HTTP ${xhr.status}`));
|
| 544 |
+
} catch {
|
| 545 |
+
reject(new Error(`HTTP ${xhr.status}`));
|
| 546 |
+
}
|
| 547 |
+
};
|
| 548 |
+
xhr.onerror = () => reject(new Error("Lỗi kết nối mạng"));
|
| 549 |
+
xhr.open("POST", `${getBackendOrigin()}/api/upload`);
|
| 550 |
+
if (token) xhr.setRequestHeader("Authorization", `Bearer ${token}`);
|
| 551 |
+
xhr.send(form);
|
| 552 |
+
});
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
// --- QUICK SHARE OPERATIONS ---
|
| 556 |
+
async function loadShares(tk = token) {
|
| 557 |
+
if (!tk) return;
|
| 558 |
+
try {
|
| 559 |
+
const res = await apiFetch("/api/shares", {
|
| 560 |
+
headers: { Authorization: `Bearer ${tk}` },
|
| 561 |
+
});
|
| 562 |
+
if (!res.ok) return;
|
| 563 |
+
const data = await res.json();
|
| 564 |
+
if (Array.isArray(data.shares)) {
|
| 565 |
+
const map: Record<string, ShareLink> = {};
|
| 566 |
+
data.shares.forEach((sh: ShareLink) => {
|
| 567 |
+
if (sh && sh.path) {
|
| 568 |
+
map[sh.path] = sh;
|
| 569 |
+
}
|
| 570 |
+
});
|
| 571 |
+
setSharesMap(map);
|
| 572 |
+
}
|
| 573 |
+
} catch {
|
| 574 |
+
// ignore
|
| 575 |
+
}
|
| 576 |
+
}
|
| 577 |
+
|
| 578 |
+
useEffect(() => {
|
| 579 |
+
if (!token || !currentUser) return;
|
| 580 |
+
const timer = setInterval(() => {
|
| 581 |
+
loadShares(token);
|
| 582 |
+
}, 6000);
|
| 583 |
+
return () => clearInterval(timer);
|
| 584 |
+
}, [token, currentUser]);
|
| 585 |
+
|
| 586 |
+
async function upsertFileShare(
|
| 587 |
+
path: string,
|
| 588 |
+
size: number,
|
| 589 |
+
enabled: boolean,
|
| 590 |
+
requireApproval: boolean,
|
| 591 |
+
regenerate = false
|
| 592 |
+
): Promise<ShareLink | null> {
|
| 593 |
+
try {
|
| 594 |
+
const res = await apiFetch("/api/shares", {
|
| 595 |
+
method: "POST",
|
| 596 |
+
headers: {
|
| 597 |
+
"Content-Type": "application/json",
|
| 598 |
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
| 599 |
+
},
|
| 600 |
+
body: JSON.stringify({
|
| 601 |
+
path,
|
| 602 |
+
size,
|
| 603 |
+
enabled,
|
| 604 |
+
require_approval: requireApproval,
|
| 605 |
+
regenerate,
|
| 606 |
+
}),
|
| 607 |
+
});
|
| 608 |
+
const data = await res.json();
|
| 609 |
+
if (!res.ok) throw new Error(data.detail || data.error || "Không thể cập nhật chia sẻ");
|
| 610 |
+
const sh: ShareLink = data.share;
|
| 611 |
+
setSharesMap((prev) => ({ ...prev, [path]: sh }));
|
| 612 |
+
if (regenerate) {
|
| 613 |
+
notify("Đã tạo lại mã liên kết chia sẻ mới!", "success", sh.id);
|
| 614 |
+
pushLog("Đổi mã liên kết chia sẻ", path, "info");
|
| 615 |
+
} else if (enabled) {
|
| 616 |
+
notify(
|
| 617 |
+
"Đã bật liên kết chia sẻ nhanh!",
|
| 618 |
+
"success",
|
| 619 |
+
requireApproval ? "Chế độ: Hỏi xin phép trước khi xem" : "Chế độ: Ai có link đều xem được"
|
| 620 |
+
);
|
| 621 |
+
pushLog("Bật chia sẻ tệp", `${path} (${sh.id})`, "success");
|
| 622 |
+
} else {
|
| 623 |
+
notify("Đã tắt liên kết chia sẻ", "info", path);
|
| 624 |
+
pushLog("Tắt chia sẻ tệp", path, "warn");
|
| 625 |
+
}
|
| 626 |
+
return sh;
|
| 627 |
+
} catch (err: any) {
|
| 628 |
+
notify("Lỗi cấu hình chia sẻ", "error", err.message);
|
| 629 |
+
return null;
|
| 630 |
+
}
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
async function respondShareRequest(
|
| 634 |
+
shareId: string,
|
| 635 |
+
requestId: string,
|
| 636 |
+
status: "approved" | "rejected"
|
| 637 |
+
): Promise<ShareLink | null> {
|
| 638 |
+
try {
|
| 639 |
+
const res = await apiFetch("/api/shares/approve", {
|
| 640 |
+
method: "POST",
|
| 641 |
+
headers: {
|
| 642 |
+
"Content-Type": "application/json",
|
| 643 |
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
| 644 |
+
},
|
| 645 |
+
body: JSON.stringify({
|
| 646 |
+
share_id: shareId,
|
| 647 |
+
request_id: requestId,
|
| 648 |
+
status,
|
| 649 |
+
}),
|
| 650 |
+
});
|
| 651 |
+
const data = await res.json();
|
| 652 |
+
if (!res.ok) throw new Error(data.detail || data.error || "Không thể xử lý yêu cầu");
|
| 653 |
+
const sh: ShareLink = data.share;
|
| 654 |
+
setSharesMap((prev) => ({ ...prev, [sh.path]: sh }));
|
| 655 |
+
notify(
|
| 656 |
+
status === "approved" ? "Đã cho phép truy cập tệp!" : "Đã từ chối / thu hồi quyền xem tệp",
|
| 657 |
+
status === "approved" ? "success" : "info",
|
| 658 |
+
sh.file_name
|
| 659 |
+
);
|
| 660 |
+
pushLog(
|
| 661 |
+
status === "approved" ? "Cho phép xem tệp chia sẻ" : "Từ chối xem tệp chia sẻ",
|
| 662 |
+
`${sh.file_name} (${requestId})`,
|
| 663 |
+
status === "approved" ? "success" : "warn"
|
| 664 |
+
);
|
| 665 |
+
return sh;
|
| 666 |
+
} catch (err: any) {
|
| 667 |
+
notify("Lỗi duyệt quyền truy cập", "error", err.message);
|
| 668 |
+
return null;
|
| 669 |
+
}
|
| 670 |
+
}
|
| 671 |
+
|
| 672 |
+
const pendingRequestsCount = useMemo(() => {
|
| 673 |
+
let count = 0;
|
| 674 |
+
Object.values(sharesMap).forEach((sh) => {
|
| 675 |
+
if (sh.enabled && Array.isArray(sh.requests)) {
|
| 676 |
+
sh.requests.forEach((r) => {
|
| 677 |
+
if (r.status === "pending") count++;
|
| 678 |
+
});
|
| 679 |
+
}
|
| 680 |
+
});
|
| 681 |
+
return count;
|
| 682 |
+
}, [sharesMap]);
|
| 683 |
+
|
| 684 |
+
// --- ADMIN RBAC ---
|
| 685 |
+
async function loadUsersList(tk = token) {
|
| 686 |
+
setLoadingUsers(true);
|
| 687 |
+
try {
|
| 688 |
+
const res = await apiFetch("/api/admin/users", {
|
| 689 |
+
headers: tk ? { Authorization: `Bearer ${tk}` } : {},
|
| 690 |
+
});
|
| 691 |
+
const data = await res.json();
|
| 692 |
+
if (res.ok && Array.isArray(data.users)) {
|
| 693 |
+
setUsersList(data.users);
|
| 694 |
+
}
|
| 695 |
+
} catch {
|
| 696 |
+
// ignore
|
| 697 |
+
} finally {
|
| 698 |
+
setLoadingUsers(false);
|
| 699 |
+
}
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
async function handleSaveUser(e: React.FormEvent) {
|
| 703 |
+
e.preventDefault();
|
| 704 |
+
if (!editingUser) return;
|
| 705 |
+
try {
|
| 706 |
+
const res = await apiFetch("/api/admin/users", {
|
| 707 |
+
method: "POST",
|
| 708 |
+
headers: {
|
| 709 |
+
"Content-Type": "application/json",
|
| 710 |
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
| 711 |
+
},
|
| 712 |
+
body: JSON.stringify(editingUser),
|
| 713 |
+
});
|
| 714 |
+
const data = await res.json();
|
| 715 |
+
if (!res.ok) throw new Error(data.detail || data.error || "Lưu người dùng thất bại");
|
| 716 |
+
notify("Đã lưu cấu hình tài khoản!", "success", `@${data.user.username} (${data.user.role})`);
|
| 717 |
+
pushLog("Admin cập nhật tài khoản", `@${data.user.username}`, "success");
|
| 718 |
+
setEditingUser(null);
|
| 719 |
+
loadUsersList(token);
|
| 720 |
+
if (currentUser && data.user.username === currentUser.username) {
|
| 721 |
+
setCurrentUser(data.user);
|
| 722 |
+
}
|
| 723 |
+
} catch (err: any) {
|
| 724 |
+
notify("Không thể lưu người dùng", "error", err.message);
|
| 725 |
+
}
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
async function handleQuickTogglePermission(u: UserProfile, field: keyof PermissionSet | "role" | "active") {
|
| 729 |
+
const updated = {
|
| 730 |
+
username: u.username,
|
| 731 |
+
display_name: u.display_name,
|
| 732 |
+
role: u.role,
|
| 733 |
+
password: "",
|
| 734 |
+
permissions: { ...u.permissions },
|
| 735 |
+
active: u.active,
|
| 736 |
+
};
|
| 737 |
+
|
| 738 |
+
if (field === "role") {
|
| 739 |
+
updated.role = u.role === "admin" ? "user" : "admin";
|
| 740 |
+
} else if (field === "active") {
|
| 741 |
+
if (u.username === "admin") {
|
| 742 |
+
notify("Không thể khóa tài khoản Admin gốc", "error");
|
| 743 |
+
return;
|
| 744 |
+
}
|
| 745 |
+
updated.active = !u.active;
|
| 746 |
+
} else {
|
| 747 |
+
updated.permissions[field] = !u.permissions[field];
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
try {
|
| 751 |
+
const res = await apiFetch("/api/admin/users", {
|
| 752 |
+
method: "POST",
|
| 753 |
+
headers: {
|
| 754 |
+
"Content-Type": "application/json",
|
| 755 |
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
| 756 |
+
},
|
| 757 |
+
body: JSON.stringify(updated),
|
| 758 |
+
});
|
| 759 |
+
const data = await res.json();
|
| 760 |
+
if (!res.ok) throw new Error(data.detail || data.error);
|
| 761 |
+
notify("Đã cập nhật phân quyền tức thì", "success", `@${u.username} • ${field}`);
|
| 762 |
+
pushLog("Thay đổi quyền RBAC", `@${u.username} (${field})`, "info");
|
| 763 |
+
loadUsersList(token);
|
| 764 |
+
} catch (err: any) {
|
| 765 |
+
notify("Lỗi cập nhật quyền", "error", err.message);
|
| 766 |
+
}
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
async function handleDeleteUser(username: string) {
|
| 770 |
+
if (username === "admin") {
|
| 771 |
+
notify("Không thể xóa tài khoản Admin gốc", "error");
|
| 772 |
+
return;
|
| 773 |
+
}
|
| 774 |
+
if (!confirm(`Xóa vĩnh viễn tài khoản người dùng "@${username}"?`)) return;
|
| 775 |
+
try {
|
| 776 |
+
const res = await apiFetch(`/api/admin/users?username=${encodeURIComponent(username)}`, {
|
| 777 |
+
method: "DELETE",
|
| 778 |
+
headers: token ? { Authorization: `Bearer ${token}` } : {},
|
| 779 |
+
});
|
| 780 |
+
const data = await res.json();
|
| 781 |
+
if (!res.ok) throw new Error(data.detail || data.error);
|
| 782 |
+
notify("Đã xóa tài khoản người dùng", "success", `@${username}`);
|
| 783 |
+
pushLog("Xóa tài khoản người dùng", `@${username}`, "warn");
|
| 784 |
+
loadUsersList(token);
|
| 785 |
+
} catch (err: any) {
|
| 786 |
+
notify("Lỗi xóa tài khoản", "error", err.message);
|
| 787 |
+
}
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
const stats = useMemo(() => {
|
| 791 |
+
const totalSize = files.reduce((acc, f) => acc + (f.size || 0), 0);
|
| 792 |
+
const counts = { video: 0, image: 0, archive: 0, doc: 0 };
|
| 793 |
+
const sizes = { video: 0, image: 0, archive: 0, doc: 0 };
|
| 794 |
+
files.forEach((f) => {
|
| 795 |
+
counts[f.category]++;
|
| 796 |
+
sizes[f.category] += f.size || 0;
|
| 797 |
+
});
|
| 798 |
+
return { totalSize, counts, sizes };
|
| 799 |
+
}, [files]);
|
| 800 |
+
|
| 801 |
+
const canUpload = Boolean(currentUser && (currentUser.role === "admin" || currentUser.permissions.can_upload));
|
| 802 |
+
const canDelete = Boolean(currentUser && (currentUser.role === "admin" || currentUser.permissions.can_delete));
|
| 803 |
+
const canRename = Boolean(currentUser && (currentUser.role === "admin" || currentUser.permissions.can_rename));
|
| 804 |
+
const isAdmin = currentUser?.role === "admin";
|
| 805 |
+
|
| 806 |
+
return (
|
| 807 |
+
<CloudContext.Provider
|
| 808 |
+
value={{
|
| 809 |
+
token,
|
| 810 |
+
currentUser,
|
| 811 |
+
authLoading,
|
| 812 |
+
bucketName,
|
| 813 |
+
hfVersion,
|
| 814 |
+
healthOk,
|
| 815 |
+
isAdmin,
|
| 816 |
+
canUpload,
|
| 817 |
+
canDelete,
|
| 818 |
+
canRename,
|
| 819 |
+
loginWithCredentials,
|
| 820 |
+
registerAccount,
|
| 821 |
+
handleLogout,
|
| 822 |
+
files,
|
| 823 |
+
loadingFiles,
|
| 824 |
+
currentFolder,
|
| 825 |
+
setCurrentFolder,
|
| 826 |
+
categoryFilter,
|
| 827 |
+
setCategoryFilter,
|
| 828 |
+
searchQuery,
|
| 829 |
+
setSearchQuery,
|
| 830 |
+
sortBy,
|
| 831 |
+
setSortBy,
|
| 832 |
+
viewMode,
|
| 833 |
+
setViewMode,
|
| 834 |
+
inspectedFile,
|
| 835 |
+
setInspectedFile,
|
| 836 |
+
stats,
|
| 837 |
+
loadFiles,
|
| 838 |
+
getDownloadUrl,
|
| 839 |
+
triggerDownload,
|
| 840 |
+
handleDeleteFile,
|
| 841 |
+
handleRenameSubmit,
|
| 842 |
+
uploadModalOpen,
|
| 843 |
+
setUploadModalOpen,
|
| 844 |
+
uploadTargetFolder,
|
| 845 |
+
setUploadTargetFolder,
|
| 846 |
+
selectedFiles,
|
| 847 |
+
setSelectedFiles,
|
| 848 |
+
uploadQueue,
|
| 849 |
+
startBatchUpload,
|
| 850 |
+
previewFile,
|
| 851 |
+
setPreviewFile,
|
| 852 |
+
renameTarget,
|
| 853 |
+
setRenameTarget,
|
| 854 |
+
newPathInput,
|
| 855 |
+
setNewPathInput,
|
| 856 |
+
renaming,
|
| 857 |
+
sharesMap,
|
| 858 |
+
pendingRequestsCount,
|
| 859 |
+
shareTarget,
|
| 860 |
+
setShareTarget,
|
| 861 |
+
loadShares,
|
| 862 |
+
upsertFileShare,
|
| 863 |
+
respondShareRequest,
|
| 864 |
+
usersList,
|
| 865 |
+
loadingUsers,
|
| 866 |
+
editingUser,
|
| 867 |
+
setEditingUser,
|
| 868 |
+
loadUsersList,
|
| 869 |
+
handleSaveUser,
|
| 870 |
+
handleQuickTogglePermission,
|
| 871 |
+
handleDeleteUser,
|
| 872 |
+
auditLogs,
|
| 873 |
+
toasts,
|
| 874 |
+
notify,
|
| 875 |
+
pushLog,
|
| 876 |
+
}}
|
| 877 |
+
>
|
| 878 |
+
{children}
|
| 879 |
+
</CloudContext.Provider>
|
| 880 |
+
);
|
| 881 |
+
}
|
| 882 |
+
|
| 883 |
+
export function useCloud() {
|
| 884 |
+
const ctx = useContext(CloudContext);
|
| 885 |
+
if (!ctx) {
|
| 886 |
+
throw new Error("useCloud must be used inside CloudProvider");
|
| 887 |
+
}
|
| 888 |
+
return ctx;
|
| 889 |
+
}
|
frontend/src/lib/api.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { FileNode, RawFileItem } from "@/types/cloud";
|
| 2 |
+
|
| 3 |
+
export function getBackendOrigin(): string {
|
| 4 |
+
if (typeof window !== "undefined") {
|
| 5 |
+
if (window.location.port === "3000") {
|
| 6 |
+
return `${window.location.protocol}//${window.location.hostname}:8080`;
|
| 7 |
+
}
|
| 8 |
+
return window.location.origin;
|
| 9 |
+
}
|
| 10 |
+
return process.env.BACKEND_URL || "http://127.0.0.1:8080";
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export async function apiFetch(path: string, init?: RequestInit): Promise<Response> {
|
| 14 |
+
return fetch(`${getBackendOrigin()}${path}`, init);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export function formatBytes(bytes: number): string {
|
| 18 |
+
if (!bytes || bytes <= 0) return "0 B";
|
| 19 |
+
const k = 1024;
|
| 20 |
+
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
| 21 |
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 22 |
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
export function detectCategory(filename: string): "video" | "image" | "archive" | "doc" {
|
| 26 |
+
const ext = (filename.split(".").pop() || "").toLowerCase();
|
| 27 |
+
if (["mp4", "mkv", "webm", "mov", "avi", "mp3", "wav", "ogg"].includes(ext)) return "video";
|
| 28 |
+
if (["png", "jpg", "jpeg", "gif", "webp", "svg", "bmp", "ico"].includes(ext)) return "image";
|
| 29 |
+
if (["zip", "rar", "7z", "tar", "gz", "bz2", "xz"].includes(ext)) return "archive";
|
| 30 |
+
return "doc";
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
export function normalizeFile(item: RawFileItem): FileNode {
|
| 34 |
+
const cleanPath = item.path.replace(/\\/g, "/").replace(/^\/+/, "");
|
| 35 |
+
const owner = (item.owner || "admin").toLowerCase();
|
| 36 |
+
let displayPath = cleanPath;
|
| 37 |
+
if (displayPath.toLowerCase().startsWith(owner + "/")) {
|
| 38 |
+
displayPath = displayPath.slice(owner.length + 1);
|
| 39 |
+
}
|
| 40 |
+
const parts = displayPath.split("/");
|
| 41 |
+
const name = parts.pop() || displayPath;
|
| 42 |
+
const folder = parts.join("/");
|
| 43 |
+
const ext = name.includes(".") ? name.split(".").pop()!.toLowerCase() : "";
|
| 44 |
+
return {
|
| 45 |
+
path: cleanPath,
|
| 46 |
+
name,
|
| 47 |
+
folder,
|
| 48 |
+
size: item.size || 0,
|
| 49 |
+
updatedAt: item.updated_at || "",
|
| 50 |
+
ext,
|
| 51 |
+
category: detectCategory(name),
|
| 52 |
+
owner: item.owner || "admin",
|
| 53 |
+
};
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
export function buildDownloadUrl(path: string, token: string, inline = false): string {
|
| 57 |
+
const params = new URLSearchParams({ path });
|
| 58 |
+
if (token) params.set("token", token);
|
| 59 |
+
if (inline) params.set("inline", "1");
|
| 60 |
+
return `${getBackendOrigin()}/api/download?${params.toString()}`;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
export function buildFrontendShareUrl(shareId: string): string {
|
| 64 |
+
if (typeof window !== "undefined") {
|
| 65 |
+
return `${window.location.origin}/share?id=${encodeURIComponent(shareId)}`;
|
| 66 |
+
}
|
| 67 |
+
return `/share?id=${encodeURIComponent(shareId)}`;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
export function buildPublicShareDownloadUrl(shareId: string, visitorToken: string, inline = false): string {
|
| 71 |
+
const params = new URLSearchParams({ id: shareId });
|
| 72 |
+
if (visitorToken) params.set("visitor_token", visitorToken);
|
| 73 |
+
if (inline) params.set("inline", "1");
|
| 74 |
+
return `${getBackendOrigin()}/api/public/share/download?${params.toString()}`;
|
| 75 |
+
}
|
| 76 |
+
|
frontend/src/types/cloud.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export interface PermissionSet {
|
| 2 |
+
can_upload: boolean;
|
| 3 |
+
can_delete: boolean;
|
| 4 |
+
can_rename: boolean;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
export interface UserProfile {
|
| 8 |
+
username: string;
|
| 9 |
+
display_name: string;
|
| 10 |
+
role: "admin" | "user";
|
| 11 |
+
permissions: PermissionSet;
|
| 12 |
+
active: boolean;
|
| 13 |
+
created_at: string;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export interface RawFileItem {
|
| 17 |
+
path: string;
|
| 18 |
+
size: number;
|
| 19 |
+
updated_at?: string;
|
| 20 |
+
owner?: string;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
export interface FileNode {
|
| 24 |
+
path: string;
|
| 25 |
+
name: string;
|
| 26 |
+
folder: string;
|
| 27 |
+
size: number;
|
| 28 |
+
updatedAt: string;
|
| 29 |
+
ext: string;
|
| 30 |
+
category: "video" | "image" | "archive" | "doc";
|
| 31 |
+
owner: string;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
export interface ToastMsg {
|
| 35 |
+
id: number;
|
| 36 |
+
title: string;
|
| 37 |
+
detail?: string;
|
| 38 |
+
type: "success" | "error" | "info";
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
export interface UploadProgressItem {
|
| 42 |
+
id: string;
|
| 43 |
+
path: string;
|
| 44 |
+
progress: number;
|
| 45 |
+
speedMBps?: string;
|
| 46 |
+
etaSec?: number;
|
| 47 |
+
status: "uploading" | "syncing" | "done" | "error";
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export interface AuditLogEntry {
|
| 51 |
+
id: string;
|
| 52 |
+
time: string;
|
| 53 |
+
actor: string;
|
| 54 |
+
action: string;
|
| 55 |
+
target: string;
|
| 56 |
+
status: "success" | "warn" | "info";
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
export interface EditingUserForm {
|
| 60 |
+
isNew: boolean;
|
| 61 |
+
username: string;
|
| 62 |
+
display_name: string;
|
| 63 |
+
role: "admin" | "user";
|
| 64 |
+
password: string;
|
| 65 |
+
permissions: PermissionSet;
|
| 66 |
+
active: boolean;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
export interface ShareAccessRequest {
|
| 70 |
+
request_id: string;
|
| 71 |
+
visitor_token: string;
|
| 72 |
+
visitor_name: string;
|
| 73 |
+
note?: string;
|
| 74 |
+
status: "pending" | "approved" | "rejected";
|
| 75 |
+
requested_at: string;
|
| 76 |
+
updated_at: string;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
export interface ShareLink {
|
| 80 |
+
id: string;
|
| 81 |
+
path: string;
|
| 82 |
+
file_name: string;
|
| 83 |
+
size: number;
|
| 84 |
+
owner: string;
|
| 85 |
+
enabled: boolean;
|
| 86 |
+
require_approval: boolean;
|
| 87 |
+
created_at: string;
|
| 88 |
+
updated_at: string;
|
| 89 |
+
requests: ShareAccessRequest[];
|
| 90 |
+
}
|
| 91 |
+
|
frontend/tailwind.config.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Config } from "tailwindcss";
|
| 2 |
+
|
| 3 |
+
const config: Config = {
|
| 4 |
+
content: [
|
| 5 |
+
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
|
| 6 |
+
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
|
| 7 |
+
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
|
| 8 |
+
],
|
| 9 |
+
theme: {
|
| 10 |
+
extend: {
|
| 11 |
+
colors: {
|
| 12 |
+
space: {
|
| 13 |
+
950: "#05070f",
|
| 14 |
+
900: "#0a0e1a",
|
| 15 |
+
800: "#111827",
|
| 16 |
+
700: "#1e293b",
|
| 17 |
+
},
|
| 18 |
+
},
|
| 19 |
+
},
|
| 20 |
+
},
|
| 21 |
+
plugins: [],
|
| 22 |
+
};
|
| 23 |
+
export default config;
|
frontend/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"compilerOptions": {
|
| 3 |
+
"lib": ["dom", "dom.iterable", "esnext"],
|
| 4 |
+
"allowJs": true,
|
| 5 |
+
"skipLibCheck": true,
|
| 6 |
+
"strict": true,
|
| 7 |
+
"noEmit": true,
|
| 8 |
+
"esModuleInterop": true,
|
| 9 |
+
"module": "esnext",
|
| 10 |
+
"moduleResolution": "bundler",
|
| 11 |
+
"resolveJsonModule": true,
|
| 12 |
+
"isolatedModules": true,
|
| 13 |
+
"jsx": "preserve",
|
| 14 |
+
"incremental": true,
|
| 15 |
+
"plugins": [
|
| 16 |
+
{
|
| 17 |
+
"name": "next"
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"paths": {
|
| 21 |
+
"@/*": ["./src/*"]
|
| 22 |
+
}
|
| 23 |
+
},
|
| 24 |
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
| 25 |
+
"exclude": ["node_modules"]
|
| 26 |
+
}
|
go.mod
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
module hf-bucket-go
|
| 2 |
+
|
| 3 |
+
go 1.22
|
| 4 |
+
|
| 5 |
+
require go.mongodb.org/mongo-driver v1.17.1
|
| 6 |
+
|
| 7 |
+
require (
|
| 8 |
+
github.com/golang/snappy v0.0.4 // indirect
|
| 9 |
+
github.com/klauspost/compress v1.13.6 // indirect
|
| 10 |
+
github.com/montanaflynn/stats v0.7.1 // indirect
|
| 11 |
+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
| 12 |
+
github.com/xdg-go/scram v1.1.2 // indirect
|
| 13 |
+
github.com/xdg-go/stringprep v1.0.4 // indirect
|
| 14 |
+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
|
| 15 |
+
golang.org/x/crypto v0.26.0 // indirect
|
| 16 |
+
golang.org/x/sync v0.8.0 // indirect
|
| 17 |
+
golang.org/x/text v0.17.0 // indirect
|
| 18 |
+
)
|
go.sum
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
| 2 |
+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
| 3 |
+
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
| 4 |
+
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
| 5 |
+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
| 6 |
+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
| 7 |
+
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
| 8 |
+
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
| 9 |
+
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
| 10 |
+
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
| 11 |
+
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
| 12 |
+
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
| 13 |
+
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
| 14 |
+
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
|
| 15 |
+
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
|
| 16 |
+
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
|
| 17 |
+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
|
| 18 |
+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
|
| 19 |
+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
| 20 |
+
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
|
| 21 |
+
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
|
| 22 |
+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
| 23 |
+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
| 24 |
+
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
| 25 |
+
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
| 26 |
+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
| 27 |
+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
| 28 |
+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
| 29 |
+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
| 30 |
+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 31 |
+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 32 |
+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
| 33 |
+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
| 34 |
+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
| 35 |
+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
| 36 |
+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 37 |
+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 38 |
+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 39 |
+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
| 40 |
+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
| 41 |
+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
| 42 |
+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
| 43 |
+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
| 44 |
+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
| 45 |
+
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
| 46 |
+
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
| 47 |
+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
| 48 |
+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
| 49 |
+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
| 50 |
+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
hf_worker.go
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"
|
| 6 |
+
"fmt"
|
| 7 |
+
"io"
|
| 8 |
+
"os"
|
| 9 |
+
"os/exec"
|
| 10 |
+
"path/filepath"
|
| 11 |
+
"strings"
|
| 12 |
+
"sync"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
const pyWorkerScript = `
|
| 16 |
+
import sys, json, os
|
| 17 |
+
from huggingface_hub import HfApi
|
| 18 |
+
|
| 19 |
+
token = os.environ.get("HF_TOKEN", "")
|
| 20 |
+
api = HfApi(token=token)
|
| 21 |
+
|
| 22 |
+
for line in sys.stdin:
|
| 23 |
+
line = line.strip()
|
| 24 |
+
if not line:
|
| 25 |
+
continue
|
| 26 |
+
try:
|
| 27 |
+
req = json.loads(line)
|
| 28 |
+
op = req.get("op")
|
| 29 |
+
bucket = req.get("bucket")
|
| 30 |
+
if op == "ping":
|
| 31 |
+
import huggingface_hub
|
| 32 |
+
res = {"ok": True, "version": huggingface_hub.__version__}
|
| 33 |
+
elif op == "ls":
|
| 34 |
+
prefix = req.get("prefix") or None
|
| 35 |
+
items = []
|
| 36 |
+
for entry in api.list_bucket_tree(bucket, prefix=prefix, recursive=True):
|
| 37 |
+
if getattr(entry, "type", "") == "file":
|
| 38 |
+
dt = getattr(entry, "uploaded_at", None)
|
| 39 |
+
updated = dt.strftime("%Y-%m-%d %H:%M:%S") if dt else ""
|
| 40 |
+
items.append({
|
| 41 |
+
"path": entry.path,
|
| 42 |
+
"size": getattr(entry, "size", 0) or 0,
|
| 43 |
+
"updated_at": updated,
|
| 44 |
+
"xet_hash": getattr(entry, "xet_hash", "") or ""
|
| 45 |
+
})
|
| 46 |
+
res = {"ok": True, "items": items}
|
| 47 |
+
elif op == "upload":
|
| 48 |
+
pairs = [(x["local"], x["remote"]) for x in req.get("files", [])]
|
| 49 |
+
api.batch_bucket_files(bucket, add=pairs)
|
| 50 |
+
res = {"ok": True}
|
| 51 |
+
elif op == "download":
|
| 52 |
+
api.download_bucket_files(bucket, [(req["remote"], req["local"])], raise_on_missing_files=True)
|
| 53 |
+
res = {"ok": True}
|
| 54 |
+
elif op == "rm":
|
| 55 |
+
api.batch_bucket_files(bucket, delete=[req["remote"]])
|
| 56 |
+
res = {"ok": True}
|
| 57 |
+
elif op == "mv":
|
| 58 |
+
old_p = req["old_path"]
|
| 59 |
+
new_p = req["new_path"]
|
| 60 |
+
infos = list(api.get_bucket_paths_info(bucket, [old_p]))
|
| 61 |
+
if not infos:
|
| 62 |
+
raise RuntimeError(f"File not found: {old_p}")
|
| 63 |
+
xhash = infos[0].xet_hash
|
| 64 |
+
api.batch_bucket_files(
|
| 65 |
+
bucket,
|
| 66 |
+
copy=[("bucket", bucket, xhash, new_p)],
|
| 67 |
+
delete=[old_p]
|
| 68 |
+
)
|
| 69 |
+
res = {"ok": True, "xet_hash": xhash}
|
| 70 |
+
else:
|
| 71 |
+
res = {"ok": False, "error": f"unknown op: {op}"}
|
| 72 |
+
except Exception as e:
|
| 73 |
+
res = {"ok": False, "error": str(e)}
|
| 74 |
+
sys.stdout.write(json.dumps(res) + "\n")
|
| 75 |
+
sys.stdout.flush()
|
| 76 |
+
`
|
| 77 |
+
|
| 78 |
+
// HFWorkerPool separates fast metadata ops (ls, mv, rm, ping) from heavy data transfers (upload, download)
|
| 79 |
+
// using channel-based free-worker queues so large uploads NEVER block /health or /api/files.
|
| 80 |
+
type HFWorkerPool struct {
|
| 81 |
+
metaQueue chan *hfWorker
|
| 82 |
+
xferQueue chan *hfWorker
|
| 83 |
+
version string
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
type hfWorker struct {
|
| 87 |
+
mu sync.Mutex
|
| 88 |
+
pyBin string
|
| 89 |
+
hfToken string
|
| 90 |
+
cmd *exec.Cmd
|
| 91 |
+
stdin io.WriteCloser
|
| 92 |
+
stdout *bufio.Reader
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
func resolvePythonFromHFCLI(hfCLI string) string {
|
| 96 |
+
if p, err := exec.LookPath("python"); err == nil {
|
| 97 |
+
return p
|
| 98 |
+
}
|
| 99 |
+
if p, err := exec.LookPath(hfCLI); err == nil {
|
| 100 |
+
dir := filepath.Dir(p)
|
| 101 |
+
candidate := filepath.Join(filepath.Dir(dir), "python.exe")
|
| 102 |
+
if _, err := os.Stat(candidate); err == nil {
|
| 103 |
+
return candidate
|
| 104 |
+
}
|
| 105 |
+
candidateUnix := filepath.Join(dir, "python3")
|
| 106 |
+
if _, err := os.Stat(candidateUnix); err == nil {
|
| 107 |
+
return candidateUnix
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
return "python"
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
func NewHFWorkerPool(xferSize int, hfCLI, hfToken string) *HFWorkerPool {
|
| 114 |
+
if xferSize < 2 {
|
| 115 |
+
xferSize = 2
|
| 116 |
+
}
|
| 117 |
+
metaSize := 2
|
| 118 |
+
pyBin := resolvePythonFromHFCLI(hfCLI)
|
| 119 |
+
pool := &HFWorkerPool{
|
| 120 |
+
metaQueue: make(chan *hfWorker, metaSize),
|
| 121 |
+
xferQueue: make(chan *hfWorker, xferSize),
|
| 122 |
+
version: "2.4.0 (Turbo Xet)",
|
| 123 |
+
}
|
| 124 |
+
for i := 0; i < metaSize; i++ {
|
| 125 |
+
w := &hfWorker{pyBin: pyBin, hfToken: hfToken}
|
| 126 |
+
_ = w.ensureRunning()
|
| 127 |
+
if i == 0 {
|
| 128 |
+
if res, err := w.call(map[string]any{"op": "ping"}); err == nil {
|
| 129 |
+
if v, ok := res["version"].(string); ok && v != "" {
|
| 130 |
+
pool.version = v
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
}
|
| 134 |
+
pool.metaQueue <- w
|
| 135 |
+
}
|
| 136 |
+
for i := 0; i < xferSize; i++ {
|
| 137 |
+
w := &hfWorker{pyBin: pyBin, hfToken: hfToken}
|
| 138 |
+
_ = w.ensureRunning()
|
| 139 |
+
pool.xferQueue <- w
|
| 140 |
+
}
|
| 141 |
+
return pool
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
func (w *hfWorker) ensureRunning() error {
|
| 145 |
+
if w.cmd != nil && w.cmd.Process != nil && w.cmd.ProcessState == nil {
|
| 146 |
+
return nil
|
| 147 |
+
}
|
| 148 |
+
cmd := exec.Command(w.pyBin, "-u", "-c", pyWorkerScript)
|
| 149 |
+
cmd.Env = append(
|
| 150 |
+
os.Environ(),
|
| 151 |
+
"HF_TOKEN="+w.hfToken,
|
| 152 |
+
"HF_HUB_DISABLE_PROGRESS_BARS=1",
|
| 153 |
+
"HF_XET_HIGH_PERFORMANCE=1",
|
| 154 |
+
"PYTHONIOENCODING=utf-8",
|
| 155 |
+
)
|
| 156 |
+
stdin, err := cmd.StdinPipe()
|
| 157 |
+
if err != nil {
|
| 158 |
+
return err
|
| 159 |
+
}
|
| 160 |
+
stdoutPipe, err := cmd.StdoutPipe()
|
| 161 |
+
if err != nil {
|
| 162 |
+
return err
|
| 163 |
+
}
|
| 164 |
+
if err := cmd.Start(); err != nil {
|
| 165 |
+
return err
|
| 166 |
+
}
|
| 167 |
+
w.cmd = cmd
|
| 168 |
+
w.stdin = stdin
|
| 169 |
+
w.stdout = bufio.NewReaderSize(stdoutPipe, 1<<20)
|
| 170 |
+
return nil
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
func (w *hfWorker) call(req map[string]any) (map[string]any, error) {
|
| 174 |
+
w.mu.Lock()
|
| 175 |
+
defer w.mu.Unlock()
|
| 176 |
+
|
| 177 |
+
if err := w.ensureRunning(); err != nil {
|
| 178 |
+
return nil, fmt.Errorf("failed to start python xet worker: %w", err)
|
| 179 |
+
}
|
| 180 |
+
payload, err := json.Marshal(req)
|
| 181 |
+
if err != nil {
|
| 182 |
+
return nil, err
|
| 183 |
+
}
|
| 184 |
+
if _, err := w.stdin.Write(append(payload, '\n')); err != nil {
|
| 185 |
+
w.cmd = nil
|
| 186 |
+
if err2 := w.ensureRunning(); err2 != nil {
|
| 187 |
+
return nil, err
|
| 188 |
+
}
|
| 189 |
+
if _, err2 := w.stdin.Write(append(payload, '\n')); err2 != nil {
|
| 190 |
+
return nil, err2
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
line, err := w.stdout.ReadString('\n')
|
| 194 |
+
if err != nil {
|
| 195 |
+
w.cmd = nil
|
| 196 |
+
return nil, fmt.Errorf("worker read failed: %w", err)
|
| 197 |
+
}
|
| 198 |
+
var resp map[string]any
|
| 199 |
+
if err := json.Unmarshal([]byte(strings.TrimSpace(line)), &resp); err != nil {
|
| 200 |
+
return nil, fmt.Errorf("invalid worker json: %w", err)
|
| 201 |
+
}
|
| 202 |
+
if ok, _ := resp["ok"].(bool); !ok {
|
| 203 |
+
errMsg, _ := resp["error"].(string)
|
| 204 |
+
return resp, fmt.Errorf("%s", errMsg)
|
| 205 |
+
}
|
| 206 |
+
return resp, nil
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
func (p *HFWorkerPool) Call(req map[string]any) (map[string]any, error) {
|
| 210 |
+
op, _ := req["op"].(string)
|
| 211 |
+
if op == "ping" {
|
| 212 |
+
return map[string]any{"ok": true, "version": p.version}, nil
|
| 213 |
+
}
|
| 214 |
+
// Route heavy transfers (upload / download) to xferQueue, and metadata ops (ls / mv / rm) to metaQueue
|
| 215 |
+
if op == "upload" || op == "download" {
|
| 216 |
+
w := <-p.xferQueue
|
| 217 |
+
defer func() { p.xferQueue <- w }()
|
| 218 |
+
return w.call(req)
|
| 219 |
+
}
|
| 220 |
+
w := <-p.metaQueue
|
| 221 |
+
defer func() { p.metaQueue <- w }()
|
| 222 |
+
return w.call(req)
|
| 223 |
+
}
|
main.go
ADDED
|
@@ -0,0 +1,1225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"bufio"
|
| 5 |
+
"context"
|
| 6 |
+
"crypto/sha256"
|
| 7 |
+
"embed"
|
| 8 |
+
"encoding/hex"
|
| 9 |
+
"encoding/json"
|
| 10 |
+
"errors"
|
| 11 |
+
"fmt"
|
| 12 |
+
"io"
|
| 13 |
+
"log"
|
| 14 |
+
"mime"
|
| 15 |
+
"net/http"
|
| 16 |
+
"net/http/httputil"
|
| 17 |
+
"net/url"
|
| 18 |
+
"os"
|
| 19 |
+
"os/exec"
|
| 20 |
+
"path"
|
| 21 |
+
"path/filepath"
|
| 22 |
+
"strconv"
|
| 23 |
+
"strings"
|
| 24 |
+
"sync"
|
| 25 |
+
"time"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
//go:embed web/index.html
|
| 29 |
+
var webFS embed.FS
|
| 30 |
+
|
| 31 |
+
const bucketID = "TwanAPI/ThTuan"
|
| 32 |
+
|
| 33 |
+
type FileItem struct {
|
| 34 |
+
Path string `json:"path"`
|
| 35 |
+
Size int64 `json:"size"`
|
| 36 |
+
UpdatedAt string `json:"updated_at,omitempty"`
|
| 37 |
+
Owner string `json:"owner,omitempty"`
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
type Config struct {
|
| 41 |
+
HFCLI string
|
| 42 |
+
HFToken string
|
| 43 |
+
APIKey string
|
| 44 |
+
ListenAddr string
|
| 45 |
+
TempDir string
|
| 46 |
+
MaxUpload int64
|
| 47 |
+
CommandTime time.Duration
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
type App struct {
|
| 51 |
+
cfg Config
|
| 52 |
+
users *UserStore
|
| 53 |
+
owners *FileOwnerStore
|
| 54 |
+
shares *ShareStore
|
| 55 |
+
mongo *MongoStore
|
| 56 |
+
pool *HFWorkerPool
|
| 57 |
+
cacheMu sync.Map // map[string]*sync.Mutex per cached file path
|
| 58 |
+
listCacheMu sync.RWMutex
|
| 59 |
+
listCache []FileItem
|
| 60 |
+
listCacheTime time.Time
|
| 61 |
+
pathAllocMu sync.Mutex
|
| 62 |
+
reservedPaths map[string]bool
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
func (a *App) invalidateListCache() {
|
| 66 |
+
a.listCacheMu.Lock()
|
| 67 |
+
a.listCacheTime = time.Time{}
|
| 68 |
+
a.listCacheMu.Unlock()
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
func (a *App) evictDownloadCache(remote string) {
|
| 72 |
+
cacheDir := filepath.Join(a.cfg.TempDir, "hf-cache")
|
| 73 |
+
hash := sha256.Sum256([]byte(remote))
|
| 74 |
+
ext := filepath.Ext(remote)
|
| 75 |
+
cachedFile := filepath.Join(cacheDir, hex.EncodeToString(hash[:16])+ext)
|
| 76 |
+
_ = os.Remove(cachedFile)
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
func (a *App) resolveUniqueRemotePath(scopedPath string) string {
|
| 80 |
+
a.pathAllocMu.Lock()
|
| 81 |
+
defer a.pathAllocMu.Unlock()
|
| 82 |
+
if a.reservedPaths == nil {
|
| 83 |
+
a.reservedPaths = make(map[string]bool)
|
| 84 |
+
if a.pool != nil {
|
| 85 |
+
if res, err := a.pool.Call(map[string]any{"op": "ls", "bucket": bucketID}); err == nil {
|
| 86 |
+
if rawItems, ok := res["items"].([]any); ok {
|
| 87 |
+
for _, ri := range rawItems {
|
| 88 |
+
if m, ok := ri.(map[string]any); ok {
|
| 89 |
+
if p, _ := m["path"].(string); p != "" {
|
| 90 |
+
a.reservedPaths[p] = true
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
unique := nextAvailableRemotePath(scopedPath, func(candidate string) bool {
|
| 99 |
+
if a.reservedPaths[candidate] {
|
| 100 |
+
return true
|
| 101 |
+
}
|
| 102 |
+
if a.owners != nil && a.owners.HasPath(candidate) {
|
| 103 |
+
return true
|
| 104 |
+
}
|
| 105 |
+
return false
|
| 106 |
+
})
|
| 107 |
+
a.reservedPaths[unique] = true
|
| 108 |
+
return unique
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
func (a *App) releaseReservedPath(remotePath string) {
|
| 112 |
+
a.pathAllocMu.Lock()
|
| 113 |
+
if a.reservedPaths != nil {
|
| 114 |
+
delete(a.reservedPaths, remotePath)
|
| 115 |
+
}
|
| 116 |
+
a.pathAllocMu.Unlock()
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
func (a *App) fileLock(key string) *sync.Mutex {
|
| 120 |
+
val, _ := a.cacheMu.LoadOrStore(key, &sync.Mutex{})
|
| 121 |
+
return val.(*sync.Mutex)
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
type contextKey string
|
| 125 |
+
|
| 126 |
+
const userContextKey contextKey = "auth_user"
|
| 127 |
+
|
| 128 |
+
type APIError struct {
|
| 129 |
+
Error string `json:"error"`
|
| 130 |
+
Detail string `json:"detail,omitempty"`
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
func main() {
|
| 134 |
+
cfg, err := loadConfig()
|
| 135 |
+
if err != nil {
|
| 136 |
+
log.Fatal(err)
|
| 137 |
+
}
|
| 138 |
+
if err := os.MkdirAll(cfg.TempDir, 0700); err != nil {
|
| 139 |
+
log.Fatal(err)
|
| 140 |
+
}
|
| 141 |
+
userStore, err := NewUserStore(env("USERS_FILE", "users.json"), cfg.APIKey)
|
| 142 |
+
if err != nil {
|
| 143 |
+
log.Fatalf("failed to load user store: %v", err)
|
| 144 |
+
}
|
| 145 |
+
ownerStore, err := NewFileOwnerStore(env("OWNERS_FILE", "file_owners.json"))
|
| 146 |
+
if err != nil {
|
| 147 |
+
log.Fatalf("failed to load file owner store: %v", err)
|
| 148 |
+
}
|
| 149 |
+
shareStore, err := NewShareStore(env("SHARES_FILE", "shares.json"))
|
| 150 |
+
if err != nil {
|
| 151 |
+
log.Fatalf("failed to load share store: %v", err)
|
| 152 |
+
}
|
| 153 |
+
var mongoStore *MongoStore
|
| 154 |
+
if mongoURI := env("MONGODB_URI", os.Getenv("MONGO_URI")); mongoURI != "" {
|
| 155 |
+
ms, mErr := NewMongoStore(mongoURI, env("MONGODB_DB", "upload_thtuanit"))
|
| 156 |
+
if mErr != nil {
|
| 157 |
+
log.Printf("WARNING: failed to connect to MongoDB (%v); falling back to local JSON store", mErr)
|
| 158 |
+
} else {
|
| 159 |
+
mongoStore = ms
|
| 160 |
+
userStore.AttachMongo(mongoStore)
|
| 161 |
+
ownerStore.AttachMongo(mongoStore)
|
| 162 |
+
shareStore.AttachMongo(mongoStore)
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
workerPool := NewHFWorkerPool(4, cfg.HFCLI, cfg.HFToken)
|
| 166 |
+
app := &App{cfg: cfg, users: userStore, owners: ownerStore, shares: shareStore, mongo: mongoStore, pool: workerPool}
|
| 167 |
+
|
| 168 |
+
mux := http.NewServeMux()
|
| 169 |
+
mux.HandleFunc("/", app.indexUI)
|
| 170 |
+
mux.HandleFunc("GET /health", app.health)
|
| 171 |
+
mux.HandleFunc("POST /api/auth/login", app.handleLogin)
|
| 172 |
+
mux.HandleFunc("POST /api/auth/register", app.handleRegister)
|
| 173 |
+
mux.HandleFunc("POST /api/auth/logout", app.handleLogout)
|
| 174 |
+
mux.HandleFunc("GET /api/auth/me", app.handleMe)
|
| 175 |
+
mux.Handle("GET /api/admin/users", app.auth(http.HandlerFunc(app.handleAdminListUsers)))
|
| 176 |
+
mux.Handle("POST /api/admin/users", app.auth(http.HandlerFunc(app.handleAdminSaveUser)))
|
| 177 |
+
mux.Handle("DELETE /api/admin/users", app.auth(http.HandlerFunc(app.handleAdminDeleteUser)))
|
| 178 |
+
mux.Handle("POST /api/upload", app.auth(http.HandlerFunc(app.upload)))
|
| 179 |
+
mux.Handle("POST /api/upload/batch", app.auth(http.HandlerFunc(app.uploadBatch)))
|
| 180 |
+
mux.Handle("GET /api/files", app.auth(http.HandlerFunc(app.listFiles)))
|
| 181 |
+
mux.Handle("PUT /api/files", app.auth(http.HandlerFunc(app.renameFile)))
|
| 182 |
+
mux.Handle("DELETE /api/files", app.auth(http.HandlerFunc(app.deleteFile)))
|
| 183 |
+
mux.Handle("GET /api/download", app.auth(http.HandlerFunc(app.download)))
|
| 184 |
+
mux.Handle("GET /api/shares", app.auth(http.HandlerFunc(app.handleListShares)))
|
| 185 |
+
mux.Handle("GET /api/shares/file", app.auth(http.HandlerFunc(app.handleGetFileShare)))
|
| 186 |
+
mux.Handle("POST /api/shares", app.auth(http.HandlerFunc(app.handleUpsertShare)))
|
| 187 |
+
mux.Handle("POST /api/shares/approve", app.auth(http.HandlerFunc(app.handleApproveShareRequest)))
|
| 188 |
+
mux.HandleFunc("GET /api/public/share", app.handlePublicGetShare)
|
| 189 |
+
mux.HandleFunc("POST /api/public/share/request", app.handlePublicRequestShareAccess)
|
| 190 |
+
mux.HandleFunc("GET /api/public/share/download", app.handlePublicShareDownload)
|
| 191 |
+
|
| 192 |
+
server := &http.Server{
|
| 193 |
+
Addr: cfg.ListenAddr, Handler: securityHeaders(mux),
|
| 194 |
+
ReadHeaderTimeout: 60 * time.Second,
|
| 195 |
+
ReadTimeout: 2 * time.Hour,
|
| 196 |
+
WriteTimeout: 2 * time.Hour,
|
| 197 |
+
IdleTimeout: 5 * time.Minute,
|
| 198 |
+
}
|
| 199 |
+
log.Printf("Hugging Face Bucket API listening on %s (bucket=%s)", cfg.ListenAddr, bucketID)
|
| 200 |
+
log.Fatal(server.ListenAndServe())
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
func loadDotEnv(filename string) {
|
| 204 |
+
f, err := os.Open(filename)
|
| 205 |
+
if err != nil {
|
| 206 |
+
return
|
| 207 |
+
}
|
| 208 |
+
defer f.Close()
|
| 209 |
+
scanner := bufio.NewScanner(f)
|
| 210 |
+
for scanner.Scan() {
|
| 211 |
+
line := strings.TrimSpace(scanner.Text())
|
| 212 |
+
if line == "" || strings.HasPrefix(line, "#") {
|
| 213 |
+
continue
|
| 214 |
+
}
|
| 215 |
+
k, v, ok := strings.Cut(line, "=")
|
| 216 |
+
if !ok {
|
| 217 |
+
continue
|
| 218 |
+
}
|
| 219 |
+
k = strings.TrimSpace(k)
|
| 220 |
+
v = strings.Trim(strings.TrimSpace(v), `"'`)
|
| 221 |
+
if k != "" && os.Getenv(k) == "" {
|
| 222 |
+
_ = os.Setenv(k, v)
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
func loadConfig() (Config, error) {
|
| 228 |
+
loadDotEnv(".env")
|
| 229 |
+
cfg := Config{
|
| 230 |
+
HFCLI: env("HF_CLI", "hf"), HFToken: os.Getenv("HF_TOKEN"),
|
| 231 |
+
APIKey: os.Getenv("API_KEY"), ListenAddr: env("LISTEN_ADDR", ":8080"),
|
| 232 |
+
TempDir: env("TEMP_DIR", os.TempDir()), MaxUpload: 10 << 30,
|
| 233 |
+
CommandTime: 30 * time.Minute,
|
| 234 |
+
}
|
| 235 |
+
if cfg.HFToken == "" {
|
| 236 |
+
return cfg, errors.New("HF_TOKEN is required")
|
| 237 |
+
}
|
| 238 |
+
if cfg.APIKey == "" {
|
| 239 |
+
return cfg, errors.New("API_KEY is required; set a private key for API access")
|
| 240 |
+
}
|
| 241 |
+
if n := os.Getenv("MAX_UPLOAD_BYTES"); n != "" {
|
| 242 |
+
v, err := strconv.ParseInt(n, 10, 64)
|
| 243 |
+
if err != nil || v <= 0 {
|
| 244 |
+
return cfg, fmt.Errorf("invalid MAX_UPLOAD_BYTES: %q", n)
|
| 245 |
+
}
|
| 246 |
+
cfg.MaxUpload = v
|
| 247 |
+
}
|
| 248 |
+
return cfg, nil
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
func env(k, fallback string) string {
|
| 252 |
+
if v := os.Getenv(k); v != "" {
|
| 253 |
+
return v
|
| 254 |
+
}
|
| 255 |
+
return fallback
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
func (a *App) auth(next http.Handler) http.Handler {
|
| 259 |
+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
| 260 |
+
u, ok := a.resolveRequestUser(r)
|
| 261 |
+
if !ok {
|
| 262 |
+
writeJSON(w, http.StatusUnauthorized, APIError{Error: "unauthorized", Detail: "Vui lòng đăng nhập hoặc cung cấp API key hợp lệ"})
|
| 263 |
+
return
|
| 264 |
+
}
|
| 265 |
+
ctx := context.WithValue(r.Context(), userContextKey, u)
|
| 266 |
+
next.ServeHTTP(w, r.WithContext(ctx))
|
| 267 |
+
})
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
func currentUser(r *http.Request) UserAccount {
|
| 271 |
+
if u, ok := r.Context().Value(userContextKey).(UserAccount); ok {
|
| 272 |
+
return u
|
| 273 |
+
}
|
| 274 |
+
return UserAccount{}
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
func (a *App) indexUI(w http.ResponseWriter, r *http.Request) {
|
| 278 |
+
if feURL := os.Getenv("FRONTEND_URL"); feURL != "" {
|
| 279 |
+
if target, err := url.Parse(feURL); err == nil {
|
| 280 |
+
proxy := httputil.NewSingleHostReverseProxy(target)
|
| 281 |
+
proxy.ErrorHandler = func(rw http.ResponseWriter, req *http.Request, e error) {
|
| 282 |
+
if req.URL.Path == "/" || req.URL.Path == "/index.html" {
|
| 283 |
+
if data, rErr := webFS.ReadFile("web/index.html"); rErr == nil {
|
| 284 |
+
rw.Header().Set("Content-Type", "text/html; charset=utf-8")
|
| 285 |
+
rw.WriteHeader(http.StatusOK)
|
| 286 |
+
_, _ = rw.Write(data)
|
| 287 |
+
return
|
| 288 |
+
}
|
| 289 |
+
}
|
| 290 |
+
http.Error(rw, "Frontend starting up...", http.StatusBadGateway)
|
| 291 |
+
}
|
| 292 |
+
proxy.ServeHTTP(w, r)
|
| 293 |
+
return
|
| 294 |
+
}
|
| 295 |
+
}
|
| 296 |
+
if r.URL.Path != "/" && r.URL.Path != "/index.html" {
|
| 297 |
+
http.NotFound(w, r)
|
| 298 |
+
return
|
| 299 |
+
}
|
| 300 |
+
data, err := webFS.ReadFile("web/index.html")
|
| 301 |
+
if err != nil {
|
| 302 |
+
http.Error(w, "UI not found", http.StatusInternalServerError)
|
| 303 |
+
return
|
| 304 |
+
}
|
| 305 |
+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
| 306 |
+
w.WriteHeader(http.StatusOK)
|
| 307 |
+
_, _ = w.Write(data)
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
func securityHeaders(next http.Handler) http.Handler {
|
| 311 |
+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
| 312 |
+
w.Header().Set("X-Content-Type-Options", "nosniff")
|
| 313 |
+
if strings.HasPrefix(r.URL.Path, "/api/") || r.URL.Path == "/health" {
|
| 314 |
+
w.Header().Set("Cache-Control", "no-store")
|
| 315 |
+
}
|
| 316 |
+
origin := r.Header.Get("Origin")
|
| 317 |
+
if origin != "" {
|
| 318 |
+
w.Header().Set("Access-Control-Allow-Origin", origin)
|
| 319 |
+
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
| 320 |
+
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-API-Key")
|
| 321 |
+
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
| 322 |
+
}
|
| 323 |
+
if r.Method == http.MethodOptions {
|
| 324 |
+
w.WriteHeader(http.StatusNoContent)
|
| 325 |
+
return
|
| 326 |
+
}
|
| 327 |
+
next.ServeHTTP(w, r)
|
| 328 |
+
})
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
func (a *App) health(w http.ResponseWriter, r *http.Request) {
|
| 332 |
+
dbEngine := "local-json"
|
| 333 |
+
if a.mongo != nil {
|
| 334 |
+
dbEngine = "mongodb-atlas (" + a.mongo.dbName + ")"
|
| 335 |
+
}
|
| 336 |
+
if a.pool != nil {
|
| 337 |
+
if res, err := a.pool.Call(map[string]any{"op": "ping"}); err == nil {
|
| 338 |
+
ver, _ := res["version"].(string)
|
| 339 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "hf_cli": true, "turbo_worker": true, "database": dbEngine, "version": ver, "bucket": bucketID})
|
| 340 |
+
return
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
ctx, cancel := context.WithTimeout(r.Context(), 15*time.Second)
|
| 344 |
+
defer cancel()
|
| 345 |
+
out, err := exec.CommandContext(ctx, a.cfg.HFCLI, "--version").CombinedOutput()
|
| 346 |
+
if err != nil {
|
| 347 |
+
writeJSON(w, http.StatusServiceUnavailable, map[string]any{"ok": false, "hf_cli": false, "detail": strings.TrimSpace(string(out))})
|
| 348 |
+
return
|
| 349 |
+
}
|
| 350 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "hf_cli": true, "version": strings.TrimSpace(string(out)), "bucket": bucketID})
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
func (a *App) upload(w http.ResponseWriter, r *http.Request) {
|
| 354 |
+
start := time.Now()
|
| 355 |
+
u := currentUser(r)
|
| 356 |
+
if u.Role != "admin" && !u.Permissions.CanUpload {
|
| 357 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Tài khoản của bạn không được cấp quyền tải tệp lên"})
|
| 358 |
+
return
|
| 359 |
+
}
|
| 360 |
+
r.Body = http.MaxBytesReader(w, r.Body, a.cfg.MaxUpload+(1<<20))
|
| 361 |
+
mr, err := r.MultipartReader()
|
| 362 |
+
if err != nil {
|
| 363 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_multipart", Detail: err.Error()})
|
| 364 |
+
return
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
var remotePath string
|
| 368 |
+
var tmpName string
|
| 369 |
+
var fileName string
|
| 370 |
+
var size int64
|
| 371 |
+
copyBuf := make([]byte, 4<<20) // 4 MiB streaming buffer
|
| 372 |
+
|
| 373 |
+
defer func() {
|
| 374 |
+
if tmpName != "" {
|
| 375 |
+
_ = os.Remove(tmpName)
|
| 376 |
+
}
|
| 377 |
+
}()
|
| 378 |
+
|
| 379 |
+
for {
|
| 380 |
+
part, err := mr.NextPart()
|
| 381 |
+
if errors.Is(err, io.EOF) {
|
| 382 |
+
break
|
| 383 |
+
}
|
| 384 |
+
if err != nil {
|
| 385 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "multipart_stream_error", Detail: err.Error()})
|
| 386 |
+
return
|
| 387 |
+
}
|
| 388 |
+
formName := part.FormName()
|
| 389 |
+
if formName == "path" {
|
| 390 |
+
b, _ := io.ReadAll(io.LimitReader(part, 4096))
|
| 391 |
+
remotePath = strings.TrimSpace(string(b))
|
| 392 |
+
_ = part.Close()
|
| 393 |
+
} else if formName == "file" {
|
| 394 |
+
fileName = part.FileName()
|
| 395 |
+
tmp, err := os.CreateTemp(a.cfg.TempDir, "hf-upload-*")
|
| 396 |
+
if err != nil {
|
| 397 |
+
_ = part.Close()
|
| 398 |
+
writeJSON(w, http.StatusInternalServerError, APIError{Error: "temp_file_error", Detail: err.Error()})
|
| 399 |
+
return
|
| 400 |
+
}
|
| 401 |
+
tmpName = tmp.Name()
|
| 402 |
+
n, copyErr := io.CopyBuffer(tmp, io.LimitReader(part, a.cfg.MaxUpload+1), copyBuf)
|
| 403 |
+
closeErr := tmp.Close()
|
| 404 |
+
_ = part.Close()
|
| 405 |
+
if copyErr != nil {
|
| 406 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "upload_read_error", Detail: copyErr.Error()})
|
| 407 |
+
return
|
| 408 |
+
}
|
| 409 |
+
if closeErr != nil {
|
| 410 |
+
writeJSON(w, http.StatusInternalServerError, APIError{Error: "temp_file_error", Detail: closeErr.Error()})
|
| 411 |
+
return
|
| 412 |
+
}
|
| 413 |
+
size = n
|
| 414 |
+
if size > a.cfg.MaxUpload {
|
| 415 |
+
writeJSON(w, http.StatusRequestEntityTooLarge, APIError{Error: "file_too_large"})
|
| 416 |
+
return
|
| 417 |
+
}
|
| 418 |
+
} else {
|
| 419 |
+
_ = part.Close()
|
| 420 |
+
}
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
if tmpName == "" {
|
| 424 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "missing_file", Detail: "send multipart field named 'file'"})
|
| 425 |
+
return
|
| 426 |
+
}
|
| 427 |
+
if remotePath == "" {
|
| 428 |
+
remotePath = fileName
|
| 429 |
+
}
|
| 430 |
+
remotePath, err = cleanRemotePath(remotePath)
|
| 431 |
+
if err != nil {
|
| 432 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_path", Detail: err.Error()})
|
| 433 |
+
return
|
| 434 |
+
}
|
| 435 |
+
remotePath = a.resolveUniqueRemotePath(scopeUserRemotePath(u.Username, remotePath))
|
| 436 |
+
a.evictDownloadCache(remotePath)
|
| 437 |
+
|
| 438 |
+
// Fast path: Persistent Python Xet Worker Pool (no process startup overhead)
|
| 439 |
+
if a.pool != nil {
|
| 440 |
+
_, err = a.pool.Call(map[string]any{
|
| 441 |
+
"op": "upload",
|
| 442 |
+
"bucket": bucketID,
|
| 443 |
+
"files": []map[string]string{
|
| 444 |
+
{"local": tmpName, "remote": remotePath},
|
| 445 |
+
},
|
| 446 |
+
})
|
| 447 |
+
if err == nil {
|
| 448 |
+
if a.owners != nil {
|
| 449 |
+
a.owners.SetOwner(remotePath, u.Username)
|
| 450 |
+
}
|
| 451 |
+
if a.mongo != nil {
|
| 452 |
+
a.mongo.UpsertFileMeta(remotePath, u.Username, size)
|
| 453 |
+
}
|
| 454 |
+
a.invalidateListCache()
|
| 455 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 456 |
+
"ok": true,
|
| 457 |
+
"bucket": bucketID,
|
| 458 |
+
"path": remotePath,
|
| 459 |
+
"owner": u.Username,
|
| 460 |
+
"size": size,
|
| 461 |
+
"duration_ms": time.Since(start).Milliseconds(),
|
| 462 |
+
"engine": "xet-worker-pool",
|
| 463 |
+
"message": "upload completed",
|
| 464 |
+
})
|
| 465 |
+
return
|
| 466 |
+
}
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
// Fallback: CLI
|
| 470 |
+
dest := "hf://buckets/" + bucketID + "/" + remotePath
|
| 471 |
+
out, err := a.runHF(r.Context(), "buckets", "cp", tmpName, dest)
|
| 472 |
+
if err != nil {
|
| 473 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "huggingface_upload_failed", Detail: out})
|
| 474 |
+
return
|
| 475 |
+
}
|
| 476 |
+
if a.owners != nil {
|
| 477 |
+
a.owners.SetOwner(remotePath, u.Username)
|
| 478 |
+
}
|
| 479 |
+
a.invalidateListCache()
|
| 480 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 481 |
+
"ok": true,
|
| 482 |
+
"bucket": bucketID,
|
| 483 |
+
"path": remotePath,
|
| 484 |
+
"owner": u.Username,
|
| 485 |
+
"size": size,
|
| 486 |
+
"duration_ms": time.Since(start).Milliseconds(),
|
| 487 |
+
"message": "upload completed",
|
| 488 |
+
})
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
func (a *App) uploadBatch(w http.ResponseWriter, r *http.Request) {
|
| 492 |
+
start := time.Now()
|
| 493 |
+
u := currentUser(r)
|
| 494 |
+
if u.Role != "admin" && !u.Permissions.CanUpload {
|
| 495 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Tài khoản của bạn không được cấp quyền tải tệp lên"})
|
| 496 |
+
return
|
| 497 |
+
}
|
| 498 |
+
r.Body = http.MaxBytesReader(w, r.Body, a.cfg.MaxUpload+(1<<20))
|
| 499 |
+
mr, err := r.MultipartReader()
|
| 500 |
+
if err != nil {
|
| 501 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_multipart", Detail: err.Error()})
|
| 502 |
+
return
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
var folderPrefix string
|
| 506 |
+
type stagedFile struct {
|
| 507 |
+
local string
|
| 508 |
+
remote string
|
| 509 |
+
size int64
|
| 510 |
+
}
|
| 511 |
+
var staged []stagedFile
|
| 512 |
+
copyBuf := make([]byte, 4<<20)
|
| 513 |
+
|
| 514 |
+
defer func() {
|
| 515 |
+
for _, sf := range staged {
|
| 516 |
+
_ = os.Remove(sf.local)
|
| 517 |
+
}
|
| 518 |
+
}()
|
| 519 |
+
|
| 520 |
+
for {
|
| 521 |
+
part, err := mr.NextPart()
|
| 522 |
+
if errors.Is(err, io.EOF) {
|
| 523 |
+
break
|
| 524 |
+
}
|
| 525 |
+
if err != nil {
|
| 526 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "multipart_stream_error", Detail: err.Error()})
|
| 527 |
+
return
|
| 528 |
+
}
|
| 529 |
+
formName := part.FormName()
|
| 530 |
+
if formName == "folder" {
|
| 531 |
+
b, _ := io.ReadAll(io.LimitReader(part, 4096))
|
| 532 |
+
folderPrefix = strings.Trim(strings.TrimSpace(string(b)), "/")
|
| 533 |
+
_ = part.Close()
|
| 534 |
+
} else if formName == "files" || formName == "file" {
|
| 535 |
+
fn := part.FileName()
|
| 536 |
+
if fn == "" {
|
| 537 |
+
_ = part.Close()
|
| 538 |
+
continue
|
| 539 |
+
}
|
| 540 |
+
remote := fn
|
| 541 |
+
if folderPrefix != "" {
|
| 542 |
+
remote = folderPrefix + "/" + fn
|
| 543 |
+
}
|
| 544 |
+
clean, cleanErr := cleanRemotePath(remote)
|
| 545 |
+
if cleanErr != nil {
|
| 546 |
+
_ = part.Close()
|
| 547 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_path", Detail: cleanErr.Error()})
|
| 548 |
+
return
|
| 549 |
+
}
|
| 550 |
+
clean = a.resolveUniqueRemotePath(scopeUserRemotePath(u.Username, clean))
|
| 551 |
+
a.evictDownloadCache(clean)
|
| 552 |
+
tmp, err := os.CreateTemp(a.cfg.TempDir, "hf-batch-*")
|
| 553 |
+
if err != nil {
|
| 554 |
+
_ = part.Close()
|
| 555 |
+
writeJSON(w, http.StatusInternalServerError, APIError{Error: "temp_file_error", Detail: err.Error()})
|
| 556 |
+
return
|
| 557 |
+
}
|
| 558 |
+
n, copyErr := io.CopyBuffer(tmp, io.LimitReader(part, a.cfg.MaxUpload+1), copyBuf)
|
| 559 |
+
_ = tmp.Close()
|
| 560 |
+
_ = part.Close()
|
| 561 |
+
if copyErr != nil {
|
| 562 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "upload_read_error", Detail: copyErr.Error()})
|
| 563 |
+
return
|
| 564 |
+
}
|
| 565 |
+
staged = append(staged, stagedFile{local: tmp.Name(), remote: clean, size: n})
|
| 566 |
+
} else {
|
| 567 |
+
_ = part.Close()
|
| 568 |
+
}
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
if len(staged) == 0 {
|
| 572 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "missing_files", Detail: "no files provided in batch"})
|
| 573 |
+
return
|
| 574 |
+
}
|
| 575 |
+
|
| 576 |
+
pairs := make([]map[string]string, 0, len(staged))
|
| 577 |
+
var totalBytes int64
|
| 578 |
+
uploadedPaths := make([]string, 0, len(staged))
|
| 579 |
+
for _, sf := range staged {
|
| 580 |
+
pairs = append(pairs, map[string]string{"local": sf.local, "remote": sf.remote})
|
| 581 |
+
totalBytes += sf.size
|
| 582 |
+
uploadedPaths = append(uploadedPaths, sf.remote)
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
if a.pool != nil {
|
| 586 |
+
if _, err := a.pool.Call(map[string]any{"op": "upload", "bucket": bucketID, "files": pairs}); err != nil {
|
| 587 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "batch_upload_failed", Detail: err.Error()})
|
| 588 |
+
return
|
| 589 |
+
}
|
| 590 |
+
} else {
|
| 591 |
+
for _, sf := range staged {
|
| 592 |
+
dest := "hf://buckets/" + bucketID + "/" + sf.remote
|
| 593 |
+
if out, err := a.runHF(r.Context(), "buckets", "cp", sf.local, dest); err != nil {
|
| 594 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "huggingface_upload_failed", Detail: out})
|
| 595 |
+
return
|
| 596 |
+
}
|
| 597 |
+
}
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
if a.owners != nil {
|
| 601 |
+
a.owners.SetOwnersBatch(uploadedPaths, u.Username)
|
| 602 |
+
}
|
| 603 |
+
if a.mongo != nil {
|
| 604 |
+
for _, sf := range staged {
|
| 605 |
+
a.mongo.UpsertFileMeta(sf.remote, u.Username, sf.size)
|
| 606 |
+
}
|
| 607 |
+
}
|
| 608 |
+
a.invalidateListCache()
|
| 609 |
+
|
| 610 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 611 |
+
"ok": true,
|
| 612 |
+
"bucket": bucketID,
|
| 613 |
+
"count": len(staged),
|
| 614 |
+
"paths": uploadedPaths,
|
| 615 |
+
"owner": u.Username,
|
| 616 |
+
"total_bytes": totalBytes,
|
| 617 |
+
"duration_ms": time.Since(start).Milliseconds(),
|
| 618 |
+
"engine": "xet-batch-commit",
|
| 619 |
+
})
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
func parseBucketLsLine(line string) (FileItem, bool) {
|
| 623 |
+
trimmed := strings.TrimSpace(line)
|
| 624 |
+
if trimmed == "" {
|
| 625 |
+
return FileItem{}, false
|
| 626 |
+
}
|
| 627 |
+
fields := strings.Fields(trimmed)
|
| 628 |
+
if len(fields) >= 4 {
|
| 629 |
+
if size, err := strconv.ParseInt(fields[0], 10, 64); err == nil {
|
| 630 |
+
datePart := fields[1]
|
| 631 |
+
timePart := fields[2]
|
| 632 |
+
if len(datePart) == 10 && strings.Count(datePart, "-") == 2 && strings.Count(timePart, ":") == 2 {
|
| 633 |
+
idx := strings.Index(trimmed, timePart)
|
| 634 |
+
if idx != -1 {
|
| 635 |
+
filePath := strings.TrimSpace(trimmed[idx+len(timePart):])
|
| 636 |
+
return FileItem{
|
| 637 |
+
Path: filePath,
|
| 638 |
+
Size: size,
|
| 639 |
+
UpdatedAt: datePart + " " + timePart,
|
| 640 |
+
}, true
|
| 641 |
+
}
|
| 642 |
+
}
|
| 643 |
+
}
|
| 644 |
+
}
|
| 645 |
+
return FileItem{Path: trimmed}, true
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
func (a *App) filterUserFiles(u UserAccount, all []FileItem) ([]string, []FileItem) {
|
| 649 |
+
lines := make([]string, 0, len(all))
|
| 650 |
+
items := make([]FileItem, 0, len(all))
|
| 651 |
+
for _, it := range all {
|
| 652 |
+
if a.owners != nil && !a.owners.CanAccess(u, it.Path) {
|
| 653 |
+
continue
|
| 654 |
+
}
|
| 655 |
+
owner := "admin"
|
| 656 |
+
if a.owners != nil {
|
| 657 |
+
owner = a.owners.GetOwnerForUser(u, it.Path)
|
| 658 |
+
}
|
| 659 |
+
it.Owner = owner
|
| 660 |
+
lines = append(lines, it.Path)
|
| 661 |
+
items = append(items, it)
|
| 662 |
+
}
|
| 663 |
+
return lines, items
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
func (a *App) listFiles(w http.ResponseWriter, r *http.Request) {
|
| 667 |
+
u := currentUser(r)
|
| 668 |
+
prefix := strings.TrimSpace(r.URL.Query().Get("prefix"))
|
| 669 |
+
if prefix != "" {
|
| 670 |
+
clean, err := cleanRemotePath(prefix)
|
| 671 |
+
if err != nil {
|
| 672 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_prefix", Detail: err.Error()})
|
| 673 |
+
return
|
| 674 |
+
}
|
| 675 |
+
prefix = clean
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
if prefix == "" {
|
| 679 |
+
a.listCacheMu.RLock()
|
| 680 |
+
cached := a.listCache
|
| 681 |
+
cachedAt := a.listCacheTime
|
| 682 |
+
a.listCacheMu.RUnlock()
|
| 683 |
+
if !cachedAt.IsZero() && time.Since(cachedAt) < 5*time.Second {
|
| 684 |
+
lines, items := a.filterUserFiles(u, cached)
|
| 685 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 686 |
+
"ok": true,
|
| 687 |
+
"bucket": bucketID,
|
| 688 |
+
"prefix": prefix,
|
| 689 |
+
"count": len(lines),
|
| 690 |
+
"entries": lines,
|
| 691 |
+
"items": items,
|
| 692 |
+
"engine": "xet-memory-cache",
|
| 693 |
+
})
|
| 694 |
+
return
|
| 695 |
+
}
|
| 696 |
+
}
|
| 697 |
+
|
| 698 |
+
if a.pool != nil {
|
| 699 |
+
if res, err := a.pool.Call(map[string]any{"op": "ls", "bucket": bucketID, "prefix": prefix}); err == nil {
|
| 700 |
+
rawItems, _ := res["items"].([]any)
|
| 701 |
+
allItems := make([]FileItem, 0, len(rawItems))
|
| 702 |
+
for _, ri := range rawItems {
|
| 703 |
+
if m, ok := ri.(map[string]any); ok {
|
| 704 |
+
p, _ := m["path"].(string)
|
| 705 |
+
sz, _ := m["size"].(float64)
|
| 706 |
+
up, _ := m["updated_at"].(string)
|
| 707 |
+
allItems = append(allItems, FileItem{Path: p, Size: int64(sz), UpdatedAt: up})
|
| 708 |
+
}
|
| 709 |
+
}
|
| 710 |
+
if prefix == "" {
|
| 711 |
+
a.listCacheMu.Lock()
|
| 712 |
+
a.listCache = allItems
|
| 713 |
+
a.listCacheTime = time.Now()
|
| 714 |
+
a.listCacheMu.Unlock()
|
| 715 |
+
}
|
| 716 |
+
lines, items := a.filterUserFiles(u, allItems)
|
| 717 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 718 |
+
"ok": true,
|
| 719 |
+
"bucket": bucketID,
|
| 720 |
+
"prefix": prefix,
|
| 721 |
+
"count": len(lines),
|
| 722 |
+
"entries": lines,
|
| 723 |
+
"items": items,
|
| 724 |
+
"engine": "xet-worker-pool",
|
| 725 |
+
})
|
| 726 |
+
return
|
| 727 |
+
}
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
args := []string{"buckets", "ls", bucketID}
|
| 731 |
+
if prefix != "" {
|
| 732 |
+
args[2] += "/" + prefix
|
| 733 |
+
}
|
| 734 |
+
args = append(args, "-R")
|
| 735 |
+
out, err := a.runHF(r.Context(), args...)
|
| 736 |
+
if err != nil {
|
| 737 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "huggingface_list_failed", Detail: out})
|
| 738 |
+
return
|
| 739 |
+
}
|
| 740 |
+
lines := make([]string, 0)
|
| 741 |
+
items := make([]FileItem, 0)
|
| 742 |
+
for _, line := range strings.Split(strings.ReplaceAll(out, "\r\n", "\n"), "\n") {
|
| 743 |
+
if item, ok := parseBucketLsLine(line); ok {
|
| 744 |
+
if a.owners != nil && !a.owners.CanAccess(u, item.Path) {
|
| 745 |
+
continue
|
| 746 |
+
}
|
| 747 |
+
if a.owners != nil {
|
| 748 |
+
item.Owner = a.owners.GetOwner(item.Path)
|
| 749 |
+
}
|
| 750 |
+
lines = append(lines, item.Path)
|
| 751 |
+
items = append(items, item)
|
| 752 |
+
}
|
| 753 |
+
}
|
| 754 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 755 |
+
"ok": true,
|
| 756 |
+
"bucket": bucketID,
|
| 757 |
+
"prefix": prefix,
|
| 758 |
+
"count": len(lines),
|
| 759 |
+
"entries": lines,
|
| 760 |
+
"items": items,
|
| 761 |
+
"raw": out,
|
| 762 |
+
})
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
func (a *App) deleteFile(w http.ResponseWriter, r *http.Request) {
|
| 766 |
+
u := currentUser(r)
|
| 767 |
+
if u.Role != "admin" && !u.Permissions.CanDelete {
|
| 768 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Chỉ Admin hoặc tài khoản có quyền Xóa mới thực hiện được thao tác này"})
|
| 769 |
+
return
|
| 770 |
+
}
|
| 771 |
+
remote, err := cleanRemotePath(r.URL.Query().Get("path"))
|
| 772 |
+
if err != nil {
|
| 773 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_path", Detail: err.Error()})
|
| 774 |
+
return
|
| 775 |
+
}
|
| 776 |
+
if a.owners != nil && !a.owners.CanAccess(u, remote) {
|
| 777 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Bạn chỉ có thể xóa tệp tin do chính mình tải lên"})
|
| 778 |
+
return
|
| 779 |
+
}
|
| 780 |
+
if a.pool != nil {
|
| 781 |
+
if _, err := a.pool.Call(map[string]any{"op": "rm", "bucket": bucketID, "remote": remote}); err == nil {
|
| 782 |
+
if a.owners != nil {
|
| 783 |
+
a.owners.Delete(remote)
|
| 784 |
+
}
|
| 785 |
+
if a.shares != nil {
|
| 786 |
+
a.shares.DeleteByPath(remote)
|
| 787 |
+
}
|
| 788 |
+
a.releaseReservedPath(remote)
|
| 789 |
+
a.evictDownloadCache(remote)
|
| 790 |
+
a.invalidateListCache()
|
| 791 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "bucket": bucketID, "path": remote, "message": "file deleted"})
|
| 792 |
+
return
|
| 793 |
+
}
|
| 794 |
+
}
|
| 795 |
+
target := bucketID + "/" + remote
|
| 796 |
+
out, err := a.runHF(r.Context(), "buckets", "rm", target, "--yes")
|
| 797 |
+
if err != nil {
|
| 798 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "huggingface_delete_failed", Detail: out})
|
| 799 |
+
return
|
| 800 |
+
}
|
| 801 |
+
if a.owners != nil {
|
| 802 |
+
a.owners.Delete(remote)
|
| 803 |
+
}
|
| 804 |
+
if a.shares != nil {
|
| 805 |
+
a.shares.DeleteByPath(remote)
|
| 806 |
+
}
|
| 807 |
+
a.releaseReservedPath(remote)
|
| 808 |
+
a.evictDownloadCache(remote)
|
| 809 |
+
a.invalidateListCache()
|
| 810 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "bucket": bucketID, "path": remote, "message": "file deleted"})
|
| 811 |
+
}
|
| 812 |
+
|
| 813 |
+
func (a *App) renameFile(w http.ResponseWriter, r *http.Request) {
|
| 814 |
+
u := currentUser(r)
|
| 815 |
+
if u.Role != "admin" && !u.Permissions.CanRename {
|
| 816 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Chỉ Admin hoặc tài khoản có quyền Chỉnh sửa mới được đổi tên/di chuyển tệp"})
|
| 817 |
+
return
|
| 818 |
+
}
|
| 819 |
+
var body struct {
|
| 820 |
+
OldPath string `json:"old_path"`
|
| 821 |
+
NewPath string `json:"new_path"`
|
| 822 |
+
}
|
| 823 |
+
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
| 824 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_json", Detail: err.Error()})
|
| 825 |
+
return
|
| 826 |
+
}
|
| 827 |
+
oldClean, err := cleanRemotePath(body.OldPath)
|
| 828 |
+
if err != nil {
|
| 829 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_old_path", Detail: err.Error()})
|
| 830 |
+
return
|
| 831 |
+
}
|
| 832 |
+
if a.owners != nil && !a.owners.CanAccess(u, oldClean) {
|
| 833 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Bạn chỉ có thể đổi tên tệp tin do chính mình tải lên"})
|
| 834 |
+
return
|
| 835 |
+
}
|
| 836 |
+
newClean, err := cleanRemotePath(body.NewPath)
|
| 837 |
+
if err != nil {
|
| 838 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_new_path", Detail: err.Error()})
|
| 839 |
+
return
|
| 840 |
+
}
|
| 841 |
+
if parts := strings.SplitN(oldClean, "/", 2); len(parts) == 2 && a.users != nil {
|
| 842 |
+
newClean = scopeUserRemotePath(parts[0], newClean)
|
| 843 |
+
}
|
| 844 |
+
if oldClean == newClean {
|
| 845 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "old_path": oldClean, "new_path": newClean, "message": "unchanged"})
|
| 846 |
+
return
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
// Zero-data-transfer server-side Xet hash rename via persistent worker pool
|
| 850 |
+
if a.pool != nil {
|
| 851 |
+
if _, err := a.pool.Call(map[string]any{
|
| 852 |
+
"op": "mv",
|
| 853 |
+
"bucket": bucketID,
|
| 854 |
+
"old_path": oldClean,
|
| 855 |
+
"new_path": newClean,
|
| 856 |
+
}); err == nil {
|
| 857 |
+
if a.owners != nil {
|
| 858 |
+
a.owners.Rename(oldClean, newClean)
|
| 859 |
+
}
|
| 860 |
+
if a.shares != nil {
|
| 861 |
+
a.shares.RenamePath(oldClean, newClean)
|
| 862 |
+
}
|
| 863 |
+
a.releaseReservedPath(oldClean)
|
| 864 |
+
a.evictDownloadCache(oldClean)
|
| 865 |
+
a.evictDownloadCache(newClean)
|
| 866 |
+
a.invalidateListCache()
|
| 867 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 868 |
+
"ok": true,
|
| 869 |
+
"bucket": bucketID,
|
| 870 |
+
"old_path": oldClean,
|
| 871 |
+
"new_path": newClean,
|
| 872 |
+
"engine": "xet-zero-copy-hash",
|
| 873 |
+
"message": "file renamed instantaneously via Xet hash",
|
| 874 |
+
})
|
| 875 |
+
return
|
| 876 |
+
}
|
| 877 |
+
}
|
| 878 |
+
|
| 879 |
+
tmpDir, err := os.MkdirTemp(a.cfg.TempDir, "hf-rename-*")
|
| 880 |
+
if err != nil {
|
| 881 |
+
writeJSON(w, http.StatusInternalServerError, APIError{Error: "temp_dir_error", Detail: err.Error()})
|
| 882 |
+
return
|
| 883 |
+
}
|
| 884 |
+
defer os.RemoveAll(tmpDir)
|
| 885 |
+
|
| 886 |
+
local := filepath.Join(tmpDir, filepath.Base(oldClean))
|
| 887 |
+
src := "hf://buckets/" + bucketID + "/" + oldClean
|
| 888 |
+
dest := "hf://buckets/" + bucketID + "/" + newClean
|
| 889 |
+
|
| 890 |
+
if out, err := a.runHF(r.Context(), "buckets", "cp", src, local); err != nil {
|
| 891 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "rename_download_failed", Detail: out})
|
| 892 |
+
return
|
| 893 |
+
}
|
| 894 |
+
if out, err := a.runHF(r.Context(), "buckets", "cp", local, dest); err != nil {
|
| 895 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "rename_upload_failed", Detail: out})
|
| 896 |
+
return
|
| 897 |
+
}
|
| 898 |
+
if out, err := a.runHF(r.Context(), "buckets", "rm", bucketID+"/"+oldClean, "--yes"); err != nil {
|
| 899 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "rename_cleanup_failed", Detail: out})
|
| 900 |
+
return
|
| 901 |
+
}
|
| 902 |
+
if a.owners != nil {
|
| 903 |
+
a.owners.Rename(oldClean, newClean)
|
| 904 |
+
}
|
| 905 |
+
if a.shares != nil {
|
| 906 |
+
a.shares.RenamePath(oldClean, newClean)
|
| 907 |
+
}
|
| 908 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 909 |
+
"ok": true,
|
| 910 |
+
"bucket": bucketID,
|
| 911 |
+
"old_path": oldClean,
|
| 912 |
+
"new_path": newClean,
|
| 913 |
+
"message": "file renamed successfully",
|
| 914 |
+
})
|
| 915 |
+
}
|
| 916 |
+
|
| 917 |
+
func (a *App) download(w http.ResponseWriter, r *http.Request) {
|
| 918 |
+
u := currentUser(r)
|
| 919 |
+
remote, err := cleanRemotePath(r.URL.Query().Get("path"))
|
| 920 |
+
if err != nil {
|
| 921 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_path", Detail: err.Error()})
|
| 922 |
+
return
|
| 923 |
+
}
|
| 924 |
+
if a.owners != nil && !a.owners.CanAccess(u, remote) {
|
| 925 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Bạn không có quyền truy cập tệp tin của người dùng khác"})
|
| 926 |
+
return
|
| 927 |
+
}
|
| 928 |
+
a.serveRemoteFile(w, r, remote)
|
| 929 |
+
}
|
| 930 |
+
|
| 931 |
+
func (a *App) serveRemoteFile(w http.ResponseWriter, r *http.Request, remote string) {
|
| 932 |
+
cacheDir := filepath.Join(a.cfg.TempDir, "hf-cache")
|
| 933 |
+
if err := os.MkdirAll(cacheDir, 0700); err != nil {
|
| 934 |
+
writeJSON(w, http.StatusInternalServerError, APIError{Error: "cache_dir_error", Detail: err.Error()})
|
| 935 |
+
return
|
| 936 |
+
}
|
| 937 |
+
hash := sha256.Sum256([]byte(remote))
|
| 938 |
+
ext := filepath.Ext(remote)
|
| 939 |
+
cachedFile := filepath.Join(cacheDir, hex.EncodeToString(hash[:16])+ext)
|
| 940 |
+
|
| 941 |
+
mu := a.fileLock(cachedFile)
|
| 942 |
+
mu.Lock()
|
| 943 |
+
needFetch := true
|
| 944 |
+
if st, err := os.Stat(cachedFile); err == nil && st.Size() > 0 && time.Since(st.ModTime()) < 30*time.Minute {
|
| 945 |
+
needFetch = false
|
| 946 |
+
}
|
| 947 |
+
if needFetch {
|
| 948 |
+
partFile := cachedFile + ".part." + strconv.FormatInt(time.Now().UnixNano(), 36)
|
| 949 |
+
fetched := false
|
| 950 |
+
if a.pool != nil {
|
| 951 |
+
if _, err := a.pool.Call(map[string]any{
|
| 952 |
+
"op": "download",
|
| 953 |
+
"bucket": bucketID,
|
| 954 |
+
"remote": remote,
|
| 955 |
+
"local": partFile,
|
| 956 |
+
}); err == nil {
|
| 957 |
+
fetched = true
|
| 958 |
+
}
|
| 959 |
+
}
|
| 960 |
+
if !fetched {
|
| 961 |
+
src := "hf://buckets/" + bucketID + "/" + remote
|
| 962 |
+
out, err := a.runHF(context.Background(), "buckets", "cp", src, partFile)
|
| 963 |
+
if err != nil {
|
| 964 |
+
_ = os.Remove(partFile)
|
| 965 |
+
mu.Unlock()
|
| 966 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "huggingface_download_failed", Detail: out})
|
| 967 |
+
return
|
| 968 |
+
}
|
| 969 |
+
}
|
| 970 |
+
_ = os.Remove(cachedFile)
|
| 971 |
+
if err := os.Rename(partFile, cachedFile); err != nil {
|
| 972 |
+
_ = os.Remove(partFile)
|
| 973 |
+
mu.Unlock()
|
| 974 |
+
writeJSON(w, http.StatusInternalServerError, APIError{Error: "cache_rename_failed", Detail: err.Error()})
|
| 975 |
+
return
|
| 976 |
+
}
|
| 977 |
+
}
|
| 978 |
+
mu.Unlock()
|
| 979 |
+
|
| 980 |
+
f, err := os.Open(cachedFile)
|
| 981 |
+
if err != nil {
|
| 982 |
+
writeJSON(w, http.StatusBadGateway, APIError{Error: "download_missing", Detail: "CLI completed but output file was not found"})
|
| 983 |
+
return
|
| 984 |
+
}
|
| 985 |
+
defer f.Close()
|
| 986 |
+
st, err := f.Stat()
|
| 987 |
+
if err != nil {
|
| 988 |
+
writeJSON(w, http.StatusInternalServerError, APIError{Error: "file_stat_failed", Detail: err.Error()})
|
| 989 |
+
return
|
| 990 |
+
}
|
| 991 |
+
name := filepath.Base(remote)
|
| 992 |
+
dispType := "attachment"
|
| 993 |
+
if r.URL.Query().Get("inline") == "1" {
|
| 994 |
+
dispType = "inline"
|
| 995 |
+
}
|
| 996 |
+
w.Header().Set("Content-Disposition", mime.FormatMediaType(dispType, map[string]string{"filename": name}))
|
| 997 |
+
ct := mime.TypeByExtension(filepath.Ext(name))
|
| 998 |
+
if ct != "" {
|
| 999 |
+
w.Header().Set("Content-Type", ct)
|
| 1000 |
+
}
|
| 1001 |
+
http.ServeContent(w, r, name, st.ModTime(), f)
|
| 1002 |
+
}
|
| 1003 |
+
|
| 1004 |
+
// --- Quick Share Handlers ---
|
| 1005 |
+
|
| 1006 |
+
func (a *App) handleListShares(w http.ResponseWriter, r *http.Request) {
|
| 1007 |
+
u := currentUser(r)
|
| 1008 |
+
if a.shares == nil {
|
| 1009 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "shares": []any{}})
|
| 1010 |
+
return
|
| 1011 |
+
}
|
| 1012 |
+
list := a.shares.ListForUser(u)
|
| 1013 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "shares": list})
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
func (a *App) handleGetFileShare(w http.ResponseWriter, r *http.Request) {
|
| 1017 |
+
u := currentUser(r)
|
| 1018 |
+
remote, err := cleanRemotePath(r.URL.Query().Get("path"))
|
| 1019 |
+
if err != nil {
|
| 1020 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_path", Detail: err.Error()})
|
| 1021 |
+
return
|
| 1022 |
+
}
|
| 1023 |
+
if a.owners != nil && !a.owners.CanAccess(u, remote) {
|
| 1024 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Bạn không có quyền quản lý chia sẻ tệp này"})
|
| 1025 |
+
return
|
| 1026 |
+
}
|
| 1027 |
+
if a.shares == nil {
|
| 1028 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "share": nil})
|
| 1029 |
+
return
|
| 1030 |
+
}
|
| 1031 |
+
sh, ok := a.shares.GetByPath(remote)
|
| 1032 |
+
if !ok {
|
| 1033 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "share": nil})
|
| 1034 |
+
return
|
| 1035 |
+
}
|
| 1036 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "share": sh})
|
| 1037 |
+
}
|
| 1038 |
+
|
| 1039 |
+
func (a *App) handleUpsertShare(w http.ResponseWriter, r *http.Request) {
|
| 1040 |
+
u := currentUser(r)
|
| 1041 |
+
var body struct {
|
| 1042 |
+
Path string `json:"path"`
|
| 1043 |
+
Size int64 `json:"size"`
|
| 1044 |
+
Enabled bool `json:"enabled"`
|
| 1045 |
+
RequireApproval bool `json:"require_approval"`
|
| 1046 |
+
Regenerate bool `json:"regenerate"`
|
| 1047 |
+
}
|
| 1048 |
+
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
| 1049 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_json", Detail: err.Error()})
|
| 1050 |
+
return
|
| 1051 |
+
}
|
| 1052 |
+
remote, err := cleanRemotePath(body.Path)
|
| 1053 |
+
if err != nil {
|
| 1054 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_path", Detail: err.Error()})
|
| 1055 |
+
return
|
| 1056 |
+
}
|
| 1057 |
+
if a.owners != nil && !a.owners.CanAccess(u, remote) {
|
| 1058 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Bạn chỉ có thể chia sẻ tệp thuộc quyền sở hữu của mình"})
|
| 1059 |
+
return
|
| 1060 |
+
}
|
| 1061 |
+
owner := u.Username
|
| 1062 |
+
if a.owners != nil {
|
| 1063 |
+
owner = a.owners.GetOwnerForUser(u, remote)
|
| 1064 |
+
}
|
| 1065 |
+
sh := a.shares.UpsertShare(remote, owner, body.Size, body.Enabled, body.RequireApproval, body.Regenerate)
|
| 1066 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "share": sh})
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
func (a *App) handleApproveShareRequest(w http.ResponseWriter, r *http.Request) {
|
| 1070 |
+
u := currentUser(r)
|
| 1071 |
+
var body struct {
|
| 1072 |
+
ShareID string `json:"share_id"`
|
| 1073 |
+
RequestID string `json:"request_id"`
|
| 1074 |
+
Status string `json:"status"` // "approved" or "rejected"
|
| 1075 |
+
}
|
| 1076 |
+
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
| 1077 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_json", Detail: err.Error()})
|
| 1078 |
+
return
|
| 1079 |
+
}
|
| 1080 |
+
if body.Status != "approved" && body.Status != "rejected" {
|
| 1081 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_status", Detail: "status phải là approved hoặc rejected"})
|
| 1082 |
+
return
|
| 1083 |
+
}
|
| 1084 |
+
sh, ok := a.shares.GetByID(body.ShareID)
|
| 1085 |
+
if !ok {
|
| 1086 |
+
writeJSON(w, http.StatusNotFound, APIError{Error: "not_found", Detail: "Không tìm thấy liên kết chia sẻ"})
|
| 1087 |
+
return
|
| 1088 |
+
}
|
| 1089 |
+
if u.Role != "admin" && !strings.EqualFold(sh.Owner, u.Username) && (a.owners != nil && !a.owners.CanAccess(u, sh.Path)) {
|
| 1090 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "forbidden", Detail: "Bạn không có quyền duyệt yêu cầu của tệp này"})
|
| 1091 |
+
return
|
| 1092 |
+
}
|
| 1093 |
+
updated, ok := a.shares.UpdateRequestStatus(body.ShareID, body.RequestID, body.Status)
|
| 1094 |
+
if !ok {
|
| 1095 |
+
writeJSON(w, http.StatusNotFound, APIError{Error: "request_not_found", Detail: "Không tìm thấy yêu cầu truy cập"})
|
| 1096 |
+
return
|
| 1097 |
+
}
|
| 1098 |
+
writeJSON(w, http.StatusOK, map[string]any{"ok": true, "share": updated})
|
| 1099 |
+
}
|
| 1100 |
+
|
| 1101 |
+
func (a *App) handlePublicGetShare(w http.ResponseWriter, r *http.Request) {
|
| 1102 |
+
shareID := strings.TrimSpace(r.URL.Query().Get("id"))
|
| 1103 |
+
visitorToken := strings.TrimSpace(r.URL.Query().Get("visitor_token"))
|
| 1104 |
+
if shareID == "" || a.shares == nil {
|
| 1105 |
+
writeJSON(w, http.StatusNotFound, APIError{Error: "not_found", Detail: "Liên kết chia sẻ không hợp lệ"})
|
| 1106 |
+
return
|
| 1107 |
+
}
|
| 1108 |
+
sh, granted, reqStatus, visitorName := a.shares.CheckVisitorAccess(shareID, visitorToken)
|
| 1109 |
+
if sh == nil {
|
| 1110 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "share_disabled", Detail: "Liên kết chia sẻ này hiện đang tắt hoặc không tồn tại"})
|
| 1111 |
+
return
|
| 1112 |
+
}
|
| 1113 |
+
// Also grant immediately if the viewer is logged in as the file owner or admin
|
| 1114 |
+
if !granted {
|
| 1115 |
+
if u, ok := a.resolveRequestUser(r); ok {
|
| 1116 |
+
if u.Role == "admin" || strings.EqualFold(u.Username, sh.Owner) || (a.owners != nil && a.owners.CanAccess(u, sh.Path)) {
|
| 1117 |
+
granted = true
|
| 1118 |
+
reqStatus = "approved"
|
| 1119 |
+
}
|
| 1120 |
+
}
|
| 1121 |
+
}
|
| 1122 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 1123 |
+
"ok": true,
|
| 1124 |
+
"access_granted": granted,
|
| 1125 |
+
"request_status": reqStatus,
|
| 1126 |
+
"visitor_name": visitorName,
|
| 1127 |
+
"share": map[string]any{
|
| 1128 |
+
"id": sh.ID,
|
| 1129 |
+
"file_name": sh.FileName,
|
| 1130 |
+
"size": sh.Size,
|
| 1131 |
+
"owner": sh.Owner,
|
| 1132 |
+
"enabled": sh.Enabled,
|
| 1133 |
+
"require_approval": sh.RequireApproval,
|
| 1134 |
+
"created_at": sh.CreatedAt,
|
| 1135 |
+
"updated_at": sh.UpdatedAt,
|
| 1136 |
+
},
|
| 1137 |
+
})
|
| 1138 |
+
}
|
| 1139 |
+
|
| 1140 |
+
func (a *App) handlePublicRequestShareAccess(w http.ResponseWriter, r *http.Request) {
|
| 1141 |
+
var body struct {
|
| 1142 |
+
ShareID string `json:"share_id"`
|
| 1143 |
+
VisitorToken string `json:"visitor_token"`
|
| 1144 |
+
VisitorName string `json:"visitor_name"`
|
| 1145 |
+
Note string `json:"note"`
|
| 1146 |
+
}
|
| 1147 |
+
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
| 1148 |
+
writeJSON(w, http.StatusBadRequest, APIError{Error: "invalid_json", Detail: err.Error()})
|
| 1149 |
+
return
|
| 1150 |
+
}
|
| 1151 |
+
sh, req, ok := a.shares.SubmitAccessRequest(body.ShareID, body.VisitorToken, body.VisitorName, body.Note)
|
| 1152 |
+
if !ok || sh == nil || req == nil {
|
| 1153 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "share_disabled", Detail: "Liên kết chia sẻ đã bị tắt hoặc không tồn tại"})
|
| 1154 |
+
return
|
| 1155 |
+
}
|
| 1156 |
+
writeJSON(w, http.StatusOK, map[string]any{
|
| 1157 |
+
"ok": true,
|
| 1158 |
+
"request_id": req.RequestID,
|
| 1159 |
+
"visitor_token": req.VisitorToken,
|
| 1160 |
+
"request_status": req.Status,
|
| 1161 |
+
})
|
| 1162 |
+
}
|
| 1163 |
+
|
| 1164 |
+
func (a *App) handlePublicShareDownload(w http.ResponseWriter, r *http.Request) {
|
| 1165 |
+
shareID := strings.TrimSpace(r.URL.Query().Get("id"))
|
| 1166 |
+
visitorToken := strings.TrimSpace(r.URL.Query().Get("visitor_token"))
|
| 1167 |
+
if shareID == "" || a.shares == nil {
|
| 1168 |
+
writeJSON(w, http.StatusNotFound, APIError{Error: "not_found", Detail: "Liên kết chia sẻ không hợp lệ"})
|
| 1169 |
+
return
|
| 1170 |
+
}
|
| 1171 |
+
sh, granted, _, _ := a.shares.CheckVisitorAccess(shareID, visitorToken)
|
| 1172 |
+
if sh == nil {
|
| 1173 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "share_disabled", Detail: "Liên kết chia sẻ này đã bị tắt hoặc không tồn tại"})
|
| 1174 |
+
return
|
| 1175 |
+
}
|
| 1176 |
+
if !granted {
|
| 1177 |
+
if u, ok := a.resolveRequestUser(r); ok {
|
| 1178 |
+
if u.Role == "admin" || strings.EqualFold(u.Username, sh.Owner) || (a.owners != nil && a.owners.CanAccess(u, sh.Path)) {
|
| 1179 |
+
granted = true
|
| 1180 |
+
}
|
| 1181 |
+
}
|
| 1182 |
+
}
|
| 1183 |
+
if !granted {
|
| 1184 |
+
writeJSON(w, http.StatusForbidden, APIError{Error: "approval_required", Detail: "Bạn cần được chủ sở hữu tệp cho phép trước khi xem hoặc tải xuống"})
|
| 1185 |
+
return
|
| 1186 |
+
}
|
| 1187 |
+
a.serveRemoteFile(w, r, sh.Path)
|
| 1188 |
+
}
|
| 1189 |
+
|
| 1190 |
+
func (a *App) runHF(parent context.Context, args ...string) (string, error) {
|
| 1191 |
+
ctx, cancel := context.WithTimeout(parent, a.cfg.CommandTime)
|
| 1192 |
+
defer cancel()
|
| 1193 |
+
cmd := exec.CommandContext(ctx, a.cfg.HFCLI, args...)
|
| 1194 |
+
cmd.Env = append(os.Environ(), "HF_TOKEN="+a.cfg.HFToken, "HF_HUB_DISABLE_PROGRESS_BARS=1")
|
| 1195 |
+
out, err := cmd.CombinedOutput()
|
| 1196 |
+
text := strings.TrimSpace(string(out))
|
| 1197 |
+
if ctx.Err() != nil {
|
| 1198 |
+
return text, fmt.Errorf("Hugging Face command timed out: %w", ctx.Err())
|
| 1199 |
+
}
|
| 1200 |
+
if err != nil {
|
| 1201 |
+
return text, fmt.Errorf("hf command failed: %w", err)
|
| 1202 |
+
}
|
| 1203 |
+
return text, nil
|
| 1204 |
+
}
|
| 1205 |
+
|
| 1206 |
+
func cleanRemotePath(s string) (string, error) {
|
| 1207 |
+
s = strings.TrimSpace(strings.ReplaceAll(s, "\\", "/"))
|
| 1208 |
+
if s == "" {
|
| 1209 |
+
return "", errors.New("path is required")
|
| 1210 |
+
}
|
| 1211 |
+
if strings.HasPrefix(s, "/") || strings.ContainsRune(s, 0) {
|
| 1212 |
+
return "", errors.New("absolute paths and NUL bytes are not allowed")
|
| 1213 |
+
}
|
| 1214 |
+
clean := path.Clean(s)
|
| 1215 |
+
if clean == "." || clean == ".." || strings.HasPrefix(clean, "../") {
|
| 1216 |
+
return "", errors.New("path traversal is not allowed")
|
| 1217 |
+
}
|
| 1218 |
+
return clean, nil
|
| 1219 |
+
}
|
| 1220 |
+
|
| 1221 |
+
func writeJSON(w http.ResponseWriter, status int, v any) {
|
| 1222 |
+
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
| 1223 |
+
w.WriteHeader(status)
|
| 1224 |
+
_ = json.NewEncoder(w).Encode(v)
|
| 1225 |
+
}
|
main_test.go
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"os"
|
| 5 |
+
"path/filepath"
|
| 6 |
+
"testing"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
func TestCleanRemotePath(t *testing.T) {
|
| 10 |
+
cases := map[string]string{
|
| 11 |
+
"file.txt": "file.txt",
|
| 12 |
+
"folder\\nested\\file.txt": "folder/nested/file.txt",
|
| 13 |
+
"folder/./file.txt": "folder/file.txt",
|
| 14 |
+
}
|
| 15 |
+
for input, want := range cases {
|
| 16 |
+
got, err := cleanRemotePath(input)
|
| 17 |
+
if err != nil || got != want {
|
| 18 |
+
t.Fatalf("cleanRemotePath(%q) = %q, %v; want %q", input, got, err, want)
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
func TestCleanRemotePathRejectsTraversal(t *testing.T) {
|
| 24 |
+
for _, input := range []string{"", "../secret", "../../x", "/etc/passwd", "..\\secret"} {
|
| 25 |
+
if _, err := cleanRemotePath(input); err == nil {
|
| 26 |
+
t.Errorf("cleanRemotePath(%q) should fail", input)
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
func TestLoadDotEnv(t *testing.T) {
|
| 32 |
+
tmp := filepath.Join(t.TempDir(), ".env")
|
| 33 |
+
content := "# comment\nTEST_DOTENV_KEY=hello_world\nTEST_QUOTED=\"quoted_val\"\n"
|
| 34 |
+
if err := os.WriteFile(tmp, []byte(content), 0600); err != nil {
|
| 35 |
+
t.Fatal(err)
|
| 36 |
+
}
|
| 37 |
+
t.Cleanup(func() {
|
| 38 |
+
os.Unsetenv("TEST_DOTENV_KEY")
|
| 39 |
+
os.Unsetenv("TEST_QUOTED")
|
| 40 |
+
})
|
| 41 |
+
loadDotEnv(tmp)
|
| 42 |
+
if got := os.Getenv("TEST_DOTENV_KEY"); got != "hello_world" {
|
| 43 |
+
t.Fatalf("TEST_DOTENV_KEY = %q; want %q", got, "hello_world")
|
| 44 |
+
}
|
| 45 |
+
if got := os.Getenv("TEST_QUOTED"); got != "quoted_val" {
|
| 46 |
+
t.Fatalf("TEST_QUOTED = %q; want %q", got, "quoted_val")
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
func TestParseBucketLsLine(t *testing.T) {
|
| 51 |
+
line := " 48999197 2026-09-15 06:37:25 folder/111.mp4"
|
| 52 |
+
item, ok := parseBucketLsLine(line)
|
| 53 |
+
if !ok {
|
| 54 |
+
t.Fatal("expected ok=true")
|
| 55 |
+
}
|
| 56 |
+
if item.Path != "folder/111.mp4" || item.Size != 48999197 || item.UpdatedAt != "2026-09-15 06:37:25" {
|
| 57 |
+
t.Fatalf("unexpected parsed item: %+v", item)
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
func TestUserStoreAndRBAC(t *testing.T) {
|
| 62 |
+
storePath := filepath.Join(t.TempDir(), "users.json")
|
| 63 |
+
store, err := NewUserStore(storePath, "test-secret-key")
|
| 64 |
+
if err != nil {
|
| 65 |
+
t.Fatalf("NewUserStore failed: %v", err)
|
| 66 |
+
}
|
| 67 |
+
// Default admin/admin should exist
|
| 68 |
+
adminUser, ok := store.Authenticate("admin", "admin")
|
| 69 |
+
if !ok || adminUser.Role != "admin" {
|
| 70 |
+
t.Fatalf("expected default admin/admin to authenticate, got ok=%v, role=%s", ok, adminUser.Role)
|
| 71 |
+
}
|
| 72 |
+
// Issue & verify token
|
| 73 |
+
token, err := store.IssueToken("admin", 10*60*1e9)
|
| 74 |
+
if err != nil {
|
| 75 |
+
t.Fatalf("IssueToken failed: %v", err)
|
| 76 |
+
}
|
| 77 |
+
verified, ok := store.VerifyToken(token)
|
| 78 |
+
if !ok || verified.Username != "admin" {
|
| 79 |
+
t.Fatalf("VerifyToken failed: ok=%v, user=%+v", ok, verified)
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
func TestFileOwnerIsolation(t *testing.T) {
|
| 84 |
+
ownerFile := filepath.Join(t.TempDir(), "file_owners.json")
|
| 85 |
+
owners, err := NewFileOwnerStore(ownerFile)
|
| 86 |
+
if err != nil {
|
| 87 |
+
t.Fatalf("NewFileOwnerStore failed: %v", err)
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
adminAcc := UserAccount{Username: "admin", Role: "admin"}
|
| 91 |
+
userAcc := UserAccount{Username: "user", Role: "user"}
|
| 92 |
+
otherAcc := UserAccount{Username: "alice", Role: "user"}
|
| 93 |
+
|
| 94 |
+
// Legacy unrecorded file defaults to "admin"
|
| 95 |
+
if !owners.CanAccess(adminAcc, "111.mp4") {
|
| 96 |
+
t.Fatal("admin should access legacy file 111.mp4")
|
| 97 |
+
}
|
| 98 |
+
if owners.CanAccess(userAcc, "111.mp4") {
|
| 99 |
+
t.Fatal("regular user should NOT access legacy admin file 111.mp4")
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
// User uploads a file
|
| 103 |
+
owners.SetOwner("demo/user_video.mp4", "user")
|
| 104 |
+
if !owners.CanAccess(userAcc, "demo/user_video.mp4") {
|
| 105 |
+
t.Fatal("user should access their own uploaded file")
|
| 106 |
+
}
|
| 107 |
+
if !owners.CanAccess(adminAcc, "demo/user_video.mp4") {
|
| 108 |
+
t.Fatal("admin should access all files including user's uploaded file")
|
| 109 |
+
}
|
| 110 |
+
if owners.CanAccess(otherAcc, "demo/user_video.mp4") {
|
| 111 |
+
t.Fatal("other user (alice) should NOT access user's uploaded file")
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
// Rename preserves ownership
|
| 115 |
+
owners.Rename("demo/user_video.mp4", "demo/renamed_video.mp4")
|
| 116 |
+
if !owners.CanAccess(userAcc, "demo/renamed_video.mp4") {
|
| 117 |
+
t.Fatal("user should still own renamed file")
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// Two users uploading the same filename/content never lose their file
|
| 121 |
+
p1 := scopeUserRemotePath("user", "same_file.mp4")
|
| 122 |
+
p2 := scopeUserRemotePath("alice", "same_file.mp4")
|
| 123 |
+
if p1 == p2 {
|
| 124 |
+
t.Fatalf("expected distinct scoped paths for different users, got %s == %s", p1, p2)
|
| 125 |
+
}
|
| 126 |
+
owners.SetOwner(p1, "user")
|
| 127 |
+
owners.SetOwner(p2, "alice")
|
| 128 |
+
if !owners.CanAccess(userAcc, p1) || !owners.CanAccess(otherAcc, p2) {
|
| 129 |
+
t.Fatal("both users must retain access to their respective uploaded file")
|
| 130 |
+
}
|
| 131 |
+
// Even on a legacy shared path, SetOwner appends rather than overwrites
|
| 132 |
+
owners.SetOwner("shared.pptx", "user")
|
| 133 |
+
owners.SetOwner("shared.pptx", "alice")
|
| 134 |
+
if !owners.CanAccess(userAcc, "shared.pptx") || !owners.CanAccess(otherAcc, "shared.pptx") {
|
| 135 |
+
t.Fatal("both users should retain access when uploading to a shared legacy path")
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
// Same user uploading same filename with different content gets auto-numbered path " (1)", " (2)"
|
| 139 |
+
existing := map[string]bool{"user/report.pptx": true}
|
| 140 |
+
second := nextAvailableRemotePath("user/report.pptx", func(c string) bool { return existing[c] })
|
| 141 |
+
if second != "user/report (1).pptx" {
|
| 142 |
+
t.Fatalf("expected user/report (1).pptx, got %s", second)
|
| 143 |
+
}
|
| 144 |
+
existing[second] = true
|
| 145 |
+
third := nextAvailableRemotePath("user/report.pptx", func(c string) bool { return existing[c] })
|
| 146 |
+
if third != "user/report (2).pptx" {
|
| 147 |
+
t.Fatalf("expected user/report (2).pptx, got %s", third)
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
mongo.go
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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import (
|
| 4 |
+
"context"
|
| 5 |
+
"log"
|
| 6 |
+
"strings"
|
| 7 |
+
"time"
|
| 8 |
+
|
| 9 |
+
"go.mongodb.org/mongo-driver/bson"
|
| 10 |
+
"go.mongodb.org/mongo-driver/mongo"
|
| 11 |
+
"go.mongodb.org/mongo-driver/mongo/options"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
type MongoStore struct {
|
| 15 |
+
client *mongo.Client
|
| 16 |
+
db *mongo.Database
|
| 17 |
+
usersCol *mongo.Collection
|
| 18 |
+
ownersCol *mongo.Collection
|
| 19 |
+
filesCol *mongo.Collection
|
| 20 |
+
sharesCol *mongo.Collection
|
| 21 |
+
dbName string
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
type mongoOwnerDoc struct {
|
| 25 |
+
ID string `bson:"_id"`
|
| 26 |
+
Path string `bson:"path"`
|
| 27 |
+
Owners []string `bson:"owners"`
|
| 28 |
+
UpdatedAt string `bson:"updated_at"`
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
type mongoFileMetaDoc struct {
|
| 32 |
+
ID string `bson:"_id"`
|
| 33 |
+
Path string `bson:"path"`
|
| 34 |
+
Owner string `bson:"owner"`
|
| 35 |
+
Size int64 `bson:"size"`
|
| 36 |
+
UpdatedAt string `bson:"updated_at"`
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
func NewMongoStore(uri, dbName string) (*MongoStore, error) {
|
| 40 |
+
uri = strings.TrimSpace(uri)
|
| 41 |
+
if uri == "" {
|
| 42 |
+
return nil, nil
|
| 43 |
+
}
|
| 44 |
+
if dbName == "" {
|
| 45 |
+
dbName = "upload_thtuanit"
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
| 49 |
+
defer cancel()
|
| 50 |
+
|
| 51 |
+
clientOpts := options.Client().
|
| 52 |
+
ApplyURI(uri).
|
| 53 |
+
SetServerSelectionTimeout(10 * time.Second).
|
| 54 |
+
SetMaxPoolSize(20)
|
| 55 |
+
|
| 56 |
+
client, err := mongo.Connect(ctx, clientOpts)
|
| 57 |
+
if err != nil {
|
| 58 |
+
return nil, err
|
| 59 |
+
}
|
| 60 |
+
if err := client.Ping(ctx, nil); err != nil {
|
| 61 |
+
_ = client.Disconnect(context.Background())
|
| 62 |
+
return nil, err
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
db := client.Database(dbName)
|
| 66 |
+
ms := &MongoStore{
|
| 67 |
+
client: client,
|
| 68 |
+
db: db,
|
| 69 |
+
usersCol: db.Collection("users"),
|
| 70 |
+
ownersCol: db.Collection("file_owners"),
|
| 71 |
+
filesCol: db.Collection("files_metadata"),
|
| 72 |
+
sharesCol: db.Collection("shares"),
|
| 73 |
+
dbName: dbName,
|
| 74 |
+
}
|
| 75 |
+
log.Printf("Connected to MongoDB Atlas successfully (database=%s)", dbName)
|
| 76 |
+
return ms, nil
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// --- Users Collection Operations ---
|
| 80 |
+
|
| 81 |
+
func (m *MongoStore) LoadAllUsers() ([]UserAccount, error) {
|
| 82 |
+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
| 83 |
+
defer cancel()
|
| 84 |
+
|
| 85 |
+
cur, err := m.usersCol.Find(ctx, bson.M{})
|
| 86 |
+
if err != nil {
|
| 87 |
+
return nil, err
|
| 88 |
+
}
|
| 89 |
+
defer cur.Close(ctx)
|
| 90 |
+
|
| 91 |
+
var out []UserAccount
|
| 92 |
+
for cur.Next(ctx) {
|
| 93 |
+
var u UserAccount
|
| 94 |
+
if err := cur.Decode(&u); err == nil && u.Username != "" {
|
| 95 |
+
out = append(out, u)
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
return out, cur.Err()
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
func (m *MongoStore) UpsertUserDoc(u UserAccount) error {
|
| 102 |
+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
| 103 |
+
defer cancel()
|
| 104 |
+
|
| 105 |
+
key := strings.ToLower(strings.TrimSpace(u.Username))
|
| 106 |
+
doc := bson.M{
|
| 107 |
+
"_id": key,
|
| 108 |
+
"username": u.Username,
|
| 109 |
+
"display_name": u.DisplayName,
|
| 110 |
+
"role": u.Role,
|
| 111 |
+
"password_salt": u.PasswordSalt,
|
| 112 |
+
"password_hash": u.PasswordHash,
|
| 113 |
+
"permissions": bson.M{
|
| 114 |
+
"can_upload": u.Permissions.CanUpload,
|
| 115 |
+
"can_delete": u.Permissions.CanDelete,
|
| 116 |
+
"can_rename": u.Permissions.CanRename,
|
| 117 |
+
},
|
| 118 |
+
"active": u.Active,
|
| 119 |
+
"created_at": u.CreatedAt,
|
| 120 |
+
}
|
| 121 |
+
_, err := m.usersCol.UpdateOne(
|
| 122 |
+
ctx,
|
| 123 |
+
bson.M{"_id": key},
|
| 124 |
+
bson.M{"$set": doc},
|
| 125 |
+
options.Update().SetUpsert(true),
|
| 126 |
+
)
|
| 127 |
+
return err
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
func (m *MongoStore) DeleteUserDoc(username string) error {
|
| 131 |
+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
| 132 |
+
defer cancel()
|
| 133 |
+
key := strings.ToLower(strings.TrimSpace(username))
|
| 134 |
+
_, err := m.usersCol.DeleteOne(ctx, bson.M{"_id": key})
|
| 135 |
+
return err
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
// --- File Owners Collection Operations ---
|
| 139 |
+
|
| 140 |
+
func (m *MongoStore) LoadAllOwners() (map[string][]string, error) {
|
| 141 |
+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
| 142 |
+
defer cancel()
|
| 143 |
+
|
| 144 |
+
cur, err := m.ownersCol.Find(ctx, bson.M{})
|
| 145 |
+
if err != nil {
|
| 146 |
+
return nil, err
|
| 147 |
+
}
|
| 148 |
+
defer cur.Close(ctx)
|
| 149 |
+
|
| 150 |
+
res := make(map[string][]string)
|
| 151 |
+
for cur.Next(ctx) {
|
| 152 |
+
var doc mongoOwnerDoc
|
| 153 |
+
if err := cur.Decode(&doc); err == nil && doc.Path != "" && len(doc.Owners) > 0 {
|
| 154 |
+
res[doc.Path] = doc.Owners
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
return res, cur.Err()
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
func (m *MongoStore) UpsertOwnerDoc(remotePath string, owners []string) error {
|
| 161 |
+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
| 162 |
+
defer cancel()
|
| 163 |
+
|
| 164 |
+
now := time.Now().Format("2006-01-02 15:04:05")
|
| 165 |
+
doc := mongoOwnerDoc{
|
| 166 |
+
ID: remotePath,
|
| 167 |
+
Path: remotePath,
|
| 168 |
+
Owners: owners,
|
| 169 |
+
UpdatedAt: now,
|
| 170 |
+
}
|
| 171 |
+
_, err := m.ownersCol.UpdateOne(
|
| 172 |
+
ctx,
|
| 173 |
+
bson.M{"_id": remotePath},
|
| 174 |
+
bson.M{"$set": doc},
|
| 175 |
+
options.Update().SetUpsert(true),
|
| 176 |
+
)
|
| 177 |
+
return err
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
func (m *MongoStore) DeleteOwnerDoc(remotePath string) error {
|
| 181 |
+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
| 182 |
+
defer cancel()
|
| 183 |
+
_, err := m.ownersCol.DeleteOne(ctx, bson.M{"_id": remotePath})
|
| 184 |
+
_, _ = m.filesCol.DeleteOne(ctx, bson.M{"_id": remotePath})
|
| 185 |
+
return err
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
func (m *MongoStore) UpsertFileMeta(remotePath, owner string, size int64) {
|
| 189 |
+
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
|
| 190 |
+
defer cancel()
|
| 191 |
+
doc := mongoFileMetaDoc{
|
| 192 |
+
ID: remotePath,
|
| 193 |
+
Path: remotePath,
|
| 194 |
+
Owner: strings.ToLower(strings.TrimSpace(owner)),
|
| 195 |
+
Size: size,
|
| 196 |
+
UpdatedAt: time.Now().Format("2006-01-02 15:04:05"),
|
| 197 |
+
}
|
| 198 |
+
_, _ = m.filesCol.UpdateOne(
|
| 199 |
+
ctx,
|
| 200 |
+
bson.M{"_id": remotePath},
|
| 201 |
+
bson.M{"$set": doc},
|
| 202 |
+
options.Update().SetUpsert(true),
|
| 203 |
+
)
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
// --- Shares Collection Operations ---
|
| 207 |
+
|
| 208 |
+
func (m *MongoStore) LoadAllShares() ([]ShareLink, error) {
|
| 209 |
+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
| 210 |
+
defer cancel()
|
| 211 |
+
|
| 212 |
+
cur, err := m.sharesCol.Find(ctx, bson.M{})
|
| 213 |
+
if err != nil {
|
| 214 |
+
return nil, err
|
| 215 |
+
}
|
| 216 |
+
defer cur.Close(ctx)
|
| 217 |
+
|
| 218 |
+
var out []ShareLink
|
| 219 |
+
for cur.Next(ctx) {
|
| 220 |
+
var sh ShareLink
|
| 221 |
+
if err := cur.Decode(&sh); err == nil && sh.ID != "" && sh.Path != "" {
|
| 222 |
+
out = append(out, sh)
|
| 223 |
+
}
|
| 224 |
+
}
|
| 225 |
+
return out, cur.Err()
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
func (m *MongoStore) UpsertShareDoc(sh ShareLink) error {
|
| 229 |
+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
| 230 |
+
defer cancel()
|
| 231 |
+
|
| 232 |
+
_, err := m.sharesCol.UpdateOne(
|
| 233 |
+
ctx,
|
| 234 |
+
bson.M{"_id": sh.ID},
|
| 235 |
+
bson.M{"$set": sh},
|
| 236 |
+
options.Update().SetUpsert(true),
|
| 237 |
+
)
|
| 238 |
+
return err
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
func (m *MongoStore) DeleteShareDoc(shareID string) error {
|
| 242 |
+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
| 243 |
+
defer cancel()
|
| 244 |
+
_, err := m.sharesCol.DeleteOne(ctx, bson.M{"_id": shareID})
|
| 245 |
+
return err
|
| 246 |
+
}
|
| 247 |
+
|
ownership.go
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
"errors"
|
| 6 |
+
"os"
|
| 7 |
+
"strings"
|
| 8 |
+
"sync"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
// FileOwnerStore tracks file ownership per remote path.
|
| 12 |
+
// It supports both per-user namespaced paths ("<username>/<path>") and multi-owner lists
|
| 13 |
+
// for legacy root paths so that two users uploading the same file never overwrite or lose each other's files.
|
| 14 |
+
type FileOwnerStore struct {
|
| 15 |
+
mu sync.RWMutex
|
| 16 |
+
path string
|
| 17 |
+
owners map[string][]string // remotePath -> list of lowercase usernames
|
| 18 |
+
mongo *MongoStore
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
func (s *FileOwnerStore) AttachMongo(m *MongoStore) {
|
| 22 |
+
if m == nil {
|
| 23 |
+
return
|
| 24 |
+
}
|
| 25 |
+
s.mu.Lock()
|
| 26 |
+
defer s.mu.Unlock()
|
| 27 |
+
s.mongo = m
|
| 28 |
+
|
| 29 |
+
dbOwners, err := m.LoadAllOwners()
|
| 30 |
+
if err == nil {
|
| 31 |
+
inMongo := make(map[string]bool)
|
| 32 |
+
for p, list := range dbOwners {
|
| 33 |
+
inMongo[p] = true
|
| 34 |
+
existing := s.owners[p]
|
| 35 |
+
for _, u := range list {
|
| 36 |
+
if !containsString(existing, u) {
|
| 37 |
+
existing = append(existing, u)
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
s.owners[p] = existing
|
| 41 |
+
}
|
| 42 |
+
// Sync local owners up to MongoDB
|
| 43 |
+
for p, list := range s.owners {
|
| 44 |
+
if !inMongo[p] || len(list) != len(dbOwners[p]) {
|
| 45 |
+
_ = m.UpsertOwnerDoc(p, list)
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
_ = s.saveLocked()
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
func NewFileOwnerStore(filePath string) (*FileOwnerStore, error) {
|
| 53 |
+
s := &FileOwnerStore{
|
| 54 |
+
path: filePath,
|
| 55 |
+
owners: make(map[string][]string),
|
| 56 |
+
}
|
| 57 |
+
if err := s.load(); err != nil {
|
| 58 |
+
return nil, err
|
| 59 |
+
}
|
| 60 |
+
return s, nil
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
// scopeUserRemotePath namespaces a user's upload under "<username>/<remotePath>"
|
| 64 |
+
// unless remotePath already starts with "<username>/".
|
| 65 |
+
func scopeUserRemotePath(username, remotePath string) string {
|
| 66 |
+
u := strings.ToLower(strings.TrimSpace(username))
|
| 67 |
+
clean := strings.TrimPrefix(strings.ReplaceAll(remotePath, "\\", "/"), "/")
|
| 68 |
+
if u == "" {
|
| 69 |
+
return clean
|
| 70 |
+
}
|
| 71 |
+
prefix := u + "/"
|
| 72 |
+
if strings.HasPrefix(strings.ToLower(clean), prefix) {
|
| 73 |
+
return clean
|
| 74 |
+
}
|
| 75 |
+
return prefix + clean
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
// nextAvailableRemotePath returns remotePath if !exists(remotePath), or appends " (1)", " (2)", ...
|
| 79 |
+
// before the file extension (like Google Drive / Windows Explorer) so same-named files never overwrite each other.
|
| 80 |
+
func nextAvailableRemotePath(remotePath string, exists func(string) bool) string {
|
| 81 |
+
if !exists(remotePath) {
|
| 82 |
+
return remotePath
|
| 83 |
+
}
|
| 84 |
+
dir := ""
|
| 85 |
+
base := remotePath
|
| 86 |
+
if idx := strings.LastIndex(remotePath, "/"); idx != -1 {
|
| 87 |
+
dir = remotePath[:idx+1]
|
| 88 |
+
base = remotePath[idx+1:]
|
| 89 |
+
}
|
| 90 |
+
stem := base
|
| 91 |
+
ext := ""
|
| 92 |
+
if dot := strings.LastIndex(base, "."); dot > 0 {
|
| 93 |
+
stem = base[:dot]
|
| 94 |
+
ext = base[dot:]
|
| 95 |
+
}
|
| 96 |
+
for i := 1; i < 10000; i++ {
|
| 97 |
+
candidate := dir + stem + " (" + itoa(i) + ")" + ext
|
| 98 |
+
if !exists(candidate) {
|
| 99 |
+
return candidate
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
return remotePath
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
func itoa(n int) string {
|
| 106 |
+
if n == 0 {
|
| 107 |
+
return "0"
|
| 108 |
+
}
|
| 109 |
+
var buf [20]byte
|
| 110 |
+
pos := len(buf)
|
| 111 |
+
for n > 0 {
|
| 112 |
+
pos--
|
| 113 |
+
buf[pos] = byte('0' + n%10)
|
| 114 |
+
n /= 10
|
| 115 |
+
}
|
| 116 |
+
return string(buf[pos:])
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
func (s *FileOwnerStore) HasPath(remotePath string) bool {
|
| 120 |
+
s.mu.RLock()
|
| 121 |
+
defer s.mu.RUnlock()
|
| 122 |
+
_, ok := s.owners[remotePath]
|
| 123 |
+
return ok
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
func (s *FileOwnerStore) load() error {
|
| 127 |
+
s.mu.Lock()
|
| 128 |
+
defer s.mu.Unlock()
|
| 129 |
+
|
| 130 |
+
data, err := os.ReadFile(s.path)
|
| 131 |
+
if err != nil {
|
| 132 |
+
if errors.Is(err, os.ErrNotExist) {
|
| 133 |
+
return s.saveLocked()
|
| 134 |
+
}
|
| 135 |
+
return err
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
// Support both map[string][]string and legacy map[string]string
|
| 139 |
+
var raw map[string]any
|
| 140 |
+
if err := json.Unmarshal(data, &raw); err != nil {
|
| 141 |
+
return err
|
| 142 |
+
}
|
| 143 |
+
for k, v := range raw {
|
| 144 |
+
switch val := v.(type) {
|
| 145 |
+
case string:
|
| 146 |
+
u := strings.ToLower(strings.TrimSpace(val))
|
| 147 |
+
if u != "" {
|
| 148 |
+
s.owners[k] = []string{u}
|
| 149 |
+
}
|
| 150 |
+
case []any:
|
| 151 |
+
var list []string
|
| 152 |
+
for _, item := range val {
|
| 153 |
+
if str, ok := item.(string); ok {
|
| 154 |
+
u := strings.ToLower(strings.TrimSpace(str))
|
| 155 |
+
if u != "" && !containsString(list, u) {
|
| 156 |
+
list = append(list, u)
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
if len(list) > 0 {
|
| 161 |
+
s.owners[k] = list
|
| 162 |
+
}
|
| 163 |
+
}
|
| 164 |
+
}
|
| 165 |
+
return nil
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
func containsString(list []string, target string) bool {
|
| 169 |
+
for _, x := range list {
|
| 170 |
+
if strings.EqualFold(x, target) {
|
| 171 |
+
return true
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
return false
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
func (s *FileOwnerStore) saveLocked() error {
|
| 178 |
+
data, err := json.MarshalIndent(s.owners, "", " ")
|
| 179 |
+
if err != nil {
|
| 180 |
+
return err
|
| 181 |
+
}
|
| 182 |
+
return os.WriteFile(s.path, data, 0600)
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
// SetOwner adds username as an owner of remotePath without erasing existing co-owners on shared paths.
|
| 186 |
+
func (s *FileOwnerStore) SetOwner(remotePath, username string) {
|
| 187 |
+
s.mu.Lock()
|
| 188 |
+
defer s.mu.Unlock()
|
| 189 |
+
u := strings.ToLower(strings.TrimSpace(username))
|
| 190 |
+
if u == "" {
|
| 191 |
+
return
|
| 192 |
+
}
|
| 193 |
+
existing := s.owners[remotePath]
|
| 194 |
+
if !containsString(existing, u) {
|
| 195 |
+
existing = append(existing, u)
|
| 196 |
+
s.owners[remotePath] = existing
|
| 197 |
+
}
|
| 198 |
+
if s.mongo != nil {
|
| 199 |
+
_ = s.mongo.UpsertOwnerDoc(remotePath, s.owners[remotePath])
|
| 200 |
+
}
|
| 201 |
+
_ = s.saveLocked()
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
func (s *FileOwnerStore) SetOwnersBatch(remotePaths []string, username string) {
|
| 205 |
+
s.mu.Lock()
|
| 206 |
+
defer s.mu.Unlock()
|
| 207 |
+
u := strings.ToLower(strings.TrimSpace(username))
|
| 208 |
+
if u == "" {
|
| 209 |
+
return
|
| 210 |
+
}
|
| 211 |
+
for _, p := range remotePaths {
|
| 212 |
+
existing := s.owners[p]
|
| 213 |
+
if !containsString(existing, u) {
|
| 214 |
+
existing = append(existing, u)
|
| 215 |
+
s.owners[p] = existing
|
| 216 |
+
}
|
| 217 |
+
if s.mongo != nil {
|
| 218 |
+
_ = s.mongo.UpsertOwnerDoc(p, s.owners[p])
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
_ = s.saveLocked()
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
func (s *FileOwnerStore) GetOwner(remotePath string) string {
|
| 225 |
+
s.mu.RLock()
|
| 226 |
+
defer s.mu.RUnlock()
|
| 227 |
+
// If path is namespaced as "<username>/...", that prefix is the primary owner
|
| 228 |
+
parts := strings.SplitN(remotePath, "/", 2)
|
| 229 |
+
if len(parts) == 2 && parts[0] != "" {
|
| 230 |
+
if list, ok := s.owners[remotePath]; ok && len(list) > 0 {
|
| 231 |
+
return list[len(list)-1]
|
| 232 |
+
}
|
| 233 |
+
return strings.ToLower(parts[0])
|
| 234 |
+
}
|
| 235 |
+
if list, ok := s.owners[remotePath]; ok && len(list) > 0 {
|
| 236 |
+
return strings.Join(list, ", ")
|
| 237 |
+
}
|
| 238 |
+
return "admin"
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
func (s *FileOwnerStore) GetOwnerForUser(u UserAccount, remotePath string) string {
|
| 242 |
+
s.mu.RLock()
|
| 243 |
+
defer s.mu.RUnlock()
|
| 244 |
+
if list, ok := s.owners[remotePath]; ok && len(list) > 0 {
|
| 245 |
+
if u.Role != "admin" && containsString(list, u.Username) {
|
| 246 |
+
return strings.ToLower(u.Username)
|
| 247 |
+
}
|
| 248 |
+
return list[len(list)-1]
|
| 249 |
+
}
|
| 250 |
+
parts := strings.SplitN(remotePath, "/", 2)
|
| 251 |
+
if len(parts) == 2 && parts[0] != "" {
|
| 252 |
+
return strings.ToLower(parts[0])
|
| 253 |
+
}
|
| 254 |
+
return "admin"
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
func (s *FileOwnerStore) Rename(oldPath, newPath string) {
|
| 258 |
+
s.mu.Lock()
|
| 259 |
+
defer s.mu.Unlock()
|
| 260 |
+
if list, ok := s.owners[oldPath]; ok {
|
| 261 |
+
delete(s.owners, oldPath)
|
| 262 |
+
s.owners[newPath] = list
|
| 263 |
+
if s.mongo != nil {
|
| 264 |
+
_ = s.mongo.DeleteOwnerDoc(oldPath)
|
| 265 |
+
_ = s.mongo.UpsertOwnerDoc(newPath, list)
|
| 266 |
+
}
|
| 267 |
+
_ = s.saveLocked()
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
func (s *FileOwnerStore) Delete(remotePath string) {
|
| 272 |
+
s.mu.Lock()
|
| 273 |
+
defer s.mu.Unlock()
|
| 274 |
+
if _, ok := s.owners[remotePath]; ok {
|
| 275 |
+
delete(s.owners, remotePath)
|
| 276 |
+
if s.mongo != nil {
|
| 277 |
+
_ = s.mongo.DeleteOwnerDoc(remotePath)
|
| 278 |
+
}
|
| 279 |
+
_ = s.saveLocked()
|
| 280 |
+
}
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
func (s *FileOwnerStore) CanAccess(u UserAccount, remotePath string) bool {
|
| 284 |
+
if u.Role == "admin" {
|
| 285 |
+
return true
|
| 286 |
+
}
|
| 287 |
+
s.mu.RLock()
|
| 288 |
+
list := s.owners[remotePath]
|
| 289 |
+
s.mu.RUnlock()
|
| 290 |
+
if len(list) > 0 {
|
| 291 |
+
return containsString(list, u.Username)
|
| 292 |
+
}
|
| 293 |
+
// Fallback: if path starts with "<username>/...", check prefix match
|
| 294 |
+
parts := strings.SplitN(remotePath, "/", 2)
|
| 295 |
+
if len(parts) == 2 && strings.EqualFold(parts[0], u.Username) {
|
| 296 |
+
return true
|
| 297 |
+
}
|
| 298 |
+
return false
|
| 299 |
+
}
|
share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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import (
|
| 4 |
+
"crypto/rand"
|
| 5 |
+
"encoding/hex"
|
| 6 |
+
"encoding/json"
|
| 7 |
+
"os"
|
| 8 |
+
"path/filepath"
|
| 9 |
+
"sort"
|
| 10 |
+
"strings"
|
| 11 |
+
"sync"
|
| 12 |
+
"time"
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
type ShareAccessRequest struct {
|
| 16 |
+
RequestID string `json:"request_id" bson:"request_id"`
|
| 17 |
+
VisitorToken string `json:"visitor_token" bson:"visitor_token"`
|
| 18 |
+
VisitorName string `json:"visitor_name" bson:"visitor_name"`
|
| 19 |
+
Note string `json:"note,omitempty" bson:"note,omitempty"`
|
| 20 |
+
Status string `json:"status" bson:"status"` // "pending", "approved", "rejected"
|
| 21 |
+
RequestedAt string `json:"requested_at" bson:"requested_at"`
|
| 22 |
+
UpdatedAt string `json:"updated_at" bson:"updated_at"`
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
type ShareLink struct {
|
| 26 |
+
ID string `json:"id" bson:"_id"`
|
| 27 |
+
Path string `json:"path" bson:"path"`
|
| 28 |
+
FileName string `json:"file_name" bson:"file_name"`
|
| 29 |
+
Size int64 `json:"size" bson:"size"`
|
| 30 |
+
Owner string `json:"owner" bson:"owner"`
|
| 31 |
+
Enabled bool `json:"enabled" bson:"enabled"`
|
| 32 |
+
RequireApproval bool `json:"require_approval" bson:"require_approval"`
|
| 33 |
+
CreatedAt string `json:"created_at" bson:"created_at"`
|
| 34 |
+
UpdatedAt string `json:"updated_at" bson:"updated_at"`
|
| 35 |
+
Requests []ShareAccessRequest `json:"requests" bson:"requests"`
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
type ShareStore struct {
|
| 39 |
+
mu sync.RWMutex
|
| 40 |
+
filePath string
|
| 41 |
+
byID map[string]*ShareLink
|
| 42 |
+
byPath map[string]string // remotePath -> shareID
|
| 43 |
+
mongo *MongoStore
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
func generateRandomToken(byteLen int) string {
|
| 47 |
+
b := make([]byte, byteLen)
|
| 48 |
+
_, _ = rand.Read(b)
|
| 49 |
+
return hex.EncodeToString(b)
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
func NewShareStore(filePath string) (*ShareStore, error) {
|
| 53 |
+
s := &ShareStore{
|
| 54 |
+
filePath: filePath,
|
| 55 |
+
byID: make(map[string]*ShareLink),
|
| 56 |
+
byPath: make(map[string]string),
|
| 57 |
+
}
|
| 58 |
+
if err := s.load(); err != nil {
|
| 59 |
+
return nil, err
|
| 60 |
+
}
|
| 61 |
+
return s, nil
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
func (s *ShareStore) load() error {
|
| 65 |
+
s.mu.Lock()
|
| 66 |
+
defer s.mu.Unlock()
|
| 67 |
+
|
| 68 |
+
data, err := os.ReadFile(s.filePath)
|
| 69 |
+
if err != nil {
|
| 70 |
+
if os.IsNotExist(err) {
|
| 71 |
+
return nil
|
| 72 |
+
}
|
| 73 |
+
return err
|
| 74 |
+
}
|
| 75 |
+
var list []*ShareLink
|
| 76 |
+
if err := json.Unmarshal(data, &list); err != nil {
|
| 77 |
+
return nil
|
| 78 |
+
}
|
| 79 |
+
for _, item := range list {
|
| 80 |
+
if item != nil && item.ID != "" && item.Path != "" {
|
| 81 |
+
if item.Requests == nil {
|
| 82 |
+
item.Requests = []ShareAccessRequest{}
|
| 83 |
+
}
|
| 84 |
+
s.byID[item.ID] = item
|
| 85 |
+
s.byPath[item.Path] = item.ID
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
return nil
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
func (s *ShareStore) saveLocked() {
|
| 92 |
+
list := make([]*ShareLink, 0, len(s.byID))
|
| 93 |
+
for _, item := range s.byID {
|
| 94 |
+
list = append(list, item)
|
| 95 |
+
}
|
| 96 |
+
data, err := json.MarshalIndent(list, "", " ")
|
| 97 |
+
if err == nil {
|
| 98 |
+
_ = os.WriteFile(s.filePath, data, 0600)
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
func (s *ShareStore) AttachMongo(m *MongoStore) {
|
| 103 |
+
if m == nil {
|
| 104 |
+
return
|
| 105 |
+
}
|
| 106 |
+
s.mu.Lock()
|
| 107 |
+
s.mongo = m
|
| 108 |
+
remoteShares, err := m.LoadAllShares()
|
| 109 |
+
if err == nil {
|
| 110 |
+
for _, sh := range remoteShares {
|
| 111 |
+
cp := sh
|
| 112 |
+
if cp.Requests == nil {
|
| 113 |
+
cp.Requests = []ShareAccessRequest{}
|
| 114 |
+
}
|
| 115 |
+
s.byID[cp.ID] = &cp
|
| 116 |
+
s.byPath[cp.Path] = cp.ID
|
| 117 |
+
}
|
| 118 |
+
for _, localShare := range s.byID {
|
| 119 |
+
_ = m.UpsertShareDoc(*localShare)
|
| 120 |
+
}
|
| 121 |
+
s.saveLocked()
|
| 122 |
+
}
|
| 123 |
+
s.mu.Unlock()
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
func cloneShare(sh *ShareLink) *ShareLink {
|
| 127 |
+
if sh == nil {
|
| 128 |
+
return nil
|
| 129 |
+
}
|
| 130 |
+
cp := *sh
|
| 131 |
+
cp.Requests = make([]ShareAccessRequest, len(sh.Requests))
|
| 132 |
+
copy(cp.Requests, sh.Requests)
|
| 133 |
+
return &cp
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
func (s *ShareStore) GetByID(id string) (*ShareLink, bool) {
|
| 137 |
+
s.mu.RLock()
|
| 138 |
+
defer s.mu.RUnlock()
|
| 139 |
+
sh, ok := s.byID[strings.TrimSpace(id)]
|
| 140 |
+
if !ok {
|
| 141 |
+
return nil, false
|
| 142 |
+
}
|
| 143 |
+
return cloneShare(sh), true
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
func (s *ShareStore) GetByPath(remotePath string) (*ShareLink, bool) {
|
| 147 |
+
s.mu.RLock()
|
| 148 |
+
defer s.mu.RUnlock()
|
| 149 |
+
id, ok := s.byPath[remotePath]
|
| 150 |
+
if !ok {
|
| 151 |
+
return nil, false
|
| 152 |
+
}
|
| 153 |
+
sh, ok := s.byID[id]
|
| 154 |
+
if !ok {
|
| 155 |
+
return nil, false
|
| 156 |
+
}
|
| 157 |
+
return cloneShare(sh), true
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
func (s *ShareStore) ListForUser(u UserAccount) []*ShareLink {
|
| 161 |
+
s.mu.RLock()
|
| 162 |
+
defer s.mu.RUnlock()
|
| 163 |
+
username := strings.ToLower(strings.TrimSpace(u.Username))
|
| 164 |
+
out := make([]*ShareLink, 0)
|
| 165 |
+
for _, sh := range s.byID {
|
| 166 |
+
if u.Role == "admin" || strings.ToLower(sh.Owner) == username {
|
| 167 |
+
out = append(out, cloneShare(sh))
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
sort.Slice(out, func(i, j int) bool {
|
| 171 |
+
return out[i].UpdatedAt > out[j].UpdatedAt
|
| 172 |
+
})
|
| 173 |
+
return out
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
func (s *ShareStore) UpsertShare(remotePath, owner string, size int64, enabled, requireApproval, regenerate bool) *ShareLink {
|
| 177 |
+
s.mu.Lock()
|
| 178 |
+
defer s.mu.Unlock()
|
| 179 |
+
|
| 180 |
+
now := time.Now().Format("2006-01-02 15:04:05")
|
| 181 |
+
existingID, exists := s.byPath[remotePath]
|
| 182 |
+
var sh *ShareLink
|
| 183 |
+
if exists {
|
| 184 |
+
sh = s.byID[existingID]
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
if sh == nil {
|
| 188 |
+
newID := "sh_" + generateRandomToken(6)
|
| 189 |
+
sh = &ShareLink{
|
| 190 |
+
ID: newID,
|
| 191 |
+
Path: remotePath,
|
| 192 |
+
FileName: filepath.Base(remotePath),
|
| 193 |
+
Size: size,
|
| 194 |
+
Owner: strings.ToLower(strings.TrimSpace(owner)),
|
| 195 |
+
Enabled: enabled,
|
| 196 |
+
RequireApproval: requireApproval,
|
| 197 |
+
CreatedAt: now,
|
| 198 |
+
UpdatedAt: now,
|
| 199 |
+
Requests: []ShareAccessRequest{},
|
| 200 |
+
}
|
| 201 |
+
s.byID[newID] = sh
|
| 202 |
+
s.byPath[remotePath] = newID
|
| 203 |
+
} else {
|
| 204 |
+
if regenerate {
|
| 205 |
+
oldID := sh.ID
|
| 206 |
+
delete(s.byID, oldID)
|
| 207 |
+
if s.mongo != nil {
|
| 208 |
+
_ = s.mongo.DeleteShareDoc(oldID)
|
| 209 |
+
}
|
| 210 |
+
sh.ID = "sh_" + generateRandomToken(6)
|
| 211 |
+
sh.Requests = []ShareAccessRequest{}
|
| 212 |
+
s.byID[sh.ID] = sh
|
| 213 |
+
s.byPath[remotePath] = sh.ID
|
| 214 |
+
}
|
| 215 |
+
sh.FileName = filepath.Base(remotePath)
|
| 216 |
+
if size > 0 {
|
| 217 |
+
sh.Size = size
|
| 218 |
+
}
|
| 219 |
+
sh.Enabled = enabled
|
| 220 |
+
sh.RequireApproval = requireApproval
|
| 221 |
+
sh.UpdatedAt = now
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
s.saveLocked()
|
| 225 |
+
if s.mongo != nil {
|
| 226 |
+
_ = s.mongo.UpsertShareDoc(*sh)
|
| 227 |
+
}
|
| 228 |
+
return cloneShare(sh)
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
func (s *ShareStore) SubmitAccessRequest(shareID, visitorToken, visitorName, note string) (*ShareLink, *ShareAccessRequest, bool) {
|
| 232 |
+
s.mu.Lock()
|
| 233 |
+
defer s.mu.Unlock()
|
| 234 |
+
|
| 235 |
+
sh, ok := s.byID[strings.TrimSpace(shareID)]
|
| 236 |
+
if !ok || !sh.Enabled {
|
| 237 |
+
return nil, nil, false
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
visitorToken = strings.TrimSpace(visitorToken)
|
| 241 |
+
if visitorToken == "" {
|
| 242 |
+
visitorToken = "vt_" + generateRandomToken(8)
|
| 243 |
+
}
|
| 244 |
+
visitorName = strings.TrimSpace(visitorName)
|
| 245 |
+
if visitorName == "" {
|
| 246 |
+
visitorName = "Khách xem tệp"
|
| 247 |
+
}
|
| 248 |
+
note = strings.TrimSpace(note)
|
| 249 |
+
now := time.Now().Format("2006-01-02 15:04:05")
|
| 250 |
+
|
| 251 |
+
for i := range sh.Requests {
|
| 252 |
+
if sh.Requests[i].VisitorToken == visitorToken {
|
| 253 |
+
sh.Requests[i].VisitorName = visitorName
|
| 254 |
+
if note != "" {
|
| 255 |
+
sh.Requests[i].Note = note
|
| 256 |
+
}
|
| 257 |
+
if sh.Requests[i].Status != "approved" {
|
| 258 |
+
sh.Requests[i].Status = "pending"
|
| 259 |
+
}
|
| 260 |
+
sh.Requests[i].UpdatedAt = now
|
| 261 |
+
sh.UpdatedAt = now
|
| 262 |
+
s.saveLocked()
|
| 263 |
+
if s.mongo != nil {
|
| 264 |
+
_ = s.mongo.UpsertShareDoc(*sh)
|
| 265 |
+
}
|
| 266 |
+
reqCopy := sh.Requests[i]
|
| 267 |
+
return cloneShare(sh), &reqCopy, true
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
req := ShareAccessRequest{
|
| 272 |
+
RequestID: "req_" + generateRandomToken(5),
|
| 273 |
+
VisitorToken: visitorToken,
|
| 274 |
+
VisitorName: visitorName,
|
| 275 |
+
Note: note,
|
| 276 |
+
Status: "pending",
|
| 277 |
+
RequestedAt: now,
|
| 278 |
+
UpdatedAt: now,
|
| 279 |
+
}
|
| 280 |
+
sh.Requests = append([]ShareAccessRequest{req}, sh.Requests...)
|
| 281 |
+
sh.UpdatedAt = now
|
| 282 |
+
s.saveLocked()
|
| 283 |
+
if s.mongo != nil {
|
| 284 |
+
_ = s.mongo.UpsertShareDoc(*sh)
|
| 285 |
+
}
|
| 286 |
+
return cloneShare(sh), &req, true
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
func (s *ShareStore) UpdateRequestStatus(shareID, requestID, status string) (*ShareLink, bool) {
|
| 290 |
+
s.mu.Lock()
|
| 291 |
+
defer s.mu.Unlock()
|
| 292 |
+
|
| 293 |
+
sh, ok := s.byID[strings.TrimSpace(shareID)]
|
| 294 |
+
if !ok {
|
| 295 |
+
return nil, false
|
| 296 |
+
}
|
| 297 |
+
now := time.Now().Format("2006-01-02 15:04:05")
|
| 298 |
+
found := false
|
| 299 |
+
for i := range sh.Requests {
|
| 300 |
+
if sh.Requests[i].RequestID == requestID {
|
| 301 |
+
sh.Requests[i].Status = status
|
| 302 |
+
sh.Requests[i].UpdatedAt = now
|
| 303 |
+
found = true
|
| 304 |
+
break
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
if !found {
|
| 308 |
+
return nil, false
|
| 309 |
+
}
|
| 310 |
+
sh.UpdatedAt = now
|
| 311 |
+
s.saveLocked()
|
| 312 |
+
if s.mongo != nil {
|
| 313 |
+
_ = s.mongo.UpsertShareDoc(*sh)
|
| 314 |
+
}
|
| 315 |
+
return cloneShare(sh), true
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
func (s *ShareStore) CheckVisitorAccess(shareID, visitorToken string) (*ShareLink, bool, string, string) {
|
| 319 |
+
s.mu.RLock()
|
| 320 |
+
defer s.mu.RUnlock()
|
| 321 |
+
|
| 322 |
+
sh, ok := s.byID[strings.TrimSpace(shareID)]
|
| 323 |
+
if !ok || !sh.Enabled {
|
| 324 |
+
return nil, false, "disabled", ""
|
| 325 |
+
}
|
| 326 |
+
if !sh.RequireApproval {
|
| 327 |
+
return cloneShare(sh), true, "approved", ""
|
| 328 |
+
}
|
| 329 |
+
visitorToken = strings.TrimSpace(visitorToken)
|
| 330 |
+
if visitorToken != "" {
|
| 331 |
+
for _, r := range sh.Requests {
|
| 332 |
+
if r.VisitorToken == visitorToken {
|
| 333 |
+
return cloneShare(sh), r.Status == "approved", r.Status, r.VisitorName
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
}
|
| 337 |
+
return cloneShare(sh), false, "none", ""
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
func (s *ShareStore) RenamePath(oldPath, newPath string) {
|
| 341 |
+
s.mu.Lock()
|
| 342 |
+
defer s.mu.Unlock()
|
| 343 |
+
id, ok := s.byPath[oldPath]
|
| 344 |
+
if !ok {
|
| 345 |
+
return
|
| 346 |
+
}
|
| 347 |
+
delete(s.byPath, oldPath)
|
| 348 |
+
s.byPath[newPath] = id
|
| 349 |
+
if sh, exists := s.byID[id]; exists {
|
| 350 |
+
sh.Path = newPath
|
| 351 |
+
sh.FileName = filepath.Base(newPath)
|
| 352 |
+
sh.UpdatedAt = time.Now().Format("2006-01-02 15:04:05")
|
| 353 |
+
s.saveLocked()
|
| 354 |
+
if s.mongo != nil {
|
| 355 |
+
_ = s.mongo.UpsertShareDoc(*sh)
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
func (s *ShareStore) DeleteByPath(remotePath string) {
|
| 361 |
+
s.mu.Lock()
|
| 362 |
+
defer s.mu.Unlock()
|
| 363 |
+
id, ok := s.byPath[remotePath]
|
| 364 |
+
if !ok {
|
| 365 |
+
return
|
| 366 |
+
}
|
| 367 |
+
delete(s.byPath, remotePath)
|
| 368 |
+
delete(s.byID, id)
|
| 369 |
+
s.saveLocked()
|
| 370 |
+
if s.mongo != nil {
|
| 371 |
+
_ = s.mongo.DeleteShareDoc(id)
|
| 372 |
+
}
|
| 373 |
+
}
|
shares.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"id": "sh_311636d4626f",
|
| 4 |
+
"path": "thtuanit/snaptik.vn_7704550036016778516.mp4",
|
| 5 |
+
"file_name": "snaptik.vn_7704550036016778516.mp4",
|
| 6 |
+
"size": 107798414,
|
| 7 |
+
"owner": "thtuanit",
|
| 8 |
+
"enabled": true,
|
| 9 |
+
"require_approval": false,
|
| 10 |
+
"created_at": "2026-11-10 13:27:06",
|
| 11 |
+
"updated_at": "2026-11-10 13:27:51",
|
| 12 |
+
"requests": []
|
| 13 |
+
}
|
| 14 |
+
]
|
start.sh
CHANGED
|
@@ -1,5 +1,8 @@
|
|
| 1 |
-
#!/bin/
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
# Khởi chạy Next.js Standalone UI ở cổng nội bộ 3000
|
| 5 |
+
PORT=3000 HOSTNAME=127.0.0.1 node /app/frontend/server.js &
|
| 6 |
+
|
| 7 |
+
# Khởi chạy Go Backend + Reverse Proxy ở cổng chính 7860 của Hugging Face Spaces
|
| 8 |
+
exec /app/server
|
users.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"username": "admin",
|
| 4 |
+
"display_name": "Administrator",
|
| 5 |
+
"role": "admin",
|
| 6 |
+
"password_salt": "17bb7c53d6e305bf4876c3d9d7a53786",
|
| 7 |
+
"password_hash": "e90db3b3ec8ae3f8baca462c62e45b5d778592cd986b53e29cd08a48fdd89441",
|
| 8 |
+
"permissions": {
|
| 9 |
+
"can_upload": true,
|
| 10 |
+
"can_delete": true,
|
| 11 |
+
"can_rename": true
|
| 12 |
+
},
|
| 13 |
+
"active": true,
|
| 14 |
+
"created_at": "2026-11-10 11:26:53"
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"username": "user",
|
| 18 |
+
"display_name": "Khách hàng / User",
|
| 19 |
+
"role": "user",
|
| 20 |
+
"password_salt": "f26f69f6d53b285668bdbc889f083e6c",
|
| 21 |
+
"password_hash": "6465d1cf02e045ee7bc7a897d8eba4724a5a424b85849235fecae597f3e5344d",
|
| 22 |
+
"permissions": {
|
| 23 |
+
"can_upload": true,
|
| 24 |
+
"can_delete": false,
|
| 25 |
+
"can_rename": false
|
| 26 |
+
},
|
| 27 |
+
"active": true,
|
| 28 |
+
"created_at": "2026-11-10 11:26:53"
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"username": "ThTuanIT",
|
| 32 |
+
"display_name": "Thanh Tuấn",
|
| 33 |
+
"role": "admin",
|
| 34 |
+
"password_salt": "95c50f606318041e362a03ab15be002d",
|
| 35 |
+
"password_hash": "55d572729bee3c8af41eb3f543e93b2b0f5fbe868b08fa770d6a8afeedf7296f",
|
| 36 |
+
"permissions": {
|
| 37 |
+
"can_upload": true,
|
| 38 |
+
"can_delete": true,
|
| 39 |
+
"can_rename": true
|
| 40 |
+
},
|
| 41 |
+
"active": true,
|
| 42 |
+
"created_at": "2026-11-10 12:06:11"
|
| 43 |
+
}
|
| 44 |
+
]
|
web/index.html
ADDED
|
@@ -0,0 +1,1266 @@
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="vi" class="dark">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>XetCloud Studio — Hugging Face Bucket Storage</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://unpkg.com/lucide@latest"></script>
|
| 9 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 10 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 11 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
|
| 12 |
+
<script>
|
| 13 |
+
tailwind.config = {
|
| 14 |
+
darkMode: 'class',
|
| 15 |
+
theme: {
|
| 16 |
+
extend: {
|
| 17 |
+
fontFamily: {
|
| 18 |
+
sans: ['Inter', 'sans-serif'],
|
| 19 |
+
mono: ['JetBrains Mono', 'monospace'],
|
| 20 |
+
},
|
| 21 |
+
colors: {
|
| 22 |
+
space: {
|
| 23 |
+
950: '#05070f',
|
| 24 |
+
900: '#0a0e1a',
|
| 25 |
+
800: '#111827',
|
| 26 |
+
700: '#1e293b',
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
</script>
|
| 33 |
+
<style>
|
| 34 |
+
body {
|
| 35 |
+
background-color: #05070f;
|
| 36 |
+
color: #f8fafc;
|
| 37 |
+
overflow-x: hidden;
|
| 38 |
+
}
|
| 39 |
+
/* Ambient Mesh Glow */
|
| 40 |
+
.bg-mesh {
|
| 41 |
+
background-image:
|
| 42 |
+
radial-gradient(at 15% 10%, rgba(99, 102, 241, 0.16) 0px, transparent 45%),
|
| 43 |
+
radial-gradient(at 85% 15%, rgba(245, 158, 11, 0.12) 0px, transparent 45%),
|
| 44 |
+
radial-gradient(at 50% 85%, rgba(16, 185, 129, 0.10) 0px, transparent 50%);
|
| 45 |
+
}
|
| 46 |
+
.glass {
|
| 47 |
+
background: rgba(15, 23, 42, 0.65);
|
| 48 |
+
backdrop-filter: blur(20px);
|
| 49 |
+
-webkit-backdrop-filter: blur(20px);
|
| 50 |
+
border: 1px solid rgba(255, 255, 255, 0.08);
|
| 51 |
+
}
|
| 52 |
+
.glass-card {
|
| 53 |
+
background: linear-gradient(145deg, rgba(30, 41, 59, 0.55), rgba(15, 23, 42, 0.75));
|
| 54 |
+
backdrop-filter: blur(16px);
|
| 55 |
+
border: 1px solid rgba(255, 255, 255, 0.07);
|
| 56 |
+
transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
|
| 57 |
+
}
|
| 58 |
+
.glass-card:hover {
|
| 59 |
+
border-color: rgba(99, 102, 241, 0.45);
|
| 60 |
+
transform: translateY(-2px);
|
| 61 |
+
box-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.5), 0 0 20px -4px rgba(99, 102, 241, 0.2);
|
| 62 |
+
}
|
| 63 |
+
.drop-active {
|
| 64 |
+
border-color: #6366f1 !important;
|
| 65 |
+
background: rgba(99, 102, 241, 0.12) !important;
|
| 66 |
+
box-shadow: 0 0 35px rgba(99, 102, 241, 0.25);
|
| 67 |
+
}
|
| 68 |
+
/* Custom Scrollbar */
|
| 69 |
+
::-webkit-scrollbar { width: 6px; height: 6px; }
|
| 70 |
+
::-webkit-scrollbar-track { background: #05070f; }
|
| 71 |
+
::-webkit-scrollbar-thumb { background: #1e293b; border-radius: 9999px; }
|
| 72 |
+
::-webkit-scrollbar-thumb:hover { background: #475569; }
|
| 73 |
+
|
| 74 |
+
@keyframes pulse-slow {
|
| 75 |
+
0%, 100% { opacity: 1; }
|
| 76 |
+
50% { opacity: 0.45; }
|
| 77 |
+
}
|
| 78 |
+
.animate-pulse-slow { animation: pulse-slow 2.5s infinite; }
|
| 79 |
+
</style>
|
| 80 |
+
</head>
|
| 81 |
+
<body class="min-h-screen bg-mesh font-sans antialiased selection:bg-indigo-500 selection:text-white flex flex-col">
|
| 82 |
+
|
| 83 |
+
<!-- TOP NAVBAR -->
|
| 84 |
+
<header class="sticky top-0 z-30 glass border-b border-white/10">
|
| 85 |
+
<div class="max-w-[1600px] mx-auto px-4 sm:px-8 h-16 flex items-center justify-between gap-4">
|
| 86 |
+
<!-- Brand -->
|
| 87 |
+
<div class="flex items-center gap-3.5">
|
| 88 |
+
<div class="w-10 h-10 rounded-xl bg-gradient-to-br from-indigo-500 via-purple-500 to-amber-500 p-[1px] shadow-lg shadow-indigo-500/20">
|
| 89 |
+
<div class="w-full h-full bg-space-900 rounded-[11px] flex items-center justify-center">
|
| 90 |
+
<span class="text-xl">🤗</span>
|
| 91 |
+
</div>
|
| 92 |
+
</div>
|
| 93 |
+
<div>
|
| 94 |
+
<div class="flex items-center gap-2">
|
| 95 |
+
<h1 class="font-bold text-base sm:text-lg tracking-tight bg-gradient-to-r from-white via-slate-200 to-indigo-300 bg-clip-text text-transparent">
|
| 96 |
+
XetCloud Studio
|
| 97 |
+
</h1>
|
| 98 |
+
<span class="hidden sm:inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-mono font-semibold uppercase tracking-wider bg-indigo-500/15 text-indigo-300 border border-indigo-500/30">
|
| 99 |
+
HF Xet Engine
|
| 100 |
+
</span>
|
| 101 |
+
</div>
|
| 102 |
+
<p class="text-xs text-slate-400 font-mono" id="bucketBadge">bucket: loading...</p>
|
| 103 |
+
</div>
|
| 104 |
+
</div>
|
| 105 |
+
|
| 106 |
+
<!-- Global Search -->
|
| 107 |
+
<div class="flex-1 max-w-md hidden md:block">
|
| 108 |
+
<div class="relative">
|
| 109 |
+
<i data-lucide="search" class="w-4 h-4 text-slate-400 absolute left-3.5 top-1/2 -translate-y-1/2 pointer-events-none"></i>
|
| 110 |
+
<input
|
| 111 |
+
id="searchInput"
|
| 112 |
+
type="text"
|
| 113 |
+
placeholder="Tìm kiếm nhanh file hoặc thư mục... (Ctrl + K)"
|
| 114 |
+
class="w-full bg-slate-900/80 border border-white/10 focus:border-indigo-500/70 rounded-xl pl-10 pr-12 py-2 text-sm text-slate-100 placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20 transition"
|
| 115 |
+
/>
|
| 116 |
+
<kbd class="absolute right-3 top-1/2 -translate-y-1/2 text-[10px] font-mono text-slate-400 bg-slate-800 px-1.5 py-0.5 rounded border border-white/10">⌘K</kbd>
|
| 117 |
+
</div>
|
| 118 |
+
</div>
|
| 119 |
+
|
| 120 |
+
<!-- Status & Actions -->
|
| 121 |
+
<div class="flex items-center gap-2.5">
|
| 122 |
+
<!-- Health Pill -->
|
| 123 |
+
<div id="healthBadge" class="hidden sm:flex items-center gap-2 px-3 py-1.5 rounded-xl bg-slate-900/90 border border-white/10 text-xs font-medium text-slate-300">
|
| 124 |
+
<span id="healthDot" class="w-2 h-2 rounded-full bg-amber-400 animate-pulse"></span>
|
| 125 |
+
<span id="healthText">Checking CLI...</span>
|
| 126 |
+
</div>
|
| 127 |
+
|
| 128 |
+
<!-- Upload Trigger Button -->
|
| 129 |
+
<button onclick="openUploadModal()" class="flex items-center gap-2 px-3.5 py-2 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 hover:from-indigo-500 hover:to-violet-500 text-white font-medium text-xs sm:text-sm shadow-lg shadow-indigo-600/25 transition active:scale-95">
|
| 130 |
+
<i data-lucide="upload-cloud" class="w-4 h-4"></i>
|
| 131 |
+
<span>Tải lên</span>
|
| 132 |
+
</button>
|
| 133 |
+
|
| 134 |
+
<!-- API Key Config Button -->
|
| 135 |
+
<button onclick="openAuthModal()" id="authBtn" class="flex items-center gap-2 px-3 py-2 rounded-xl bg-slate-900/90 hover:bg-slate-800 border border-white/10 text-xs sm:text-sm text-slate-300 transition" title="Cấu hình API Key">
|
| 136 |
+
<i data-lucide="key-round" class="w-4 h-4 text-amber-400"></i>
|
| 137 |
+
<span id="authStatusText" class="hidden lg:inline">API Key</span>
|
| 138 |
+
</button>
|
| 139 |
+
|
| 140 |
+
<!-- Refresh -->
|
| 141 |
+
<button onclick="loadFiles(true)" class="p-2 rounded-xl bg-slate-900/90 hover:bg-slate-800 border border-white/10 text-slate-300 hover:text-white transition" title="Làm mới (R)">
|
| 142 |
+
<i data-lucide="refresh-cw" id="refreshIcon" class="w-4 h-4"></i>
|
| 143 |
+
</button>
|
| 144 |
+
</div>
|
| 145 |
+
</div>
|
| 146 |
+
</header>
|
| 147 |
+
|
| 148 |
+
<!-- MAIN WORKSPACE -->
|
| 149 |
+
<div class="max-w-[1600px] w-full mx-auto px-4 sm:px-8 py-6 flex-1 grid grid-cols-1 lg:grid-cols-12 gap-6">
|
| 150 |
+
|
| 151 |
+
<!-- LEFT SIDEBAR: STORAGE STATS & QUICK FILTERS -->
|
| 152 |
+
<aside class="lg:col-span-3 space-y-5">
|
| 153 |
+
<!-- Storage Overview Card -->
|
| 154 |
+
<div class="glass rounded-2xl p-5 relative overflow-hidden">
|
| 155 |
+
<div class="absolute -right-8 -top-8 w-32 h-32 bg-indigo-500/15 rounded-full blur-2xl pointer-events-none"></div>
|
| 156 |
+
<div class="flex items-center justify-between mb-4">
|
| 157 |
+
<span class="text-xs font-semibold uppercase tracking-wider text-slate-400">Dung lượng Bucket</span>
|
| 158 |
+
<span class="px-2 py-0.5 text-[11px] font-mono rounded-md bg-emerald-500/15 text-emerald-300 border border-emerald-500/30">Active</span>
|
| 159 |
+
</div>
|
| 160 |
+
<div class="flex items-baseline gap-2 mb-1">
|
| 161 |
+
<span id="statTotalSize" class="text-3xl font-extrabold tracking-tight text-white">0 B</span>
|
| 162 |
+
<span class="text-xs text-slate-400 font-mono">/ 10 GiB max upload</span>
|
| 163 |
+
</div>
|
| 164 |
+
<p class="text-xs text-slate-400 mb-4">Tổng cộng <strong id="statTotalFiles" class="text-slate-200">0</strong> tệp tin trên đám mây</p>
|
| 165 |
+
|
| 166 |
+
<!-- Category Breakdown Bar -->
|
| 167 |
+
<div class="w-full h-2 rounded-full bg-slate-800 overflow-hidden flex gap-0.5 mb-4">
|
| 168 |
+
<div id="barVideo" class="bg-rose-500 h-full transition-all duration-500" style="width: 0%"></div>
|
| 169 |
+
<div id="barImage" class="bg-indigo-500 h-full transition-all duration-500" style="width: 0%"></div>
|
| 170 |
+
<div id="barArchive" class="bg-amber-500 h-full transition-all duration-500" style="width: 0%"></div>
|
| 171 |
+
<div id="barOther" class="bg-emerald-500 h-full transition-all duration-500" style="width: 0%"></div>
|
| 172 |
+
</div>
|
| 173 |
+
|
| 174 |
+
<div class="grid grid-cols-2 gap-2 text-xs">
|
| 175 |
+
<div class="flex items-center gap-2 text-slate-300">
|
| 176 |
+
<span class="w-2 h-2 rounded-full bg-rose-500"></span>
|
| 177 |
+
<span>Video:</span>
|
| 178 |
+
<span id="countVideo" class="font-mono text-slate-400 ml-auto">0</span>
|
| 179 |
+
</div>
|
| 180 |
+
<div class="flex items-center gap-2 text-slate-300">
|
| 181 |
+
<span class="w-2 h-2 rounded-full bg-indigo-500"></span>
|
| 182 |
+
<span>Hình ảnh:</span>
|
| 183 |
+
<span id="countImage" class="font-mono text-slate-400 ml-auto">0</span>
|
| 184 |
+
</div>
|
| 185 |
+
<div class="flex items-center gap-2 text-slate-300">
|
| 186 |
+
<span class="w-2 h-2 rounded-full bg-amber-500"></span>
|
| 187 |
+
<span>Nén/Archive:</span>
|
| 188 |
+
<span id="countArchive" class="font-mono text-slate-400 ml-auto">0</span>
|
| 189 |
+
</div>
|
| 190 |
+
<div class="flex items-center gap-2 text-slate-300">
|
| 191 |
+
<span class="w-2 h-2 rounded-full bg-emerald-500"></span>
|
| 192 |
+
<span>Tài liệu/Khác:</span>
|
| 193 |
+
<span id="countOther" class="font-mono text-slate-400 ml-auto">0</span>
|
| 194 |
+
</div>
|
| 195 |
+
</div>
|
| 196 |
+
</div>
|
| 197 |
+
|
| 198 |
+
<!-- Navigation / Category Filter -->
|
| 199 |
+
<div class="glass rounded-2xl p-3 space-y-1">
|
| 200 |
+
<div class="px-3 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-slate-400">Bộ lọc thông minh</div>
|
| 201 |
+
<button onclick="setCategory('all')" id="nav-all" class="nav-btn w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-sm font-medium bg-indigo-600/20 text-indigo-300 border border-indigo-500/30 transition">
|
| 202 |
+
<span class="flex items-center gap-2.5"><i data-lucide="folder-kanban" class="w-4 h-4"></i> Tất cả tệp tin</span>
|
| 203 |
+
<span id="badge-all" class="text-xs font-mono px-2 py-0.5 rounded-md bg-white/10">0</span>
|
| 204 |
+
</button>
|
| 205 |
+
<button onclick="setCategory('video')" id="nav-video" class="nav-btn w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-sm font-medium text-slate-300 hover:bg-white/5 transition">
|
| 206 |
+
<span class="flex items-center gap-2.5"><i data-lucide="film" class="w-4 h-4 text-rose-400"></i> Video & Media</span>
|
| 207 |
+
<span id="badge-video" class="text-xs font-mono px-2 py-0.5 rounded-md bg-white/5">0</span>
|
| 208 |
+
</button>
|
| 209 |
+
<button onclick="setCategory('image')" id="nav-image" class="nav-btn w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-sm font-medium text-slate-300 hover:bg-white/5 transition">
|
| 210 |
+
<span class="flex items-center gap-2.5"><i data-lucide="image" class="w-4 h-4 text-indigo-400"></i> Hình ảnh</span>
|
| 211 |
+
<span id="badge-image" class="text-xs font-mono px-2 py-0.5 rounded-md bg-white/5">0</span>
|
| 212 |
+
</button>
|
| 213 |
+
<button onclick="setCategory('archive')" id="nav-archive" class="nav-btn w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-sm font-medium text-slate-300 hover:bg-white/5 transition">
|
| 214 |
+
<span class="flex items-center gap-2.5"><i data-lucide="archive" class="w-4 h-4 text-amber-400"></i> File nén (.zip, .tar)</span>
|
| 215 |
+
<span id="badge-archive" class="text-xs font-mono px-2 py-0.5 rounded-md bg-white/5">0</span>
|
| 216 |
+
</button>
|
| 217 |
+
<button onclick="setCategory('doc')" id="nav-doc" class="nav-btn w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-sm font-medium text-slate-300 hover:bg-white/5 transition">
|
| 218 |
+
<span class="flex items-center gap-2.5"><i data-lucide="file-code-2" class="w-4 h-4 text-emerald-400"></i> Tài liệu & Code</span>
|
| 219 |
+
<span id="badge-doc" class="text-xs font-mono px-2 py-0.5 rounded-md bg-white/5">0</span>
|
| 220 |
+
</button>
|
| 221 |
+
</div>
|
| 222 |
+
|
| 223 |
+
<!-- Quick Dropzone Card -->
|
| 224 |
+
<div
|
| 225 |
+
id="quickDropzone"
|
| 226 |
+
onclick="openUploadModal()"
|
| 227 |
+
class="glass rounded-2xl p-5 border-2 border-dashed border-indigo-500/30 hover:border-indigo-400/70 transition cursor-pointer group text-center"
|
| 228 |
+
>
|
| 229 |
+
<div class="w-12 h-12 rounded-2xl bg-indigo-500/15 border border-indigo-500/30 flex items-center justify-center mx-auto mb-3 group-hover:scale-110 transition">
|
| 230 |
+
<i data-lucide="cloud-upload" class="w-6 h-6 text-indigo-400"></i>
|
| 231 |
+
</div>
|
| 232 |
+
<p class="text-sm font-semibold text-slate-200 mb-1">Kéo & Thả file vào đây</p>
|
| 233 |
+
<p class="text-xs text-slate-400">Hỗ trợ tải nhiều file cùng lúc qua giao thức Xet tốc độ cao</p>
|
| 234 |
+
</div>
|
| 235 |
+
</aside>
|
| 236 |
+
|
| 237 |
+
<!-- RIGHT MAIN EXPLORER -->
|
| 238 |
+
<main class="lg:col-span-9 flex flex-col space-y-4">
|
| 239 |
+
<!-- Explorer Toolbar -->
|
| 240 |
+
<div class="glass rounded-2xl p-3.5 sm:px-5 flex flex-wrap items-center justify-between gap-3">
|
| 241 |
+
<!-- Breadcrumbs -->
|
| 242 |
+
<div id="breadcrumbs" class="flex items-center gap-1.5 text-sm overflow-x-auto py-1">
|
| 243 |
+
<!-- Populated by JS -->
|
| 244 |
+
</div>
|
| 245 |
+
|
| 246 |
+
<!-- Controls: Prefix filter, Sort, View switcher -->
|
| 247 |
+
<div class="flex items-center gap-2 ml-auto">
|
| 248 |
+
<!-- Mobile search -->
|
| 249 |
+
<div class="relative md:hidden">
|
| 250 |
+
<input
|
| 251 |
+
id="mobileSearchInput"
|
| 252 |
+
type="text"
|
| 253 |
+
placeholder="Lọc tên file..."
|
| 254 |
+
class="w-36 bg-slate-900/90 border border-white/10 rounded-xl px-3 py-1.5 text-xs text-slate-100 focus:outline-none"
|
| 255 |
+
/>
|
| 256 |
+
</div>
|
| 257 |
+
|
| 258 |
+
<!-- Sort Dropdown -->
|
| 259 |
+
<select id="sortSelect" onchange="renderExplorer()" class="bg-slate-900/90 border border-white/10 rounded-xl px-3 py-1.5 text-xs text-slate-200 focus:outline-none focus:border-indigo-500 cursor-pointer">
|
| 260 |
+
<option value="date_desc">Mới nhất trước</option>
|
| 261 |
+
<option value="size_desc">Dung lượng giảm dần</option>
|
| 262 |
+
<option value="size_asc">Dung lượng tăng dần</option>
|
| 263 |
+
<option value="name_asc">Tên A → Z</option>
|
| 264 |
+
</select>
|
| 265 |
+
|
| 266 |
+
<!-- View Switcher -->
|
| 267 |
+
<div class="flex items-center bg-slate-900/90 p-1 rounded-xl border border-white/10">
|
| 268 |
+
<button onclick="setViewMode('grid')" id="viewGridBtn" class="p-1.5 rounded-lg bg-indigo-600 text-white transition" title="Chế độ Lưới">
|
| 269 |
+
<i data-lucide="layout-grid" class="w-4 h-4"></i>
|
| 270 |
+
</button>
|
| 271 |
+
<button onclick="setViewMode('list')" id="viewListBtn" class="p-1.5 rounded-lg text-slate-400 hover:text-white transition" title="Chế độ Danh sách">
|
| 272 |
+
<i data-lucide="list" class="w-4 h-4"></i>
|
| 273 |
+
</button>
|
| 274 |
+
</div>
|
| 275 |
+
</div>
|
| 276 |
+
</div>
|
| 277 |
+
|
| 278 |
+
<!-- Active Upload Queue Banner (Hidden when idle) -->
|
| 279 |
+
<div id="uploadQueuePanel" class="hidden glass rounded-2xl p-4 border border-indigo-500/40 space-y-3">
|
| 280 |
+
<div class="flex items-center justify-between">
|
| 281 |
+
<div class="flex items-center gap-2 text-sm font-semibold text-indigo-300">
|
| 282 |
+
<i data-lucide="loader-2" class="w-4 h-4 animate-spin"></i>
|
| 283 |
+
<span>Tiến trình tải lên Hugging Face Bucket</span>
|
| 284 |
+
</div>
|
| 285 |
+
<span id="uploadQueueSummary" class="text-xs font-mono text-slate-400">0/0 hoàn tất</span>
|
| 286 |
+
</div>
|
| 287 |
+
<div id="uploadQueueList" class="space-y-2 max-h-44 overflow-y-auto pr-1"></div>
|
| 288 |
+
</div>
|
| 289 |
+
|
| 290 |
+
<!-- File Explorer Container -->
|
| 291 |
+
<div id="explorerContainer" class="glass rounded-2xl p-5 flex-1 min-h-[480px] flex flex-col justify-between relative">
|
| 292 |
+
<!-- Loading Skeleton -->
|
| 293 |
+
<div id="loadingSkeleton" class="hidden grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4">
|
| 294 |
+
<div class="h-36 rounded-2xl bg-slate-800/50 animate-pulse border border-white/5"></div>
|
| 295 |
+
<div class="h-36 rounded-2xl bg-slate-800/50 animate-pulse border border-white/5"></div>
|
| 296 |
+
<div class="h-36 rounded-2xl bg-slate-800/50 animate-pulse border border-white/5"></div>
|
| 297 |
+
<div class="h-36 rounded-2xl bg-slate-800/50 animate-pulse border border-white/5"></div>
|
| 298 |
+
<div class="h-36 rounded-2xl bg-slate-800/50 animate-pulse border border-white/5"></div>
|
| 299 |
+
<div class="h-36 rounded-2xl bg-slate-800/50 animate-pulse border border-white/5"></div>
|
| 300 |
+
</div>
|
| 301 |
+
|
| 302 |
+
<!-- Folders + Files Dynamic Area -->
|
| 303 |
+
<div id="explorerContent" class="space-y-6"></div>
|
| 304 |
+
|
| 305 |
+
<!-- Empty State -->
|
| 306 |
+
<div id="emptyState" class="hidden my-auto py-16 text-center">
|
| 307 |
+
<div class="w-16 h-16 rounded-3xl bg-slate-800/80 border border-white/10 flex items-center justify-center mx-auto mb-4 text-slate-400">
|
| 308 |
+
<i data-lucide="folder-open" class="w-8 h-8"></i>
|
| 309 |
+
</div>
|
| 310 |
+
<h3 class="text-base font-semibold text-slate-200 mb-1">Không tìm thấy tệp tin nào</h3>
|
| 311 |
+
<p class="text-xs text-slate-400 max-w-sm mx-auto mb-5">Thư mục này đang trống hoặc không có tệp nào khớp với bộ lọc tìm kiếm hiện tại.</p>
|
| 312 |
+
<button onclick="openUploadModal()" class="inline-flex items-center gap-2 px-4 py-2 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-white text-xs font-semibold transition">
|
| 313 |
+
<i data-lucide="plus" class="w-4 h-4"></i> Tải tệp đầu tiên lên
|
| 314 |
+
</button>
|
| 315 |
+
</div>
|
| 316 |
+
|
| 317 |
+
<!-- Footer Status Bar -->
|
| 318 |
+
<div class="mt-6 pt-3 border-t border-white/5 flex items-center justify-between text-[11px] text-slate-400 font-mono">
|
| 319 |
+
<span id="explorerFooterLeft">Sẵn sàng</span>
|
| 320 |
+
<span id="explorerFooterRight">Xet Storage Engine • Go REST API</span>
|
| 321 |
+
</div>
|
| 322 |
+
</div>
|
| 323 |
+
</main>
|
| 324 |
+
</div>
|
| 325 |
+
|
| 326 |
+
<!-- ================= MODALS ================= -->
|
| 327 |
+
|
| 328 |
+
<!-- 1. UPLOAD MODAL -->
|
| 329 |
+
<div id="uploadModal" class="fixed inset-0 z-50 hidden items-center justify-center bg-black/75 backdrop-blur-sm p-4">
|
| 330 |
+
<div class="glass w-full max-w-lg rounded-3xl p-6 border border-white/15 shadow-2xl relative animate-in fade-in zoom-in-95 duration-200">
|
| 331 |
+
<div class="flex items-center justify-between mb-5">
|
| 332 |
+
<div class="flex items-center gap-3">
|
| 333 |
+
<div class="w-10 h-10 rounded-2xl bg-indigo-500/20 border border-indigo-500/30 flex items-center justify-center text-indigo-400">
|
| 334 |
+
<i data-lucide="upload-cloud" class="w-5 h-5"></i>
|
| 335 |
+
</div>
|
| 336 |
+
<div>
|
| 337 |
+
<h3 class="text-base font-bold text-white">Tải tệp lên Bucket</h3>
|
| 338 |
+
<p class="text-xs text-slate-400">Truyền tải trực tiếp qua giao thức Hugging Face Xet</p>
|
| 339 |
+
</div>
|
| 340 |
+
</div>
|
| 341 |
+
<button onclick="closeUploadModal()" class="p-1.5 rounded-xl bg-white/5 hover:bg-white/10 text-slate-400 hover:text-white transition">
|
| 342 |
+
<i data-lucide="x" class="w-4 h-4"></i>
|
| 343 |
+
</button>
|
| 344 |
+
</div>
|
| 345 |
+
|
| 346 |
+
<div class="space-y-4">
|
| 347 |
+
<!-- Target Folder / Prefix -->
|
| 348 |
+
<div>
|
| 349 |
+
<label class="block text-xs font-medium text-slate-300 mb-1.5">Thư mục đích trên Bucket (tùy chọn)</label>
|
| 350 |
+
<div class="relative">
|
| 351 |
+
<i data-lucide="folder-git-2" class="w-4 h-4 text-slate-400 absolute left-3.5 top-1/2 -translate-y-1/2"></i>
|
| 352 |
+
<input
|
| 353 |
+
id="uploadFolderInput"
|
| 354 |
+
type="text"
|
| 355 |
+
placeholder="Ví dụ: videos/2026 hoặc để trống lưu ở gốc"
|
| 356 |
+
class="w-full bg-slate-900/90 border border-white/10 focus:border-indigo-500 rounded-xl pl-10 pr-4 py-2.5 text-sm text-white placeholder-slate-500 focus:outline-none font-mono"
|
| 357 |
+
/>
|
| 358 |
+
</div>
|
| 359 |
+
</div>
|
| 360 |
+
|
| 361 |
+
<!-- File Drop Area -->
|
| 362 |
+
<label
|
| 363 |
+
id="modalDropzone"
|
| 364 |
+
class="flex flex-col items-center justify-center p-8 border-2 border-dashed border-white/15 hover:border-indigo-500/60 rounded-2xl bg-slate-900/50 cursor-pointer transition"
|
| 365 |
+
>
|
| 366 |
+
<input id="fileInput" type="file" multiple class="hidden" onchange="handleFileSelect(this.files)" />
|
| 367 |
+
<i data-lucide="file-up" class="w-10 h-10 text-indigo-400 mb-2.5"></i>
|
| 368 |
+
<span class="text-sm font-medium text-slate-200">Nhấn để chọn file hoặc kéo thả vào đây</span>
|
| 369 |
+
<span class="text-xs text-slate-400 mt-1">Hỗ trợ chọn nhiều file cùng lúc (Tối đa 10 GiB/file)</span>
|
| 370 |
+
</label>
|
| 371 |
+
|
| 372 |
+
<!-- Selected Files Preview -->
|
| 373 |
+
<div id="selectedFilesList" class="hidden space-y-1.5 max-h-40 overflow-y-auto pr-1"></div>
|
| 374 |
+
|
| 375 |
+
<div class="flex items-center justify-end gap-2.5 pt-2">
|
| 376 |
+
<button onclick="closeUploadModal()" class="px-4 py-2.5 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-medium text-slate-300 transition">
|
| 377 |
+
Hủy
|
| 378 |
+
</button>
|
| 379 |
+
<button id="startUploadBtn" onclick="startBatchUpload()" class="px-5 py-2.5 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 hover:from-indigo-500 hover:to-violet-500 text-xs font-semibold text-white shadow-lg shadow-indigo-600/30 transition flex items-center gap-2">
|
| 380 |
+
<i data-lucide="sparkles" class="w-4 h-4"></i>
|
| 381 |
+
<span>Bắt đầu tải lên</span>
|
| 382 |
+
</button>
|
| 383 |
+
</div>
|
| 384 |
+
</div>
|
| 385 |
+
</div>
|
| 386 |
+
</div>
|
| 387 |
+
|
| 388 |
+
<!-- 2. MEDIA PREVIEW & FILE INSPECTOR MODAL -->
|
| 389 |
+
<div id="previewModal" class="fixed inset-0 z-50 hidden items-center justify-center bg-black/80 backdrop-blur-md p-4">
|
| 390 |
+
<div class="glass w-full max-w-4xl rounded-3xl overflow-hidden border border-white/15 shadow-2xl flex flex-col max-h-[90vh]">
|
| 391 |
+
<!-- Modal Header -->
|
| 392 |
+
<div class="px-6 py-4 border-b border-white/10 flex items-center justify-between gap-4">
|
| 393 |
+
<div class="flex items-center gap-3 min-w-0">
|
| 394 |
+
<div id="previewIconBox" class="w-9 h-9 rounded-xl bg-indigo-500/20 flex items-center justify-center text-indigo-400 shrink-0">
|
| 395 |
+
<i data-lucide="file" class="w-5 h-5"></i>
|
| 396 |
+
</div>
|
| 397 |
+
<div class="min-w-0">
|
| 398 |
+
<h3 id="previewTitle" class="text-sm sm:text-base font-bold text-white truncate">filename.mp4</h3>
|
| 399 |
+
<p id="previewSubtitle" class="text-xs text-slate-400 font-mono truncate">46.7 MB • 2026-09-15</p>
|
| 400 |
+
</div>
|
| 401 |
+
</div>
|
| 402 |
+
<div class="flex items-center gap-2 shrink-0">
|
| 403 |
+
<button id="previewCopyCurlBtn" class="px-3 py-1.5 rounded-xl bg-white/5 hover:bg-white/10 text-xs font-mono text-slate-300 flex items-center gap-1.5 transition" title="Copy lệnh cURL tải file">
|
| 404 |
+
<i data-lucide="terminal" class="w-3.5 h-3.5"></i> cURL
|
| 405 |
+
</button>
|
| 406 |
+
<button id="previewDownloadBtn" class="px-3.5 py-1.5 rounded-xl bg-indigo-600 hover:bg-indigo-500 text-xs font-semibold text-white flex items-center gap-1.5 transition">
|
| 407 |
+
<i data-lucide="download" class="w-3.5 h-3.5"></i> Tải xuống
|
| 408 |
+
</button>
|
| 409 |
+
<button id="previewDeleteBtn" class="p-1.5 rounded-xl bg-rose-500/15 hover:bg-rose-500/30 text-rose-400 transition" title="Xóa tệp tin">
|
| 410 |
+
<i data-lucide="trash-2" class="w-4 h-4"></i>
|
| 411 |
+
</button>
|
| 412 |
+
<button onclick="closePreviewModal()" class="p-1.5 rounded-xl bg-white/5 hover:bg-white/10 text-slate-400 hover:text-white transition">
|
| 413 |
+
<i data-lucide="x" class="w-4 h-4"></i>
|
| 414 |
+
</button>
|
| 415 |
+
</div>
|
| 416 |
+
</div>
|
| 417 |
+
|
| 418 |
+
<!-- Preview Body -->
|
| 419 |
+
<div id="previewBody" class="p-6 flex-1 overflow-auto flex items-center justify-center bg-space-950/60 min-h-[320px]">
|
| 420 |
+
<!-- Dynamic video / image / text / metadata card -->
|
| 421 |
+
</div>
|
| 422 |
+
</div>
|
| 423 |
+
</div>
|
| 424 |
+
|
| 425 |
+
<!-- 3. API KEY AUTH MODAL -->
|
| 426 |
+
<div id="authModal" class="fixed inset-0 z-50 hidden items-center justify-center bg-black/75 backdrop-blur-sm p-4">
|
| 427 |
+
<div class="glass w-full max-w-md rounded-3xl p-6 border border-white/15 shadow-2xl">
|
| 428 |
+
<div class="flex items-center justify-between mb-4">
|
| 429 |
+
<div class="flex items-center gap-3">
|
| 430 |
+
<div class="w-10 h-10 rounded-2xl bg-amber-500/20 border border-amber-500/30 flex items-center justify-center text-amber-400">
|
| 431 |
+
<i data-lucide="shield-check" class="w-5 h-5"></i>
|
| 432 |
+
</div>
|
| 433 |
+
<div>
|
| 434 |
+
<h3 class="text-base font-bold text-white">Xác thực API Key</h3>
|
| 435 |
+
<p class="text-xs text-slate-400">Bảo vệ kết nối tới Go Bucket Server</p>
|
| 436 |
+
</div>
|
| 437 |
+
</div>
|
| 438 |
+
<button onclick="closeAuthModal()" class="p-1.5 rounded-xl bg-white/5 hover:bg-white/10 text-slate-400 hover:text-white">
|
| 439 |
+
<i data-lucide="x" class="w-4 h-4"></i>
|
| 440 |
+
</button>
|
| 441 |
+
</div>
|
| 442 |
+
|
| 443 |
+
<p class="text-xs text-slate-300 mb-4 leading-relaxed">
|
| 444 |
+
Nhập khóa <code class="text-amber-300 font-mono">API_KEY</code> được cấu hình trong file <code class="text-indigo-300 font-mono">.env</code> của server. Khóa được lưu cục bộ trên trình duyệt của bạn.
|
| 445 |
+
</p>
|
| 446 |
+
|
| 447 |
+
<div class="space-y-4">
|
| 448 |
+
<div class="relative">
|
| 449 |
+
<i data-lucide="key" class="w-4 h-4 text-slate-400 absolute left-3.5 top-1/2 -translate-y-1/2"></i>
|
| 450 |
+
<input
|
| 451 |
+
id="apiKeyInput"
|
| 452 |
+
type="password"
|
| 453 |
+
placeholder="Nhập API_KEY..."
|
| 454 |
+
class="w-full bg-slate-900 border border-white/15 focus:border-amber-400 rounded-xl pl-10 pr-10 py-2.5 text-sm text-white font-mono focus:outline-none"
|
| 455 |
+
/>
|
| 456 |
+
<button type="button" onclick="toggleApiKeyVisibility()" class="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-white">
|
| 457 |
+
<i data-lucide="eye" class="w-4 h-4"></i>
|
| 458 |
+
</button>
|
| 459 |
+
</div>
|
| 460 |
+
|
| 461 |
+
<div class="flex justify-end gap-2">
|
| 462 |
+
<button onclick="closeAuthModal()" class="px-4 py-2 rounded-xl bg-white/5 hover:bg-white/10 text-xs text-slate-300">Đóng</button>
|
| 463 |
+
<button onclick="saveApiKey()" class="px-5 py-2 rounded-xl bg-amber-500 hover:bg-amber-400 text-slate-950 font-semibold text-xs transition">
|
| 464 |
+
Lưu & Kết nối
|
| 465 |
+
</button>
|
| 466 |
+
</div>
|
| 467 |
+
</div>
|
| 468 |
+
</div>
|
| 469 |
+
</div>
|
| 470 |
+
|
| 471 |
+
<!-- TOAST CONTAINER -->
|
| 472 |
+
<div id="toastContainer" class="fixed bottom-5 right-5 z-50 flex flex-col gap-2.5 max-w-sm w-full pointer-events-none"></div>
|
| 473 |
+
|
| 474 |
+
<!-- APPLICATION SCRIPT -->
|
| 475 |
+
<script>
|
| 476 |
+
// --- STATE ---
|
| 477 |
+
const state = {
|
| 478 |
+
apiKey: localStorage.getItem('hf_bucket_api_key') || 'thtuanit207',
|
| 479 |
+
bucket: 'TwanAPI/ThTuan',
|
| 480 |
+
files: [], // [{ path, name, folder, size, updatedAt, ext, category }]
|
| 481 |
+
currentFolder: '', // '' is root
|
| 482 |
+
category: 'all',
|
| 483 |
+
search: '',
|
| 484 |
+
viewMode: localStorage.getItem('hf_view_mode') || 'grid',
|
| 485 |
+
selectedUploadFiles: [],
|
| 486 |
+
};
|
| 487 |
+
|
| 488 |
+
// --- UTILITIES ---
|
| 489 |
+
function formatBytes(bytes) {
|
| 490 |
+
if (!bytes || bytes === 0) return '0 B';
|
| 491 |
+
const k = 1024;
|
| 492 |
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
| 493 |
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 494 |
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
function getFileCategory(filename) {
|
| 498 |
+
const ext = (filename.split('.').pop() || '').toLowerCase();
|
| 499 |
+
if (['mp4', 'mkv', 'webm', 'mov', 'avi', 'mp3', 'wav', 'flac', 'ogg'].includes(ext)) return 'video';
|
| 500 |
+
if (['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'bmp', 'ico'].includes(ext)) return 'image';
|
| 501 |
+
if (['zip', 'rar', '7z', 'tar', 'gz', 'bz2', 'xz'].includes(ext)) return 'archive';
|
| 502 |
+
return 'doc';
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
function getCategoryMeta(cat, ext) {
|
| 506 |
+
switch (cat) {
|
| 507 |
+
case 'video':
|
| 508 |
+
return { icon: 'film', color: 'text-rose-400', bg: 'bg-rose-500/15', border: 'border-rose-500/30', label: ext.toUpperCase() || 'MEDIA' };
|
| 509 |
+
case 'image':
|
| 510 |
+
return { icon: 'image', color: 'text-indigo-400', bg: 'bg-indigo-500/15', border: 'border-indigo-500/30', label: ext.toUpperCase() || 'IMG' };
|
| 511 |
+
case 'archive':
|
| 512 |
+
return { icon: 'archive', color: 'text-amber-400', bg: 'bg-amber-500/15', border: 'border-amber-500/30', label: ext.toUpperCase() || 'ARCHIVE' };
|
| 513 |
+
default:
|
| 514 |
+
return { icon: 'file-code-2', color: 'text-emerald-400', bg: 'bg-emerald-500/15', border: 'border-emerald-500/30', label: ext.toUpperCase() || 'FILE' };
|
| 515 |
+
}
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
function showToast(message, type = 'info', detail = '') {
|
| 519 |
+
const container = document.getElementById('toastContainer');
|
| 520 |
+
const el = document.createElement('div');
|
| 521 |
+
const colors = {
|
| 522 |
+
success: 'border-emerald-500/40 bg-emerald-950/90 text-emerald-200',
|
| 523 |
+
error: 'border-rose-500/40 bg-rose-950/90 text-rose-200',
|
| 524 |
+
info: 'border-indigo-500/40 bg-slate-900/95 text-slate-200',
|
| 525 |
+
};
|
| 526 |
+
const icons = {
|
| 527 |
+
success: 'check-circle-2',
|
| 528 |
+
error: 'alert-triangle',
|
| 529 |
+
info: 'sparkles',
|
| 530 |
+
};
|
| 531 |
+
el.className = `pointer-events-auto glass px-4 py-3 rounded-2xl border shadow-xl flex items-start gap-3 transition-all duration-300 ${colors[type] || colors.info}`;
|
| 532 |
+
el.innerHTML = `
|
| 533 |
+
<i data-lucide="${icons[type] || 'info'}" class="w-5 h-5 shrink-0 mt-0.5"></i>
|
| 534 |
+
<div class="min-w-0 flex-1">
|
| 535 |
+
<p class="text-xs font-semibold">${message}</p>
|
| 536 |
+
${detail ? `<p class="text-[11px] opacity-80 font-mono truncate mt-0.5">${detail}</p>` : ''}
|
| 537 |
+
</div>
|
| 538 |
+
`;
|
| 539 |
+
container.appendChild(el);
|
| 540 |
+
lucide.createIcons({ nodes: [el] });
|
| 541 |
+
setTimeout(() => {
|
| 542 |
+
el.style.opacity = '0';
|
| 543 |
+
el.style.transform = 'translateY(8px)';
|
| 544 |
+
setTimeout(() => el.remove(), 300);
|
| 545 |
+
}, 4200);
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
// --- API CALLS ---
|
| 549 |
+
async function checkHealth() {
|
| 550 |
+
try {
|
| 551 |
+
const res = await fetch('/health');
|
| 552 |
+
const data = await res.json();
|
| 553 |
+
const dot = document.getElementById('healthDot');
|
| 554 |
+
const txt = document.getElementById('healthText');
|
| 555 |
+
if (data.ok) {
|
| 556 |
+
state.bucket = data.bucket || state.bucket;
|
| 557 |
+
document.getElementById('bucketBadge').textContent = `hf://buckets/${state.bucket}`;
|
| 558 |
+
dot.className = 'w-2 h-2 rounded-full bg-emerald-400 shadow-[0_0_8px_#34d399]';
|
| 559 |
+
txt.textContent = `hf CLI v${data.version}`;
|
| 560 |
+
} else {
|
| 561 |
+
dot.className = 'w-2 h-2 rounded-full bg-rose-500';
|
| 562 |
+
txt.textContent = 'CLI Offline';
|
| 563 |
+
}
|
| 564 |
+
} catch (e) {
|
| 565 |
+
document.getElementById('healthDot').className = 'w-2 h-2 rounded-full bg-rose-500';
|
| 566 |
+
document.getElementById('healthText').textContent = 'Server Offline';
|
| 567 |
+
}
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
async function loadFiles(showToastOnSuccess = false) {
|
| 571 |
+
const refreshIcon = document.getElementById('refreshIcon');
|
| 572 |
+
const skeleton = document.getElementById('loadingSkeleton');
|
| 573 |
+
const content = document.getElementById('explorerContent');
|
| 574 |
+
refreshIcon?.classList.add('animate-spin');
|
| 575 |
+
if (state.files.length === 0) {
|
| 576 |
+
skeleton.classList.remove('hidden');
|
| 577 |
+
content.classList.add('hidden');
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
try {
|
| 581 |
+
const res = await fetch('/api/files', {
|
| 582 |
+
headers: { 'X-API-Key': state.apiKey }
|
| 583 |
+
});
|
| 584 |
+
const data = await res.json();
|
| 585 |
+
|
| 586 |
+
if (res.status === 401) {
|
| 587 |
+
showToast('API Key không hợp lệ hoặc bị thiếu', 'error', 'Vui lòng nhập API_KEY của bạn');
|
| 588 |
+
openAuthModal();
|
| 589 |
+
return;
|
| 590 |
+
}
|
| 591 |
+
if (!res.ok) {
|
| 592 |
+
throw new Error(data.detail || data.error || 'Lỗi tải danh sách file');
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
state.bucket = data.bucket || state.bucket;
|
| 596 |
+
document.getElementById('bucketBadge').textContent = `hf://buckets/${state.bucket}`;
|
| 597 |
+
|
| 598 |
+
// Parse structured items if provided by backend, else fallback to entries
|
| 599 |
+
if (Array.isArray(data.items)) {
|
| 600 |
+
state.files = data.items.map(item => normalizeFileItem(item.path, item.size || 0, item.updated_at || ''));
|
| 601 |
+
} else if (Array.isArray(data.entries)) {
|
| 602 |
+
state.files = data.entries.map(line => normalizeFileItem(line, 0, ''));
|
| 603 |
+
} else {
|
| 604 |
+
state.files = [];
|
| 605 |
+
}
|
| 606 |
+
|
| 607 |
+
updateStats();
|
| 608 |
+
renderExplorer();
|
| 609 |
+
if (showToastOnSuccess) {
|
| 610 |
+
showToast('Đã đồng bộ dữ liệu Bucket', 'success', `${state.files.length} tệp tin hiện có`);
|
| 611 |
+
}
|
| 612 |
+
} catch (err) {
|
| 613 |
+
showToast('Không thể tải danh sách tệp', 'error', err.message);
|
| 614 |
+
} finally {
|
| 615 |
+
refreshIcon?.classList.remove('animate-spin');
|
| 616 |
+
skeleton.classList.add('hidden');
|
| 617 |
+
content.classList.remove('hidden');
|
| 618 |
+
}
|
| 619 |
+
}
|
| 620 |
+
|
| 621 |
+
function normalizeFileItem(rawPath, size, updatedAt) {
|
| 622 |
+
const cleanPath = rawPath.replace(/\\/g, '/').replace(/^\/+/, '');
|
| 623 |
+
const parts = cleanPath.split('/');
|
| 624 |
+
const name = parts.pop();
|
| 625 |
+
const folder = parts.join('/');
|
| 626 |
+
const ext = name.includes('.') ? name.split('.').pop().toLowerCase() : '';
|
| 627 |
+
const category = getFileCategory(name);
|
| 628 |
+
return { path: cleanPath, name, folder, size, updatedAt, ext, category };
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
function updateStats() {
|
| 632 |
+
const totalSize = state.files.reduce((acc, f) => acc + (f.size || 0), 0);
|
| 633 |
+
document.getElementById('statTotalSize').textContent = formatBytes(totalSize);
|
| 634 |
+
document.getElementById('statTotalFiles').textContent = state.files.length;
|
| 635 |
+
|
| 636 |
+
const counts = { video: 0, image: 0, archive: 0, doc: 0 };
|
| 637 |
+
const sizes = { video: 0, image: 0, archive: 0, doc: 0 };
|
| 638 |
+
state.files.forEach(f => {
|
| 639 |
+
counts[f.category] = (counts[f.category] || 0) + 1;
|
| 640 |
+
sizes[f.category] = (sizes[f.category] || 0) + (f.size || 1);
|
| 641 |
+
});
|
| 642 |
+
|
| 643 |
+
document.getElementById('countVideo').textContent = counts.video;
|
| 644 |
+
document.getElementById('countImage').textContent = counts.image;
|
| 645 |
+
document.getElementById('countArchive').textContent = counts.archive;
|
| 646 |
+
document.getElementById('countOther').textContent = counts.doc;
|
| 647 |
+
|
| 648 |
+
document.getElementById('badge-all').textContent = state.files.length;
|
| 649 |
+
document.getElementById('badge-video').textContent = counts.video;
|
| 650 |
+
document.getElementById('badge-image').textContent = counts.image;
|
| 651 |
+
document.getElementById('badge-archive').textContent = counts.archive;
|
| 652 |
+
document.getElementById('badge-doc').textContent = counts.doc;
|
| 653 |
+
|
| 654 |
+
const denom = Math.max(totalSize, state.files.length, 1);
|
| 655 |
+
const useSize = totalSize > 0;
|
| 656 |
+
document.getElementById('barVideo').style.width = `${((useSize ? sizes.video : counts.video) / denom) * 100}%`;
|
| 657 |
+
document.getElementById('barImage').style.width = `${((useSize ? sizes.image : counts.image) / denom) * 100}%`;
|
| 658 |
+
document.getElementById('barArchive').style.width = `${((useSize ? sizes.archive : counts.archive) / denom) * 100}%`;
|
| 659 |
+
document.getElementById('barOther').style.width = `${((useSize ? sizes.doc : counts.doc) / denom) * 100}%`;
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
// --- RENDERING EXPLORER ---
|
| 663 |
+
function renderBreadcrumbs() {
|
| 664 |
+
const container = document.getElementById('breadcrumbs');
|
| 665 |
+
const parts = state.currentFolder ? state.currentFolder.split('/') : [];
|
| 666 |
+
let html = `
|
| 667 |
+
<button onclick="navigateToFolder('')" class="flex items-center gap-1.5 px-2.5 py-1 rounded-lg ${parts.length === 0 ? 'bg-indigo-500/20 text-indigo-300 font-semibold' : 'text-slate-400 hover:text-white hover:bg-white/5'} transition">
|
| 668 |
+
<i data-lucide="hard-drive" class="w-3.5 h-3.5"></i>
|
| 669 |
+
<span>${state.bucket}</span>
|
| 670 |
+
</button>
|
| 671 |
+
`;
|
| 672 |
+
let acc = '';
|
| 673 |
+
parts.forEach((p, idx) => {
|
| 674 |
+
acc = acc ? `${acc}/${p}` : p;
|
| 675 |
+
const isLast = idx === parts.length - 1;
|
| 676 |
+
html += `
|
| 677 |
+
<i data-lucide="chevron-right" class="w-3.5 h-3.5 text-slate-600 shrink-0"></i>
|
| 678 |
+
<button onclick="navigateToFolder('${acc.replace(/'/g, "\\'")}')" class="px-2.5 py-1 rounded-lg ${isLast ? 'bg-indigo-500/20 text-indigo-300 font-semibold' : 'text-slate-400 hover:text-white hover:bg-white/5'} transition truncate max-w-[160px]">
|
| 679 |
+
${p}
|
| 680 |
+
</button>
|
| 681 |
+
`;
|
| 682 |
+
});
|
| 683 |
+
container.innerHTML = html;
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
function renderExplorer() {
|
| 687 |
+
renderBreadcrumbs();
|
| 688 |
+
const content = document.getElementById('explorerContent');
|
| 689 |
+
const empty = document.getElementById('emptyState');
|
| 690 |
+
const sortBy = document.getElementById('sortSelect').value;
|
| 691 |
+
const q = state.search.trim().toLowerCase();
|
| 692 |
+
|
| 693 |
+
// Determine subfolders when in folder navigation mode (only when category === 'all' and no search query)
|
| 694 |
+
const subfolders = new Map();
|
| 695 |
+
const matchingFiles = [];
|
| 696 |
+
|
| 697 |
+
state.files.forEach(file => {
|
| 698 |
+
if (state.category !== 'all' && file.category !== state.category) return;
|
| 699 |
+
if (q) {
|
| 700 |
+
if (file.path.toLowerCase().includes(q)) matchingFiles.push(file);
|
| 701 |
+
return;
|
| 702 |
+
}
|
| 703 |
+
if (state.category !== 'all') {
|
| 704 |
+
matchingFiles.push(file);
|
| 705 |
+
return;
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
// Hierarchy filtering inside currentFolder
|
| 709 |
+
if (state.currentFolder === '') {
|
| 710 |
+
if (file.folder === '') {
|
| 711 |
+
matchingFiles.push(file);
|
| 712 |
+
} else {
|
| 713 |
+
const topFolder = file.folder.split('/')[0];
|
| 714 |
+
const stat = subfolders.get(topFolder) || { count: 0, size: 0 };
|
| 715 |
+
stat.count += 1;
|
| 716 |
+
stat.size += file.size || 0;
|
| 717 |
+
subfolders.set(topFolder, stat);
|
| 718 |
+
}
|
| 719 |
+
} else if (file.folder === state.currentFolder) {
|
| 720 |
+
matchingFiles.push(file);
|
| 721 |
+
} else if (file.folder.startsWith(state.currentFolder + '/')) {
|
| 722 |
+
const rest = file.folder.slice(state.currentFolder.length + 1);
|
| 723 |
+
const nextFolder = rest.split('/')[0];
|
| 724 |
+
const fullSubPath = `${state.currentFolder}/${nextFolder}`;
|
| 725 |
+
const stat = subfolders.get(fullSubPath) || { name: nextFolder, count: 0, size: 0 };
|
| 726 |
+
stat.count += 1;
|
| 727 |
+
stat.size += file.size || 0;
|
| 728 |
+
subfolders.set(fullSubPath, stat);
|
| 729 |
+
}
|
| 730 |
+
});
|
| 731 |
+
|
| 732 |
+
// Sort files
|
| 733 |
+
matchingFiles.sort((a, b) => {
|
| 734 |
+
if (sortBy === 'size_desc') return (b.size || 0) - (a.size || 0);
|
| 735 |
+
if (sortBy === 'size_asc') return (a.size || 0) - (b.size || 0);
|
| 736 |
+
if (sortBy === 'name_asc') return a.name.localeCompare(b.name);
|
| 737 |
+
return (b.updatedAt || '').localeCompare(a.updatedAt || '');
|
| 738 |
+
});
|
| 739 |
+
|
| 740 |
+
if (subfolders.size === 0 && matchingFiles.length === 0) {
|
| 741 |
+
content.innerHTML = '';
|
| 742 |
+
empty.classList.remove('hidden');
|
| 743 |
+
document.getElementById('explorerFooterLeft').textContent = '0 mục';
|
| 744 |
+
lucide.createIcons();
|
| 745 |
+
return;
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
empty.classList.add('hidden');
|
| 749 |
+
let html = '';
|
| 750 |
+
|
| 751 |
+
// 1. Subfolders Section
|
| 752 |
+
if (subfolders.size > 0) {
|
| 753 |
+
html += `
|
| 754 |
+
<div>
|
| 755 |
+
<h4 class="text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3 flex items-center gap-2">
|
| 756 |
+
<i data-lucide="folder" class="w-3.5 h-3.5 text-amber-400"></i> Thư mục (${subfolders.size})
|
| 757 |
+
</h4>
|
| 758 |
+
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 xl:grid-cols-4 gap-3.5">
|
| 759 |
+
`;
|
| 760 |
+
for (const [folderPath, info] of subfolders.entries()) {
|
| 761 |
+
const displayName = info.name || folderPath;
|
| 762 |
+
html += `
|
| 763 |
+
<div onclick="navigateToFolder('${folderPath.replace(/'/g, "\\'")}')" class="glass-card rounded-2xl p-4 cursor-pointer flex items-center gap-3.5 group">
|
| 764 |
+
<div class="w-11 h-11 rounded-xl bg-amber-500/15 border border-amber-500/30 flex items-center justify-center text-amber-400 group-hover:scale-105 transition shrink-0">
|
| 765 |
+
<i data-lucide="folder" class="w-5 h-5 fill-amber-400/20"></i>
|
| 766 |
+
</div>
|
| 767 |
+
<div class="min-w-0 flex-1">
|
| 768 |
+
<p class="text-sm font-semibold text-slate-100 truncate group-hover:text-amber-300 transition">${displayName}</p>
|
| 769 |
+
<p class="text-xs text-slate-400 font-mono">${info.count} tệp • ${formatBytes(info.size)}</p>
|
| 770 |
+
</div>
|
| 771 |
+
<i data-lucide="chevron-right" class="w-4 h-4 text-slate-500 group-hover:text-slate-200 transition"></i>
|
| 772 |
+
</div>
|
| 773 |
+
`;
|
| 774 |
+
}
|
| 775 |
+
html += `</div></div>`;
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
// 2. Files Section
|
| 779 |
+
if (matchingFiles.length > 0) {
|
| 780 |
+
html += `
|
| 781 |
+
<div>
|
| 782 |
+
<h4 class="text-xs font-semibold uppercase tracking-wider text-slate-400 mb-3 flex items-center gap-2">
|
| 783 |
+
<i data-lucide="files" class="w-3.5 h-3.5 text-indigo-400"></i> Tệp tin (${matchingFiles.length})
|
| 784 |
+
</h4>
|
| 785 |
+
`;
|
| 786 |
+
|
| 787 |
+
if (state.viewMode === 'grid') {
|
| 788 |
+
html += `<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4">`;
|
| 789 |
+
matchingFiles.forEach(file => {
|
| 790 |
+
const meta = getCategoryMeta(file.category, file.ext);
|
| 791 |
+
const escapedPath = file.path.replace(/'/g, "\\'");
|
| 792 |
+
html += `
|
| 793 |
+
<div class="glass-card rounded-2xl p-4 flex flex-col justify-between group relative overflow-hidden">
|
| 794 |
+
<div onclick="openPreviewModal('${escapedPath}')" class="cursor-pointer">
|
| 795 |
+
<div class="flex items-start justify-between gap-3 mb-3">
|
| 796 |
+
<div class="w-11 h-11 rounded-xl ${meta.bg} border ${meta.border} flex items-center justify-center ${meta.color} shrink-0 group-hover:scale-105 transition">
|
| 797 |
+
<i data-lucide="${meta.icon}" class="w-5 h-5"></i>
|
| 798 |
+
</div>
|
| 799 |
+
<span class="px-2 py-0.5 rounded-md text-[10px] font-mono font-semibold ${meta.bg} ${meta.color} border ${meta.border}">
|
| 800 |
+
${meta.label}
|
| 801 |
+
</span>
|
| 802 |
+
</div>
|
| 803 |
+
<h5 class="text-sm font-semibold text-slate-100 truncate group-hover:text-indigo-300 transition" title="${file.path}">
|
| 804 |
+
${file.name}
|
| 805 |
+
</h5>
|
| 806 |
+
<p class="text-[11px] text-slate-400 font-mono truncate mt-0.5">
|
| 807 |
+
${file.folder ? `📁 ${file.folder}` : 'Root'}
|
| 808 |
+
</p>
|
| 809 |
+
</div>
|
| 810 |
+
|
| 811 |
+
<div class="mt-4 pt-3 border-t border-white/5 flex items-center justify-between text-xs text-slate-400">
|
| 812 |
+
<div class="font-mono text-[11px]">
|
| 813 |
+
<span class="text-slate-200 font-medium">${formatBytes(file.size)}</span>
|
| 814 |
+
${file.updatedAt ? `<span class="text-slate-500"> • ${file.updatedAt.split(' ')[0]}</span>` : ''}
|
| 815 |
+
</div>
|
| 816 |
+
<div class="flex items-center gap-1">
|
| 817 |
+
<button onclick="openPreviewModal('${escapedPath}')" class="p-1.5 rounded-lg hover:bg-white/10 text-slate-300 hover:text-white transition" title="Xem trước / Chi tiết">
|
| 818 |
+
<i data-lucide="eye" class="w-3.5 h-3.5"></i>
|
| 819 |
+
</button>
|
| 820 |
+
<button onclick="downloadFile('${escapedPath}')" class="p-1.5 rounded-lg hover:bg-indigo-500/20 text-indigo-400 hover:text-indigo-300 transition" title="Tải xuống">
|
| 821 |
+
<i data-lucide="download" class="w-3.5 h-3.5"></i>
|
| 822 |
+
</button>
|
| 823 |
+
<button onclick="deleteFile('${escapedPath}')" class="p-1.5 rounded-lg hover:bg-rose-500/20 text-rose-400 hover:text-rose-300 transition" title="Xóa file">
|
| 824 |
+
<i data-lucide="trash-2" class="w-3.5 h-3.5"></i>
|
| 825 |
+
</button>
|
| 826 |
+
</div>
|
| 827 |
+
</div>
|
| 828 |
+
</div>
|
| 829 |
+
`;
|
| 830 |
+
});
|
| 831 |
+
html += `</div>`;
|
| 832 |
+
} else {
|
| 833 |
+
// Table / List View
|
| 834 |
+
html += `
|
| 835 |
+
<div class="overflow-x-auto rounded-2xl border border-white/10">
|
| 836 |
+
<table class="w-full text-left border-collapse">
|
| 837 |
+
<thead>
|
| 838 |
+
<tr class="border-b border-white/10 text-[11px] font-semibold uppercase tracking-wider text-slate-400 bg-slate-900/60">
|
| 839 |
+
<th class="py-3 px-4">Tên tệp</th>
|
| 840 |
+
<th class="py-3 px-4 hidden md:table-cell">Đường dẫn</th>
|
| 841 |
+
<th class="py-3 px-4">Kích thước</th>
|
| 842 |
+
<th class="py-3 px-4 hidden sm:table-cell">Cập nhật</th>
|
| 843 |
+
<th class="py-3 px-4 text-right">Thao tác</th>
|
| 844 |
+
</tr>
|
| 845 |
+
</thead>
|
| 846 |
+
<tbody class="divide-y divide-white/5 text-sm">
|
| 847 |
+
`;
|
| 848 |
+
matchingFiles.forEach(file => {
|
| 849 |
+
const meta = getCategoryMeta(file.category, file.ext);
|
| 850 |
+
const escapedPath = file.path.replace(/'/g, "\\'");
|
| 851 |
+
html += `
|
| 852 |
+
<tr class="hover:bg-white/5 transition group">
|
| 853 |
+
<td onclick="openPreviewModal('${escapedPath}')" class="py-3 px-4 cursor-pointer">
|
| 854 |
+
<div class="flex items-center gap-3">
|
| 855 |
+
<div class="w-8 h-8 rounded-lg ${meta.bg} border ${meta.border} flex items-center justify-center ${meta.color} shrink-0">
|
| 856 |
+
<i data-lucide="${meta.icon}" class="w-4 h-4"></i>
|
| 857 |
+
</div>
|
| 858 |
+
<span class="font-medium text-slate-100 group-hover:text-indigo-300 transition truncate max-w-[240px]">${file.name}</span>
|
| 859 |
+
</div>
|
| 860 |
+
</td>
|
| 861 |
+
<td class="py-3 px-4 hidden md:table-cell font-mono text-xs text-slate-400">${file.folder || '/'}</td>
|
| 862 |
+
<td class="py-3 px-4 font-mono text-xs text-slate-200">${formatBytes(file.size)}</td>
|
| 863 |
+
<td class="py-3 px-4 hidden sm:table-cell font-mono text-xs text-slate-400">${file.updatedAt || '—'}</td>
|
| 864 |
+
<td class="py-3 px-4 text-right">
|
| 865 |
+
<div class="inline-flex items-center gap-1">
|
| 866 |
+
<button onclick="openPreviewModal('${escapedPath}')" class="p-1.5 rounded-lg hover:bg-white/10 text-slate-300" title="Xem">
|
| 867 |
+
<i data-lucide="eye" class="w-4 h-4"></i>
|
| 868 |
+
</button>
|
| 869 |
+
<button onclick="downloadFile('${escapedPath}')" class="p-1.5 rounded-lg hover:bg-indigo-500/20 text-indigo-400" title="Tải về">
|
| 870 |
+
<i data-lucide="download" class="w-4 h-4"></i>
|
| 871 |
+
</button>
|
| 872 |
+
<button onclick="deleteFile('${escapedPath}')" class="p-1.5 rounded-lg hover:bg-rose-500/20 text-rose-400" title="Xóa">
|
| 873 |
+
<i data-lucide="trash-2" class="w-4 h-4"></i>
|
| 874 |
+
</button>
|
| 875 |
+
</div>
|
| 876 |
+
</td>
|
| 877 |
+
</tr>
|
| 878 |
+
`;
|
| 879 |
+
});
|
| 880 |
+
html += `</tbody></table></div>`;
|
| 881 |
+
}
|
| 882 |
+
html += `</div>`;
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
content.innerHTML = html;
|
| 886 |
+
const shownSize = matchingFiles.reduce((acc, f) => acc + (f.size || 0), 0);
|
| 887 |
+
document.getElementById('explorerFooterLeft').textContent =
|
| 888 |
+
`Hiển thị ${subfolders.size} thư mục, ${matchingFiles.length} tệp tin (${formatBytes(shownSize)})`;
|
| 889 |
+
lucide.createIcons();
|
| 890 |
+
}
|
| 891 |
+
|
| 892 |
+
// --- NAVIGATION & FILTERS ---
|
| 893 |
+
function navigateToFolder(folderPath) {
|
| 894 |
+
state.currentFolder = folderPath;
|
| 895 |
+
state.category = 'all';
|
| 896 |
+
updateNavButtons();
|
| 897 |
+
renderExplorer();
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
function setCategory(cat) {
|
| 901 |
+
state.category = cat;
|
| 902 |
+
updateNavButtons();
|
| 903 |
+
renderExplorer();
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
function updateNavButtons() {
|
| 907 |
+
['all', 'video', 'image', 'archive', 'doc'].forEach(c => {
|
| 908 |
+
const btn = document.getElementById(`nav-${c}`);
|
| 909 |
+
if (!btn) return;
|
| 910 |
+
if (c === state.category) {
|
| 911 |
+
btn.className = 'nav-btn w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-sm font-medium bg-indigo-600/20 text-indigo-300 border border-indigo-500/30 transition';
|
| 912 |
+
} else {
|
| 913 |
+
btn.className = 'nav-btn w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-sm font-medium text-slate-300 hover:bg-white/5 transition';
|
| 914 |
+
}
|
| 915 |
+
});
|
| 916 |
+
}
|
| 917 |
+
|
| 918 |
+
function setViewMode(mode) {
|
| 919 |
+
state.viewMode = mode;
|
| 920 |
+
localStorage.setItem('hf_view_mode', mode);
|
| 921 |
+
const gridBtn = document.getElementById('viewGridBtn');
|
| 922 |
+
const listBtn = document.getElementById('viewListBtn');
|
| 923 |
+
if (mode === 'grid') {
|
| 924 |
+
gridBtn.className = 'p-1.5 rounded-lg bg-indigo-600 text-white transition';
|
| 925 |
+
listBtn.className = 'p-1.5 rounded-lg text-slate-400 hover:text-white transition';
|
| 926 |
+
} else {
|
| 927 |
+
listBtn.className = 'p-1.5 rounded-lg bg-indigo-600 text-white transition';
|
| 928 |
+
gridBtn.className = 'p-1.5 rounded-lg text-slate-400 hover:text-white transition';
|
| 929 |
+
}
|
| 930 |
+
renderExplorer();
|
| 931 |
+
}
|
| 932 |
+
|
| 933 |
+
// --- DOWNLOAD & DELETE & PREVIEW ---
|
| 934 |
+
function getDownloadUrl(path, inline = false) {
|
| 935 |
+
const params = new URLSearchParams({
|
| 936 |
+
path: path,
|
| 937 |
+
api_key: state.apiKey,
|
| 938 |
+
});
|
| 939 |
+
if (inline) params.set('inline', '1');
|
| 940 |
+
return `/api/download?${params.toString()}`;
|
| 941 |
+
}
|
| 942 |
+
|
| 943 |
+
function downloadFile(path) {
|
| 944 |
+
showToast('Đang chuẩn bị tải xuống từ Hugging Face...', 'info', path);
|
| 945 |
+
const a = document.createElement('a');
|
| 946 |
+
a.href = getDownloadUrl(path, false);
|
| 947 |
+
a.download = path.split('/').pop();
|
| 948 |
+
document.body.appendChild(a);
|
| 949 |
+
a.click();
|
| 950 |
+
a.remove();
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
async function deleteFile(path) {
|
| 954 |
+
if (!confirm(`Bạn có chắc chắn muốn xóa tệp "${path}" khỏi Bucket không?`)) return;
|
| 955 |
+
try {
|
| 956 |
+
showToast('Đang xóa tệp trên Bucket...', 'info', path);
|
| 957 |
+
const res = await fetch(`/api/files?path=${encodeURIComponent(path)}`, {
|
| 958 |
+
method: 'DELETE',
|
| 959 |
+
headers: { 'X-API-Key': state.apiKey }
|
| 960 |
+
});
|
| 961 |
+
const data = await res.json();
|
| 962 |
+
if (!res.ok) throw new Error(data.detail || data.error || 'Xóa thất bại');
|
| 963 |
+
showToast('Đã xóa tệp thành công', 'success', path);
|
| 964 |
+
closePreviewModal();
|
| 965 |
+
loadFiles(false);
|
| 966 |
+
} catch (err) {
|
| 967 |
+
showToast('Lỗi khi xóa tệp', 'error', err.message);
|
| 968 |
+
}
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
function openPreviewModal(path) {
|
| 972 |
+
const file = state.files.find(f => f.path === path);
|
| 973 |
+
if (!file) return;
|
| 974 |
+
const modal = document.getElementById('previewModal');
|
| 975 |
+
const body = document.getElementById('previewBody');
|
| 976 |
+
document.getElementById('previewTitle').textContent = file.name;
|
| 977 |
+
document.getElementById('previewSubtitle').textContent =
|
| 978 |
+
`${formatBytes(file.size)} • ${file.path} ${file.updatedAt ? '• ' + file.updatedAt : ''}`;
|
| 979 |
+
|
| 980 |
+
document.getElementById('previewDownloadBtn').onclick = () => downloadFile(file.path);
|
| 981 |
+
document.getElementById('previewDeleteBtn').onclick = () => deleteFile(file.path);
|
| 982 |
+
document.getElementById('previewCopyCurlBtn').onclick = () => {
|
| 983 |
+
const url = `${window.location.origin}/api/download?path=${encodeURIComponent(file.path)}`;
|
| 984 |
+
const cmd = `curl -L "${url}" -H "X-API-Key: ${state.apiKey}" -o "${file.name}"`;
|
| 985 |
+
navigator.clipboard.writeText(cmd);
|
| 986 |
+
showToast('Đã sao chép lệnh cURL vào Clipboard', 'success');
|
| 987 |
+
};
|
| 988 |
+
|
| 989 |
+
const streamUrl = getDownloadUrl(file.path, true);
|
| 990 |
+
if (file.category === 'video') {
|
| 991 |
+
body.innerHTML = `
|
| 992 |
+
<video controls autoplay class="max-h-[65vh] w-full rounded-2xl bg-black shadow-2xl outline-none">
|
| 993 |
+
<source src="${streamUrl}" />
|
| 994 |
+
Trình duyệt của bạn không hỗ trợ phát video trực tiếp.
|
| 995 |
+
</video>
|
| 996 |
+
`;
|
| 997 |
+
} else if (file.category === 'image') {
|
| 998 |
+
body.innerHTML = `
|
| 999 |
+
<img src="${streamUrl}" alt="${file.name}" class="max-h-[65vh] rounded-2xl object-contain shadow-2xl" />
|
| 1000 |
+
`;
|
| 1001 |
+
} else {
|
| 1002 |
+
const meta = getCategoryMeta(file.category, file.ext);
|
| 1003 |
+
body.innerHTML = `
|
| 1004 |
+
<div class="text-center py-10 px-6 max-w-md">
|
| 1005 |
+
<div class="w-20 h-20 rounded-3xl ${meta.bg} border ${meta.border} flex items-center justify-center ${meta.color} mx-auto mb-4">
|
| 1006 |
+
<i data-lucide="${meta.icon}" class="w-10 h-10"></i>
|
| 1007 |
+
</div>
|
| 1008 |
+
<h4 class="text-base font-bold text-white mb-1">${file.name}</h4>
|
| 1009 |
+
<p class="text-xs text-slate-400 font-mono mb-6">hf://buckets/${state.bucket}/${file.path}</p>
|
| 1010 |
+
<div class="glass rounded-2xl p-4 text-left space-y-2 text-xs font-mono mb-6">
|
| 1011 |
+
<div class="flex justify-between"><span class="text-slate-400">Kích thước:</span><span class="text-slate-200">${formatBytes(file.size)} (${(file.size || 0).toLocaleString()} bytes)</span></div>
|
| 1012 |
+
<div class="flex justify-between"><span class="text-slate-400">Định dạng:</span><span class="text-slate-200">.${file.ext || 'unknown'}</span></div>
|
| 1013 |
+
<div class="flex justify-between"><span class="text-slate-400">Cập nhật:</span><span class="text-slate-200">${file.updatedAt || 'N/A'}</span></div>
|
| 1014 |
+
</div>
|
| 1015 |
+
<button onclick="downloadFile('${file.path.replace(/'/g, "\\'")}')" class="w-full py-3 rounded-xl bg-gradient-to-r from-indigo-600 to-violet-600 hover:from-indigo-500 hover:to-violet-500 text-white font-semibold text-xs shadow-lg shadow-indigo-600/30 transition">
|
| 1016 |
+
Tải tệp tin này về máy
|
| 1017 |
+
</button>
|
| 1018 |
+
</div>
|
| 1019 |
+
`;
|
| 1020 |
+
}
|
| 1021 |
+
|
| 1022 |
+
modal.classList.remove('hidden');
|
| 1023 |
+
modal.classList.add('flex');
|
| 1024 |
+
lucide.createIcons({ nodes: [modal] });
|
| 1025 |
+
}
|
| 1026 |
+
|
| 1027 |
+
function closePreviewModal() {
|
| 1028 |
+
const modal = document.getElementById('previewModal');
|
| 1029 |
+
const body = document.getElementById('previewBody');
|
| 1030 |
+
body.innerHTML = ''; // Stop playing media
|
| 1031 |
+
modal.classList.add('hidden');
|
| 1032 |
+
modal.classList.remove('flex');
|
| 1033 |
+
}
|
| 1034 |
+
|
| 1035 |
+
// --- UPLOAD LOGIC WITH PROGRESS ---
|
| 1036 |
+
function openUploadModal(preselectedFiles = null) {
|
| 1037 |
+
const modal = document.getElementById('uploadModal');
|
| 1038 |
+
document.getElementById('uploadFolderInput').value = state.currentFolder;
|
| 1039 |
+
if (preselectedFiles && preselectedFiles.length > 0) {
|
| 1040 |
+
handleFileSelect(preselectedFiles);
|
| 1041 |
+
} else {
|
| 1042 |
+
state.selectedUploadFiles = [];
|
| 1043 |
+
renderSelectedFiles();
|
| 1044 |
+
}
|
| 1045 |
+
modal.classList.remove('hidden');
|
| 1046 |
+
modal.classList.add('flex');
|
| 1047 |
+
}
|
| 1048 |
+
|
| 1049 |
+
function closeUploadModal() {
|
| 1050 |
+
const modal = document.getElementById('uploadModal');
|
| 1051 |
+
modal.classList.add('hidden');
|
| 1052 |
+
modal.classList.remove('flex');
|
| 1053 |
+
}
|
| 1054 |
+
|
| 1055 |
+
function handleFileSelect(fileList) {
|
| 1056 |
+
state.selectedUploadFiles = Array.from(fileList);
|
| 1057 |
+
renderSelectedFiles();
|
| 1058 |
+
}
|
| 1059 |
+
|
| 1060 |
+
function renderSelectedFiles() {
|
| 1061 |
+
const container = document.getElementById('selectedFilesList');
|
| 1062 |
+
if (state.selectedUploadFiles.length === 0) {
|
| 1063 |
+
container.classList.add('hidden');
|
| 1064 |
+
container.innerHTML = '';
|
| 1065 |
+
return;
|
| 1066 |
+
}
|
| 1067 |
+
container.classList.remove('hidden');
|
| 1068 |
+
container.innerHTML = state.selectedUploadFiles.map((f, idx) => `
|
| 1069 |
+
<div class="flex items-center justify-between px-3 py-2 rounded-xl bg-slate-900/90 border border-white/10 text-xs">
|
| 1070 |
+
<div class="flex items-center gap-2 min-w-0">
|
| 1071 |
+
<i data-lucide="file-check" class="w-4 h-4 text-indigo-400 shrink-0"></i>
|
| 1072 |
+
<span class="truncate text-slate-200 font-medium">${f.name}</span>
|
| 1073 |
+
</div>
|
| 1074 |
+
<span class="font-mono text-slate-400 shrink-0 ml-2">${formatBytes(f.size)}</span>
|
| 1075 |
+
</div>
|
| 1076 |
+
`).join('');
|
| 1077 |
+
lucide.createIcons({ nodes: [container] });
|
| 1078 |
+
}
|
| 1079 |
+
|
| 1080 |
+
async function startBatchUpload() {
|
| 1081 |
+
if (state.selectedUploadFiles.length === 0) {
|
| 1082 |
+
showToast('Vui lòng chọn ít nhất 1 tệp tin', 'error');
|
| 1083 |
+
return;
|
| 1084 |
+
}
|
| 1085 |
+
const folderPrefix = document.getElementById('uploadFolderInput').value.trim().replace(/^\/+|\/+$/g, '');
|
| 1086 |
+
const filesToUpload = [...state.selectedUploadFiles];
|
| 1087 |
+
closeUploadModal();
|
| 1088 |
+
|
| 1089 |
+
const queuePanel = document.getElementById('uploadQueuePanel');
|
| 1090 |
+
const queueList = document.getElementById('uploadQueueList');
|
| 1091 |
+
const queueSummary = document.getElementById('uploadQueueSummary');
|
| 1092 |
+
queuePanel.classList.remove('hidden');
|
| 1093 |
+
queueList.innerHTML = '';
|
| 1094 |
+
|
| 1095 |
+
let completed = 0;
|
| 1096 |
+
queueSummary.textContent = `0/${filesToUpload.length} hoàn tất`;
|
| 1097 |
+
|
| 1098 |
+
for (let i = 0; i < filesToUpload.length; i++) {
|
| 1099 |
+
const file = filesToUpload[i];
|
| 1100 |
+
const remotePath = folderPrefix ? `${folderPrefix}/${file.name}` : file.name;
|
| 1101 |
+
const rowId = `upload-row-${Date.now()}-${i}`;
|
| 1102 |
+
|
| 1103 |
+
const row = document.createElement('div');
|
| 1104 |
+
row.id = rowId;
|
| 1105 |
+
row.className = 'p-3 rounded-xl bg-slate-900/90 border border-white/10 space-y-1.5';
|
| 1106 |
+
row.innerHTML = `
|
| 1107 |
+
<div class="flex items-center justify-between text-xs">
|
| 1108 |
+
<span class="font-medium text-slate-200 truncate max-w-[260px]">${remotePath}</span>
|
| 1109 |
+
<span id="${rowId}-status" class="font-mono text-indigo-300">0%</span>
|
| 1110 |
+
</div>
|
| 1111 |
+
<div class="w-full h-1.5 rounded-full bg-slate-800 overflow-hidden">
|
| 1112 |
+
<div id="${rowId}-bar" class="bg-gradient-to-r from-indigo-500 to-amber-400 h-full transition-all duration-200" style="width: 0%"></div>
|
| 1113 |
+
</div>
|
| 1114 |
+
`;
|
| 1115 |
+
queueList.appendChild(row);
|
| 1116 |
+
|
| 1117 |
+
try {
|
| 1118 |
+
await uploadSingleFileXHR(file, remotePath, (pct) => {
|
| 1119 |
+
const bar = document.getElementById(`${rowId}-bar`);
|
| 1120 |
+
const st = document.getElementById(`${rowId}-status`);
|
| 1121 |
+
if (bar) bar.style.width = `${pct}%`;
|
| 1122 |
+
if (st) st.textContent = pct >= 100 ? 'Đang đồng bộ HF Xet...' : `${pct}%`;
|
| 1123 |
+
});
|
| 1124 |
+
const st = document.getElementById(`${rowId}-status`);
|
| 1125 |
+
if (st) {
|
| 1126 |
+
st.textContent = 'Hoàn tất ✓';
|
| 1127 |
+
st.className = 'font-mono text-emerald-400';
|
| 1128 |
+
}
|
| 1129 |
+
completed++;
|
| 1130 |
+
queueSummary.textContent = `${completed}/${filesToUpload.length} hoàn tất`;
|
| 1131 |
+
} catch (err) {
|
| 1132 |
+
const st = document.getElementById(`${rowId}-status`);
|
| 1133 |
+
if (st) {
|
| 1134 |
+
st.textContent = 'Lỗi ✗';
|
| 1135 |
+
st.className = 'font-mono text-rose-400';
|
| 1136 |
+
}
|
| 1137 |
+
showToast(`Lỗi tải lên ${file.name}`, 'error', err.message);
|
| 1138 |
+
}
|
| 1139 |
+
}
|
| 1140 |
+
|
| 1141 |
+
showToast(`Đã tải lên ${completed}/${filesToUpload.length} tệp tin!`, 'success');
|
| 1142 |
+
await loadFiles(false);
|
| 1143 |
+
setTimeout(() => {
|
| 1144 |
+
queuePanel.classList.add('hidden');
|
| 1145 |
+
}, 4500);
|
| 1146 |
+
}
|
| 1147 |
+
|
| 1148 |
+
function uploadSingleFileXHR(file, remotePath, onProgress) {
|
| 1149 |
+
return new Promise((resolve, reject) => {
|
| 1150 |
+
const xhr = new XMLHttpRequest();
|
| 1151 |
+
const formData = new FormData();
|
| 1152 |
+
formData.append('file', file);
|
| 1153 |
+
formData.append('path', remotePath);
|
| 1154 |
+
|
| 1155 |
+
xhr.upload.addEventListener('progress', (e) => {
|
| 1156 |
+
if (e.lengthComputable) {
|
| 1157 |
+
const pct = Math.round((e.loaded / e.total) * 100);
|
| 1158 |
+
onProgress(pct);
|
| 1159 |
+
}
|
| 1160 |
+
});
|
| 1161 |
+
|
| 1162 |
+
xhr.addEventListener('load', () => {
|
| 1163 |
+
try {
|
| 1164 |
+
const res = JSON.parse(xhr.responseText || '{}');
|
| 1165 |
+
if (xhr.status >= 200 && xhr.status < 300) {
|
| 1166 |
+
resolve(res);
|
| 1167 |
+
} else {
|
| 1168 |
+
reject(new Error(res.detail || res.error || `HTTP ${xhr.status}`));
|
| 1169 |
+
}
|
| 1170 |
+
} catch (e) {
|
| 1171 |
+
reject(new Error(`HTTP ${xhr.status}`));
|
| 1172 |
+
}
|
| 1173 |
+
});
|
| 1174 |
+
|
| 1175 |
+
xhr.addEventListener('error', () => reject(new Error('Lỗi kết nối mạng')));
|
| 1176 |
+
xhr.open('POST', '/api/upload');
|
| 1177 |
+
xhr.setRequestHeader('X-API-Key', state.apiKey);
|
| 1178 |
+
xhr.send(formData);
|
| 1179 |
+
});
|
| 1180 |
+
}
|
| 1181 |
+
|
| 1182 |
+
// --- AUTH MODAL ---
|
| 1183 |
+
function openAuthModal() {
|
| 1184 |
+
document.getElementById('apiKeyInput').value = state.apiKey;
|
| 1185 |
+
const modal = document.getElementById('authModal');
|
| 1186 |
+
modal.classList.remove('hidden');
|
| 1187 |
+
modal.classList.add('flex');
|
| 1188 |
+
}
|
| 1189 |
+
|
| 1190 |
+
function closeAuthModal() {
|
| 1191 |
+
const modal = document.getElementById('authModal');
|
| 1192 |
+
modal.classList.add('hidden');
|
| 1193 |
+
modal.classList.remove('flex');
|
| 1194 |
+
}
|
| 1195 |
+
|
| 1196 |
+
function toggleApiKeyVisibility() {
|
| 1197 |
+
const input = document.getElementById('apiKeyInput');
|
| 1198 |
+
input.type = input.type === 'password' ? 'text' : 'password';
|
| 1199 |
+
}
|
| 1200 |
+
|
| 1201 |
+
function saveApiKey() {
|
| 1202 |
+
const val = document.getElementById('apiKeyInput').value.trim();
|
| 1203 |
+
if (!val) {
|
| 1204 |
+
showToast('API Key không được để trống', 'error');
|
| 1205 |
+
return;
|
| 1206 |
+
}
|
| 1207 |
+
state.apiKey = val;
|
| 1208 |
+
localStorage.setItem('hf_bucket_api_key', val);
|
| 1209 |
+
closeAuthModal();
|
| 1210 |
+
showToast('Đã lưu API Key', 'success');
|
| 1211 |
+
loadFiles(true);
|
| 1212 |
+
}
|
| 1213 |
+
|
| 1214 |
+
// --- GLOBAL DRAG & DROP + SHORTCUTS ---
|
| 1215 |
+
window.addEventListener('DOMContentLoaded', () => {
|
| 1216 |
+
lucide.createIcons();
|
| 1217 |
+
setViewMode(state.viewMode);
|
| 1218 |
+
checkHealth();
|
| 1219 |
+
loadFiles(false);
|
| 1220 |
+
|
| 1221 |
+
// Search input bindings
|
| 1222 |
+
const searchIn = document.getElementById('searchInput');
|
| 1223 |
+
const mobileSearchIn = document.getElementById('mobileSearchInput');
|
| 1224 |
+
searchIn?.addEventListener('input', (e) => {
|
| 1225 |
+
state.search = e.target.value;
|
| 1226 |
+
renderExplorer();
|
| 1227 |
+
});
|
| 1228 |
+
mobileSearchIn?.addEventListener('input', (e) => {
|
| 1229 |
+
state.search = e.target.value;
|
| 1230 |
+
renderExplorer();
|
| 1231 |
+
});
|
| 1232 |
+
|
| 1233 |
+
// Keyboard shortcuts
|
| 1234 |
+
window.addEventListener('keydown', (e) => {
|
| 1235 |
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') {
|
| 1236 |
+
e.preventDefault();
|
| 1237 |
+
searchIn?.focus();
|
| 1238 |
+
}
|
| 1239 |
+
if (e.key === 'Escape') {
|
| 1240 |
+
closeUploadModal();
|
| 1241 |
+
closePreviewModal();
|
| 1242 |
+
closeAuthModal();
|
| 1243 |
+
}
|
| 1244 |
+
});
|
| 1245 |
+
|
| 1246 |
+
// Drag and drop on quickDropzone & modalDropzone
|
| 1247 |
+
['quickDropzone', 'modalDropzone'].forEach(id => {
|
| 1248 |
+
const zone = document.getElementById(id);
|
| 1249 |
+
if (!zone) return;
|
| 1250 |
+
zone.addEventListener('dragover', (e) => {
|
| 1251 |
+
e.preventDefault();
|
| 1252 |
+
zone.classList.add('drop-active');
|
| 1253 |
+
});
|
| 1254 |
+
zone.addEventListener('dragleave', () => zone.classList.remove('drop-active'));
|
| 1255 |
+
zone.addEventListener('drop', (e) => {
|
| 1256 |
+
e.preventDefault();
|
| 1257 |
+
zone.classList.remove('drop-active');
|
| 1258 |
+
if (e.dataTransfer?.files?.length) {
|
| 1259 |
+
openUploadModal(e.dataTransfer.files);
|
| 1260 |
+
}
|
| 1261 |
+
});
|
| 1262 |
+
});
|
| 1263 |
+
});
|
| 1264 |
+
</script>
|
| 1265 |
+
</body>
|
| 1266 |
+
</html>
|