1
0
This commit is contained in:
Your Name 2024-02-21 09:16:45 +00:00
parent f7df1224e0
commit 5edf656f53
71 changed files with 309 additions and 176 deletions

View File

@ -1 +1 @@
web: bin/t web: bin/api

View File

@ -6,7 +6,18 @@ su=5000
go generate ./... go generate ./...
cp -rf $d/ent/openapi.json $d/tmp/ cp -rf $d/ent/openapi.json $d/tmp/
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/ogent/oas_parameters_gen.go
sed -i '' "s/255/$su/g" $d/ent/openapi.json 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/ 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

133
docs/wiki.md Normal file
View File

@ -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

View File

@ -3,10 +3,10 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/user"
"fmt" "fmt"
"strings" "strings"
"t/ent/card"
"t/ent/user"
"time" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"

View File

@ -3,7 +3,7 @@
package card package card
import ( import (
"t/ent/predicate" "api/ent/predicate"
"time" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"

View File

@ -3,11 +3,11 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"t/ent/card"
"t/ent/user"
"time" "time"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/predicate"
"context" "context"
"t/ent/card"
"t/ent/predicate"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/predicate"
"api/ent/user"
"context" "context"
"fmt" "fmt"
"math" "math"
"t/ent/card"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/predicate"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"t/ent/card"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -8,12 +8,12 @@ import (
"fmt" "fmt"
"log" "log"
"t/ent/migrate" "api/ent/migrate"
"t/ent/card" "api/ent/card"
"t/ent/group" "api/ent/group"
"t/ent/ue" "api/ent/ue"
"t/ent/user" "api/ent/user"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/dialect" "entgo.io/ent/dialect"

View File

@ -3,14 +3,14 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/group"
"api/ent/ue"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"reflect" "reflect"
"t/ent/card"
"t/ent/group"
"t/ent/ue"
"t/ent/user"
"entgo.io/ent" "entgo.io/ent"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"

View File

@ -3,12 +3,12 @@
package enttest package enttest
import ( import (
"api/ent"
"context" "context"
"t/ent"
// required by schema hooks. // required by schema hooks.
_ "t/ent/runtime" _ "api/ent/runtime"
"t/ent/migrate" "api/ent/migrate"
"entgo.io/ent/dialect/sql/schema" "entgo.io/ent/dialect/sql/schema"
) )

View File

@ -3,9 +3,9 @@
package ent package ent
import ( import (
"api/ent/group"
"fmt" "fmt"
"strings" "strings"
"t/ent/group"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
) )

View File

@ -3,7 +3,7 @@
package group package group
import ( import (
"t/ent/predicate" "api/ent/predicate"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,11 +3,11 @@
package ent package ent
import ( import (
"api/ent/group"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"t/ent/group"
"t/ent/user"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"

View File

@ -3,9 +3,9 @@
package ent package ent
import ( import (
"api/ent/group"
"api/ent/predicate"
"context" "context"
"t/ent/group"
"t/ent/predicate"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,13 +3,13 @@
package ent package ent
import ( import (
"api/ent/group"
"api/ent/predicate"
"api/ent/user"
"context" "context"
"database/sql/driver" "database/sql/driver"
"fmt" "fmt"
"math" "math"
"t/ent/group"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent package ent
import ( import (
"api/ent/group"
"api/ent/predicate"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"t/ent/group"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package hook package hook
import ( import (
"api/ent"
"context" "context"
"fmt" "fmt"
"t/ent"
) )
// The CardFunc type is an adapter to allow the use of ordinary // The CardFunc type is an adapter to allow the use of ordinary

View File

@ -129,7 +129,7 @@ var (
{Name: "ten_post", Type: field.TypeString, Nullable: true}, {Name: "ten_post", Type: field.TypeString, Nullable: true},
{Name: "ten_get", Type: field.TypeString, Nullable: true}, {Name: "ten_get", Type: field.TypeString, Nullable: true},
{Name: "ten_at", Type: field.TypeTime, 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: "room", Type: field.TypeInt, Nullable: true},
{Name: "model", Type: field.TypeBool, Nullable: true}, {Name: "model", Type: field.TypeBool, Nullable: true},
{Name: "model_at", Type: field.TypeTime, Nullable: true}, {Name: "model_at", Type: field.TypeTime, Nullable: true},

View File

@ -3,15 +3,15 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/group"
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"sync" "sync"
"t/ent/card"
"t/ent/group"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"time" "time"
"entgo.io/ent" "entgo.io/ent"

View File

@ -2,7 +2,7 @@
package ogent package ogent
import "t/ent" import "api/ent"
func NewCardCreate(e *ent.Card) *CardCreate { func NewCardCreate(e *ent.Card) *CardCreate {
if e == nil { if e == nil {

View File

@ -3,11 +3,11 @@
package ent package ent
import ( import (
"t/ent/card" "api/ent/card"
"t/ent/group" "api/ent/group"
"t/ent/schema" "api/ent/schema"
"t/ent/ue" "api/ent/ue"
"t/ent/user" "api/ent/user"
"time" "time"
) )

View File

@ -2,7 +2,7 @@
package runtime 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 ( const (
Version = "v0.11.10" // Version of ent codegen. Version = "v0.11.10" // Version of ent codegen.

View File

@ -3,10 +3,10 @@
package ent package ent
import ( import (
"api/ent/ue"
"api/ent/user"
"fmt" "fmt"
"strings" "strings"
"t/ent/ue"
"t/ent/user"
"time" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"

View File

@ -3,7 +3,7 @@
package ue package ue
import ( import (
"t/ent/predicate" "api/ent/predicate"
"time" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"

View File

@ -3,11 +3,11 @@
package ent package ent
import ( import (
"api/ent/ue"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"t/ent/ue"
"t/ent/user"
"time" "time"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package ent package ent
import ( import (
"api/ent/predicate"
"api/ent/ue"
"context" "context"
"t/ent/predicate"
"t/ent/ue"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent package ent
import ( import (
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context" "context"
"fmt" "fmt"
"math" "math"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,12 +3,12 @@
package ent package ent
import ( import (
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package ent package ent
import ( import (
"api/ent/user"
"fmt" "fmt"
"strings" "strings"
"t/ent/user"
"time" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"

View File

@ -3,7 +3,7 @@
package user package user
import ( import (
"t/ent/predicate" "api/ent/predicate"
"time" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"

View File

@ -3,12 +3,12 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/ue"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"t/ent/card"
"t/ent/ue"
"t/ent/user"
"time" "time"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,9 +3,9 @@
package ent package ent
import ( import (
"api/ent/predicate"
"api/ent/user"
"context" "context"
"t/ent/predicate"
"t/ent/user"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,14 +3,14 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context" "context"
"database/sql/driver" "database/sql/driver"
"fmt" "fmt"
"math" "math"
"t/ent/card"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/dialect/sql/sqlgraph"

View File

@ -3,13 +3,13 @@
package ent package ent
import ( import (
"api/ent/card"
"api/ent/predicate"
"api/ent/ue"
"api/ent/user"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"t/ent/card"
"t/ent/predicate"
"t/ent/ue"
"t/ent/user"
"time" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"

4
go.mod
View File

@ -1,6 +1,6 @@
module t module api
go 1.19 go 1.21
//replace ariga.io/ogent => ../../ //replace ariga.io/ogent => ../../

BIN
icon/card.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

View File

@ -5,8 +5,8 @@ import (
"log" "log"
"net/http" "net/http"
"t/ent" "api/ent"
"t/ent/ogent" "api/ent/ogent"
"entgo.io/ent/dialect" "entgo.io/ent/dialect"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"entgo.io/ent/dialect/sql/schema" "entgo.io/ent/dialect/sql/schema"

View File

@ -1,94 +1,16 @@
### build ## ai `api`
<img src="./icon/card.png" width="100">
- name : ai `api`
- base : [go](https://go.dev/)
- host : [card.syui.ai](https://card.syui.ai)
```sh ```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 $ curl -sL https://api.syui.ai/users/1
``` ```
```sh ## link
# 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 - 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")
```

View File

@ -1,3 +0,0 @@
#!/bin/zsh
d=${0:a:h}
PASS=`cat token.json|jq -r .password` go run -mod=mod main.go

23
scpt/card_day.zsh Executable file
View File

@ -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

23
scpt/card_delete.zsh Executable file
View File

@ -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

24
scpt/card_limit.zsh Executable file
View File

@ -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