Skip to content

Commit 65fa3c9

Browse files
committed
update:readme
1 parent c87e388 commit 65fa3c9

File tree

4 files changed

+87
-63
lines changed

4 files changed

+87
-63
lines changed

history.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

main.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import asyncio
44
from pathlib import Path
55
import os
6+
67
try:
78
import chardet
89
from fastapi import FastAPI, Depends, UploadFile, Form, File, HTTPException, BackgroundTasks
@@ -116,6 +117,25 @@ async def index():
116117
return HTMLResponse(index_html)
117118

118119

120+
@app.post('/')
121+
async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession = Depends(get_session)):
122+
query = select(Codes).where(Codes.code == code)
123+
info = (await s.execute(query)).scalars().first()
124+
if not info:
125+
error_count = settings.ERROR_COUNT - error_ip_limit.add_ip(ip)
126+
raise HTTPException(status_code=404, detail=f"取件码错误,{error_count}次后将被禁止{settings.ERROR_MINUTE}分钟")
127+
if info.exp_time < datetime.datetime.now() or info.count == 0:
128+
raise HTTPException(status_code=404, detail="取件码已失效,请联系寄件人")
129+
await s.execute(update(Codes).where(Codes.id == info.id).values(count=info.count - 1))
130+
await s.commit()
131+
if info.type != 'text':
132+
info.text = f'/select?code={code}'
133+
return {
134+
'detail': f'取件成功,文件将在{settings.DELETE_EXPIRE_FILES_INTERVAL}分钟后删除',
135+
'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code}
136+
}
137+
138+
119139
@app.get('/banner')
120140
async def banner(request: Request, s: AsyncSession = Depends(get_session)):
121141
# 数据库查询config
@@ -161,25 +181,6 @@ async def get_file(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession
161181
return FileResponse(filepath, filename=info.name)
162182

163183

164-
@app.post('/')
165-
async def index(code: str, ip: str = Depends(error_ip_limit), s: AsyncSession = Depends(get_session)):
166-
query = select(Codes).where(Codes.code == code)
167-
info = (await s.execute(query)).scalars().first()
168-
if not info:
169-
error_count = settings.ERROR_COUNT - error_ip_limit.add_ip(ip)
170-
raise HTTPException(status_code=404, detail=f"取件码错误,{error_count}次后将被禁止{settings.ERROR_MINUTE}分钟")
171-
if info.exp_time < datetime.datetime.now() or info.count == 0:
172-
raise HTTPException(status_code=404, detail="取件码已失效,请联系寄件人")
173-
await s.execute(update(Codes).where(Codes.id == info.id).values(count=info.count - 1))
174-
await s.commit()
175-
if info.type != 'text':
176-
info.text = f'/select?code={code}'
177-
return {
178-
'detail': f'取件成功,文件将在{settings.DELETE_EXPIRE_FILES_INTERVAL}分钟后删除',
179-
'data': {'type': info.type, 'text': info.text, 'name': info.name, 'code': info.code}
180-
}
181-
182-
183184
@app.post('/share', dependencies=[Depends(admin_required)], description='分享文件')
184185
async def share(background_tasks: BackgroundTasks, text: str = Form(default=None),
185186
style: str = Form(default='2'), value: int = Form(default=1), file: UploadFile = File(default=None),

readme.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,9 @@ docker run -d --restart=always -p 12345:12345 -v /opt/FileCodeBox/:/app/data --n
5252
## 项目规划
5353

5454
2022年12月14日
55-
5655
这个项目的灵感来源于丁丁快传,然后写了这么一个基于本机存储的快传系统,本系统主要是以轻量,单用户,离线环境(`私有化`
5756
)为主,因此也不需要加太多东西,所以其实这个项目到这基本功能已经完成了,剩下的就是维护和完善现有功能。
58-
59-
也不会再加入新的大功能了,如果有新的功能的话,那就是我们的Pro版本了,当然也是继续开源的,能和@veoco一起开源挺荣幸的,在他的代码中我学到了许多,此前我基本上是使用Django那一套,对Fastapi仅限于使用,他的许多写法让我受益匪浅,也让我对Fastapi有了更深的了解,所以我也会在Pro版本中使用Fastapi。
60-
61-
根据目前一些使用反馈来说,希望加入登录功能,还有多存储引擎等,欢迎各位继续提意见,加入我们共同开发。
62-
63-
如果你有更好的想法和建议欢迎提issue。
57+
也不会再加入新的大功能了,如果你有更好的想法和建议欢迎提issue。
6458

6559
## 预览
6660

@@ -166,6 +160,68 @@ KEYWORDS=FileCodeBox,文件快递柜,口令传送箱,匿名口令分享文
166160
STORAGE_ENGINE=filesystem
167161
```
168162

163+
## 接口文档
164+
165+
前端比较简陋,可以使用接口进行二次开发
166+
167+
### 取件
168+
169+
#### PATH
170+
171+
`/`
172+
173+
#### METHOD
174+
175+
`POST`
176+
177+
#### PARAMS
178+
179+
code: 取件码
180+
181+
#### Response
182+
183+
```json
184+
{
185+
"detail": "msg",
186+
"data": {
187+
"type": "类型",
188+
"text": "文本",
189+
"name": "名称",
190+
"code": "取件码"
191+
}
192+
}
193+
```
194+
195+
### 寄件
196+
197+
#### PATH
198+
199+
`/share`
200+
201+
#### METHOD
202+
203+
`POST`
204+
205+
#### PARAMS
206+
207+
style: 1为次数,2为时间
208+
value: 次数或时间
209+
text: 取件码
210+
file: 文件
211+
212+
#### Response
213+
214+
```json
215+
{
216+
"detail": "msg",
217+
"data": {
218+
"code": "类型",
219+
"key": "唯一ID",
220+
"name": "名称"
221+
}
222+
}
223+
```
224+
169225
## 状态
170226

171227
![Alt](https://repobeats.axiom.co/api/embed/7a6c92f1d96ee57e6fb67f0df371528397b0c9ac.svg "Repobeats analytics image")

settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from starlette.config import Config
22
import os
33
import shutil
4-
import encoding_convert
4+
# import encoding_convert
55

66
# 配置文件.env
77
# 请将.env移动至data目录,方便docker部署
88
# 判断根目录下是否存在.env文件
99
if os.path.exists('.env'):
1010
# 将文件复制到data目录
1111
shutil.copy('.env', 'data/.env')
12-
if os.path.exists('data/.env'):
13-
# 获取data目录下的.env文件编码,如果为utf-8编码,就转换为gbk编码
14-
encoding_convert.convert_encoding('./data/.env')
12+
# if os.path.exists('data/.env'):
13+
# # 获取data目录下的.env文件编码,如果为utf-8编码,就转换为gbk编码
14+
# encoding_convert.convert_encoding('./data/.env')
1515

1616
config = Config("data/.env")
1717
# 是否开启DEBUG模式

0 commit comments

Comments
 (0)