Skip to content

Commit

Permalink
初始化项目架构
Browse files Browse the repository at this point in the history
  • Loading branch information
shitianGit committed Aug 10, 2023
0 parents commit 5da8049
Show file tree
Hide file tree
Showing 427 changed files with 87,278 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sd-pics-hub
===============


<div style="font-size: 1.5rem;">
<a href="./README.md">English</a> |
<a href="./README_ZH.md">中文</a>
</div>
</br>


This is an application that utilizes stable diffusion to create personalized AI portraits. You simply need to upload a clear selfie, and the application will generate AI portraits in various styles.

## Copyright Information

sd-pics-hub is released under the [Apache License 2.0]() open-source license and is available for free use.

Copyright © 2023 by EMart
38 changes: 38 additions & 0 deletions README_ZH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
sd-pics-hub
===============


<div style="font-size: 1.5rem;">
<a href="./README.md">English</a> |
<a href="./README_ZH.md">中文</a>
</div>
</br>

这是一个利用stable diffusion生成个人AI写真的应用,你只需要上传一张清晰的自拍照,就可以生成多种风格的AI写真

## 目录结构

总体目录结构如下

```
├─sd-pics-hub
│ ├─api (数据接口部分,使用Egg.js框架)
│ ├─client 客户端,暂定使用hbuild+vue构建,支持多端发布)
│ ├─doc (文档、资料等)
│ │ ├─database.md (数据结构)
│ ├─worker (用于接收任务,调用stable-diffusion接口完成工作的工人模块)
│ ├─docker-compose.yml (用于一键启动docker-compose容器编排配置文件)
│ ├─README.md (项目说明文档)
│ ├─README_ZH.md (项目说明文档-中文)
```
## 功能规划

**1.0 版本**

1.

## 版权信息

sd-pics-hub 遵循 [Apache License 2.0]() 开源协议发布,并提供免费使用。

Copyright © 2023 by EMart
44 changes: 44 additions & 0 deletions api/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# OpenAI API Key - https://platform.openai.com/overview
OPENAI_API_KEY=

# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
OPENAI_ACCESS_TOKEN=

# OpenAI API Base URL - https://api.openai.com
OPENAI_API_BASE_URL=

# OpenAI API Model - https://platform.openai.com/docs/models
OPENAI_API_MODEL=

# set `true` to disable OpenAI API debug log
OPENAI_API_DISABLE_DEBUG=

# Reverse Proxy - Available on accessToken
# Default: https://bypass.churchless.tech/api/conversation
# More: https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy
API_REVERSE_PROXY=

# timeout
TIMEOUT_MS=100000

# Rate Limit
MAX_REQUEST_PER_HOUR=

# Secret key
AUTH_SECRET_KEY=

# Socks Proxy Host
SOCKS_PROXY_HOST=192.168.8.105

# Socks Proxy Port
SOCKS_PROXY_PORT=18991

# Socks Proxy Username
SOCKS_PROXY_USERNAME=

# Socks Proxy Password
SOCKS_PROXY_PASSWORD=

# HTTPS PROXY
HTTPS_PROXY=

1 change: 1 addition & 0 deletions api/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
9 changes: 9 additions & 0 deletions api/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"overlay": {
"warnings": false,
"errors": false
},
"lintOnSave": false,
"extends": "eslint-config-egg",
"root": false
}
46 changes: 46 additions & 0 deletions api/.github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
schedule:
- cron: '0 2 * * *'

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
node-version: [16, 18]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout Git Source
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install Dependencies
run: npm i

- name: Continuous Integration
run: npm run ci

- name: Code Coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
15 changes: 15 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
logs/
npm-debug.log
yarn-error.log
node_modules/
*-lock.json
*-lock.yaml
yarn.lock
coverage/
.idea/
run/
.DS_Store
*.sw*
*.un~
typings/
.nyc_output/
40 changes: 40 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 设置基础镜像,如果本地没有该镜像,会从Docker.io服务器pull镜像
FROM node:18.14.2-alpine3.17

# # 设置时区
# RUN apk --update add tzdata \
# && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
# && echo "Asia/Shanghai" > /etc/timezone \
# && apk del tzdata

# 创建app目录
RUN mkdir -p /app

# 设置工作目录
WORKDIR /app

# 拷贝package.json文件到工作目录
# !!重要:package.json需要单独添加。
# Docker在构建镜像的时候,是一层一层构建的,仅当这一层有变化时,重新构建对应的层。
# 如果package.json和源代码一起添加到镜像,则每次修改源码都需要重新安装npm模块,这样木有必要。
# 所以,正确的顺序是: 添加package.json;安装npm模块;添加源代码。
COPY package.json /app/package.json

# 安装npm依赖(使用淘宝的镜像源)
# 如果使用的境外服务器,无需使用淘宝的镜像源,即改为`RUN npm i`。
RUN npm install -g [email protected]
RUN npm i --production --registry=https://registry.npmmirror.com

# 拷贝所有源代码到工作目录
COPY . /app

RUN cd /app/lib/plugins/egg-lu-redis && npm i --registry=https://registry.npmmirror.com


WORKDIR /app

# 暴露容器端口
EXPOSE 7001

# 启动node应用
CMD npm start
33 changes: 33 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# chat-egg-server



## QuickStart

<!-- add docs here for user -->

see [egg docs][egg] for more detail.

### Development

```bash
$ npm i
$ npm run dev
$ open http://localhost:7001/
```

### Deploy

```bash
$ npm start
$ npm stop
```

### npm scripts

- Use `npm run lint` to check code style.
- Use `npm test` to run unit test.
- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail.


[egg]: https://eggjs.org
99 changes: 99 additions & 0 deletions api/app/controller/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use strict';

const { Controller } = require('egg');

class AccountController extends Controller {

/**
* 验证码登录
*/
async phoneLogin() {

}

/**
* 发送短信验证码
*/
async sendSMS() {

}

/**
* 登录账号
*/
async login() {
const { ctx, app, service } = this;
const input = ctx.request.body;
// 验证参数合法性
const errors = app.validator.validate(
{
user_name: { type: 'string', required: true },
timestamp: { type: 'number', required: true },
random_number: { type: 'number', required: true },
user_key: { type: 'string', max: 32, min: 32, required: true },
},
input
);
if (errors && errors.length > 0)
throw ctx.ltool.err(`"${errors[0].field}"${errors[0].message}`, 4011);

// 验证登录信息合法性
const userinfo = await ctx.service.user.userKeyLogin(input, ctx.request.ip);
const token_3rd_session = ctx.ltool.nonceString(22);

// 更新用户登录token
await ctx.service.user.updateSessionID(
userinfo.id,
token_3rd_session,
input.logintype
);

//返回信息
ctx.body = {
token: token_3rd_session,
userid: userinfo.id,
logintype: input.logintype,
};
}
/**
* 注册账号
*/
async register() {
const { ctx, app } = this;
const { account, nick_name, pwd, logintype } = ctx.request.body;
const input = { account, nick_name, pwd ,logintype};

// 验证参数合法性
const errors = app.validator.validate(
{
account: { type: 'string', required: true },
nick_name: { type: 'string', required: true },
pwd: { type: 'password', required: true },
},
input
);
if (errors && errors.length > 0)
throw ctx.ltool.err(`"${errors[0].field}"${errors[0].message}`, 4011);

// 尝试注册
const userinfo = await ctx.service.user.register(input, ctx.request.ip);

// 生成token
const token_3rd_session = ctx.ltool.nonceString(22);
// 更新用户登录token
await ctx.service.user.updateSessionID(
userinfo.id,
token_3rd_session,
input.logintype
);

//返回信息
ctx.body = {
token: token_3rd_session,
userid: userinfo.id,
logintype: input.logintype,
};
}
}

module.exports = AccountController;
23 changes: 23 additions & 0 deletions api/app/controller/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const { Controller } = require('egg');

class DefaultController extends Controller {
async getnowtime() {
this.ctx.body = new Date().getTime();
}
async test() {
const { ctx , app} = this;
const user = await this.ctx.service.user.findByNameDB('[email protected]');
ctx.body = user?user:"";
}

async pubChat() {
const { ctx, app } = this;
const { messages} = ctx.request.body;
const result = await ctx.service.chatgpt.SendMsg(messages);
ctx.body = result;
}
}

module.exports = DefaultController;
14 changes: 14 additions & 0 deletions api/app/controller/doppelganger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 数字分身相关
*/

'use strict';

const { Controller } = require('egg');

class DoppelgangerController extends Controller {
async create(){}
async getList(){}
}

module.exports = DoppelgangerController;
Loading

0 comments on commit 5da8049

Please sign in to comment.