v1.2.8 fix zip upload

This commit is contained in:
LanQian 2024-06-16 15:44:55 +08:00
parent 79d4556828
commit b5b20d4293
6 changed files with 71 additions and 10 deletions

View File

@ -37,7 +37,7 @@ jobs:
images: lanqian528/chat2api
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=v1.2.7
type=raw,value=v1.2.8
- name: Build and push
uses: docker/build-push-action@v5

View File

@ -22,7 +22,7 @@
## 功能
### 最新版 v1.2.7
### 最新版 v1.2.8
> 已完成
> - [x] 流式、非流式传输

View File

@ -74,11 +74,72 @@ async def get_file_extension(mime_type):
"text/x-csharp": ".cs",
"application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx",
"text/x-c++": ".cpp",
"application/x-latext": ".latex",
"application/x-latex": ".latex",
"text/markdown": ".md",
"text/plain": ".txt",
"text/x-ruby": ".rb",
"text/x-script.python": ".py",
# 其他 MIME 类型和扩展名...
"application/zip": ".zip",
"application/zip-compressed": ".zip",
"application/x-tar": ".tar",
"application/x-tar-compressed": ".tar",
"application/x-rar": ".rar",
"application/x-rar-compressed": ".rar",
"application/x-7z": ".7z",
"application/x-7z-compressed": ".7z",
"application/octet-stream": ".bin",
"audio/mpeg": ".mp3",
"audio/wav": ".wav",
"audio/ogg": ".ogg",
"audio/aac": ".aac",
"video/mp4": ".mp4",
"video/x-msvideo": ".avi",
"video/x-matroska": ".mkv",
"video/webm": ".webm",
"application/rtf": ".rtf",
"application/vnd.ms-excel": ".xls",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ".xlsx",
"text/css": ".css",
"text/xml": ".xml",
"application/xml": ".xml",
"application/vnd.android.package-archive": ".apk",
"application/vnd.apple.installer+xml": ".mpkg",
"application/x-bzip": ".bz",
"application/x-bzip2": ".bz2",
"application/x-csh": ".csh",
"application/x-debian-package": ".deb",
"application/x-dvi": ".dvi",
"application/java-archive": ".jar",
"application/x-java-jnlp-file": ".jnlp",
"application/vnd.mozilla.xul+xml": ".xul",
"application/vnd.ms-fontobject": ".eot",
"application/ogg": ".ogx",
"application/x-font-ttf": ".ttf",
"application/font-woff": ".woff",
"application/x-shockwave-flash": ".swf",
"application/vnd.visio": ".vsd",
"application/xhtml+xml": ".xhtml",
"application/vnd.ms-powerpoint": ".ppt",
"application/vnd.oasis.opendocument.text": ".odt",
"application/vnd.oasis.opendocument.spreadsheet": ".ods",
"application/x-xpinstall": ".xpi",
"application/vnd.google-earth.kml+xml": ".kml",
"application/vnd.google-earth.kmz": ".kmz",
"application/x-font-otf": ".otf",
"application/vnd.ms-excel.addin.macroEnabled.12": ".xlam",
"application/vnd.ms-excel.sheet.binary.macroEnabled.12": ".xlsb",
"application/vnd.ms-excel.template.macroEnabled.12": ".xltm",
"application/vnd.ms-powerpoint.addin.macroEnabled.12": ".ppam",
"application/vnd.ms-powerpoint.presentation.macroEnabled.12": ".pptm",
"application/vnd.ms-powerpoint.slideshow.macroEnabled.12": ".ppsm",
"application/vnd.ms-powerpoint.template.macroEnabled.12": ".potm",
"application/vnd.ms-word.document.macroEnabled.12": ".docm",
"application/vnd.ms-word.template.macroEnabled.12": ".dotm",
"application/x-ms-application": ".application",
"application/x-ms-wmd": ".wmd",
"application/x-ms-wmz": ".wmz",
"application/x-ms-xbap": ".xbap",
"application/vnd.ms-xpsdocument": ".xps",
"application/x-silverlight-app": ".xap"
}
return extension_mapping.get(mime_type, "")

View File

@ -439,9 +439,6 @@ class ChatService:
file_extension = await get_file_extension(mime_type)
file_name = f"{uuid.uuid4()}{file_extension}"
use_case = await determine_file_use_case(mime_type)
if use_case == "ace_upload":
mime_type = ''
logger.error(f"Error file mime_type, change to None")
file_id, upload_url = await self.get_upload_url(file_name, file_size, use_case)
if file_id and upload_url:
@ -454,7 +451,8 @@ class ChatService:
"size_bytes": file_size,
"mime_type": mime_type,
"width": width,
"height": height
"height": height,
"use_case": use_case
}
logger.info(f"File_meta: {file_meta}")
return file_meta

View File

@ -331,6 +331,7 @@ async def api_messages_to_chat(service, api_messages, upload_by_url=False):
file_size = file_meta["size_bytes"]
file_name = file_meta["file_name"]
mime_type = file_meta["mime_type"]
use_case = file_meta["use_case"]
if mime_type.startswith("image/"):
width, height = file_meta["width"], file_meta["height"]
file_tokens += await calculate_image_tokens(width, height, detail)
@ -350,7 +351,8 @@ async def api_messages_to_chat(service, api_messages, upload_by_url=False):
"height": height
})
else:
await service.check_upload(file_id)
if not use_case == "ace_upload":
await service.check_upload(file_id)
file_tokens += file_size // 1000
attachments.append({
"id": file_id,

View File

@ -42,7 +42,7 @@ arkose_token_url_list = arkose_token_url.split(',') if arkose_token_url else []
proxy_url_list = proxy_url.split(',') if proxy_url else []
logger.info("-" * 60)
logger.info("Chat2Api v1.2.7 | https://github.com/lanqian528/chat2api")
logger.info("Chat2Api v1.2.8 | https://github.com/lanqian528/chat2api")
logger.info("-" * 60)
logger.info("Environment variables:")
logger.info("API_PREFIX: " + str(api_prefix))