Skip to content

Commit

Permalink
feat(version):
Browse files Browse the repository at this point in the history
- new version with notice
  • Loading branch information
MorvanZhou committed May 19, 2024
1 parent d467987 commit c1aaf4c
Show file tree
Hide file tree
Showing 29 changed files with 2,670 additions and 1,859 deletions.
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,33 @@
<strong>English</strong> | <a href="README_ZH.md" target="_blank">简体中文</a>
</p>

A note-taking app dependent on python.
Rethink is my understanding of self-developing.

Every time a new thought is recorded,
the relevant old thought will automatically emerge,
cross-connect, and continuously analogize and upgrade cognition.

The official web version can be found at [https://rethink.run](https://rethink.run).

![demo](https://github.com/MorvanZhou/rethink/raw/main/img/demo.gif)

## Why Rethink
## Let ideas find you rather than you find them

Rethink was born out of my inability to find a note-taking app that truly catered to my needs. My vision for a
note-taking app includes:
Let people who love to record with no useless thought.
Even with a continuous stream of input, you don't need to worry about finding it.

1. **Effortless Recording**: When capturing ideas, rethink provides with a swift and seamless recording process.
2. **Easy Application**: To facilitate easy application, merely jotting down notes is insufficient.
The recorded information should be able to form a knowledge network,
enabling your accumulated knowledge to compound over time.
This foundation allows for effective application and each new idea recorded serves to reinforce
and strengthen the existing knowledge network.
We introduce a recommendation mechanism that allows old records to come back while recording a new thought.
Making the new thought more connectable and memorable.

## Features

1. **Bi-directional links**: A knowledge network is important.
Rethink allows you to @ link to other notes in the note with one click;
2. **Markdown syntax**: Seamless support for Markdown syntax, the format of notes is more controllable;
3. **Automatic association**: Too many notes? Don't remember what you wrote before?
Unable to effectively form a note network?
Rethink automatically recommend related notes while writing,
1. **Bi-directional links**: To @ link in the note with one click;
2. **Markdown syntax**: Seamless support for Markdown syntax;
3. **Automatic association**: Automatically recommend related notes while writing,
actively assist you in forming a knowledge network.
4. **Local storage**: Rethink attaches great importance to data security.
You can store data in a local storage.
Or you can also use the online version [https://rethink.run](https://rethink.run),
Or the online version [https://rethink.run](https://rethink.run),
which makes it easy to synchronize across multiple platforms.
5. **Multi-language**: Support multiple languages, including Chinese and English.

Expand Down
23 changes: 12 additions & 11 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,27 @@
</p>


一个依赖于 Python 的笔记应用。
Rethink 表示重新思考,是我对于成长的理解。

每次记下新的认知时,相关的老认知都会自动涌现,交叉贯通,新旧认知不断 类比-迁移。
使得每次记录都有再次发光的机会。所以 Rethink 的中文名是 比移。

官方网页版可以在 [https://rethink.run](https://rethink.run) 找到。

![demo](https://github.com/MorvanZhou/rethink/raw/main/img/demo.gif)

## 为什么有 Rethink
## 让想法主动找你

Rethink 的诞生源于我无法找到一款真正满足我的需求的记笔记应用。我对记笔记应用的期望包括:
让爱记录的人,没有无效记录。即使有源源不断的信息输入,也不用担心找不到,想不起。

1. **轻松记录**:在捕捉想法时,Rethink 提供了快速且无缝的记录过程;
2. **便捷应用**:为了实现便捷应用,仅仅记录笔记是不够的。记录的信息应该能够形成一个知识网络,
使您积累的知识随着时间的推移不断增值。这个基础使得有效应用成为可能,
每个新记录的想法都有助于加强和巩固现有的知识网络。
我们引入推荐机制,让每一条记录都可以再次发光。 让它在未来的某个时刻,会再次回到面前,成为新认知的一部分。

## Rethink 主要有的特点

1. **双向链接**知识网络至关重要。Rethink 允许您在笔记中一键 @ 链接到其他笔记
2. **Markdown 语法**:无缝支持 Markdown 语法,笔记格式更易控制
3. **自动关联**笔记太多?记不住以前写过什么?无法有效形成笔记网络?Rethink 在您编写时自动推荐相关笔记,积极帮助您建立知识网络;
4. **本地存储**:Rethink 非常重视数据安全。您可以将数据存储在本地存储中。或者,您也可以使用在线版本 https://rethink.run
1. **双向链接**使用 @ 链接到其它笔记
2. **Markdown 语法**:无缝支持 Markdown 语法;
3. **自动关联**在编写时自动推荐相关笔记,积极帮助您建立知识网络;
4. **本地存储**:Rethink 非常重视数据安全。您可以将数据存储在本地存储中。另外,也有在线版本 https://rethink.run
,便于在多个平台之间同步;
5. **多语言**:支持多种语言,包括中文和英文。

Expand Down
Binary file modified img/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = retk
version = 0.2.7
version = 0.2.8
author = MorvanZhou
author_email = [email protected]
description = keep and reuse your thoughts
Expand Down
5 changes: 4 additions & 1 deletion src/retk/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
account,
manager,
statistic,
notice,
)


Expand Down Expand Up @@ -66,7 +67,8 @@ async def lifespan(app: FastAPI):
# on shutdown
scheduler.stop()
await client.close()
logger.debug("fastapi shutdown event: db closed")
await client.search.close()
logger.debug("fastapi shutdown event: db and searcher closed")

async_tasks.stop()
logger.debug("fastapi shutdown event: async_tasks stopped")
Expand Down Expand Up @@ -101,6 +103,7 @@ async def lifespan(app: FastAPI):
account,
manager,
statistic,
notice,
]:
app.include_router(r.router)

Expand Down
3 changes: 3 additions & 0 deletions src/retk/const/response_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CodeEnum(IntEnum):
USER_NOT_EXIST = 34
INVALID_PARAMS = 35
INVALID_SCHEDULE_JOB_ID = 36
NOTICE_NOT_FOUND = 37


@dataclass
Expand Down Expand Up @@ -100,6 +101,7 @@ class CodeMessage:
CodeEnum.USER_NOT_EXIST: CodeMessage(zh="用户不存在", en="User does not exist"),
CodeEnum.INVALID_PARAMS: CodeMessage(zh="无效参数", en="Invalid parameter"),
CodeEnum.INVALID_SCHEDULE_JOB_ID: CodeMessage(zh="无效的任务 ID", en="Invalid schedule job ID"),
CodeEnum.NOTICE_NOT_FOUND: CodeMessage(zh="通知未找到", en="Notice not found"),
}

CODE2STATUS_CODE: Dict[CodeEnum, int] = {
Expand Down Expand Up @@ -140,6 +142,7 @@ class CodeMessage:
CodeEnum.USER_NOT_EXIST: 404,
CodeEnum.INVALID_PARAMS: 400,
CodeEnum.INVALID_SCHEDULE_JOB_ID: 400,
CodeEnum.NOTICE_NOT_FOUND: 404,
}


Expand Down
32 changes: 32 additions & 0 deletions src/retk/controllers/notice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from retk import core
from retk.controllers import schemas
from retk.controllers.utils import maybe_raise_json_exception
from retk.models.tps import AuthedUser
from retk.utils import datetime2str


async def get_system_notice(
au: AuthedUser,
notice_id: str,
) -> schemas.notice.SystemNoticeResponse:
code = await core.notice.mark_system_notice_read(
uid=au.u.id,
notice_id=notice_id,
)
maybe_raise_json_exception(au=au, code=code)

n, code = await core.notice.get_system_notice(
uid=au.u.id,
notice_id=notice_id,
)
maybe_raise_json_exception(au=au, code=code)

return schemas.notice.SystemNoticeResponse(
requestId=au.request_id,
notice=schemas.notice.SystemNoticeResponse.Notice(
id=str(n["_id"]),
title=n["title"],
html=n["html"],
publishAt=datetime2str(n["publishAt"]),
),
)
1 change: 1 addition & 0 deletions src/retk/controllers/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
app_system,
manager,
statistic,
notice,
)


Expand Down
3 changes: 2 additions & 1 deletion src/retk/controllers/schemas/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class GetSystemNoticesResponse(BaseModel):
class Notice(BaseModel):
id: str = Field(description="notice ID")
title: str = Field(description="title")
content: str = Field(description="content")
html: str = Field(description="html")
snippet: str = Field(description="snippet")
recipientType: notice.RecipientTypeEnum = Field(description="recipient type")
batchTypeIds: List[str] = Field(description="list of user ID if the recipientType is batch")
publishAt: datetime = Field(description="publish time")
Expand Down
12 changes: 12 additions & 0 deletions src/retk/controllers/schemas/notice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pydantic import BaseModel


class SystemNoticeResponse(BaseModel):
class Notice(BaseModel):
id: str
title: str
html: str
publishAt: str

requestId: str
notice: Notice
3 changes: 2 additions & 1 deletion src/retk/controllers/schemas/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class System(BaseModel):
class Notice(BaseModel):
id: str
title: str
content: str
snippet: str
publishAt: str
read: bool
readTime: Optional[datetime]
Expand All @@ -116,4 +116,5 @@ class Notice(BaseModel):
notices: List[Notice]

requestId: str
hasUnread: bool
system: System
62 changes: 51 additions & 11 deletions src/retk/controllers/self_hosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from bson.tz_util import utc

from retk import const, __version__
from retk.core import self_hosted
from retk.core import self_hosted, scheduler, user
from retk.core.notice import post_in_manager_delivery
from retk.logger import logger
from retk.models.client import client
Expand All @@ -23,7 +23,7 @@
disabled=False,
modified_at=datetime.now(tz=utc),
used_space=0,
type=const.USER_TYPE.MANAGER,
type=const.USER_TYPE.MANAGER.id,
last_state=AuthedUser.User.LastState(
node_display_method=0,
node_display_sort_key="",
Expand All @@ -44,6 +44,28 @@
request_id=""
)

__new_version_title_zh = "发现新版本 ({})"
__new_version_content_temp_zh = """
更新您的本地版本 ({}) 到最新 ({}) 以获取最新功能和错误修复。
请在终端中运行此命令来升级:
```
pip install -U retk
```
"""

__new_version_title_en = "Find new version ({})"
__new_version_content_temp_en = """
Update your local version ({}) to the latest version ({}) to get the latest features and bug fixes.
Please run this command in your terminal to update:
```
pip install -U retk
```
"""


async def notice_new_pkg_version():
remote, code = await self_hosted.get_latest_pkg_version()
Expand All @@ -64,12 +86,30 @@ async def notice_new_pkg_version():
res = await client.coll.notice_manager_delivery.find({
"senderId": "system",
}).to_list(None)
if len(res) == 0:
await post_in_manager_delivery(
au=_local_system_authed_user,
title="New version available",
content="New version available, please update your client",
recipient_type=const.notice.RecipientTypeEnum.ALL,
batch_type_ids=[],
publish_at=datetime.now(tz=utc)
)
u, code = await user.get_by_email(const.DEFAULT_USER["email"])
if code != const.CodeEnum.OK:
logger.error("get user failed")
return
language = u["settings"]["language"]

local_version_str = ".".join(map(str, local))
remote_version_str = ".".join(map(str, remote))

title = (
__new_version_title_zh if language == "zh" else __new_version_title_en
).format(local_version_str, remote_version_str)
content = (
__new_version_content_temp_zh if language == "zh" else __new_version_content_temp_en
).format(local_version_str, remote_version_str)
for notice in res:
if notice["title"] == __new_version_title_zh or notice["title"] == __new_version_title_en:
return
await post_in_manager_delivery(
au=_local_system_authed_user,
title=title,
content=content,
recipient_type=const.notice.RecipientTypeEnum.ALL.value,
batch_type_ids=[],
publish_at=datetime.now(tz=utc)
)
await scheduler.tasks.notice.async_deliver_unscheduled_system_notices()
10 changes: 7 additions & 3 deletions src/retk/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,23 @@ async def update_password(

async def get_user_notices(
au: AuthedUser,
unread_only: bool,
page: int,
limit: int,
) -> schemas.user.NotificationResponse:
nt, code = await notice.get_user_notices(au=au)
nt, code = await notice.get_user_notices(au=au, unread_only=unread_only, page=page, limit=limit)
maybe_raise_json_exception(au=au, code=code)

return schemas.user.NotificationResponse(
requestId=au.request_id,
hasUnread=nt["hasUnread"],
system=schemas.user.NotificationResponse.System(
total=nt["system"]["total"],
notices=[
schemas.user.NotificationResponse.System.Notice(
id=n["id"],
title=n["title"],
content=n["content"],
snippet=n["snippet"],
publishAt=n["publishAt"],
read=n["read"],
readTime=n["readTime"],
Expand All @@ -107,7 +111,7 @@ async def mark_system_notice_read(
au: AuthedUser,
notice_id: str,
) -> schemas.RequestIdResponse:
code = await notice.mark_system_notice_read(au=au, notice_id=notice_id)
code = await notice.mark_system_notice_read(uid=au.u.id, notice_id=notice_id)
maybe_raise_json_exception(au=au, code=code)

return schemas.RequestIdResponse(
Expand Down
Loading

0 comments on commit c1aaf4c

Please sign in to comment.