This commit is contained in:
2023-04-19 09:29:31 +08:00
parent cf199dfc01
commit c5e713c784
3 changed files with 129 additions and 11 deletions

View File

@@ -31,6 +31,8 @@ GET /api/images
id: 1234, // 原图ID id: 1234, // 原图ID
width: 512, // 原图宽度 width: 512, // 原图宽度
height: 512, // 原图高度 height: 512, // 原图高度
createdAt: '', // 創建時間
updatedAt: '', // 更新時間
user: { // 来源用户 user: { // 来源用户
id: 1234, id: 1234,
user_name: 'LAST', user_name: 'LAST',
@@ -80,3 +82,98 @@ GET | /api/images?sort=choice | 根据精选集推荐(指定精选集I
* 注意, 筛选规则为多条件取交集, 单条件的复数取并集 * 注意, 筛选规则为多条件取交集, 单条件的复数取并集
* 权重强化属于排序规则而非过滤规则 * 权重强化属于排序规则而非过滤规则
### 獲取模型列表
GET /api/models
```javascript
{
page: 1, // 当前页码
pageSize: 20, // 分页数
next: true, // 是否存在下一页
list: [{
id: 'xxxxx', // 模型ID
name: 'xxx', // 模型名稱
createdAt: '', // 創建時間
updatedAt: '', // 更新時間
}]
}
```
篩選規則:(數據過濾)
-----------------------------------------------------------
Method | URL | Info
-------|--------------------------------|------------------
GET | /api/models?user=1234 | 按用戶ID篩選
GET | /api/models?tag=xxx | 按標籤分類篩選
### 獲取標籤
GET /api/tags
```javascript
{
page: 1, // 当前页码
pageSize: 20, // 分页数
next: true, // 是否存在下一页
list: [{
id: 'xxxxx', // 標籤ID
name: 'xxx', // 標籤名稱
createdAt: '', // 創建時間
updatedAt: '', // 更新時間
}]
}
```
篩選規則:(數據過濾)
-----------------------------------------------------------
Method | URL | Info
-------|--------------------------------|------------------
GET | /api/tags?user=1234 | 按用戶ID篩選
GET | /api/tags?tag=xxx | 按標籤分類篩選
### 獲取任務
GET /api/tasks
```javascript
{
page: 1, // 当前页码
pageSize: 20, // 分页数
next: true, // 是否存在下一页
list: [{
id: 'xxxxx', // 任務ID
name: 'xxx', // 任務名稱
data: {}, // 任務數據
createdAt: '', // 創建時間
updatedAt: '', // 更新時間
}]
}
```
篩選規則:(數據過濾)
-----------------------------------------------------------
Method | URL | Info
-------|--------------------------------|------------------
GET | /api/tasks?user=1234 | 按用戶ID篩選
GET | /api/tasks?tag=xxx | 按標籤分類篩選
### 監聽任務
WebSocket /api/tasks/{task_id}
```javascript
{
id: 'xxxx', // 任務ID
// 任務狀態
// 任務進度
// 返回數據
}
```
* 使用websocket建立連接以對指定任務監聽狀態變化
* 離開頁面時,或是任務結束時, 應斷開websocket連接
* 當任務狀態發生變化時, 服務端向瀏覽器主動發送消息
* 返回數據:任務執行中爲預覽, 任務完成時爲生成結果

21
main.go
View File

@@ -13,25 +13,24 @@ import (
func main() { func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
wecome := "Welcome to the home page!"
w.Write([]byte(wecome))
})
http.HandleFunc("/api/images", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志 defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
var listview models.ListView var listview models.ListView
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(listview.ToJson()) w.Write(listview.ToJson())
}) })
http.HandleFunc("/images", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api/models", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志 defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
var listview models.ListView var listview models.ListView
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(listview.ToJson()) w.Write(listview.ToJson())
}) })
http.HandleFunc("/models", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api/tasks", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
var listview models.ListView
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(listview.ToJson())
})
http.HandleFunc("/tasks", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志 defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
// 查詢一組任務 // 查詢一組任務
@@ -51,13 +50,13 @@ func main() {
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(listview.ToJson()) w.Write(listview.ToJson())
}) })
http.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api/users", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志 defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
var listview models.ListView var listview models.ListView
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(listview.ToJson()) w.Write(listview.ToJson())
}) })
http.HandleFunc("/tags", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/api/tags", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志 defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
var listview models.ListView var listview models.ListView
w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Content-Type", "application/json; charset=utf-8")

22
update.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
# 靜態編譯
go mod tidy
go build -o data/gameui-ai-server main.go
# 上传文件
scp ./data/gameui-ai-server root@47.103.40.152:~/gameui-ai-server_new
# 重啓服務
ssh root@47.103.40.152 '''
ps -ef | grep -v grep | grep ./gameui-ai-server;
if [ $? -eq 0 ]; then
echo "kill gameui-ai-server"
killall ./gameui-ai-server
fi
rm -rf ./gameui-ai-server;
mv ./gameui-ai-server_new ./gameui-ai-server;
nohup ./gameui-ai-server >> nohup-ai.out 2>&1 &
echo "start gameui-ai-server:8080 ok"
'''