Skip to content

Commit

Permalink
feat: 添加docker启动方式
Browse files Browse the repository at this point in the history
  • Loading branch information
zhukai committed May 6, 2023
1 parent efb30b1 commit 8991213
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 28 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
logs
*.log
npm-debug.log*
.env
*memory-card.json
56 changes: 56 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
FROM node:18.16.0

WORKDIR /app

RUN apt-get update && apt-get install -y \
ca-certificates \
fonts-liberation \
libappindicator3-1 \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgbm-dev \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
lsb-release \
wget \
xdg-utils \
libnss3 \
&& rm -rf /var/lib/apt/lists/*

COPY package*.json ./

RUN npm install

COPY . .
RUN cp .env.example .env

EXPOSE 4120

CMD ["npm", "run", "dev"]
61 changes: 33 additions & 28 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,41 @@ async function main() {
main();

app.post("/notify", async (req: Request, res: Response): Promise<Response> => {
const state = req.body.state;
const i = state.indexOf(":");
const roomName = state.substring(0, i);
const userName = state.substring(i + 1);
const room = await client.Room.find({ topic: roomName });
if (!room) {
return res.status(404).send("room not found");
}
const action = req.body.action;
const status = req.body.status;
const description = req.body.description;
if (status == 'IN_PROGRESS') {
room.say(`@${userName} \n✅ 您的任务已提交\n✨ ${description}\n🚀 正在快速处理中,请稍后`);
} else if (status == 'FAILURE') {
room.say(`@${userName} \n❌ 任务执行失败\n✨ ${description}`);
} else if (status == 'SUCCESS') {
const time = req.body.finishTime - req.body.submitTime;
if (action == 'UPSCALE') {
await room.say(`@${userName} \n🎨 图片放大,用时: ${displayMilliseconds(time)}\n✨ ${description}`);
const image = FileBox.fromUrl(req.body.imageUrl);
room.say(image);
} else {
const taskId = req.body.id;
const prompt = req.body.prompt;
await room.say(`@${userName} \n🎨 ${action == 'IMAGINE' ? '绘图' : '变换'}成功,用时 ${displayMilliseconds(time)}\n✨ Prompt: ${prompt}\n📨 任务ID: ${taskId}\n🪄 放大 U1~U4 ,变换 V1~V4\n✏️ 使用[/up 任务ID 操作]\n/up ${taskId} U1`);
const image = FileBox.fromUrl(req.body.imageUrl);
room.say(image);
try {
const state = req.body.state;
const i = state.indexOf(":");
const roomName = state.substring(0, i);
const userName = state.substring(i + 1);
const room = await client.Room.find({ topic: roomName });
if (!room) {
return res.status(404).send("room not found");
}
const action = req.body.action;
const status = req.body.status;
const description = req.body.description;
if (status == 'IN_PROGRESS') {
room.say(`@${userName} \n✅ 您的任务已提交\n✨ ${description}\n🚀 正在快速处理中,请稍后`);
} else if (status == 'FAILURE') {
room.say(`@${userName} \n❌ 任务执行失败\n✨ ${description}`);
} else if (status == 'SUCCESS') {
const time = req.body.finishTime - req.body.submitTime;
if (action == 'UPSCALE') {
await room.say(`@${userName} \n🎨 图片放大,用时: ${displayMilliseconds(time)}\n✨ ${description}`);
const image = FileBox.fromUrl(req.body.imageUrl);
room.say(image);
} else {
const taskId = req.body.id;
const prompt = req.body.prompt;
await room.say(`@${userName} \n🎨 ${action == 'IMAGINE' ? '绘图' : '变换'}成功,用时 ${displayMilliseconds(time)}\n✨ Prompt: ${prompt}\n📨 任务ID: ${taskId}\n🪄 放大 U1~U4 ,变换 V1~V4\n✏️ 使用[/up 任务ID 操作]\n/up ${taskId} U1`);
const image = FileBox.fromUrl(req.body.imageUrl);
room.say(image);
}
}
return res.status(200).send({ code: 1 });
} catch (e) {
console.error(`notify callback failed: ${e}`);
return res.status(500).send({ code: -9 });
}
return res.status(200).send({ code: 1 });
});

try {
Expand Down

0 comments on commit 8991213

Please sign in to comment.