5 Commits
1.0.0 ... main

Author SHA1 Message Date
86a03647df Merge branch 'main' of https://git.frik.su/n0one/habr-article-API
All checks were successful
Build and Push Docker Image / build-and-push (release) Successful in 2m6s
2025-09-17 16:09:43 +03:00
73da634029 both /article/get/ endpoints now return json 2025-09-17 16:09:29 +03:00
9424276474 fixed typo in dockerfile
All checks were successful
Build and Push Docker Image / build-and-push (release) Successful in 1m57s
2025-09-17 15:56:17 +03:00
7949312f9a Added username parameter to json load for /rate and /remove_rate
Some checks failed
Build and Push Docker Image / build-and-push (release) Failing after 42s
2025-09-17 15:47:22 +03:00
f814a1ba00 Update dockerfile 2025-09-15 15:22:41 +03:00
2 changed files with 8 additions and 4 deletions

View File

@ -2,10 +2,12 @@ FROM python:3.13-slim
WORKDIR /app WORKDIR /app
COPY . .
RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev build-essential RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev build-essential
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "src/main.py"] CMD ["python", "src/main.py"]

View File

@ -11,6 +11,7 @@ router = APIRouter(prefix='/api')
class Entry(BaseModel): class Entry(BaseModel):
username: str
url: str url: str
rating: int | None = None rating: int | None = None
@ -47,6 +48,7 @@ async def save_rating(entry: Entry, response: Response):
message = 'internal server error' message = 'internal server error'
finally: finally:
return {'message': message, return {'message': message,
'username': entry.username,
'url': entry.url, 'url': entry.url,
'rating': entry.rating 'rating': entry.rating
} }
@ -68,14 +70,14 @@ async def remove_rating(entry: Entry, response: Response):
async def get_article_html(article: Article, response: Response = None): async def get_article_html(article: Article, response: Response = None):
html_string = await scraper.get_article_html(article.url) html_string = await scraper.get_article_html(article.url)
b64_string = base64.b64encode(html_string.encode('utf-8')).decode('utf-8') b64_string = base64.b64encode(html_string.encode('utf-8')).decode('utf-8')
return Response(content=article.url + '\r\n' + b64_string, media_type='text/plain') return {article.url: b64_string}
@router.post('/article/get/md') @router.post('/article/get/md')
async def get_article_md(article: Article, response: Response = None): async def get_article_md(article: Article, response: Response = None):
md_string = await scraper.get_article_html(article.url, md=True) md_string = await scraper.get_article_html(article.url, md=True)
b64_string = base64.b64encode(md_string.encode('utf-8')).decode('utf-8') b64_string = base64.b64encode(md_string.encode('utf-8')).decode('utf-8')
return Response(content=article.url + '\r\n' + b64_string, media_type='text/plain') return {article.url: b64_string}
@router.post('/articles/get/html') @router.post('/articles/get/html')