forked from ChatGPTNextWeb/ChatGPT-Next-Web
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
181 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,7 @@ | |
.env | ||
|
||
*.key | ||
*.key.pub | ||
*.key.pub | ||
|
||
# upload files | ||
/uploads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,5 +45,5 @@ dev | |
*.key | ||
*.key.pub | ||
|
||
/public/uploads | ||
/uploads | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getServerSideConfig } from "@/app/config/server"; | ||
import { DallEAPIWrapper } from "./dalle_image_generator"; | ||
import S3FileStorage from "@/app/utils/s3_file_storage"; | ||
import LocalFileStorage from "@/app/utils/local_file_storage"; | ||
|
||
export class DallEAPINodeWrapper extends DallEAPIWrapper { | ||
async saveImageFromUrl(url: string) { | ||
const response = await fetch(url); | ||
const content = await response.arrayBuffer(); | ||
const buffer = Buffer.from(content); | ||
|
||
var filePath = ""; | ||
const serverConfig = getServerSideConfig(); | ||
var fileName = `${Date.now()}.png`; | ||
if (serverConfig.isStoreFileToLocal) { | ||
filePath = await LocalFileStorage.put(fileName, buffer); | ||
} else { | ||
filePath = await S3FileStorage.put(fileName, buffer); | ||
} | ||
return filePath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/api/langchain-tools/stable_diffusion_image_generator_node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import S3FileStorage from "@/app/utils/s3_file_storage"; | ||
import { StableDiffusionWrapper } from "./stable_diffusion_image_generator"; | ||
import { getServerSideConfig } from "@/app/config/server"; | ||
import LocalFileStorage from "@/app/utils/local_file_storage"; | ||
|
||
export class StableDiffusionNodeWrapper extends StableDiffusionWrapper { | ||
async saveImage(imageBase64: string) { | ||
var filePath = ""; | ||
var fileName = `${Date.now()}.png`; | ||
const buffer = Buffer.from(imageBase64, "base64"); | ||
const serverConfig = getServerSideConfig(); | ||
if (serverConfig.isStoreFileToLocal) { | ||
filePath = await LocalFileStorage.put(fileName, buffer); | ||
} else { | ||
filePath = await S3FileStorage.put(fileName, buffer); | ||
} | ||
return filePath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
export default class LocalFileStorage { | ||
static async get(fileName: string) { | ||
const filePath = path.resolve(`./uploads`, fileName); | ||
const file = fs.readFileSync(filePath); | ||
if (!file) { | ||
throw new Error("not found."); | ||
} | ||
return file; | ||
} | ||
|
||
static async put(fileName: string, data: Buffer) { | ||
try { | ||
const filePath = path.resolve(`./uploads`, fileName); | ||
const dir = path.dirname(filePath); | ||
if (!fs.existsSync(dir)) { | ||
fs.mkdirSync(dir, { recursive: true }); | ||
} | ||
await fs.promises.writeFile(filePath, data); | ||
console.log("[LocalFileStorage]", filePath); | ||
return `/api/file/${fileName}`; | ||
} catch (e) { | ||
console.error("[LocalFileStorage]", e); | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
296df59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大佬您是真的辛苦!~太感谢了