forked from wuranxu/pity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
223 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from app.crud import Mapper | ||
from app.models.oss_file import PityOssFile | ||
from app.utils.decorator import dao | ||
from app.utils.logger import Log | ||
|
||
|
||
@dao(PityOssFile, Log("PityOssDao")) | ||
class PityOssDao(Mapper): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import json | ||
from datetime import datetime | ||
from typing import Any | ||
|
||
|
||
class JsonEncoder(json.JSONEncoder): | ||
|
||
def default(self, o: Any) -> Any: | ||
if isinstance(o, set): | ||
return list(o) | ||
if isinstance(o, datetime): | ||
return o.strftime("%Y-%m-%d %H:%M:%S") | ||
return self.default(o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
grpc客户端,根据方法/参数请求grpc接口 | ||
""" | ||
import asyncio | ||
|
||
from grpc_requests import AsyncClient | ||
|
||
|
||
class GrpcClient(object): | ||
""" | ||
usage: | ||
result = GrpcClient.invoke("localhost:50001", "hello", "greeter", {"name": "woody"}) | ||
print(result) | ||
""" | ||
|
||
@staticmethod | ||
async def invoke(address: str, iface: str, method: str, request_data=None): | ||
client = AsyncClient(address) | ||
service = await client.service(iface) | ||
return await getattr(service, method)(request_data) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(GrpcClient.invoke("localhost:50052", "Hello", "Edit", {"number": 10})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
pity oss文件映射表 | ||
""" | ||
from sqlalchemy import String, Column, UniqueConstraint | ||
|
||
from app.models.basic import PityBase | ||
|
||
units = ( | ||
"B", "KB", "MB", "GB", "TB" | ||
) | ||
|
||
|
||
class PityOssFile(PityBase): | ||
# 因为没有目录的概念,都是目录+文件名 | ||
file_path = Column(String(64), nullable=False, index=True, comment="文件路径") | ||
view_url = Column(String(256), nullable=False, comment="文件预览url") | ||
file_size = Column(String(16), comment="文件大小") | ||
sha = Column(String(128), comment="gitee独有,sha代表一个文件的标识,gitee必须存这个变量") | ||
__tablename__ = "pity_oss_file" | ||
__fields__ = (file_path, view_url, file_size) | ||
__tag__ = "oss" | ||
__alias__ = dict(file_path="文件路径", view_url="地址", file_size="文件大小") | ||
__show__ = 1 | ||
__table_args__ = ( | ||
UniqueConstraint('file_path', 'deleted_at'), | ||
) | ||
|
||
def __init__(self, user, file_path, view_url, file_size, sha=None, id=None): | ||
super().__init__(user, id) | ||
self.file_path = file_path | ||
self.sha = sha | ||
self.view_url = view_url | ||
self.file_size = file_size | ||
|
||
@staticmethod | ||
def get_size(file_size: int): | ||
""" | ||
计算文件大小 | ||
:param file_size: | ||
:return: | ||
""" | ||
unit_index = 0 | ||
while file_size >= 1024: | ||
# 说明可以写成kb | ||
file_size //= 1024 | ||
unit_index += 1 | ||
return f"{file_size}{units[unit_index]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.