Skip to content

Commit

Permalink
Fix copy_images, Add support .arc files
Browse files Browse the repository at this point in the history
  • Loading branch information
hlohaus committed Feb 12, 2025
1 parent 226c69d commit 5676752
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions g4f/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os.path
import hashlib
import asyncio
from urllib.parse import quote_plus
from fastapi import FastAPI, Response, Request, UploadFile, Depends
from fastapi.middleware.wsgi import WSGIMiddleware
from fastapi.responses import StreamingResponse, RedirectResponse, HTMLResponse, JSONResponse
Expand Down Expand Up @@ -552,7 +551,7 @@ async def get_json(filename, request: Request):
HTTP_404_NOT_FOUND: {}
})
async def get_image(filename, request: Request):
target = os.path.join(images_dir, quote_plus(filename))
target = os.path.join(images_dir, os.path.basename(filename))
ext = os.path.splitext(filename)[1][1:]
stat_result = SimpleNamespace()
stat_result.st_size = 0
Expand Down
6 changes: 3 additions & 3 deletions g4f/image/copy_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ async def copy_images(
) as session:
async def copy_image(image: str, target: str = None) -> str:
"""Process individual image and return its local URL"""
target_path = None
try:
target_path = target
if target_path is None:
# Generate filename components
file_hash = hashlib.sha256(image.encode()).hexdigest()[:16]
timestamp = int(time.time())
Expand All @@ -88,7 +88,7 @@ async def copy_image(image: str, target: str = None) -> str:
f"{extension}"
)
target_path = os.path.join(images_dir, filename)

try:
# Handle different image types
if image.startswith("data:"):
with open(target_path, "wb") as f:
Expand Down
2 changes: 1 addition & 1 deletion g4f/tools/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
from ..errors import MissingRequirementsError
from .. import debug

PLAIN_FILE_EXTENSIONS = ["txt", "xml", "json", "js", "har", "sh", "py", "php", "css", "yaml", "sql", "log", "csv", "twig", "md"]
PLAIN_FILE_EXTENSIONS = ["txt", "xml", "json", "js", "har", "sh", "py", "php", "css", "yaml", "sql", "log", "csv", "twig", "md", "arc"]
PLAIN_CACHE = "plain.cache"
DOWNLOADS_FILE = "downloads.json"
FILE_LIST = "files.txt"
Expand Down

0 comments on commit 5676752

Please sign in to comment.