12345678910111213141516171819202122232425262728293031 |
- def uploadshare(uploadId, shareUserId):
- r = Response(mimetype="application/json")
- r.headers["Content-Type"] = "text/json; charset=utf-8"
- token = request.headers['Authorization'].split(' ')[1]
- data = jwt.decode(token.encode('UTF-8'), 'SECRET', algorithm='HS256')
- upload = get_db().uploads.find_one({'_id': ObjectId(uploadId), 'status': 'done', 'ownerid': data['sub']})
- if upload is None:
- r.response = json.dumps({'error': 'upload id not found'})
- r.status_code = HTTPStatus.NOT_FOUND
- return r
- u = get_db().users.find_one({"name": shareUserId})
- if u is None:
- r.response = json.dumps({'error': 'user not found'})
- r.status_code = HTTPStatus.NOT_FOUND
- return r
- if shareUserId in upload['users']:
- r.response = json.dumps({'status': 'already shared'})
- r.status_code = HTTPStatus.OK
- return r
- get_db().uploads.update_one({'_id': ObjectId(uploadId)}, {'$push': {'users': shareUserId}})
- r.response = json.dumps({'status': 'share success'})
- r.status_code = HTTPStatus.OK
- return r
|