Skip to content

Commit

Permalink
支持UTF-8,修改权限
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Porter committed Jul 11, 2024
1 parent 99547a0 commit af479b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class User(db.Model):
tasks = db.relationship('SyncTask', backref='user', lazy=True)
devices = db.relationship('Device', backref='user', lazy=True)
is_active = db.Column(db.Boolean, default=True)
__table_args__ = { 'mysql_charset' : 'utf8mb4'}
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
Expand All @@ -60,6 +61,7 @@ class Device(db.Model):
deviceName = db.Column(db.String(100), nullable=False)
lastOnline = db.Column(db.DateTime, nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
__table_args__ = { 'mysql_charset' : 'utf8mb4'}

class SyncTask(db.Model):
id = db.Column(db.Integer, primary_key=True)
Expand All @@ -71,6 +73,7 @@ class SyncTask(db.Model):
totalSize = db.Column(db.BigInteger, nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
created_at = db.Column(db.DateTime, nullable=False)
__table_args__ = { 'mysql_charset' : 'utf8mb4'}

@login_manager.user_loader
def user_loader(id):
Expand Down Expand Up @@ -241,6 +244,9 @@ def addTask():
myS3.createDir(s3Dir)
except Exception as e:
return flask.jsonify({"code": 500, "message": e, "data": {}}), 500
mySameTask=SyncTask.query.filter_by(localDir=localDir, s3Dir=s3Dir, user_id=user.id).first()
if mySameTask:
return flask.jsonify({"code": 201, "message": "Same Task Already Exists", "data": {}}), 201
created_at = datetime.datetime.now()
task = SyncTask(localDir=localDir, s3Dir=s3Dir, syncType=syncType, usedSize=usedSize, totalSize=totalSize, user_id=user.id, created_at=created_at)
db.session.add(task)
Expand Down Expand Up @@ -284,9 +290,9 @@ def getTaskToken():
if(task.syncType==1):
role="upload_download"
elif(task.syncType==2):
role="download"
else:
role="upload"
else:
role="download"
try:
data=myS3.get_credential_demo(allow_prefix,role)
except Exception as e:
Expand Down
6 changes: 6 additions & 0 deletions s3Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,32 @@ def get_actions_list(self, role):
actions = [
'name/cos:PutObject',
'name/cos:PostObject',
'name/cos:HeadObject',
'name/cos:InitiateMultipartUpload',
'name/cos:ListMultipartUploads',
'name/cos:ListParts',
'name/cos:UploadPart',
'name/cos:CompleteMultipartUpload',
'name/cos:AbortMultipartUpload',
'name/cos:PutObjectCopy',
'name/cos:HeadBucket'
]
elif role == 'download':
actions = [
'name/cos:GetBucket',
'name/cos:HeadBucket'
'name/cos:HeadObject',
'name/cos:GetObject',
]
elif role == 'upload_download':
actions = [
'name/cos:GetBucket',
'name/cos:HeadBucket',
'name/cos:DeleteObject',
'name/cos:PutObject',
'name/cos:GetObject',
'name/cos:PutObjectCopy',
'name/cos:HeadObject',
'name/cos:PostObject',
'name/cos:InitiateMultipartUpload',
'name/cos:ListMultipartUploads',
Expand Down

0 comments on commit af479b9

Please sign in to comment.