Skip to content

Commit

Permalink
update file storage
Browse files Browse the repository at this point in the history
  • Loading branch information
MorvanZhou committed Nov 10, 2023
1 parent 76d93aa commit eb27577
Show file tree
Hide file tree
Showing 24 changed files with 954 additions and 491 deletions.
9 changes: 5 additions & 4 deletions src/rethink/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ async def index() -> HTMLResponse:
)


@app.get("/i/{path}", response_class=FileResponse)
async def img(
path: str,
@app.get("/userData/{uid}/{fid}", response_class=FileResponse)
async def user_data(
uid: str,
fid: str,
) -> FileResponse:
if config.is_local_db():
prefix = config.get_settings().LOCAL_STORAGE_PATH
else:
raise HTTPException(status_code=404, detail="only support local storage")
return FileResponse(
path=prefix / ".data" / "images" / path,
path=prefix / ".data" / "userData" / uid / fid,
status_code=200,
)
32 changes: 31 additions & 1 deletion src/rethink/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

RETHINK_DIR = Path(__file__).parent
FRONTEND_DIR = RETHINK_DIR / "dist-local"
MD_MAX_LENGTH = 100000
MD_MAX_LENGTH = 100_000


class NodeType(Enum):
Expand Down Expand Up @@ -39,6 +39,7 @@ class Code(Enum):
FILENAME_EXIST = auto() # 23
IMPORT_PROCESS_NOT_FINISHED = auto() # 24
UPLOAD_TASK_TIMEOUT = auto() # 25
USER_SPACE_NOT_ENOUGH = auto() # 26


INT_CODE_MAP = {
Expand Down Expand Up @@ -80,6 +81,7 @@ class CodeMessage:
zh="正在完成上一批数据导入,请稍后再试",
en="Last import process not finished, please try again later"),
Code.UPLOAD_TASK_TIMEOUT: CodeMessage(zh="文件上传任务超时", en="Upload task timeout"),
Code.USER_SPACE_NOT_ENOUGH: CodeMessage(zh="用户空间不足", en="User space not enough"),
}

DEFAULT_USER = {
Expand Down Expand Up @@ -193,3 +195,31 @@ def __str__(self):
class NodeDisplayMethod(Enum):
CARD = 0
LIST = auto() # 1


@dataclass
class UserConfig:
id: int
max_store_space: int


class UserType:
NORMAL = UserConfig(
id=0,
max_store_space=1024 * 1024 * 500, # 500MB
)
ADMIN = UserConfig(
id=1,
max_store_space=1024 * 1024 * 1024 * 100, # 100GB
)

def id2config(self, _id: int):
if _id == self.NORMAL.id:
return self.NORMAL
elif _id == self.ADMIN.id:
return self.ADMIN
else:
raise ValueError(f"Invalid user type: {_id}")


USER_TYPE = UserType()
2 changes: 2 additions & 0 deletions src/rethink/controllers/schemas/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class User(BaseModel):
createdAt: str
language: Literal["en", "zh"]
nodeDisplayMethod: NonNegativeInt
usedSpace: NonNegativeInt = 0
maxSpace: NonNegativeInt = 0

code: NonNegativeInt
message: str
Expand Down
7 changes: 6 additions & 1 deletion src/rethink/controllers/user/user_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def get_user(
code=code.value,
message=const.get_msg_by_code(code, td.language),
)

if config.is_local_db():
max_space = 0
else:
max_space = const.USER_TYPE.id2config(u["type"]).max_store_space
return schemas.user.UserInfoResponse(
requestId=req_id,
code=code.value,
Expand All @@ -88,6 +91,8 @@ def get_user(
createdAt=datetime2str(u["_id"].generation_time),
language=u["language"],
nodeDisplayMethod=u["nodeDisplayMethod"],
usedSpace=u["usedSpace"],
maxSpace=max_space,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,43 +432,93 @@ footer {

.user-page[data-v-708d9590] {
margin: 0 auto;
width: 60%;
max-width: 400px;
width: 95%;
max-width: 600px;
}

h1[data-v-708d9590] {
text-align: center;
margin-bottom: 20px;
}

label[data-v-708d9590] {
font-weight: bold;
}

.user-img[data-v-708d9590] {
margin: 0 auto;
text-align: center;
}

.user-img img[data-v-708d9590] {
width: 50px;
height: 50px;
border-radius: 50%;
margin: 0 auto;
}
.user-meta[data-v-708d9590] {

.section[data-v-708d9590] {
display: flex;
flex-direction: column;
gap: 10px;
margin: 10px auto;
}
.user-meta label[data-v-708d9590] {
font-weight: bold;
margin: 0 auto;
padding: 10px 0 40px 0;
border-bottom: 1px solid #e7e7e7;
}

.user-meta input[data-v-708d9590] {
padding: 5px;
border-radius: 5px;
border: 1px solid #ccc;
}

.user-meta input[data-v-708d9590]:focus {
outline: none;
border: 1px solid #3d3d3d;
}

.user-meta select[data-v-708d9590] {
padding: 5px;
border-radius: 5px;
border: 1px solid #ccc;
}

.storage-usage[data-v-708d9590] {
display: flex;
flex-direction: column;
gap: 5px;
}

.storage-usage span[data-v-708d9590] {
font-size: 0.8rem;
}

.progress-info[data-v-708d9590] {
display: flex;
justify-content: space-between;
align-items: center;
gap: 5px;
}

.progress-bar[data-v-708d9590] {
width: 100%;
height: 13px;
background-color: #e7e7e7;
border-radius: 5px;
}

.progress[data-v-708d9590] {
height: 100%;
background-color: #55bb8e;
border-radius: 5px;
transition: width 0.5s ease-in-out;
}

.percentage[data-v-708d9590] {
text-align: right;
font-size: 0.7rem;
padding-left: 5px;
}

/*!***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** css ./node_modules/css-loader/dist/cjs.js??clonedRuleSet-12.use[1]!./node_modules/vue-loader/dist/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-12.use[2]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/signin/SignupWindow.vue?vue&type=style&index=0&id=21397f96&scoped=true&lang=css ***!
\***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
Expand Down Expand Up @@ -784,8 +834,8 @@ h1[data-v-708d9590] {

.user-page[data-v-9a15286a] {
margin: 0 auto;
width: 60%;
max-width: 400px;
width: 95%;
max-width: 600px;
}
h1[data-v-9a15286a] {
text-align: center;
Expand Down Expand Up @@ -3457,13 +3507,26 @@ img[data-v-4f42ee16] {
height: 15px;
margin-right: 5px;
}

.status span[data-v-6e2de383] {
color: #999;
color: #818181;
font-weight: 200;
overflow-x: hidden;
white-space: nowrap;
}

.status-sm[data-v-6e2de383] {
margin: 0 0 0 10px;
font-size: 0.8em;
}

.status-sm img[data-v-6e2de383] {
width: 13px;
height: 13px;
margin-right: 5px;
}


/*!****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** css ./node_modules/css-loader/dist/cjs.js??clonedRuleSet-12.use[1]!./node_modules/vue-loader/dist/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-12.use[2]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/components/app/nav/top/EditorHeader.vue?vue&type=style&index=0&id=55779ec4&scoped=true&lang=css ***!
\****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
Expand All @@ -3473,12 +3536,18 @@ img[data-v-4f42ee16] {
margin: 5px 5px 5px 0;
display: flex;
align-items: center;
width: 97%;
overflow-x: clip;
}

.menu[data-v-55779ec4] {
margin: 0 20px 0 5px;
padding: 0 5px;
}

.menu-sm[data-v-55779ec4] {
margin: 0 10px 0 0;
}

/*!*************************************************************************************************************************************************************************************************************************************************************************************************************************************************!*\
!*** css ./node_modules/css-loader/dist/cjs.js??clonedRuleSet-12.use[1]!./node_modules/vue-loader/dist/stylePostLoader.js!./node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-12.use[2]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/views/app/EditorView.vue?vue&type=style&index=0&id=5cd56b1a&scoped=true&lang=css ***!
Expand Down Expand Up @@ -3916,7 +3985,7 @@ tr.tr-sm .node-more-ops {
box-sizing: border-box;
overflow-y: auto;
color: #333;
line-height: 1.2em;
line-height: 1.4em;
}
.quick-post-footer[data-v-dc31438a] {
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion src/rethink/dist-local/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<script defer src="/js/chunk-vendors.js"></script>
<script defer src="/js/app.js"></script>
<link href="/css/app.7c0d6dae.css" rel="stylesheet">
<link href="/css/app.bab7d903.css" rel="stylesheet">
</head>
<body>
<div id="app"></div>
Expand Down
Loading

0 comments on commit eb27577

Please sign in to comment.