Compare commits

...

9 Commits

26 changed files with 1218 additions and 17 deletions

View File

@ -1,14 +1,33 @@
package dev.usbharu.dev.usbharu.unos.illust.crud
package dev.usbharu.unos.illust.crud
import illust.IllustOuterClass
import illust.crud.IllustCRUDServiceGrpcKt.IllustCRUDServiceCoroutineImplBase
import illust.crud.IllustCrud
import illust.data.IllustDataServiceGrpcKt
import illust.illust
import java.util.*
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
class CrudService(coroutineContext: CoroutineContext = EmptyCoroutineContext) :
class CrudService(
private val illustDataServiceCoroutineStub: IllustDataServiceGrpcKt.IllustDataServiceCoroutineStub,
coroutineContext: CoroutineContext = EmptyCoroutineContext
) :
IllustCRUDServiceCoroutineImplBase(coroutineContext) {
override suspend fun create(request: IllustCrud.CreateIllust): IllustOuterClass.Illust {
return super.create(request)
val illust = illust {
id = UUID.randomUUID().toString()
name = request.name
sha256 = request.sha256
s3Id = request.s3Id
tags.addAll(request.tagsList)
originals.addAll(request.originalsList)
characters.addAll(request.charactersList)
description = request.description
}
illustDataServiceCoroutineStub.save(
illust
)
return illust
}
}

View File

@ -0,0 +1,31 @@
package dev.usbharu.unos.illust.crud
import illust.tag.IllustTaggingServiceGrpcKt
import illust.tag.taggingRequest
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.withContext
import java.util.*
interface RequestTaggingService {
suspend fun requestTagging(illustId: UUID): List<String>
}
class RequestTaggingServiceImpl(private val clients: List<IllustTaggingServiceGrpcKt.IllustTaggingServiceCoroutineStub>) :
RequestTaggingService {
override suspend fun requestTagging(illustId: UUID): List<String> {
val taggingResults = withContext(Dispatchers.IO) {
clients.map {
async {
it.requestTagging(taggingRequest {
this.illustId = illustId.toString()
})
}
}.awaitAll()
}
return taggingResults.flatMap { it.tagsList }
}
}

13
illust-data/Taskfile.yml Normal file
View File

@ -0,0 +1,13 @@
version: 3
includes:
tasks:
build:
deps:
- generate
cmds:
- cmd: go build
generate:
cmds:
- cmd: protoc -I ../unos-proto/src/main/proto --go_out=. ../unos-proto/src/main/proto/illust/data/illust_data.proto --go_opt=module=git.usbharu.dev/usbharu/unos --go-grpc_opt=module=git.usbharu.dev/usbharu/unos --go-grpc_out=.
- cmd: protoc -I ../unos-proto/src/main/proto --go_out=. ../unos-proto/src/main/proto/illust/illust.proto --go_opt=module=git.usbharu.dev/usbharu/unos --go-grpc_opt=module=git.usbharu.dev/usbharu/unos --go-grpc_out=.

0
illust-data/config.ini Normal file
View File

29
illust-data/go.mod Normal file
View File

@ -0,0 +1,29 @@
module git.usbharu.dev/usbharu/unos
go 1.22
require (
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
)
require (
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible // indirect
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)

78
illust-data/go.sum Normal file
View File

@ -0,0 +1,78 @@
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible h1:msy24VGS42fKO9K1vLz82/GeYW1cILu7Nuuj1N3BBkE=
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es=
github.com/go-ozzo/ozzo-validation/v4 v4.3.0/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@ -0,0 +1,240 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v4.25.3
// source: illust/data/illust_data.proto
package data
import (
illust "git.usbharu.dev/usbharu/unos/illust"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type IllustGetById struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *IllustGetById) Reset() {
*x = IllustGetById{}
if protoimpl.UnsafeEnabled {
mi := &file_illust_data_illust_data_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *IllustGetById) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*IllustGetById) ProtoMessage() {}
func (x *IllustGetById) ProtoReflect() protoreflect.Message {
mi := &file_illust_data_illust_data_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use IllustGetById.ProtoReflect.Descriptor instead.
func (*IllustGetById) Descriptor() ([]byte, []int) {
return file_illust_data_illust_data_proto_rawDescGZIP(), []int{0}
}
func (x *IllustGetById) GetId() string {
if x != nil {
return x.Id
}
return ""
}
type IllustAddTag struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Tags []string `protobuf:"bytes,2,rep,name=tags,proto3" json:"tags,omitempty"`
}
func (x *IllustAddTag) Reset() {
*x = IllustAddTag{}
if protoimpl.UnsafeEnabled {
mi := &file_illust_data_illust_data_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *IllustAddTag) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*IllustAddTag) ProtoMessage() {}
func (x *IllustAddTag) ProtoReflect() protoreflect.Message {
mi := &file_illust_data_illust_data_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use IllustAddTag.ProtoReflect.Descriptor instead.
func (*IllustAddTag) Descriptor() ([]byte, []int) {
return file_illust_data_illust_data_proto_rawDescGZIP(), []int{1}
}
func (x *IllustAddTag) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *IllustAddTag) GetTags() []string {
if x != nil {
return x.Tags
}
return nil
}
var File_illust_data_illust_data_proto protoreflect.FileDescriptor
var file_illust_data_illust_data_proto_rawDesc = []byte{
0x0a, 0x1d, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x69, 0x6c,
0x6c, 0x75, 0x73, 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
0x0b, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x13, 0x69, 0x6c,
0x6c, 0x75, 0x73, 0x74, 0x2f, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x1f,
0x0a, 0x0d, 0x49, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x47, 0x65, 0x74, 0x42, 0x79, 0x49, 0x64, 0x12,
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22,
0x32, 0x0a, 0x0c, 0x49, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x41, 0x64, 0x64, 0x54, 0x61, 0x67, 0x12,
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12,
0x12, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74,
0x61, 0x67, 0x73, 0x32, 0xaf, 0x01, 0x0a, 0x11, 0x49, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x44, 0x61,
0x74, 0x61, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x26, 0x0a, 0x04, 0x73, 0x61, 0x76,
0x65, 0x12, 0x0e, 0x2e, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2e, 0x49, 0x6c, 0x6c, 0x75, 0x73,
0x74, 0x1a, 0x0e, 0x2e, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2e, 0x49, 0x6c, 0x6c, 0x75, 0x73,
0x74, 0x12, 0x35, 0x0a, 0x07, 0x67, 0x65, 0x74, 0x42, 0x79, 0x49, 0x64, 0x12, 0x1a, 0x2e, 0x69,
0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x2e, 0x49, 0x6c, 0x6c, 0x75, 0x73,
0x74, 0x47, 0x65, 0x74, 0x42, 0x79, 0x49, 0x64, 0x1a, 0x0e, 0x2e, 0x69, 0x6c, 0x6c, 0x75, 0x73,
0x74, 0x2e, 0x49, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x12, 0x3b, 0x0a, 0x06, 0x61, 0x64, 0x64, 0x54,
0x61, 0x67, 0x12, 0x19, 0x2e, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2e, 0x64, 0x61, 0x74, 0x61,
0x2e, 0x49, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x41, 0x64, 0x64, 0x54, 0x61, 0x67, 0x1a, 0x16, 0x2e,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x69, 0x74, 0x2e, 0x75, 0x73, 0x62,
0x68, 0x61, 0x72, 0x75, 0x2e, 0x64, 0x65, 0x76, 0x2f, 0x75, 0x73, 0x62, 0x68, 0x61, 0x72, 0x75,
0x2f, 0x75, 0x6e, 0x6f, 0x73, 0x2f, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2f, 0x64, 0x61, 0x74,
0x61, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_illust_data_illust_data_proto_rawDescOnce sync.Once
file_illust_data_illust_data_proto_rawDescData = file_illust_data_illust_data_proto_rawDesc
)
func file_illust_data_illust_data_proto_rawDescGZIP() []byte {
file_illust_data_illust_data_proto_rawDescOnce.Do(func() {
file_illust_data_illust_data_proto_rawDescData = protoimpl.X.CompressGZIP(file_illust_data_illust_data_proto_rawDescData)
})
return file_illust_data_illust_data_proto_rawDescData
}
var file_illust_data_illust_data_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_illust_data_illust_data_proto_goTypes = []interface{}{
(*IllustGetById)(nil), // 0: illust.data.IllustGetById
(*IllustAddTag)(nil), // 1: illust.data.IllustAddTag
(*illust.Illust)(nil), // 2: illust.Illust
(*emptypb.Empty)(nil), // 3: google.protobuf.Empty
}
var file_illust_data_illust_data_proto_depIdxs = []int32{
2, // 0: illust.data.IllustDataService.save:input_type -> illust.Illust
0, // 1: illust.data.IllustDataService.getById:input_type -> illust.data.IllustGetById
1, // 2: illust.data.IllustDataService.addTag:input_type -> illust.data.IllustAddTag
2, // 3: illust.data.IllustDataService.save:output_type -> illust.Illust
2, // 4: illust.data.IllustDataService.getById:output_type -> illust.Illust
3, // 5: illust.data.IllustDataService.addTag:output_type -> google.protobuf.Empty
3, // [3:6] is the sub-list for method output_type
0, // [0:3] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_illust_data_illust_data_proto_init() }
func file_illust_data_illust_data_proto_init() {
if File_illust_data_illust_data_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_illust_data_illust_data_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*IllustGetById); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_illust_data_illust_data_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*IllustAddTag); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_illust_data_illust_data_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_illust_data_illust_data_proto_goTypes,
DependencyIndexes: file_illust_data_illust_data_proto_depIdxs,
MessageInfos: file_illust_data_illust_data_proto_msgTypes,
}.Build()
File_illust_data_illust_data_proto = out.File
file_illust_data_illust_data_proto_rawDesc = nil
file_illust_data_illust_data_proto_goTypes = nil
file_illust_data_illust_data_proto_depIdxs = nil
}

View File

@ -0,0 +1,50 @@
package data
import (
"context"
"git.usbharu.dev/usbharu/unos/illust"
"google.golang.org/protobuf/types/known/emptypb"
)
type IllustDataServiceImpl struct {
UnimplementedIllustDataServiceServer
IllustDataRepository
}
func NewIllustDataServiceImpl(repository IllustDataRepository) *IllustDataServiceImpl {
return &IllustDataServiceImpl{
IllustDataRepository: repository,
}
}
func (s *IllustDataServiceImpl) Save(ctx context.Context, req *illust.Illust) (*illust.Illust, error) {
err := req.Validate()
if err != nil {
return nil, err
}
err = s.IllustDataRepository.Save(req)
if err != nil {
return nil, err
}
return req, nil
}
func (s *IllustDataServiceImpl) GetById(ctx context.Context, req *IllustGetById) (*illust.Illust, error) {
return s.IllustDataRepository.FindById(req.Id)
}
func (s *IllustDataServiceImpl) AddTag(ctx context.Context, tag *IllustAddTag) (*emptypb.Empty, error) {
id, err := s.IllustDataRepository.FindById(tag.Id)
if err != nil {
return nil, err
}
id.Tags = append(id.Tags, tag.Tags...)
err = s.IllustDataRepository.Save(id)
if err != nil {
return nil, err
}
return &emptypb.Empty{}, nil
}

View File

@ -0,0 +1,179 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v4.25.3
// source: illust/data/illust_data.proto
package data
import (
context "context"
illust "git.usbharu.dev/usbharu/unos/illust"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// IllustDataServiceClient is the client API for IllustDataService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type IllustDataServiceClient interface {
Save(ctx context.Context, in *illust.Illust, opts ...grpc.CallOption) (*illust.Illust, error)
GetById(ctx context.Context, in *IllustGetById, opts ...grpc.CallOption) (*illust.Illust, error)
AddTag(ctx context.Context, in *IllustAddTag, opts ...grpc.CallOption) (*emptypb.Empty, error)
}
type illustDataServiceClient struct {
cc grpc.ClientConnInterface
}
func NewIllustDataServiceClient(cc grpc.ClientConnInterface) IllustDataServiceClient {
return &illustDataServiceClient{cc}
}
func (c *illustDataServiceClient) Save(ctx context.Context, in *illust.Illust, opts ...grpc.CallOption) (*illust.Illust, error) {
out := new(illust.Illust)
err := c.cc.Invoke(ctx, "/illust.data.IllustDataService/save", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *illustDataServiceClient) GetById(ctx context.Context, in *IllustGetById, opts ...grpc.CallOption) (*illust.Illust, error) {
out := new(illust.Illust)
err := c.cc.Invoke(ctx, "/illust.data.IllustDataService/getById", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *illustDataServiceClient) AddTag(ctx context.Context, in *IllustAddTag, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/illust.data.IllustDataService/addTag", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// IllustDataServiceServer is the server API for IllustDataService service.
// All implementations must embed UnimplementedIllustDataServiceServer
// for forward compatibility
type IllustDataServiceServer interface {
Save(context.Context, *illust.Illust) (*illust.Illust, error)
GetById(context.Context, *IllustGetById) (*illust.Illust, error)
AddTag(context.Context, *IllustAddTag) (*emptypb.Empty, error)
mustEmbedUnimplementedIllustDataServiceServer()
}
// UnimplementedIllustDataServiceServer must be embedded to have forward compatible implementations.
type UnimplementedIllustDataServiceServer struct {
}
func (UnimplementedIllustDataServiceServer) Save(context.Context, *illust.Illust) (*illust.Illust, error) {
return nil, status.Errorf(codes.Unimplemented, "method Save not implemented")
}
func (UnimplementedIllustDataServiceServer) GetById(context.Context, *IllustGetById) (*illust.Illust, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetById not implemented")
}
func (UnimplementedIllustDataServiceServer) AddTag(context.Context, *IllustAddTag) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method AddTag not implemented")
}
func (UnimplementedIllustDataServiceServer) mustEmbedUnimplementedIllustDataServiceServer() {}
// UnsafeIllustDataServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to IllustDataServiceServer will
// result in compilation errors.
type UnsafeIllustDataServiceServer interface {
mustEmbedUnimplementedIllustDataServiceServer()
}
func RegisterIllustDataServiceServer(s grpc.ServiceRegistrar, srv IllustDataServiceServer) {
s.RegisterService(&IllustDataService_ServiceDesc, srv)
}
func _IllustDataService_Save_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(illust.Illust)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(IllustDataServiceServer).Save(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/illust.data.IllustDataService/save",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(IllustDataServiceServer).Save(ctx, req.(*illust.Illust))
}
return interceptor(ctx, in, info, handler)
}
func _IllustDataService_GetById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(IllustGetById)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(IllustDataServiceServer).GetById(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/illust.data.IllustDataService/getById",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(IllustDataServiceServer).GetById(ctx, req.(*IllustGetById))
}
return interceptor(ctx, in, info, handler)
}
func _IllustDataService_AddTag_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(IllustAddTag)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(IllustDataServiceServer).AddTag(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/illust.data.IllustDataService/addTag",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(IllustDataServiceServer).AddTag(ctx, req.(*IllustAddTag))
}
return interceptor(ctx, in, info, handler)
}
// IllustDataService_ServiceDesc is the grpc.ServiceDesc for IllustDataService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var IllustDataService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "illust.data.IllustDataService",
HandlerType: (*IllustDataServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "save",
Handler: _IllustDataService_Save_Handler,
},
{
MethodName: "getById",
Handler: _IllustDataService_GetById_Handler,
},
{
MethodName: "addTag",
Handler: _IllustDataService_AddTag_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "illust/data/illust_data.proto",
}

View File

@ -0,0 +1,38 @@
package data
import (
"context"
"git.usbharu.dev/usbharu/unos/illust"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
type IllustDataRepository interface {
Save(illust *illust.Illust) error
FindById(id string) (*illust.Illust, error)
}
type MongodbIllustDataRepository struct {
mongo.Collection
}
func NewMongodbIllustDataRepository(database mongo.Database) *MongodbIllustDataRepository {
return &MongodbIllustDataRepository{Collection: *database.Collection("illusts")}
}
func (m *MongodbIllustDataRepository) Save(illust *illust.Illust) error {
if _, err := m.ReplaceOne(context.Background(), bson.D{{"_id", illust.Id}}, illust, options.Replace().SetUpsert(true)); err != nil {
return err
}
return nil
}
func (m *MongodbIllustDataRepository) FindById(id string) (*illust.Illust, error) {
var i = &illust.Illust{}
err := m.FindOne(context.Background(), bson.D{{"_id", id}}).Decode(i)
if err != nil {
return nil, err
}
return i, nil
}

View File

@ -0,0 +1,210 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v4.25.3
// source: illust/illust.proto
package illust
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Illust struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Sha256 []byte `protobuf:"bytes,3,opt,name=sha256,proto3" json:"sha256,omitempty"`
S3Id string `protobuf:"bytes,16,opt,name=s3_id,json=s3Id,proto3" json:"s3_id,omitempty"`
Tags []string `protobuf:"bytes,17,rep,name=tags,proto3" json:"tags,omitempty"`
Originals []string `protobuf:"bytes,18,rep,name=originals,proto3" json:"originals,omitempty"`
Characters []string `protobuf:"bytes,19,rep,name=characters,proto3" json:"characters,omitempty"`
Description string `protobuf:"bytes,20,opt,name=description,proto3" json:"description,omitempty"`
}
func (x *Illust) Reset() {
*x = Illust{}
if protoimpl.UnsafeEnabled {
mi := &file_illust_illust_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Illust) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Illust) ProtoMessage() {}
func (x *Illust) ProtoReflect() protoreflect.Message {
mi := &file_illust_illust_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Illust.ProtoReflect.Descriptor instead.
func (*Illust) Descriptor() ([]byte, []int) {
return file_illust_illust_proto_rawDescGZIP(), []int{0}
}
func (x *Illust) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *Illust) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *Illust) GetSha256() []byte {
if x != nil {
return x.Sha256
}
return nil
}
func (x *Illust) GetS3Id() string {
if x != nil {
return x.S3Id
}
return ""
}
func (x *Illust) GetTags() []string {
if x != nil {
return x.Tags
}
return nil
}
func (x *Illust) GetOriginals() []string {
if x != nil {
return x.Originals
}
return nil
}
func (x *Illust) GetCharacters() []string {
if x != nil {
return x.Characters
}
return nil
}
func (x *Illust) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
var File_illust_illust_proto protoreflect.FileDescriptor
var file_illust_illust_proto_rawDesc = []byte{
0x0a, 0x13, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2f, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x69, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x22, 0xcd, 0x01,
0x0a, 0x06, 0x49, 0x6c, 0x6c, 0x75, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65,
0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06,
0x73, 0x68, 0x61, 0x32, 0x35, 0x36, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x68,
0x61, 0x32, 0x35, 0x36, 0x12, 0x13, 0x0a, 0x05, 0x73, 0x33, 0x5f, 0x69, 0x64, 0x18, 0x10, 0x20,
0x01, 0x28, 0x09, 0x52, 0x04, 0x73, 0x33, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67,
0x73, 0x18, 0x11, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x12, 0x1c, 0x0a,
0x09, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x73, 0x18, 0x12, 0x20, 0x03, 0x28, 0x09,
0x52, 0x09, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x63,
0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x73, 0x18, 0x13, 0x20, 0x03, 0x28, 0x09, 0x52,
0x0a, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x64,
0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09,
0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x25, 0x5a,
0x23, 0x67, 0x69, 0x74, 0x2e, 0x75, 0x73, 0x62, 0x68, 0x61, 0x72, 0x75, 0x2e, 0x64, 0x65, 0x76,
0x2f, 0x75, 0x73, 0x62, 0x68, 0x61, 0x72, 0x75, 0x2f, 0x75, 0x6e, 0x6f, 0x73, 0x2f, 0x69, 0x6c,
0x6c, 0x75, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_illust_illust_proto_rawDescOnce sync.Once
file_illust_illust_proto_rawDescData = file_illust_illust_proto_rawDesc
)
func file_illust_illust_proto_rawDescGZIP() []byte {
file_illust_illust_proto_rawDescOnce.Do(func() {
file_illust_illust_proto_rawDescData = protoimpl.X.CompressGZIP(file_illust_illust_proto_rawDescData)
})
return file_illust_illust_proto_rawDescData
}
var file_illust_illust_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_illust_illust_proto_goTypes = []interface{}{
(*Illust)(nil), // 0: illust.Illust
}
var file_illust_illust_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_illust_illust_proto_init() }
func file_illust_illust_proto_init() {
if File_illust_illust_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_illust_illust_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Illust); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_illust_illust_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_illust_illust_proto_goTypes,
DependencyIndexes: file_illust_illust_proto_depIdxs,
MessageInfos: file_illust_illust_proto_msgTypes,
}.Build()
File_illust_illust_proto = out.File
file_illust_illust_proto_rawDesc = nil
file_illust_illust_proto_goTypes = nil
file_illust_illust_proto_depIdxs = nil
}

View File

@ -0,0 +1,27 @@
package illust
import validation "github.com/go-ozzo/ozzo-validation"
type IllustValidator struct {
}
func (iv *IllustValidator) Validate(i interface{}) error {
if c, ok := i.(validation.Validatable); ok {
return c.Validate()
}
return nil
}
func (i Illust) Validate() error {
return validation.ValidateStruct(
&i,
validation.Field(&i.Id, validation.Required),
validation.Field(&i.Name, validation.Required),
validation.Field(&i.Sha256, validation.Required),
validation.Field(&i.S3Id, validation.Required),
validation.Field(&i.Tags, validation.Required),
validation.Field(&i.Originals, validation.Required),
validation.Field(&i.Characters, validation.Required),
validation.Field(&i.Description, validation.Required),
)
}

62
illust-data/main.go Normal file
View File

@ -0,0 +1,62 @@
package main
import (
"context"
"fmt"
"git.usbharu.dev/usbharu/unos/illust/data"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"gopkg.in/ini.v1"
"log"
"net"
"os"
"os/signal"
)
func main() {
load, err := ini.Load("config.ini")
if err != nil {
log.Fatal(err)
return
}
port := load.Section("gRPC").Key("port").MustInt(50051)
mongoUrl := load.Section("mongodb").Key("url").MustString("mongodb://localhost:27017")
listen, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
log.Fatal(err)
}
server := grpc.NewServer()
connect, err := mongo.Connect(context.Background(), options.Client().ApplyURI(mongoUrl))
if err != nil {
log.Fatal(err)
return
}
database := connect.Database("illust-data")
data.RegisterIllustDataServiceServer(server, data.NewIllustDataServiceImpl(data.NewMongodbIllustDataRepository(*database)))
reflection.Register(server)
go func() {
log.Printf("start gRPC server port: %v", port)
server.Serve(listen)
}()
defer func() {
if err := connect.Disconnect(context.Background()); err != nil {
panic(err)
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
server.GracefulStop()
}

1
illust-data/wire.go Normal file
View File

@ -0,0 +1 @@
package main

View File

@ -43,4 +43,30 @@ dependencies {
testImplementation("io.ktor:ktor-server-tests-jvm")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.9.22")
protobuf(files("../unos-proto/src/main/proto"))
implementation("software.amazon.awssdk:s3:2.25.16")
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.25.3"
}
plugins {
create("grpc") {
artifact = "io.grpc:protoc-gen-grpc-java:1.61.1"
}
create("grpckt") {
artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar"
}
}
generateProtoTasks {
all().forEach {
it.plugins {
create("grpc")
create("grpckt")
}
it.builtins {
create("kotlin")
}
}
}
}

View File

@ -0,0 +1,39 @@
package dev.usbharu.unos.illust.front
data class CreateIllust(
val name: String,
val sha256: ByteArray,
val s3Id: String,
val tags: List<String>,
val characters: List<String>,
val originals: List<String>,
val description: String
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as CreateIllust
if (name != other.name) return false
if (!sha256.contentEquals(other.sha256)) return false
if (s3Id != other.s3Id) return false
if (tags != other.tags) return false
if (characters != other.characters) return false
if (originals != other.originals) return false
if (description != other.description) return false
return true
}
override fun hashCode(): Int {
var result = name.hashCode()
result = 31 * result + sha256.contentHashCode()
result = 31 * result + s3Id.hashCode()
result = 31 * result + tags.hashCode()
result = 31 * result + characters.hashCode()
result = 31 * result + originals.hashCode()
result = 31 * result + description.hashCode()
return result
}
}

View File

@ -0,0 +1,7 @@
package dev.usbharu.unos.illust.front
data class S3Config(
val bucket: String,
val region: String,
val endpoint: String
)

View File

@ -1,10 +1,25 @@
package dev.usbharu.unos.illust.front.controller
import com.google.protobuf.kotlin.toByteString
import dev.usbharu.unos.illust.front.CreateIllust
import dev.usbharu.unos.illust.front.service.UploadIllustService
import illust.crud.IllustCRUDServiceGrpcKt
import illust.crud.createIllust
class IllustController(private val illustCrudStub:IllustCRUDServiceGrpcKt.IllustCRUDServiceCoroutineStub) {
suspend fun create(){
illustCrudStub.create(createIllust { })
class IllustController(
private val uploadIllustService: UploadIllustService,
private val illustCrudStub: IllustCRUDServiceGrpcKt.IllustCRUDServiceCoroutineStub
) {
suspend fun create(createIllust: CreateIllust, illust: ByteArray) {
uploadIllustService.upload(illust)
illustCrudStub.create(createIllust {
name = createIllust.name
sha256 = createIllust.sha256.toByteString()
s3Id = createIllust.s3Id
tags.addAll(createIllust.tags)
characters.addAll(createIllust.characters)
originals.addAll(createIllust.originals)
description = createIllust.description
})
}
}

View File

@ -1,13 +1,66 @@
package dev.usbharu.unos.illust.front.plugins
import dev.usbharu.unos.illust.front.controller.IllustController
import io.ktor.http.content.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.request.*
import io.ktor.server.routing.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach
fun Application.configureRouting() {
fun Application.configureRouting(controller: IllustController) {
routing {
get("/") {
call.respondText("Hello World!")
route("/api/v1") {
post("/illusts") {
val receiveMultipart = call.receiveMultipart()
var name: String
var sha256: String
var s3Id: String
var tags: List<String>
var originals: List<String>
var characters: List<String>
var description: String
var file: ByteArray
receiveMultipart.forEachPart {
when (it) {
is PartData.BinaryChannelItem -> {
}
is PartData.BinaryItem -> {
}
is PartData.FileItem -> {
if (it.name == "file") {
file = it.streamProvider.invoke().readAllBytes()
}
}
is PartData.FormItem -> {
when (it.name) {
"name" -> name = it.value
"sha256" -> sha256 = it.value
"s3Id" -> s3Id = it.value
"tags" -> tags = it.value.split(";")
"originals" -> originals = it.value.split(";")
"characters" -> characters = it.value.split(";")
"description" -> description = it.value
else -> {
}
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,22 @@
package dev.usbharu.unos.illust.front.service
import dev.usbharu.unos.illust.front.S3Config
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import software.amazon.awssdk.core.sync.RequestBody
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.s3.model.PutObjectRequest
import java.util.UUID
class UploadIllustService(private val s3: S3Client, private val s3Config: S3Config) {
suspend fun upload(byteArray: ByteArray): UUID {
val randomUUID = UUID.randomUUID()
val putObjectRequest = PutObjectRequest.builder().bucket(s3Config.bucket).key(randomUUID.toString()).build()
withContext(Dispatchers.IO) {
s3.putObject(putObjectRequest, RequestBody.fromBytes(byteArray))
}
return randomUUID
}
}

View File

@ -0,0 +1,11 @@
from grpc_tools import protoc
protoc.main((
'',
'-I',
'../unos-proto/src/main/proto',
'--python_out=.',
'--grpc_python_out=.',
'../unos-proto/src/main/proto/illust/data/illust_data.proto',
))

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.11 (illust-tag-deepdanbooru)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -7,9 +7,9 @@ message CreateIllust {
string name = 1;
bytes sha256 = 2;
string s3_id = 3;
map<string, string> tags = 16;
map<string, string> characters = 17;
map<string, string> originals = 18;
repeated string tags = 16;
repeated string characters = 17;
repeated string originals = 18;
string description = 19;
}

View File

@ -0,0 +1,21 @@
syntax = "proto3";
import "illust/illust.proto";
import "google/protobuf/empty.proto";
package illust.data;
option go_package = "git.usbharu.dev/usbharu/unos/illust/data";
message IllustGetById{
string id = 1;
}
message IllustAddTag {
string id = 1;
repeated string tags = 2;
}
service IllustDataService{
rpc save (illust.Illust) returns (illust.Illust);
rpc getById (IllustGetById) returns (illust.Illust);
rpc addTag (IllustAddTag) returns (google.protobuf.Empty);
}

View File

@ -1,14 +1,14 @@
syntax = "proto3";
package illust;
option go_package = "git.usbharu.dev/usbharu/unos/illust";
message Illust{
string id = 1;
string name = 2;
bytes sha256 = 3;
string s3_id = 16;
map<string, string> tags = 17;
map<string, string> originals = 18;
map<string, string> characters = 19;
repeated string tags = 17;
repeated string originals = 18;
repeated string characters = 19;
string description = 20;
}

View File

@ -0,0 +1,19 @@
syntax = "proto3";
import "google/protobuf/empty.proto";
package illust.tag;
option go_package = "git.usbharu.dev/usbharu/unos/illust/tag";
message TaggingRequest{
string illust_id = 1;
}
message TaggingRequests {
repeated string illust_id = 1;
}
service IllustTaggingService {
rpc requestTagging(TaggingRequest) returns (google.protobuf.Empty);
rpc requestsTagging(TaggingRequests) returns (google.protobuf.Empty);
}