|
18 | 18 | """ |
19 | 19 | from __future__ import annotations |
20 | 20 |
|
21 | | -import asyncio |
22 | 21 | import datetime |
23 | 22 | import json |
24 | 23 | import pathlib |
|
27 | 26 | from typing import Dict, List, Optional, Union |
28 | 27 |
|
29 | 28 | from asyncpg import Record |
30 | | -from fastapi import APIRouter, Response, UploadFile, File |
| 29 | +from fastapi import APIRouter, File, Response, UploadFile |
31 | 30 | from fastapi.responses import UJSONResponse |
32 | 31 | from models import errors, payloads, responses |
33 | 32 |
|
@@ -177,43 +176,45 @@ async def put_pastes( |
177 | 176 | paste = recursive_hook(paste.dict()) |
178 | 177 | return UJSONResponse(paste, status_code=201) |
179 | 178 |
|
| 179 | + |
180 | 180 | @router.put( |
181 | 181 | "/images/upload/{paste_id}", |
182 | 182 | tags=["pastes"], |
183 | 183 | responses={ |
184 | 184 | 201: {"model": responses.PastePostResponse}, |
185 | 185 | 401: {"model": errors.Unauthorized}, |
186 | | - 404: {"model": errors.NotFound} |
| 186 | + 404: {"model": errors.NotFound}, |
187 | 187 | }, |
188 | 188 | include_in_schema=False, |
189 | 189 | ) |
190 | 190 | @limit("postpastes") |
191 | | -async def get_image_upload_link(request: MystbinRequest, paste_id: str, password: Optional[str] = None, images: List[UploadFile] = File(...)): |
192 | | - """ user = request.state.user |
| 191 | +async def get_image_upload_link( |
| 192 | + request: MystbinRequest, paste_id: str, password: Optional[str] = None, images: List[UploadFile] = File(...) |
| 193 | +): |
| 194 | + """user = request.state.user |
193 | 195 | if not user: |
194 | 196 | return UJSONResponse({"error": "Unauthorized", "notice": "You must be signed in to use this route"}, status_code=401)""" |
195 | 197 |
|
196 | 198 | paste = await request.app.state.db.get_paste(paste_id, password) |
197 | 199 | if paste is None: |
198 | 200 | return UJSONResponse({"error": "Not Found"}, status_code=404) |
199 | 201 |
|
200 | | - headers = { |
201 | | - "Content-Type": "application/octet-stream", |
202 | | - "AccessKey": f"{__config['bunny_cdn']['token']}" |
203 | | - } |
| 202 | + headers = {"Content-Type": "application/octet-stream", "AccessKey": f"{__config['bunny_cdn']['token']}"} |
204 | 203 |
|
205 | 204 | for image in images: |
206 | 205 | i = image.filename[0] |
207 | | - await request.app.state.db.update_paste_with_files(paste_id=paste_id, tab_id=i, url=f'https://mystbin.b-cdn.net/images/{image.filename}') |
| 206 | + await request.app.state.db.update_paste_with_files( |
| 207 | + paste_id=paste_id, tab_id=i, url=f"https://mystbin.b-cdn.net/images/{image.filename}" |
| 208 | + ) |
208 | 209 |
|
209 | 210 | URL = f'https://storage.bunnycdn.com/{__config["bunny_cdn"]["hostname"]}/images/{image.filename}' |
210 | 211 | data = await image.read() |
211 | 212 |
|
212 | | - async with request.app.state.client.put(URL, headers=headers, data=data) as resp: |
213 | | - pass |
| 213 | + await request.app.state.client.put(URL, headers=headers, data=data) |
214 | 214 |
|
215 | 215 | return Response(status_code=201) |
216 | 216 |
|
| 217 | + |
217 | 218 | desc = f"""Get a paste by ID. |
218 | 219 |
|
219 | 220 | This endpoint falls under the `getpaste` ratelimit bucket. |
|
0 commit comments