Skip to content

Commit 6b763a7

Browse files
authored
migrate: example views change
1 parent d3f1f53 commit 6b763a7

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

views/sekai.py

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
"""
88

99
from typing import Optional
10-
from urllib.parse import urlparse
10+
import json
1111
import msgpack
1212
from Crypto.Cipher import AES
13-
from mitmproxy import contentviews
14-
from mitmproxy import flow
15-
from mitmproxy import http
16-
# from mitmproxy import ctx
13+
from mitmproxy.contentviews import Contentview
1714

1815
class SekaiCore:
19-
# To use this you need a valid key and IV.
16+
# To use this class, you need a valid key and IV.
2017
aes_key = b""
2118
aes_iv = b""
2219

@@ -48,39 +45,31 @@ def decrypt_data(cls, crypttext):
4845
return {}
4946

5047

51-
class ViewSekai(contentviews.View):
52-
name = "sekai"
53-
54-
def __call__(
55-
self,
56-
data: bytes,
57-
*,
58-
content_type: Optional[str] = None,
59-
flow: Optional[flow.Flow] = None,
60-
http_message: Optional[http.Message] = None,
61-
**unknown_metadata,
62-
) -> contentviews.TViewResult:
63-
""" Decrypts data upon response. """
64-
try:
65-
plaintext: Optional[dict] = SekaiCore.decrypt_data(data)
66-
return "sekai", contentviews.json.format_json(plaintext)
67-
except Exception as e:
68-
return "sekai", contentviews.format_text(e)
48+
class ViewProjectSekai(Contentview):
49+
name = "pjsekai"
6950

7051
def render_priority(
7152
self,
7253
data: bytes,
73-
*,
74-
content_type: Optional[str] = None,
75-
flow: Optional[flow.Flow] = None,
76-
http_message: Optional[http.Message] = None,
77-
**unknown_metadata,
54+
metadata
7855
) -> float:
7956
""" prioritize using this when priority is set """
8057
try:
81-
if not data:
58+
if not data or not metadata:
8259
return 0
83-
_ = SekaiCore.decrypt_data(data)
84-
return 1
60+
61+
decrypt_result = SekaiCore.decrypt_data(data)
62+
return 1 if decrypt_result else 0
8563
except Exception as e:
8664
return 0
65+
66+
def prettify(
67+
self,
68+
data: bytes,
69+
_
70+
) -> str:
71+
try:
72+
plaintext: Optional[dict] = SekaiCore.decrypt_data(data)
73+
return json.dumps(plaintext, indent=4, ensure_ascii=False)
74+
except Exception as e:
75+
return e

0 commit comments

Comments
 (0)