11import { inCfWorker } from "@/server/lib/env" ;
2- import { buildDataURI } from "@/server/lib/util" ;
2+ import { base64ToDataURI , readableStreamToDataURI } from "@/server/lib/util" ;
33import { getContext } from "@/server/service/context" ;
44import type { AiProvider , ApiProviderSettings , ApiProviderSettingsItem } from "../types/provider" ;
55import { type ProviderSettingsType , doParseSettings , getProviderSettingsSchema } from "../types/provider" ;
@@ -54,24 +54,24 @@ const Cloudflare: AiProvider = {
5454 ability : "t2i" ,
5555 enabledByDefault : true ,
5656 } ,
57- {
58- id : "@cf/bytedance/stable-diffusion-xl-lightning" ,
59- name : "Stable Diffusion XL Lightning" ,
60- ability : "t2i" ,
61- enabledByDefault : true ,
62- } ,
6357 {
6458 id : "@cf/lykon/dreamshaper-8-lcm" ,
6559 name : "DreamShaper 8 LCM" ,
6660 ability : "t2i" ,
6761 enabledByDefault : true ,
6862 } ,
6963 {
70- id : "@cf/runwayml /stable-diffusion-v1-5-img2img " ,
71- name : "Stable Diffusion v1.5 Img2Img " ,
72- ability : "i2i " ,
64+ id : "@cf/bytedance /stable-diffusion-xl-lightning " ,
65+ name : "Stable Diffusion XL Lightning " ,
66+ ability : "t2i " ,
7367 enabledByDefault : true ,
7468 } ,
69+ // {
70+ // id: "@cf/runwayml/stable-diffusion-v1-5-img2img",
71+ // name: "Stable Diffusion v1.5 Img2Img",
72+ // ability: "i2i",
73+ // enabledByDefault: true,
74+ // },
7575 {
7676 id : "@cf/stabilityai/stable-diffusion-xl-base-1.0" ,
7777 name : "Stable Diffusion XL Base 1.0" ,
@@ -92,8 +92,14 @@ const Cloudflare: AiProvider = {
9292 prompt : request . prompt ,
9393 } ) ;
9494
95+ if ( resp instanceof ReadableStream ) {
96+ return {
97+ images : [ await readableStreamToDataURI ( resp ) ] ,
98+ } ;
99+ }
100+
95101 return {
96- images : [ buildDataURI ( resp . image ) ] ,
102+ images : [ base64ToDataURI ( resp . image ) ] ,
97103 } ;
98104 }
99105
@@ -116,13 +122,13 @@ const Cloudflare: AiProvider = {
116122 if ( contentType ?. includes ( "image/png" ) === true ) {
117123 const imageBuffer = await resp . arrayBuffer ( ) ;
118124 return {
119- images : [ buildDataURI ( Buffer . from ( imageBuffer ) . toString ( "base64" ) ) ] ,
125+ images : [ base64ToDataURI ( Buffer . from ( imageBuffer ) . toString ( "base64" ) ) ] ,
120126 } ;
121127 }
122128
123129 const result = ( await resp . json ( ) ) as unknown as any ;
124130 return {
125- images : [ buildDataURI ( result . result . image ) ] ,
131+ images : [ base64ToDataURI ( result . result . image ) ] ,
126132 } ;
127133 } ,
128134} ;
0 commit comments