@@ -50,7 +50,6 @@ class NSFWParams(TypedDict):
5050 file_store_key : NotRequired [str ]
5151
5252
53-
5453class NSFWResponse (TypedDict ):
5554 success : bool
5655 nsfw : bool
@@ -107,25 +106,39 @@ def email(self, params: EmailValidationParams) -> EmailValidationResponse:
107106 verb = "get" ,
108107 ).perform_with_content ()
109108 return resp
110-
111- def nsfw (self , params : Union [NSFWParams , bytes ]) -> NSFWResponse :
112- path = "/validate/nsfw"
113- if isinstance (params , dict ):
109+
110+ @overload
111+ def nsfw (self , params : NSFWParams ) -> NSFWResponse : ...
112+ @overload
113+ def nsfw (self , blob : bytes , options : NSFWParams = None ) -> NSFWResponse : ...
114+
115+ def nsfw (
116+ self ,
117+ blob : Union [NSFWParams , bytes ],
118+ options : NSFWParams = None ,
119+ ) -> NSFWResponse :
120+ if isinstance (
121+ blob , dict
122+ ): # If params is provided as a dict, we assume it's the first argument
114123 resp = Request (
115124 config = self .config ,
116- path = path ,
117- params = cast (Dict [Any , Any ], params ),
125+ path = "/validate/nsfw" ,
126+ params = cast (Dict [Any , Any ], blob ),
118127 verb = "post" ,
119128 ).perform_with_content ()
120129 return resp
121130
122- _headers = {"Content-Type" : "application/octet-stream" }
131+ options = options or {}
132+ path = build_path (base_path = "/validate/nsfw" , params = options )
133+ content_type = options .get ("content_type" , "application/octet-stream" )
134+ headers = {"Content-Type" : content_type }
135+
123136 resp = Request (
124137 config = self .config ,
125138 path = path ,
126- params = {}, #since we're already passing data.
127- data = params ,
128- headers = _headers ,
139+ params = options ,
140+ data = blob ,
141+ headers = headers ,
129142 verb = "post" ,
130143 ).perform_with_content ()
131144 return resp
@@ -138,9 +151,7 @@ def profanity(self, params: ProfanityParams) -> ProfanityResponse:
138151 resp = Request (
139152 config = self .config ,
140153 path = path ,
141- params = cast (
142- Dict [Any , Any ], params
143- ),
154+ params = cast (Dict [Any , Any ], params ),
144155 verb = "post" ,
145156 ).perform_with_content ()
146157 return resp
@@ -198,25 +209,39 @@ async def email(self, params: EmailValidationParams) -> EmailValidationResponse:
198209 verb = "get" ,
199210 ).perform_with_content ()
200211 return resp
201-
202- async def nsfw (self , params : Union [NSFWParams , bytes ]) -> NSFWResponse :
203- path = "/validate/nsfw"
204- if isinstance (params , dict ):
212+
213+ @overload
214+ async def nsfw (self , params : NSFWParams ) -> NSFWResponse : ...
215+ @overload
216+ async def nsfw (self , blob : bytes , options : NSFWParams = None ) -> NSFWResponse : ...
217+
218+ async def nsfw (
219+ self ,
220+ blob : Union [NSFWParams , bytes ],
221+ options : NSFWParams = None ,
222+ ) -> NSFWResponse :
223+ if isinstance (
224+ blob , dict
225+ ): # If params is provided as a dict, we assume it's the first argument
205226 resp = await AsyncRequest (
206227 config = self .config ,
207- path = path ,
208- params = cast (Dict [Any , Any ], params ),
228+ path = "/validate/nsfw" ,
229+ params = cast (Dict [Any , Any ], blob ),
209230 verb = "post" ,
210231 ).perform_with_content ()
211232 return resp
212233
213- _headers = {"Content-Type" : "application/octet-stream" }
234+ options = options or {}
235+ path = build_path (base_path = "/validate/nsfw" , params = options )
236+ content_type = options .get ("content_type" , "application/octet-stream" )
237+ headers = {"Content-Type" : content_type }
238+
214239 resp = await AsyncRequest (
215240 config = self .config ,
216241 path = path ,
217- params = {} ,
218- data = params ,
219- headers = _headers ,
242+ params = options ,
243+ data = blob ,
244+ headers = headers ,
220245 verb = "post" ,
221246 ).perform_with_content ()
222247 return resp
@@ -229,9 +254,7 @@ async def profanity(self, params: ProfanityParams) -> ProfanityResponse:
229254 resp = await AsyncRequest (
230255 config = self .config ,
231256 path = path ,
232- params = cast (
233- Dict [Any , Any ], params
234- ),
257+ params = cast (Dict [Any , Any ], params ),
235258 verb = "post" ,
236259 ).perform_with_content ()
237260 return resp
0 commit comments