XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Support for application/octet-stream media_type

714412f8
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

4 个文件 +22 -10
Modified g4f/gui/client/demo.html +1 -1
@@ -277,7 +277,7 @@
277 277 document.getElementById("signin").style.removeProperty("display");
278 278 document.getElementById("signin").onclick = async function() {
279 279 window.location.href = (await oauthLoginUrl({
280 clientId: 'ed074164-4f8d-4fb2-8bec-44952707965e',
280 clientId: '{{client_id}}',
281 281 scopes: ['inference-api']
282 282 }));
283 283 }
Modified g4f/gui/client/qrcode.html +9 -3
@@ -31,7 +31,13 @@
31 31 <button id="generateQRCode">Generate QR Code</button>
32 32
33 33 <script type="module">
34 const share_url = "{{share_url}}" || window.location.origin;
34 35 const conversation_id = "{{conversation_id}}";
36 if (!conversation_id) {
37 document.getElementById('generateQRCode')
38 .setAttribute('disabled', 'disabled');
39 }
40
35 41 import QrScanner from 'https://cdn.jsdelivr.net/npm/qr-scanner/qr-scanner.min.js';
36 42
37 43 function generate_uuid() {
@@ -69,13 +75,13 @@
69 75 document.getElementById('generateQRCode').addEventListener('click', () => {
70 76 const chat_id = generate_uuid();
71 77
72 const url = `/backend-api/v2/chat/${encodeURI(chat_id)}`;
78 const url = `${share_url}/backend-api/v2/chat/${encodeURI(chat_id)}`;
73 79 fetch(url, {
74 80 method: 'POST',
75 81 headers: {'content-type': 'application/json'},
76 82 body: localStorage.getItem(`conversation:${conversation_id}`)
77 83 });
78 const share = `${window.location.origin}/chat/${encodeURI(chat_id)}/${encodeURI(conversation_id)}`;
84 const share = `${share_url}/chat/${encodeURI(chat_id)}/${encodeURI(conversation_id)}`;
79 85 document.getElementById('qrcode-status').innerText = share;
80 86 document.getElementById("qrcode").innerHTML = '';
81 87 const qrcode = new QRCode(
@@ -116,7 +122,7 @@
116 122 qrScanner = new QrScanner(videoElem, result => {
117 123 camStatus.innerText = 'Camera Success: ', result;
118 124 console.log('decoded QR code:', result.data);
119 if (result.data.startsWith(window.location.origin)) {
125 if (result.data.startsWith(share_url)) {
120 126 location.href = result.data;
121 127 }
122 128 }, {
Modified g4f/gui/server/backend_api.py +7 -3
@@ -63,15 +63,19 @@ class Backend_Api(Api):
63 63 if app.demo:
64 64 @app.route('/', methods=['GET'])
65 65 def home():
66 return render_template('demo.html', backend_url=os.environ.get("G4F_BACKEND_URL", ""))
66 client_id = os.environ.get("OAUTH_CLIENT_ID", "ed074164-4f8d-4fb2-8bec-44952707965e")
67 backend_url = os.environ.get("G4F_BACKEND_URL", "")
68 return render_template('demo.html', backend_url=backend_url, client_id=client_id)
67 69 else:
68 70 @app.route('/', methods=['GET'])
69 71 def home():
70 72 return render_template('home.html')
71 73
74 @app.route('/qrcode', methods=['GET'])
72 75 @app.route('/qrcode/<conversation_id>', methods=['GET'])
73 def qrcode(conversation_id: str):
74 return render_template('qrcode.html', conversation_id=conversation_id)
76 def qrcode(conversation_id: str = ""):
77 share_url = os.environ.get("G4F_SHARE_URL", "")
78 return render_template('qrcode.html', conversation_id=conversation_id, share_url=share_url)
75 79
76 80 @app.route('/backend-api/v2/models', methods=['GET'])
77 81 def jsonify_models(**kwargs):
Modified g4f/image/copy_images.py +5 -3
@@ -134,10 +134,12 @@ async def copy_media(
134 134
135 135 async with session.get(image, ssl=request_ssl, headers=request_headers) as response:
136 136 response.raise_for_status()
137 if not is_valid_media_type(response.headers.get("content-type")):
138 raise ValueError(f"Unsupported media type: {response.headers.get('content-type')}")
137 media_type = response.headers.get("content-type", "application/octet-stream")
138 if media_type != "application/octet-stream":
139 if not is_valid_media_type(media_type):
140 raise ValueError(f"Unsupported media type: {media_type}")
139 141 with open(target_path, "wb") as f:
140 async for chunk in response.content.iter_chunked(4096):
142 async for chunk in response.content.iter_any():
141 143 f.write(chunk)
142 144
143 145 # Verify file format