Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
76e4d52
[init]: 初始化项目和数据库结构
Fantasylee21 Apr 11, 2025
066d17c
[docs]:dev分支开发规范
coder0xe Apr 11, 2025
cb4fbf8
Merge pull request #1 from BUAA-SE-coders007/chore/init
coder0xe Apr 11, 2025
5c78e5e
[feat]: 实现登录注册的相关功能
Fantasylee21 Apr 12, 2025
889c538
[docs]: 更新requirements.txt
Fantasylee21 Apr 12, 2025
aa8b1f4
Merge pull request #2 from BUAA-SE-coders007/feature/login
coder0xe Apr 12, 2025
48786fe
[chore]: 更新邮箱设置
Fantasylee21 Apr 12, 2025
1bb15bc
Merge pull request #3 from BUAA-SE-coders007/chore/email_change
coder0xe Apr 12, 2025
0ba75a9
[feat]: 实现笔记的增删改
Fantasylee21 Apr 12, 2025
279f50f
Merge pull request #4 from BUAA-SE-coders007/feature/note_management
coder0xe Apr 12, 2025
e60b2b4
[feat]: 完成笔记导出和身份校验
Fantasylee21 Apr 13, 2025
7caf5b6
Merge pull request #5 from BUAA-SE-coders007/feature/export_note
coder0xe Apr 13, 2025
3718933
[chore]: 将后端代码换为异步程序,提高服务效率
Fantasylee21 Apr 14, 2025
f4e9138
[docs]: 更新requirements.txt
Fantasylee21 Apr 14, 2025
81dcdeb
Merge pull request #6 from BUAA-SE-coders007/chore/change2async
coder0xe Apr 14, 2025
61ec7b5
[feat]: 完成用户信息的更新
Fantasylee21 Apr 18, 2025
856a87f
Merge pull request #7 from BUAA-SE-coders007/feature/user_update
coder0xe Apr 18, 2025
4e51069
[feat]: 实现多轮对话持久化的AI对话
Fantasylee21 Apr 18, 2025
f11100b
Merge pull request #8 from BUAA-SE-coders007/feature/aichat
coder0xe Apr 19, 2025
b79f501
[feat]: 文献管理的基本功能
Xian-Yu0 Apr 20, 2025
4532420
Merge pull request #9 from BUAA-SE-coders007/feature/article_basic
coder0xe Apr 21, 2025
a590ab9
[feat]: 增加OCR
Fantasylee21 Apr 21, 2025
9b933c8
Merge pull request #10 from BUAA-SE-coders007/feature/ocr
coder0xe Apr 21, 2025
a96208b
[fix]: fix import problems
Xian-Yu0 Apr 21, 2025
4057ac8
[fix]: replace jwt with jose in utils/auth.py
Xian-Yu0 Apr 21, 2025
d23bdd1
Merge remote-tracking branch 'origin/dev' into fix/12
coder0xe Apr 21, 2025
69304f3
Merge pull request #13 from BUAA-SE-coders007/fix/12
coder0xe Apr 21, 2025
adb1a43
[chore]:set up workflow
coder0xe Apr 21, 2025
1231e43
[fix]:fix workflow, there are no tests
coder0xe Apr 21, 2025
f457ce8
[fix]:set up redis in workflow, fix requirements.txt, fuck that
coder0xe Apr 21, 2025
ebeeb67
Merge pull request #15 from BUAA-SE-coders007/chore/workflow_setup
coder0xe Apr 21, 2025
53c29a7
[feat]: 增加文献库
Fantasylee21 Apr 22, 2025
ea11d77
Merge pull request #16 from BUAA-SE-coders007/feature/articleDB
coder0xe Apr 22, 2025
98d8173
[chore]: 调整笔记返回数据
Fantasylee21 Apr 22, 2025
6a2adc8
Merge pull request #17 from BUAA-SE-coders007/chore/note_title
coder0xe Apr 22, 2025
cfcf316
[feat]: 导入导出文献
Xian-Yu0 Apr 22, 2025
f116394
[feat]: import, export and tag
Xian-Yu0 Apr 23, 2025
b0ffb5d
Merge pull request #23 from BUAA-SE-coders007/feature/import_export_tag
coder0xe Apr 23, 2025
f99e900
[feat]: 实现用户信息
Fantasylee21 Apr 23, 2025
be841ca
Merge pull request #25 from BUAA-SE-coders007/feature/user_info
coder0xe Apr 23, 2025
74679b3
[feat]: 添加测试
indexYk Apr 24, 2025
36e08c5
[fix]: delete异常
Fantasylee21 Apr 24, 2025
cc47f8f
Merge pull request #27 from BUAA-SE-coders007/chore/buildtest
coder0xe Apr 24, 2025
3d9fe44
Merge pull request #28 from BUAA-SE-coders007/fix/26
coder0xe Apr 24, 2025
f12a0dd
[feat]: 指定文献所有Tag及顺序,改名
Xian-Yu0 Apr 26, 2025
2eb9ce0
Merge pull request #29 from BUAA-SE-coders007/feature/tag_order&rename
coder0xe Apr 26, 2025
49a01c6
[fix]:fix redis config in redis.py
coder0xe Apr 27, 2025
a14e239
[fix]:fix check.yml(pytest and redis config)
coder0xe Apr 27, 2025
15456b5
[fix]:fix check.yml
coder0xe Apr 27, 2025
8525ac2
[fix]:fix check.yml
coder0xe Apr 27, 2025
b324fe8
[fix]:what the hell
coder0xe Apr 27, 2025
f8ae9c6
[fix]:测试增添数据库保护
indexYk Apr 27, 2025
dcb7270
[fix]:小纠错
indexYk Apr 27, 2025
dec4391
[fix]:删除本地articles
indexYk Apr 27, 2025
d48e541
Merge pull request #33 from BUAA-SE-coders007/chore/buildtest
coder0xe Apr 27, 2025
7b04a66
Merge branch 'dev' into fix/30
coder0xe Apr 27, 2025
b17638f
[fix]: 测试修改密码
indexYk Apr 27, 2025
8ce0d2e
Merge pull request #35 from BUAA-SE-coders007/chore/buildtest
coder0xe Apr 27, 2025
559656f
Merge branch 'dev' into fix/30
coder0xe Apr 27, 2025
f6d793c
[fix]:cancel pytest
coder0xe Apr 27, 2025
0b958b9
[fix]:try to fix connection
coder0xe Apr 27, 2025
61dbd95
Merge pull request #34 from BUAA-SE-coders007/fix/30
coder0xe Apr 27, 2025
ef05afc
[feat]: 实现日志和获得笔记时间
Fantasylee21 Apr 27, 2025
152de9c
[docs]: 更新requirements.txt
Fantasylee21 Apr 27, 2025
3beb80b
Merge pull request #37 from BUAA-SE-coders007/feature/note_time
coder0xe Apr 27, 2025
e5da25d
[chore]: try to auto deploy
coder0xe Apr 28, 2025
fcba4f4
[fix]:fix os name
coder0xe Apr 28, 2025
e0d3d9f
[fix]:add ip to known hosts
coder0xe Apr 28, 2025
fec5613
[fix]:delete push action
coder0xe Apr 28, 2025
f0dab74
Merge pull request #39 from BUAA-SE-coders007/chore/autodeploy
coder0xe Apr 28, 2025
1b340ca
[feat]: 增加文献统计和OCS存储
Xian-Yu0 Apr 28, 2025
d980244
[feat]: 增加文献统计和OCS存储
Xian-Yu0 Apr 28, 2025
a23b515
[feat]: 增加文献统计和OCS存储
Xian-Yu0 Apr 28, 2025
a1b05ac
[feat]: 增加文献统计和OCS存储
Xian-Yu0 Apr 28, 2025
8bba2bc
Merge pull request #41 from BUAA-SE-coders007/feature/article_statist…
coder0xe Apr 28, 2025
89f4647
[feat]: 实现文献库和跨域
Fantasylee21 Apr 28, 2025
d0315e3
[fix[: file_path
Fantasylee21 Apr 28, 2025
06ee84d
Merge pull request #43 from BUAA-SE-coders007/feature/articleDBoss
coder0xe Apr 29, 2025
f64600c
[chore]: 调整数据库作者名限制
Fantasylee21 Apr 29, 2025
a92b7e3
Merge pull request #44 from BUAA-SE-coders007/chore/articleDB_name_size
coder0xe Apr 29, 2025
d5fead2
[feat]: 创建和加入组织
Xian-Yu0 Apr 29, 2025
78644d7
Merge pull request #45 from BUAA-SE-coders007/feature/create_enter_group
coder0xe Apr 29, 2025
fed0e71
[fix]: 更改参数全为空情况
Fantasylee21 May 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SECRET_KEY=bN3hZ6LbHG7nH9YXWULCr-crcS3GAaRELbNBdAyHBuiHH5TRctd0Zbd6OuLRHHa4Fbs
SENDER_PASSWORD=TXVU2unpCAE2EtEX
KIMI_API_KEY=sk-icdiHIiv6x8XjJCaN6J6Un7uoVxm6df5WPhflq10ZVFo03D9
56 changes: 56 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Check FastAPI Backend

on:
pull_request:
branches:
- dev

jobs:
test:
name: Run Tests and Check FastAPI
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13
env:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
POSTGRES_DB: test_db
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U test_user"
--health-interval=10s
--health-timeout=5s
--health-retries=5

redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd="redis-cli ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Check FastAPI Server
run: |
uvicorn app.main:app --host 0.0.0.0 --port 8000 --log-level warning &
sleep 5
curl -f http://localhost:8000/docs
43 changes: 43 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy FastAPI Backend

on:
pull_request:
branches:
- main
- dev

jobs:
deploy:
name: Deploy to Server
runs-on: ubuntu-22.04

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup SSH
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SERVER_SSH_KEY }}

- name: Add server to known_hosts
run: |
ssh-keyscan -H jienote.top >> ~/.ssh/known_hosts

- name: Sync Code to Server
run: |
rsync -avz --delete \
--exclude '.git' \
--exclude '.github' \
./ \
${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }}:${{ secrets.REMOTE_PATH }}

- name: Build and Restart Docker on Server
run: |
ssh ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST }} << 'EOF'
cd ${{ secrets.REMOTE_PATH }}
cd ..
docker-compose down
docker-compose build
docker-compose up -d
EOF
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env
__pycache__
articles
app.log
119 changes: 117 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,117 @@
# JieNote_backend
2025春季软件工程课程团队项目JieNote项目后端
# JieNote Backend

This is the backend service for JieNote, built with FastAPI.

## Features
- RESTful API endpoints
- Modular structure for scalability

## File Structure
- `app/`: Contains the main application code.
- `main.py`: Entry point for the FastAPI application.
- `models/`: Database models and schemas.
- `core/`: Core configurations and settings.
- include database settings
- include JWT settings
- include CORS settings
- ……
- `curd/`: CRUD operations for database interactions.
- `db/`: Database connection and session management.
- `schemas/`: Pydantic schemas for data validation.
- `static/`: Static files (e.g., images, CSS).
- `routers/`: API route definitions.
- `tests/`: Contains test cases for the application.
- `requirements.txt`: List of dependencies.
- `README.md`: Documentation for the project.
- `alembic/`: Database migration scripts and configurations.
- `env/`: Virtual environment (not included in version control).
- `img/`: Images used in the project.

## Setup
1. Create a virtual environment: ✔
```bash
python -m venv env
```
2. Activate the virtual environment:
- On Windows:
```bash
.\env\Scripts\activate
```
- On macOS/Linux:
```bash
source env/bin/activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
4. freeze requirements(do before commit !!!):
```bash
pip freeze > requirements.txt
```

## Database Migration
<!-- 数据库迁移使用alembic -->
1. Install Alembic: ✔
```bash
pip install alembic
```
2. Initialize Alembic: ✔
```bash
alembic init alembic
```
3. Configure Alembic: ✔

1. Edit `alembic.ini` to set the database URL.
2. Edit `alembic/env.py` to set up the target metadata.
```python
from app.models import Base # Import your models here
target_metadata = Base.metadata
```
4. Create a migration script: need to modify the script
```bash
alembic revision --autogenerate -m "提交信息"
```
5. Apply the migration: need to modify the script
```bash
alembic upgrade head
```


## Run the Application
```bash
uvicorn app.main:app --reload
```

## Redis
- Redis is used for caching and session management.
- Make sure to have Redis installed and running.

```bash
cd path/to/redis
# Start Redis server
redis-server.exe redis.windows.conf
```
Attention!!!
- Make sure the port is not occupied by other services.
- If you want to use the default port, please modify the `redis.windows.conf` file.
- Must connect Redis before running the application. ‼️‼️‼️


## Token Authentication
- JWT (JSON Web Token) is used for authentication.
- Refresh tokens for 7 days and access tokens for 5min.

## Folder Structure
- `app/`: Contains the main application code.
- `tests/`: Contains test cases.
- `env/`: Virtual environment (not included in version control).

## OCR
- Must install Poppler

## ER Diagram
![ER Diagram](img/er_diagram.jpg)

## License
MIT License
119 changes: 119 additions & 0 deletions alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# A generic, single database configuration.

[alembic]
# path to migration scripts
# Use forward slashes (/) also on windows to provide an os agnostic path
script_location = alembic

# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
# for all available tokens
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s

# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
prepend_sys_path = .

# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
# string value is passed to ZoneInfo()
# leave blank for localtime
# timezone =

# max length of characters to apply to the "slug" field
# truncate_slug_length = 40

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false

# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false

# version location specification; This defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions

# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
# version_path_separator = newline
#
# Use os.pathsep. Default configuration used for new projects.
version_path_separator = os

# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false

# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = mysql+pymysql://root:[email protected]:3306/JieNote


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples

# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
# hooks = ruff
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = check --fix REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARNING
handlers = console
qualname =

[logger_sqlalchemy]
level = WARNING
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
1 change: 1 addition & 0 deletions alembic/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
Loading