486CHD commited on
Commit
e5e7589
·
verified ·
1 Parent(s): 8bd92e1

Upload 13 files

Browse files
Files changed (2) hide show
  1. index.html +26 -1
  2. server.js +7 -2
index.html CHANGED
@@ -379,6 +379,7 @@
379
 
380
  };
381
  const IMAGE_SIZE_STORAGE_KEY = 'BananaPro_ImageSize';
 
382
  const API_BASE_STORAGE_KEY = 'BananaPro_ApiBase';
383
 
384
  const resolveApiBase = () => {
@@ -423,6 +424,27 @@
423
 
424
  const IMAGE_SIZE = resolveImageSize();
425
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  const resolveAssetUrl = (value) => {
427
  if (!value || typeof value !== 'string') return '';
428
  if (/^https?:\/\//i.test(value) || value.startsWith('data:') || value.startsWith('blob:')) {
@@ -3005,10 +3027,13 @@
3005
 
3006
 
3007
 
 
 
3008
  const requestBody = {
3009
  prompt: prompt,
3010
  images: AppState.currentImages,
3011
- preferUrl: false,
 
3012
  imageSize: IMAGE_SIZE
3013
  };
3014
 
 
379
 
380
  };
381
  const IMAGE_SIZE_STORAGE_KEY = 'BananaPro_ImageSize';
382
+ const IMAGE_RESPONSE_STORAGE_KEY = 'BananaPro_ImageResponse';
383
  const API_BASE_STORAGE_KEY = 'BananaPro_ApiBase';
384
 
385
  const resolveApiBase = () => {
 
424
 
425
  const IMAGE_SIZE = resolveImageSize();
426
 
427
+ const normalizeResponseMode = (value, fallback) => {
428
+ const normalized = String(value || '').trim().toLowerCase();
429
+ if (normalized === 'url' || normalized === 'base64' || normalized === 'both') {
430
+ return normalized;
431
+ }
432
+ return fallback;
433
+ };
434
+
435
+ const resolveResponseMode = () => {
436
+ const params = new URLSearchParams(window.location.search);
437
+ const paramMode = params.get('response');
438
+ if (paramMode) {
439
+ localStorage.setItem(IMAGE_RESPONSE_STORAGE_KEY, paramMode);
440
+ }
441
+ const stored = localStorage.getItem(IMAGE_RESPONSE_STORAGE_KEY);
442
+ const fallback = Device.isMobile ? 'url' : 'base64';
443
+ return normalizeResponseMode(paramMode || stored, fallback);
444
+ };
445
+
446
+ const RESPONSE_MODE = resolveResponseMode();
447
+
448
  const resolveAssetUrl = (value) => {
449
  if (!value || typeof value !== 'string') return '';
450
  if (/^https?:\/\//i.test(value) || value.startsWith('data:') || value.startsWith('blob:')) {
 
3027
 
3028
 
3029
 
3030
+ const wantsUrl = RESPONSE_MODE !== 'base64';
3031
+ const wantsBase64 = RESPONSE_MODE !== 'url';
3032
  const requestBody = {
3033
  prompt: prompt,
3034
  images: AppState.currentImages,
3035
+ preferUrl: wantsUrl,
3036
+ returnBase64: wantsBase64,
3037
  imageSize: IMAGE_SIZE
3038
  };
3039
 
server.js CHANGED
@@ -648,7 +648,7 @@ app.get('/api/check-auth', (req, res) => {
648
 
649
  // Generate image (multi-image)
650
  app.post('/api/generate', authMiddleware, async (req, res) => {
651
- const { prompt, images, preferUrl, imageSize, aspectRatio } = req.body;
652
  const requestStart = Date.now();
653
  StatsStore.activeRequests += 1;
654
  let recorded = false;
@@ -717,6 +717,7 @@ app.post('/api/generate', authMiddleware, async (req, res) => {
717
  const apiResponse = await APIService.generateImage(trimmedPrompt, uploadedImages, apiOptions);
718
  const imageData = APIService.extractImageFromResponse(apiResponse);
719
  const wantsUrl = Boolean(preferUrl);
 
720
  let imageUrl = null;
721
  let imageId = null;
722
 
@@ -739,6 +740,10 @@ app.post('/api/generate', authMiddleware, async (req, res) => {
739
  console.log(`[${new Date().toISOString()}] Image generated`);
740
 
741
  recordOnce(true);
 
 
 
 
742
  const responsePayload = {
743
  success: true,
744
  imageUrl,
@@ -748,7 +753,7 @@ app.post('/api/generate', authMiddleware, async (req, res) => {
748
  timestamp: new Date().toISOString()
749
  };
750
 
751
- if (!wantsUrl || !imageUrl) {
752
  responsePayload.image = imageData;
753
  }
754
 
 
648
 
649
  // Generate image (multi-image)
650
  app.post('/api/generate', authMiddleware, async (req, res) => {
651
+ const { prompt, images, preferUrl, imageSize, aspectRatio, returnBase64 } = req.body;
652
  const requestStart = Date.now();
653
  StatsStore.activeRequests += 1;
654
  let recorded = false;
 
717
  const apiResponse = await APIService.generateImage(trimmedPrompt, uploadedImages, apiOptions);
718
  const imageData = APIService.extractImageFromResponse(apiResponse);
719
  const wantsUrl = Boolean(preferUrl);
720
+ const wantsBase64 = returnBase64 !== false;
721
  let imageUrl = null;
722
  let imageId = null;
723
 
 
740
  console.log(`[${new Date().toISOString()}] Image generated`);
741
 
742
  recordOnce(true);
743
+ if (wantsUrl && !imageUrl && !wantsBase64) {
744
+ throw new Error('生成图片保存失败,请稍后重试');
745
+ }
746
+
747
  const responsePayload = {
748
  success: true,
749
  imageUrl,
 
753
  timestamp: new Date().toISOString()
754
  };
755
 
756
+ if ((!wantsUrl || !imageUrl) && wantsBase64) {
757
  responsePayload.image = imageData;
758
  }
759