diff --git a/Procfile b/Procfile index 26a0787..3b13075 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: bin/t +web: bin/api diff --git a/build.zsh b/build.zsh index 6fa36fe..904964e 100755 --- a/build.zsh +++ b/build.zsh @@ -6,7 +6,18 @@ su=5000 go generate ./... cp -rf $d/ent/openapi.json $d/tmp/ -sed -i '' "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go -sed -i '' "s/255/$su/g" $d/ent/openapi.json + +case $OSTYPE in + darwin*) + sed -i '' "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go + sed -i '' "s/255/$su/g" $d/ent/openapi.json + ;; + linux*) + sed -i "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go + sed -i "s/255/$su/g" $d/ent/openapi.json + ;; +esac cp -rf $d/tmp/ogent ent/ +#PASS=`cat token.json|jq -r .password` TOKEN=`cat token.json|jq -r .token` go build +#PASS=`cat token.json|jq -r .password` TOKEN=`cat token.json|jq -r .token` go run -mod=mod main.go diff --git a/docs/wiki.md b/docs/wiki.md new file mode 100644 index 0000000..c8dfe72 --- /dev/null +++ b/docs/wiki.md @@ -0,0 +1,133 @@ +### build + +```sh +$ vim ent/entc.go +$ vim ent/schema/users.go +$ go generate ./... +$ go build +$ ./card + +$ go generate ./... +$ PASS=`cat ./token.json|jq -r .password` TOKEN=`cat ./token.json|jq -r .token` go run -mod=mod main.go +$ curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"syui\",\"password\":\"$pass\"}" localhost:8080/users +$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"password\":\"$pass\"}" localhost:8080/cards +$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"card\":1,\"cp\":11,\"status\":\"normal\",\"password\":\"$pass\"}" localhost:8080/cards +$ curl localhost:8080/users +$ curl localhost:8080/cards +$ curl localhost:8080/users/1 +$ curl localhost:8080/users/1/card +``` + +### use + +```sh +$ curl -X POST -H "Content-Type: application/json" -d '{"username":"syui",\"password\":\"$pass\"}' https://api.syui.ai/users + +# onconflict +$ !! + +$ curl -sL https://api.syui.ai/users/1 +``` + +```sh +# item select +$ curl -sL "https://api.syui.ai/users?itemsPerPage=255" +$ curl -sL "https://api.syui.ai/cards?itemsPerPage=255" +$ curl -sL "https://api.syui.ai/users/1/card?itemsPerPage=255" +``` + +### ref + +```sh +$ vim ./ent/ogent/ogent.go +// 新規登録の停止 +// CreateUsers handles POST /users-slice requests. +func (h *OgentHandler) CreateUsers(ctx context.Context, req CreateUsersReq) (CreateUsersRes, error) { + b := h.client.Users.Create() + //b.SetUser(req.User) + b.SetUser("syui") +} + +// 削除の無効 +// DeleteUsers handles DELETE /users-slice/{id} requests. +func (h *OgentHandler) DeleteUsers(ctx context.Context, params DeleteUsersParams) (DeleteUsersRes, error) { + if params.ID != 1 { +err := h.client.Users.DeleteOneID(params.ID).Exec(ctx) + } + return new(DeleteUsersNoContent), nil +} + +// 要素の書き換えの禁止 +// UpdateUsers handles PATCH /users-slice/{id} requests. +func (h *OgentHandler) UpdateUsers(ctx context.Context, req UpdateUsersReq, params UpdateUsersParams) (UpdateUsersRes, error) { + b := h.client.Users.UpdateOneID(params.ID) + // Add all fields. + //if v, ok := req.Hp.Get(); ok { + // b.SetHp(v) + //} +``` + +### link + +- https://entgo.io/ja/blog/2022/02/15/generate-rest-crud-with-ent-and-ogen/ + +- https://github.com/ariga/ogent/blob/main/example/todo/ent/entc.go + +- https://github.com/ent/ent/blob/master/dialect/sql/schema/postgres_test.go + +- https://github.com/go-kratos/beer-shop/tree/main/app/catalog/service/internal/data/ent + + +### update + +```sh +$ curl --dump-header - 'https://api.syui.ai/users' -H 'Origin: https://card.syui.ai'|less +``` + +> ent/ogent/oas_response_encoders_gen.go + +```go +func encodeCreateGroupResponse(response CreateGroupRes, w http.ResponseWriter, span trace.Span) error { + w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai") + switch response := response.(type) { + w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai") +``` + +### northflank + +#### backup sqlite + +- `cron`, `repo(private)`, `pass(token)` + +```sh +#!/bin/zsh + +pass=password +/usr/bin/northflank exec service --project $project --service $service --cmd "/app/data/api/backup.sh $pass" + +function f(){ + rm /app/data/api/backup.sh + echo '#!/bin/bash + pass=$1 + git config --global user.email syui@syui.ai + git config --global user.name syui + cp -rf /app/data/new.sqlite /app/data/api/latest.sqlite + cp -rf /app/data/new.sqlite /app/data/api/`date '+%w'`.sqlite + cd /app/data/api + git remote add origin https://$pass@github.com/ai/api + git add . + git commit -m backup + git push origin main + git remote rm origin + ' >> /app/data/api/backup.sh + chmod +x /app/data/api/backup.sh +} +``` + +#### setting + +- ports : http, 8080, dns=api.syui.ai +- env : PASS=xxx, TOKEN=xxx +- cmd-override : /bin/api +- volumes : /app/data + diff --git a/ent/card.go b/ent/card.go index 8901be2..f46858a 100644 --- a/ent/card.go +++ b/ent/card.go @@ -3,10 +3,10 @@ package ent import ( + "api/ent/card" + "api/ent/user" "fmt" "strings" - "t/ent/card" - "t/ent/user" "time" "entgo.io/ent/dialect/sql" diff --git a/ent/card/where.go b/ent/card/where.go index 85f82ed..12ee43d 100644 --- a/ent/card/where.go +++ b/ent/card/where.go @@ -3,7 +3,7 @@ package card import ( - "t/ent/predicate" + "api/ent/predicate" "time" "entgo.io/ent/dialect/sql" diff --git a/ent/card_create.go b/ent/card_create.go index b6e7906..fccf027 100644 --- a/ent/card_create.go +++ b/ent/card_create.go @@ -3,11 +3,11 @@ package ent import ( + "api/ent/card" + "api/ent/user" "context" "errors" "fmt" - "t/ent/card" - "t/ent/user" "time" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/card_delete.go b/ent/card_delete.go index 6682804..d5c599e 100644 --- a/ent/card_delete.go +++ b/ent/card_delete.go @@ -3,9 +3,9 @@ package ent import ( + "api/ent/card" + "api/ent/predicate" "context" - "t/ent/card" - "t/ent/predicate" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/card_query.go b/ent/card_query.go index 2151949..e7fea7a 100644 --- a/ent/card_query.go +++ b/ent/card_query.go @@ -3,12 +3,12 @@ package ent import ( + "api/ent/card" + "api/ent/predicate" + "api/ent/user" "context" "fmt" "math" - "t/ent/card" - "t/ent/predicate" - "t/ent/user" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/card_update.go b/ent/card_update.go index 8824aab..86d66dd 100644 --- a/ent/card_update.go +++ b/ent/card_update.go @@ -3,12 +3,12 @@ package ent import ( + "api/ent/card" + "api/ent/predicate" + "api/ent/user" "context" "errors" "fmt" - "t/ent/card" - "t/ent/predicate" - "t/ent/user" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/client.go b/ent/client.go index 8788c10..d8f8762 100644 --- a/ent/client.go +++ b/ent/client.go @@ -8,12 +8,12 @@ import ( "fmt" "log" - "t/ent/migrate" + "api/ent/migrate" - "t/ent/card" - "t/ent/group" - "t/ent/ue" - "t/ent/user" + "api/ent/card" + "api/ent/group" + "api/ent/ue" + "api/ent/user" "entgo.io/ent" "entgo.io/ent/dialect" diff --git a/ent/ent.go b/ent/ent.go index ecd2707..9910b37 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -3,14 +3,14 @@ package ent import ( + "api/ent/card" + "api/ent/group" + "api/ent/ue" + "api/ent/user" "context" "errors" "fmt" "reflect" - "t/ent/card" - "t/ent/group" - "t/ent/ue" - "t/ent/user" "entgo.io/ent" "entgo.io/ent/dialect/sql" diff --git a/ent/enttest/enttest.go b/ent/enttest/enttest.go index 9ddd3d3..8486b44 100644 --- a/ent/enttest/enttest.go +++ b/ent/enttest/enttest.go @@ -3,12 +3,12 @@ package enttest import ( + "api/ent" "context" - "t/ent" // required by schema hooks. - _ "t/ent/runtime" + _ "api/ent/runtime" - "t/ent/migrate" + "api/ent/migrate" "entgo.io/ent/dialect/sql/schema" ) diff --git a/ent/group.go b/ent/group.go index 3fa14d1..8d8df48 100644 --- a/ent/group.go +++ b/ent/group.go @@ -3,9 +3,9 @@ package ent import ( + "api/ent/group" "fmt" "strings" - "t/ent/group" "entgo.io/ent/dialect/sql" ) diff --git a/ent/group/where.go b/ent/group/where.go index c3a2806..a90c84f 100644 --- a/ent/group/where.go +++ b/ent/group/where.go @@ -3,7 +3,7 @@ package group import ( - "t/ent/predicate" + "api/ent/predicate" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/group_create.go b/ent/group_create.go index a3ef377..ee575c1 100644 --- a/ent/group_create.go +++ b/ent/group_create.go @@ -3,11 +3,11 @@ package ent import ( + "api/ent/group" + "api/ent/user" "context" "errors" "fmt" - "t/ent/group" - "t/ent/user" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" diff --git a/ent/group_delete.go b/ent/group_delete.go index 10161fa..0a7049d 100644 --- a/ent/group_delete.go +++ b/ent/group_delete.go @@ -3,9 +3,9 @@ package ent import ( + "api/ent/group" + "api/ent/predicate" "context" - "t/ent/group" - "t/ent/predicate" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/group_query.go b/ent/group_query.go index 7f3b189..0d44bde 100644 --- a/ent/group_query.go +++ b/ent/group_query.go @@ -3,13 +3,13 @@ package ent import ( + "api/ent/group" + "api/ent/predicate" + "api/ent/user" "context" "database/sql/driver" "fmt" "math" - "t/ent/group" - "t/ent/predicate" - "t/ent/user" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/group_update.go b/ent/group_update.go index 94bb7c8..574bb44 100644 --- a/ent/group_update.go +++ b/ent/group_update.go @@ -3,12 +3,12 @@ package ent import ( + "api/ent/group" + "api/ent/predicate" + "api/ent/user" "context" "errors" "fmt" - "t/ent/group" - "t/ent/predicate" - "t/ent/user" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/hook/hook.go b/ent/hook/hook.go index 2da55e8..269aa33 100644 --- a/ent/hook/hook.go +++ b/ent/hook/hook.go @@ -3,9 +3,9 @@ package hook import ( + "api/ent" "context" "fmt" - "t/ent" ) // The CardFunc type is an adapter to allow the use of ordinary diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index 1ed4e83..0c0d345 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -129,7 +129,7 @@ var ( {Name: "ten_post", Type: field.TypeString, Nullable: true}, {Name: "ten_get", Type: field.TypeString, Nullable: true}, {Name: "ten_at", Type: field.TypeTime, Nullable: true}, - {Name: "next", Type: field.TypeString, Nullable: true, Default: "20240213"}, + {Name: "next", Type: field.TypeString, Nullable: true, Default: "20240220"}, {Name: "room", Type: field.TypeInt, Nullable: true}, {Name: "model", Type: field.TypeBool, Nullable: true}, {Name: "model_at", Type: field.TypeTime, Nullable: true}, diff --git a/ent/mutation.go b/ent/mutation.go index d6cb5a4..2baff0e 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -3,15 +3,15 @@ package ent import ( + "api/ent/card" + "api/ent/group" + "api/ent/predicate" + "api/ent/ue" + "api/ent/user" "context" "errors" "fmt" "sync" - "t/ent/card" - "t/ent/group" - "t/ent/predicate" - "t/ent/ue" - "t/ent/user" "time" "entgo.io/ent" diff --git a/ent/ogent/responses.go b/ent/ogent/responses.go index 9160f5d..84fdcc0 100644 --- a/ent/ogent/responses.go +++ b/ent/ogent/responses.go @@ -2,7 +2,7 @@ package ogent -import "t/ent" +import "api/ent" func NewCardCreate(e *ent.Card) *CardCreate { if e == nil { diff --git a/ent/runtime.go b/ent/runtime.go index 7f9450b..16e53fb 100644 --- a/ent/runtime.go +++ b/ent/runtime.go @@ -3,11 +3,11 @@ package ent import ( - "t/ent/card" - "t/ent/group" - "t/ent/schema" - "t/ent/ue" - "t/ent/user" + "api/ent/card" + "api/ent/group" + "api/ent/schema" + "api/ent/ue" + "api/ent/user" "time" ) diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go index c48ce31..880917e 100644 --- a/ent/runtime/runtime.go +++ b/ent/runtime/runtime.go @@ -2,7 +2,7 @@ package runtime -// The schema-stitching logic is generated in t/ent/runtime.go +// The schema-stitching logic is generated in api/ent/runtime.go const ( Version = "v0.11.10" // Version of ent codegen. diff --git a/ent/ue.go b/ent/ue.go index 459a685..57801f2 100644 --- a/ent/ue.go +++ b/ent/ue.go @@ -3,10 +3,10 @@ package ent import ( + "api/ent/ue" + "api/ent/user" "fmt" "strings" - "t/ent/ue" - "t/ent/user" "time" "entgo.io/ent/dialect/sql" diff --git a/ent/ue/where.go b/ent/ue/where.go index 7ee84d7..2f1f157 100644 --- a/ent/ue/where.go +++ b/ent/ue/where.go @@ -3,7 +3,7 @@ package ue import ( - "t/ent/predicate" + "api/ent/predicate" "time" "entgo.io/ent/dialect/sql" diff --git a/ent/ue_create.go b/ent/ue_create.go index dd0eba5..bff03e5 100644 --- a/ent/ue_create.go +++ b/ent/ue_create.go @@ -3,11 +3,11 @@ package ent import ( + "api/ent/ue" + "api/ent/user" "context" "errors" "fmt" - "t/ent/ue" - "t/ent/user" "time" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/ue_delete.go b/ent/ue_delete.go index 98f3dc5..0cfb9e5 100644 --- a/ent/ue_delete.go +++ b/ent/ue_delete.go @@ -3,9 +3,9 @@ package ent import ( + "api/ent/predicate" + "api/ent/ue" "context" - "t/ent/predicate" - "t/ent/ue" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/ue_query.go b/ent/ue_query.go index 240b74e..c5f8af8 100644 --- a/ent/ue_query.go +++ b/ent/ue_query.go @@ -3,12 +3,12 @@ package ent import ( + "api/ent/predicate" + "api/ent/ue" + "api/ent/user" "context" "fmt" "math" - "t/ent/predicate" - "t/ent/ue" - "t/ent/user" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/ue_update.go b/ent/ue_update.go index 649304c..318636a 100644 --- a/ent/ue_update.go +++ b/ent/ue_update.go @@ -3,12 +3,12 @@ package ent import ( + "api/ent/predicate" + "api/ent/ue" + "api/ent/user" "context" "errors" "fmt" - "t/ent/predicate" - "t/ent/ue" - "t/ent/user" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/user.go b/ent/user.go index 9bae624..73ca2cb 100644 --- a/ent/user.go +++ b/ent/user.go @@ -3,9 +3,9 @@ package ent import ( + "api/ent/user" "fmt" "strings" - "t/ent/user" "time" "entgo.io/ent/dialect/sql" diff --git a/ent/user/where.go b/ent/user/where.go index 1f1154b..4a4e5a2 100644 --- a/ent/user/where.go +++ b/ent/user/where.go @@ -3,7 +3,7 @@ package user import ( - "t/ent/predicate" + "api/ent/predicate" "time" "entgo.io/ent/dialect/sql" diff --git a/ent/user_create.go b/ent/user_create.go index 0b46208..02b3347 100644 --- a/ent/user_create.go +++ b/ent/user_create.go @@ -3,12 +3,12 @@ package ent import ( + "api/ent/card" + "api/ent/ue" + "api/ent/user" "context" "errors" "fmt" - "t/ent/card" - "t/ent/ue" - "t/ent/user" "time" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/user_delete.go b/ent/user_delete.go index 3ae1ce7..e5baebc 100644 --- a/ent/user_delete.go +++ b/ent/user_delete.go @@ -3,9 +3,9 @@ package ent import ( + "api/ent/predicate" + "api/ent/user" "context" - "t/ent/predicate" - "t/ent/user" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/user_query.go b/ent/user_query.go index 3833ac4..d2da861 100644 --- a/ent/user_query.go +++ b/ent/user_query.go @@ -3,14 +3,14 @@ package ent import ( + "api/ent/card" + "api/ent/predicate" + "api/ent/ue" + "api/ent/user" "context" "database/sql/driver" "fmt" "math" - "t/ent/card" - "t/ent/predicate" - "t/ent/ue" - "t/ent/user" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" diff --git a/ent/user_update.go b/ent/user_update.go index 463de22..880d654 100644 --- a/ent/user_update.go +++ b/ent/user_update.go @@ -3,13 +3,13 @@ package ent import ( + "api/ent/card" + "api/ent/predicate" + "api/ent/ue" + "api/ent/user" "context" "errors" "fmt" - "t/ent/card" - "t/ent/predicate" - "t/ent/ue" - "t/ent/user" "time" "entgo.io/ent/dialect/sql" diff --git a/go.mod b/go.mod index 61d185e..fab473f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module t +module api -go 1.19 +go 1.21 //replace ariga.io/ogent => ../../ diff --git a/icon/card.png b/icon/card.png new file mode 100644 index 0000000..1b089bf Binary files /dev/null and b/icon/card.png differ diff --git a/main.go b/main.go index 382e82b..e217553 100644 --- a/main.go +++ b/main.go @@ -5,8 +5,8 @@ import ( "log" "net/http" - "t/ent" - "t/ent/ogent" + "api/ent" + "api/ent/ogent" "entgo.io/ent/dialect" _ "github.com/mattn/go-sqlite3" "entgo.io/ent/dialect/sql/schema" diff --git a/readme.md b/readme.md index 3f07c99..99ffd74 100644 --- a/readme.md +++ b/readme.md @@ -1,94 +1,16 @@ -### build +## ai `api` + + + +- name : ai `api` +- base : [go](https://go.dev/) +- host : [card.syui.ai](https://card.syui.ai) ```sh -$ vim ent/entc.go -$ vim ent/schema/users.go -$ go generate ./... -$ go build -$ ./card - -$ go generate ./... -$ PASS=`cat ./token.json|jq -r .password` TOKEN=`cat ./token.json|jq -r .token` go run -mod=mod main.go -$ curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"syui\",\"password\":\"$pass\"}" localhost:8080/users -$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"password\":\"$pass\"}" localhost:8080/cards -$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"card\":1,\"cp\":11,\"status\":\"normal\",\"password\":\"$pass\"}" localhost:8080/cards -$ curl localhost:8080/users -$ curl localhost:8080/cards -$ curl localhost:8080/users/1 -$ curl localhost:8080/users/1/card -``` - -### use - -```sh -$ curl -X POST -H "Content-Type: application/json" -d '{"username":"syui",\"password\":\"$pass\"}' https://api.syui.ai/users - -# onconflict -$ !! - $ curl -sL https://api.syui.ai/users/1 ``` -```sh -# item select -$ curl -sL "https://api.syui.ai/users?itemsPerPage=255" -$ curl -sL "https://api.syui.ai/cards?itemsPerPage=255" -$ curl -sL "https://api.syui.ai/users/1/card?itemsPerPage=255" -``` +## link -### ref +- https://github.com/ariga/ogent -```sh -$ vim ./ent/ogent/ogent.go -// 新規登録の停止 -// CreateUsers handles POST /users-slice requests. -func (h *OgentHandler) CreateUsers(ctx context.Context, req CreateUsersReq) (CreateUsersRes, error) { - b := h.client.Users.Create() - //b.SetUser(req.User) - b.SetUser("syui") -} - -// 削除の無効 -// DeleteUsers handles DELETE /users-slice/{id} requests. -func (h *OgentHandler) DeleteUsers(ctx context.Context, params DeleteUsersParams) (DeleteUsersRes, error) { - if params.ID != 1 { -err := h.client.Users.DeleteOneID(params.ID).Exec(ctx) - } - return new(DeleteUsersNoContent), nil -} - -// 要素の書き換えの禁止 -// UpdateUsers handles PATCH /users-slice/{id} requests. -func (h *OgentHandler) UpdateUsers(ctx context.Context, req UpdateUsersReq, params UpdateUsersParams) (UpdateUsersRes, error) { - b := h.client.Users.UpdateOneID(params.ID) - // Add all fields. - //if v, ok := req.Hp.Get(); ok { - // b.SetHp(v) - //} -``` - -### link - -- https://entgo.io/ja/blog/2022/02/15/generate-rest-crud-with-ent-and-ogen/ - -- https://github.com/ariga/ogent/blob/main/example/todo/ent/entc.go - -- https://github.com/ent/ent/blob/master/dialect/sql/schema/postgres_test.go - -- https://github.com/go-kratos/beer-shop/tree/main/app/catalog/service/internal/data/ent - - -### update - -```sh -$ curl --dump-header - 'https://api.syui.ai/users' -H 'Origin: https://card.syui.ai'|less -``` - -> ent/ogent/oas_response_encoders_gen.go - -```go -func encodeCreateGroupResponse(response CreateGroupRes, w http.ResponseWriter, span trace.Span) error { - w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai") - switch response := response.(type) { - w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai") -``` diff --git a/run.zsh b/run.zsh deleted file mode 100755 index dc3e192..0000000 --- a/run.zsh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/zsh -d=${0:a:h} -PASS=`cat token.json|jq -r .password` go run -mod=mod main.go diff --git a/tmp/card_account_change.zsh b/scpt/card_account_change.zsh similarity index 100% rename from tmp/card_account_change.zsh rename to scpt/card_account_change.zsh diff --git a/tmp/card_account_change_fix.zsh b/scpt/card_account_change_fix.zsh similarity index 100% rename from tmp/card_account_change_fix.zsh rename to scpt/card_account_change_fix.zsh diff --git a/tmp/card_account_delete.zsh b/scpt/card_account_delete.zsh similarity index 100% rename from tmp/card_account_delete.zsh rename to scpt/card_account_delete.zsh diff --git a/tmp/card_account_select_delete.zsh b/scpt/card_account_select_delete.zsh similarity index 100% rename from tmp/card_account_select_delete.zsh rename to scpt/card_account_select_delete.zsh diff --git a/tmp/card_add.zsh b/scpt/card_add.zsh similarity index 100% rename from tmp/card_add.zsh rename to scpt/card_add.zsh diff --git a/tmp/card_add_16.zsh b/scpt/card_add_16.zsh similarity index 100% rename from tmp/card_add_16.zsh rename to scpt/card_add_16.zsh diff --git a/tmp/card_add_45.zsh b/scpt/card_add_45.zsh similarity index 100% rename from tmp/card_add_45.zsh rename to scpt/card_add_45.zsh diff --git a/tmp/card_add_book1.zsh b/scpt/card_add_book1.zsh similarity index 100% rename from tmp/card_add_book1.zsh rename to scpt/card_add_book1.zsh diff --git a/tmp/card_add_change.zsh b/scpt/card_add_change.zsh similarity index 100% rename from tmp/card_add_change.zsh rename to scpt/card_add_change.zsh diff --git a/tmp/card_author_first.zsh b/scpt/card_author_first.zsh similarity index 100% rename from tmp/card_author_first.zsh rename to scpt/card_author_first.zsh diff --git a/scpt/card_day.zsh b/scpt/card_day.zsh new file mode 100755 index 0000000..eff9ea5 --- /dev/null +++ b/scpt/card_day.zsh @@ -0,0 +1,23 @@ +#!/bin/zsh + +case $OSTYPE in + darwin*) + alias date="/opt/homebrew/bin/gdate" + ;; +esac +host=https://api.syui.ai +token=`cat ~/.config/atr/api_card.json|jq -r .token` +host_users="$host/users?itemsPerPage=2550" +data=`curl -sL "$host_users"|jq .` +nd=`date +"%Y%m%d"` + +n=`echo $data|jq length` +n=$((n - 1)) + +for ((i=0;i<=$n;i++)) +do + name=`echo $data|jq ".[$i]"|jq -r .username` + id=`echo $data|jq ".[$i]"|jq -r .id` + echo "{\"next\":\"$nd\"} -s $host/users/$id" + curl -X PATCH -H "Content-Type: application/json" -d "{\"next\":\"$nd\",\"token\":\"$token\"}" -s $host/users/$id +done diff --git a/scpt/card_delete.zsh b/scpt/card_delete.zsh new file mode 100755 index 0000000..8f01d94 --- /dev/null +++ b/scpt/card_delete.zsh @@ -0,0 +1,23 @@ +#!/bin/zsh + +if [ -z "$1" ];then + exit +fi +echo delete-id +read +id=$1 +data=`curl -sL "https://api.syui.ai/users/$id/card?itemsPerPage=2550"` +token=`cat ~/.config/atr/api_card.json|jq -r .token` +pass=`cat ~/.config/atr/api_card.json|jq -r .password` + +n=`echo $data|jq length` + +n=$((n - 1)) + +for ((i=0;i<=$n;i++)) +do + card_id=`echo $data|jq -r ".[$i].id"` + echo $card + curl -X DELETE -H "Content-Type: application/json" -d "{\"owner\":$id,\"password\":\"$pass\"}" https://api.syui.ai/cards/$card_id +done +#curl -X DELETE -H "Content-Type: application/json" https://api.syui.ai/users/$id diff --git a/tmp/card_did_change.zsh b/scpt/card_did_change.zsh similarity index 100% rename from tmp/card_did_change.zsh rename to scpt/card_did_change.zsh diff --git a/tmp/card_fav_first.zsh b/scpt/card_fav_first.zsh similarity index 100% rename from tmp/card_fav_first.zsh rename to scpt/card_fav_first.zsh diff --git a/tmp/card_fav_second.zsh b/scpt/card_fav_second.zsh similarity index 100% rename from tmp/card_fav_second.zsh rename to scpt/card_fav_second.zsh diff --git a/scpt/card_limit.zsh b/scpt/card_limit.zsh new file mode 100755 index 0000000..220209b --- /dev/null +++ b/scpt/card_limit.zsh @@ -0,0 +1,24 @@ +#!/bin/zsh + +case $OSTYPE in + darwin*) + alias date="/opt/homebrew/bin/gdate" + ;; +esac +host=https://api.syui.ai +token=`cat ~/.config/atr/api_card.json|jq -r .token` +host_users="$host/users?itemsPerPage=2550" +updated_at_n=`date --iso-8601=seconds -d '1 days ago'` +#updated_at_n=`date --iso-8601=seconds` +data=`curl -sL "$host_users"|jq .` + +n=`echo $data|jq length` +n=$((n - 1)) + +for ((i=0;i<=$n;i++)) +do + name=`echo $data|jq ".[$i]"|jq -r .username` + id=`echo $data|jq ".[$i]"|jq -r .id` + echo "{\"updated_at\":\"$updated_at_n\"} -s $host/users/$id" + curl -X PATCH -H "Content-Type: application/json" -d "{\"raid_at\": \"$updated_at_n\",\"updated_at\":\"$updated_at_n\",\"token\":\"$token\",\"ten_at\":\"$updated_at_n\"}" -s $host/users/$id +done diff --git a/tmp/card_limit_all.zsh b/scpt/card_limit_all.zsh similarity index 100% rename from tmp/card_limit_all.zsh rename to scpt/card_limit_all.zsh diff --git a/tmp/card_limit_loop.zsh b/scpt/card_limit_loop.zsh similarity index 100% rename from tmp/card_limit_loop.zsh rename to scpt/card_limit_loop.zsh diff --git a/tmp/card_limit_select.zsh b/scpt/card_limit_select.zsh similarity index 100% rename from tmp/card_limit_select.zsh rename to scpt/card_limit_select.zsh diff --git a/tmp/card_search.zsh b/scpt/card_search.zsh similarity index 100% rename from tmp/card_search.zsh rename to scpt/card_search.zsh diff --git a/tmp/card_sqlite.zsh b/scpt/card_sqlite.zsh similarity index 100% rename from tmp/card_sqlite.zsh rename to scpt/card_sqlite.zsh diff --git a/tmp/card_test.zsh b/scpt/card_test.zsh similarity index 100% rename from tmp/card_test.zsh rename to scpt/card_test.zsh diff --git a/tmp/game_account.zsh b/scpt/game_account.zsh similarity index 100% rename from tmp/game_account.zsh rename to scpt/game_account.zsh diff --git a/tmp/model_account.zsh b/scpt/model_account.zsh similarity index 100% rename from tmp/model_account.zsh rename to scpt/model_account.zsh diff --git a/tmp/model_account_all.zsh b/scpt/model_account_all.zsh similarity index 100% rename from tmp/model_account_all.zsh rename to scpt/model_account_all.zsh diff --git a/tmp/t.zsh b/scpt/t.zsh similarity index 100% rename from tmp/t.zsh rename to scpt/t.zsh diff --git a/tmp/test.zsh b/scpt/test.zsh similarity index 100% rename from tmp/test.zsh rename to scpt/test.zsh diff --git a/tmp/ue_add_test.zsh b/scpt/ue_add_test.zsh similarity index 100% rename from tmp/ue_add_test.zsh rename to scpt/ue_add_test.zsh diff --git a/tmp/user_did.zsh b/scpt/user_did.zsh similarity index 100% rename from tmp/user_did.zsh rename to scpt/user_did.zsh diff --git a/tmp/user_json.zsh b/scpt/user_json.zsh similarity index 100% rename from tmp/user_json.zsh rename to scpt/user_json.zsh