-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathchunk_upload.py
More file actions
38 lines (31 loc) · 1.45 KB
/
chunk_upload.py
File metadata and controls
38 lines (31 loc) · 1.45 KB
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
"""
Chunk Upload Database Model
分片上传数据库模型
"""
from sqlalchemy import Column, String, Integer, DateTime
from sqlalchemy.sql import func
from app.db.models.base_entity import Base
class ChunkUploadPreRequest(Base):
"""分片上传预请求"""
__tablename__ = "t_chunk_upload_request"
id = Column(String(36), primary_key=True, comment="请求ID")
total_file_num = Column(Integer, nullable=False, comment="总文件数")
uploaded_file_num = Column(Integer, nullable=True, comment="已上传文件数")
upload_path = Column(String(512), nullable=False, comment="文件路径")
timeout = Column(DateTime, nullable=False, comment="上传请求超时时间")
service_id = Column(String(64), nullable=True, comment="上传请求所属服务ID")
check_info = Column(String(512), nullable=True, comment="业务信息")
def increment_uploaded_file_num(self):
"""增加已上传文件数"""
if self.uploaded_file_num is None:
self.uploaded_file_num = 1
else:
self.uploaded_file_num += 1
def is_upload_complete(self) -> bool:
"""检查是否已完成上传"""
return (self.uploaded_file_num is not None and
self.uploaded_file_num == self.total_file_num)
def is_request_timeout(self) -> bool:
"""检查是否已超时"""
from datetime import datetime
return self.timeout is not None and datetime.utcnow() > self.timeout