@@ -71,6 +71,7 @@ async def _run_scenario(self):
7171 await self ._assert_count_consumption_is_atomic ()
7272 await self ._assert_time_expiration_and_usage_are_atomic ()
7373 await self ._assert_download_url_is_single_use ()
74+ await self ._assert_text_share_downloads_as_txt ()
7475 await self ._assert_limited_files_do_not_expose_direct_urls ()
7576 await self ._assert_metadata_counts_all_attempts ()
7677 finally :
@@ -156,6 +157,30 @@ async def _assert_download_url_is_single_use(self):
156157 self .assertEqual (record .expired_count , 0 )
157158 self .assertEqual (record .used_count , 1 )
158159
160+ async def _assert_text_share_downloads_as_txt (self ):
161+ record = await FileCodes .create (
162+ code = "text-download" ,
163+ prefix = "TAG" ,
164+ text = "hello, 文本直链" ,
165+ expired_count = - 1 ,
166+ expired_at = None ,
167+ )
168+
169+ with patch .dict (views .storages , {"local" : FakeStorage }):
170+ response = await views .get_code_file (
171+ code = record .code , ip = "127.0.0.1"
172+ )
173+
174+ self .assertEqual (response .status_code , 200 )
175+ self .assertEqual (response .body .decode ("utf-8" ), record .text )
176+ self .assertEqual (response .media_type , "text/plain" )
177+ self .assertEqual (
178+ response .headers ["content-disposition" ],
179+ "attachment; filename*=UTF-8''TAG.txt" ,
180+ )
181+ await record .refresh_from_db ()
182+ self .assertEqual (record .used_count , 1 )
183+
159184 async def _assert_limited_files_do_not_expose_direct_urls (self ):
160185 record = await FileCodes .create (
161186 code = "proxy-only" ,
0 commit comments