Skip to content

Commit

Permalink
feat: 接入 sentry 平台
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Dec 18, 2024
1 parent 0238982 commit 7301953
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 21 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ docker build -t xiaomusic .
- [pure 主题 xiaomusicUI](https://github.com/52fisher/xiaomusicUI)
- [移动端的播放器主题](https://github.com/52fisher/XMusicPlayer)
- [一个第三方的主题](https://github.com/DarrenWen/xiaomusicui)
- [Umami 统计](https://github.com/umami-software/umami)
- [Sentry 报错监控](https://github.com/getsentry/sentry)
- 所有帮忙调试和测试的朋友
- 所有反馈问题和建议的朋友

Expand Down
1 change: 0 additions & 1 deletion docs/.vitepress/vitepress-plugin-github-issues.mts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ function prependToFile(filePath: string, text: string) {
function replaceGithubAssetUrls(content: string, githubProxy: string): string {
const pattern1 = /https:\/\/github\.com\/[^\/]+\/[^\/]+\/assets\/[\w-]+/g;
const pattern2 = /https:\/\/github\.com\/user-attachments\/assets\/[\w-]+/g;
const proxyPrefix = "https://cloudflare-github-proxy.hanxi-info.workers.dev/proxy";

// 使用正则表达式替换符合条件的链接
const transformedContent = content.replace(pattern1, (match) => {
Expand Down
35 changes: 34 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"pillow>=10.4.0",
"python-multipart>=0.0.12",
"requests>=2.32.3",
"sentry-sdk[fastapi]>=2.19.2",
]
requires-python = ">=3.10,<=3.12"
readme = "README.md"
Expand Down
3 changes: 2 additions & 1 deletion xiaomusic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
from xiaomusic.cli import main

if __name__ == "__main__":
from xiaomusic.cli import main

main()
34 changes: 27 additions & 7 deletions xiaomusic/cli.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/usr/bin/env python3
import argparse
import json
import logging
import os
import signal

import uvicorn

from xiaomusic import __version__
from xiaomusic.config import Config
from xiaomusic.httpserver import HttpInit
from xiaomusic.httpserver import app as HttpApp
from xiaomusic.xiaomusic import XiaoMusic
import sentry_sdk
from sentry_sdk.integrations.asyncio import AsyncioIntegration
from sentry_sdk.integrations.logging import LoggingIntegration

LOGO = r"""
__ __ _ __ __ _
Expand All @@ -22,7 +19,30 @@
"""


sentry_sdk.init(
dsn="https://[email protected]/sentry/4508470200434688",
traces_sample_rate=0.1,
profiles_sample_rate=0.05,
integrations=[
AsyncioIntegration(),
LoggingIntegration(
level=logging.WARNING,
event_level=logging.ERROR,
),
],
# debug=True,
)


def main():
import uvicorn

from xiaomusic import __version__
from xiaomusic.config import Config
from xiaomusic.httpserver import HttpInit
from xiaomusic.httpserver import app as HttpApp
from xiaomusic.xiaomusic import XiaoMusic

parser = argparse.ArgumentParser()
parser.add_argument(
"--port",
Expand Down
25 changes: 14 additions & 11 deletions xiaomusic/xiaomusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,19 @@ async def init_all_data(self, session):
self.cookie_jar = session.cookie_jar

async def login_miboy(self, session):
account = MiAccount(
session,
self.config.account,
self.config.password,
str(self.mi_token_home),
)
# Forced login to refresh to refresh token
await account.login("micoapi")
self.mina_service = MiNAService(account)
self.miio_service = MiIOService(account)
try:
account = MiAccount(
session,
self.config.account,
self.config.password,
str(self.mi_token_home),
)
# Forced login to refresh to refresh token
await account.login("micoapi")
self.mina_service = MiNAService(account)
self.miio_service = MiIOService(account)
except Exception as e:
self.log.warning(f"可能登录失败. {e}")

async def try_update_device_id(self):
try:
Expand All @@ -254,7 +257,7 @@ async def try_update_device_id(self):
self.config.devices = devices
self.log.info(f"选中的设备: {devices}")
except Exception as e:
self.log.exception(f"Execption {e}")
self.log.warning(f"可能登录失败. {e}")

def get_cookie(self):
if self.config.cookie:
Expand Down

0 comments on commit 7301953

Please sign in to comment.