21 |
22 |
23 |
24 |
25 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/ResultPageSet.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | /** 具有分页功能的结果集
20 | *
21 | * @param data
22 | * 每页数据
23 | * @param pages
24 | * 页数
25 | * @tparam T
26 | * 分页内容
27 | * @since 2022年1月1日
28 | * @author
29 | * 梦境迷离
30 | */
31 | final case class ResultPageSet[T](override val data: List[T] = Nil, pages: Int) extends ResultSet(data)
32 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/ws/Group.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.ws
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** 添加群的信息
23 | */
24 | final case class Group(groupId: Int, remark: String)
25 |
26 | object Group {
27 |
28 | implicit val decoder: Decoder[Group] = deriveDecoder[Group]
29 | implicit val encoder: Encoder[Group] = deriveEncoder[Group]
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 | zim_server:
4 | image: liguobin/zim:0.6.3
5 | container_name: zim_server
6 | depends_on:
7 | - zim_mysql_server
8 | - zim_redis_server
9 | ports:
10 | - "9000:9000"
11 |
12 | zim_mysql_server:
13 | image: mysql:oracle
14 | restart: always
15 | container_name: zim_mysql_server
16 | command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
17 | ports:
18 | - "3306:3306"
19 | # FIXME The MySQL host directory must already exist, change it to your own MySQL location
20 | volumes:
21 | - /usr/local/mysql/data:/var/lib/mysql
22 | - ./my.cnf:/etc/mysql/conf.d/my.cnf
23 | - ./init.sql:/docker-entrypoint-initdb.d/init.sql
24 | environment:
25 | - MYSQL_DATABASE=trace
26 | - MYSQL_ALLOW_EMPTY_PASSWORD=yes
27 | - TZ=Asia/Shanghai
28 |
29 | zim_redis_server:
30 | image: redis
31 | container_name: zim_redis_server
32 | command: redis-server
33 | restart: always
34 | ports:
35 | - "6379:6379"
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/MultipartInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api
18 |
19 | import sttp.model.Part
20 | import sttp.tapir.TapirFile
21 |
22 | /** 文件上传
23 | *
24 | * @author
25 | * 梦境迷离
26 | * @since 2022/2/3
27 | * @version 1.0
28 | */
29 | final case class MultipartInput(file: Part[TapirFile]) extends Serializable {
30 |
31 | def getFileName: String = file.fileName.getOrElse(file.name)
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-server/src/test/scala/org/bitlap/zim/server/CommonTestSupport.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server
18 |
19 | import zio._
20 |
21 | /** @since 2022/8/27
22 | * @author
23 | * 梦境迷离
24 | */
25 | trait CommonTestSupport {
26 |
27 | def unsafeRun[T](action: => ZIO[Any, Throwable, T]): T =
28 | Unsafe.unsafe { implicit runtime =>
29 | Runtime.default.unsafe.run(action).getOrThrowFiberFailure()
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/ws/Constants.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.ws
18 |
19 | /** @author
20 | * 梦境迷离
21 | * @version 1.0,2022/1/11
22 | */
23 | object Constants {
24 |
25 | final val SCHEDULE_JOB_ACTOR: String = "scheduleJobActor"
26 | final val USER_STATUS_CHANGE_ACTOR: String = "userStatusChangeActor"
27 | final val WS_MESSAGE_FORWARD_ACTOR: String = "wsMessageForwardActor"
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/RemoveFriendInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** @author
23 | * 梦境迷离
24 | * @since 2022/2/5
25 | * @version 1.0
26 | */
27 | final case class RemoveFriendInput(friendId: Int)
28 |
29 | object RemoveFriendInput {
30 |
31 | implicit val decoder: Decoder[RemoveFriendInput] = deriveDecoder[RemoveFriendInput]
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/ChangeGroupInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** @author
23 | * 梦境迷离
24 | * @since 2022/2/5
25 | * @version 1.0
26 | */
27 | final case class ChangeGroupInput(groupId: Int, userId: Int)
28 |
29 | object ChangeGroupInput {
30 |
31 | implicit val decoder: Decoder[ChangeGroupInput] = deriveDecoder[ChangeGroupInput]
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/RefuseFriendInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** @author
23 | * 梦境迷离
24 | * @since 2022/2/5
25 | * @version 1.0
26 | */
27 | final case class RefuseFriendInput(messageBoxId: Int, to: Int)
28 |
29 | object RefuseFriendInput {
30 |
31 | implicit val decoder: Decoder[RefuseFriendInput] = deriveDecoder[RefuseFriendInput]
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/static/html/createusergroup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 创建分组
6 |
7 |
8 |
9 |
10 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/LeaveOutGroupInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** @author
23 | * 梦境迷离
24 | * @since 2022/2/5
25 | * @version 1.0
26 | */
27 | final case class LeaveOutGroupInput(groupId: Int, uid: Int)
28 |
29 | object LeaveOutGroupInput {
30 |
31 | implicit val decoder: Decoder[LeaveOutGroupInput] = deriveDecoder[LeaveOutGroupInput]
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/repository/FriendGroupRepository.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api.repository
18 |
19 | import org.bitlap.zim.domain.model._
20 |
21 | /** 好友分组操作定义
22 | *
23 | * @author
24 | * LittleTear
25 | * @since 2021/12/31
26 | * @version 1.0
27 | */
28 | trait FriendGroupRepository[F[_]] extends BaseRepository[F, FriendGroup] {
29 |
30 | def createFriendGroup(friend: FriendGroup): F[Int]
31 |
32 | def findFriendGroupsById(uid: Int): F[FriendGroup]
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/FriendGroupInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** 好友分组 输入
23 | *
24 | * @param uid
25 | * 创建人
26 | * @param groupname
27 | * 分组名称
28 | */
29 | final case class FriendGroupInput(uid: Int, groupname: String)
30 |
31 | object FriendGroupInput {
32 |
33 | implicit val decoder: Decoder[FriendGroupInput] = deriveDecoder[FriendGroupInput]
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/AgreeFriendInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** @author
23 | * 梦境迷离
24 | * @since 2022/2/5
25 | * @version 1.0
26 | */
27 | final case class AgreeFriendInput(uid: Int, from_group: Int, group: Int, messageBoxId: Int)
28 |
29 | object AgreeFriendInput {
30 |
31 | implicit val decoder: Decoder[AgreeFriendInput] = deriveDecoder[AgreeFriendInput]
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/static/html/setting.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | 设置
7 |
8 |
11 |
12 |
13 |
14 |
15 |
设置1
16 |
设置2
17 |
18 |
19 |
哈哈哈哈哈哈
20 |
哈哈哈哈哈哈
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/ExistEmailInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** 校验注册邮件 输入
23 | * @param email
24 | */
25 | final case class ExistEmailInput(email: String)
26 |
27 | object ExistEmailInput {
28 |
29 | implicit val decoder: Decoder[ExistEmailInput] = deriveDecoder[ExistEmailInput]
30 |
31 | implicit val encoder: Encoder[ExistEmailInput] = deriveEncoder[ExistEmailInput]
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/UploadResult.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** @author
23 | * 梦境迷离
24 | * @since 2022/1/1
25 | * @version 1.0
26 | */
27 | final case class UploadResult(src: String, name: String)
28 |
29 | object UploadResult {
30 |
31 | implicit val decoder: Decoder[UploadResult] = deriveDecoder[UploadResult]
32 | implicit val encoder: Encoder[UploadResult] = deriveEncoder[UploadResult]
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/repository/GroupMemberRepository.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api.repository
18 |
19 | import org.bitlap.zim.domain.model._
20 |
21 | /** @author
22 | * 梦境迷离
23 | * @since 2022/1/15
24 | * @version 1.0
25 | */
26 | trait GroupMemberRepository[F[_]] extends BaseRepository[F, GroupMember] {
27 |
28 | def leaveOutGroup(groupMember: GroupMember): F[Int]
29 |
30 | def findGroupMembers(gid: Int): F[Int]
31 |
32 | def addGroupMember(groupMember: GroupMember): F[Int]
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | System.out
6 |
7 | %X{akkaTimestamp} %-5level[%thread] %logger{0} - %msg%n
8 |
9 |
10 |
11 |
12 | logs/zim-akka.log
13 |
14 | %date %level %msg%n
15 |
16 |
17 | 10
18 | logs/zim-akka.log.%i.gz
19 |
20 |
21 | 512MB
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/project/Information.scala:
--------------------------------------------------------------------------------
1 | import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport.headerCreateAll
2 | import sbt.*
3 | import sbt.Keys._
4 |
5 | /** @author
6 | * 梦境迷离
7 | * @since 2022/1/15
8 | * @version 1.0
9 | */
10 | object Information {
11 |
12 | val value: Seq[Def.Setting[_]] = Seq(
13 | Compile / compile := (Compile / compile).dependsOn(Compile / headerCreateAll).value,
14 | organization := "org.bitlap",
15 | organizationName := "bitlap",
16 | startYear := Some(2023),
17 | description := "zim is a functional-style, asynchronous and streaming IM based on scala and zio",
18 | homepage := Some(url(s"https://github.com/bitlap/zim")),
19 | licenses += ("Apache-2.0", new URL("https://www.apache.org/licenses/LICENSE-2.0.txt")),
20 | developers := List(
21 | Developer(
22 | "jxnu-liguobin",
23 | "梦境迷离",
24 | "dreamylost@outlook.com",
25 | url("https://github.com/jxnu-liguobin")
26 | )
27 | ),
28 | scmInfo := Some(
29 | ScmInfo(
30 | url("https://github.com/bitlap/zim"),
31 | "scm:git@github.com:bitlap/zim.git"
32 | )
33 | )
34 | )
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/modules/zim-cache-redis4cats/src/main/scala/org/bitlap/zim/cache/redis4cats/CatsRedisConfiguration.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.cache.redis4cats
18 |
19 | import com.typesafe.config._
20 |
21 | /** redis configuration
22 | *
23 | * @author
24 | * 梦境迷离
25 | * @since 2022/8/18
26 | * @version 1.0
27 | */
28 | object CatsRedisConfiguration {
29 |
30 | private val conf: Config = ConfigFactory.load().getConfig("cache.redis")
31 | lazy val redisHost: String = conf.getString("host")
32 | lazy val redisPort: Int = conf.getInt("port")
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/Add.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** 添加好友、群组
23 | *
24 | * @param groupId
25 | * 好友列表id或群组id
26 | * @param remark
27 | * 附言
28 | * @param `type`
29 | * 类型,好友或群组
30 | */
31 | final case class Add(groupId: Int, remark: String, `type`: Int)
32 |
33 | object Add {
34 |
35 | implicit val decoder: Decoder[Add] = deriveDecoder[Add]
36 | implicit val encoder: Encoder[Add] = deriveEncoder[Add]
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/UpdateSignInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** @author
23 | * 梦境迷离
24 | * @since 2022/2/5
25 | * @version 1.0
26 | */
27 | final case class UpdateSignInput(sign: String)
28 |
29 | object UpdateSignInput {
30 |
31 | implicit val decoder: Decoder[UpdateSignInput] = deriveDecoder[UpdateSignInput]
32 |
33 | implicit val encoder: Encoder[UpdateSignInput] = deriveEncoder[UpdateSignInput]
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/modules/zim-server/src/test/resources/application.conf:
--------------------------------------------------------------------------------
1 | infrastructure {
2 | mysql {
3 | # INIT=RUNSCRIPT FROM 'classpath:sql/schema.sql'
4 | url = "jdbc:h2:mem:zim?caseSensitive=false;MODE=MYSQL;TRACE_LEVEL_FILE=2;"
5 | user = ""
6 | password = ""
7 | databaseName = "zim"
8 | connection {
9 | initialPoolSize = 1,
10 | maxPoolSize = 5,
11 | timeoutMillis = 3000,
12 | validationQuery = "select 1",
13 | driver = "org.h2.Driver"
14 | }
15 | }
16 |
17 | javamail {
18 | host = "smtp.qq.com",
19 | username = "568845948@qq.com",
20 | password = "xxx",
21 | sender = "568845948@qq.com"
22 | port = 587,
23 | threadPoolSize = 20,
24 | connectionPoolCoreSize = 10,
25 | debug = true
26 | }
27 | }
28 |
29 | caffeine.disabledLog = false
30 | caffeine.expireAfterWriteSeconds = 300
31 |
32 | application {
33 |
34 | name = "Zim-Application"
35 | server {
36 | webHost = "im.dreamylost.cn"
37 | port = 9000
38 | interface = "localhost"
39 | }
40 | }
41 |
42 | akka {
43 | loggers = ["akka.event.slf4j.Slf4jLogger"]
44 | loglevel = "DEBUG"
45 | logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
46 | }
47 |
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/repository/AddMessageRepository.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api.repository
18 |
19 | import org.bitlap.zim.domain.model._
20 |
21 | /** @author
22 | * 梦境迷离
23 | * @since 2022/1/15
24 | * @version 1.0
25 | */
26 | trait AddMessageRepository[F[_]] extends BaseRepository[F, AddMessage] {
27 |
28 | def countUnHandMessage(uid: Int, agree: Option[Int]): F[Int]
29 |
30 | def findAddInfo(uid: Int): F[AddMessage]
31 |
32 | def updateAgree(id: Int, agree: Int): F[Int]
33 |
34 | def saveAddMessage(addMessage: AddMessage): F[Int]
35 | }
36 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/ws/RefuseOrAgreeMessage.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.ws
18 |
19 | import org.bitlap.zim.domain.Mine
20 |
21 | import io.circe._
22 | import io.circe.generic.semiauto._
23 |
24 | /** 同意或拒绝添加群的信息
25 | */
26 | final case class RefuseOrAgreeMessage(toUid: Int, groupId: Int, messageBoxId: Int, mine: Mine)
27 |
28 | object RefuseOrAgreeMessage {
29 |
30 | implicit val decoder: Decoder[RefuseOrAgreeMessage] = deriveDecoder[RefuseOrAgreeMessage]
31 | implicit val encoder: Encoder[RefuseOrAgreeMessage] = deriveEncoder[RefuseOrAgreeMessage]
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/util/DateUtil.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.infrastructure.util
18 |
19 | import java.time.ZonedDateTime
20 | import java.time.format.DateTimeFormatter
21 |
22 | /** 时间工具
23 | *
24 | * @since 2021年12月31日
25 | * @author
26 | * 梦境迷离
27 | */
28 | object DateUtil {
29 |
30 | final lazy val pattern: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
31 |
32 | /** 获取格式化后的当前时间yyyy-MM-dd
33 | * @param now
34 | */
35 | def getDateString(now: ZonedDateTime = ZonedDateTime.now()): String =
36 | now.format(pattern)
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/util/UuidUtil.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.infrastructure.util
18 |
19 | import java.util.UUID
20 |
21 | import zio._
22 |
23 | /** UUID工具
24 | *
25 | * @since 2021年12月31日
26 | * @author
27 | * 梦境迷离
28 | */
29 | object UuidUtil {
30 |
31 | /** 64位随机UUID
32 | */
33 | def getUuid64: UIO[String] =
34 | ZIO.succeed((UUID.randomUUID.toString + UUID.randomUUID.toString).replace("-", ""))
35 |
36 | /** 32位随机UUID
37 | */
38 | def getUuid32: UIO[String] =
39 | ZIO.succeed(UUID.randomUUID.toString.replace("-", ""))
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/GroupInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** 群组 输入
23 | *
24 | * @param groupname
25 | * 分组名称
26 | * @param avatar
27 | * 头像
28 | * @param createId
29 | * 创建人 creator Id
30 | */
31 | final case class GroupInput(groupname: String, avatar: String, createId: Int)
32 |
33 | object GroupInput {
34 |
35 | implicit val decoder: Decoder[GroupInput] = deriveDecoder[GroupInput]
36 |
37 | implicit val encoder: Encoder[GroupInput] = deriveEncoder[GroupInput]
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/repository/FriendGroupFriendRepository.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api.repository
18 |
19 | import org.bitlap.zim.domain.model._
20 |
21 | /** 好友分组操作定义
22 | *
23 | * @author
24 | * 梦境迷离
25 | * @since 2022/1/2
26 | * @version 1.0
27 | */
28 | trait FriendGroupFriendRepository[F[_]] extends BaseRepository[F, AddFriend] {
29 |
30 | def removeFriend(friendId: Int, uId: Int): F[Int]
31 |
32 | def changeGroup(groupId: Int, originRecordId: Int): F[Int]
33 |
34 | def findUserGroup(uId: Int, mId: Int): F[Int]
35 |
36 | def addFriend(from: AddFriend, to: AddFriend): F[Int]
37 | }
38 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/ResultSet.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | /** 结果集
20 | *
21 | * @param code
22 | * 状态,0表示成功,其他表示失败
23 | * @param msg
24 | * 额外信息
25 | * @since 2021年12月25日
26 | * @author
27 | * 梦境迷离
28 | */
29 | class ResultSet[T](
30 | val data: T,
31 | val code: Int = SystemConstant.SUCCESS,
32 | val msg: String = SystemConstant.SUCCESS_MESSAGE
33 | )
34 |
35 | object ResultSet {
36 |
37 | def apply[T](
38 | data: T = null,
39 | code: Int = SystemConstant.SUCCESS,
40 | msg: String = SystemConstant.SUCCESS_MESSAGE
41 | ): ResultSet[T] = new ResultSet(data, code, msg)
42 | }
43 |
--------------------------------------------------------------------------------
/modules/zim-server/src/test/scala/org/bitlap/zim/server/util/DateHelper.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.util
18 |
19 | import java.time.{ZonedDateTime, ZoneId}
20 | import java.time.format.DateTimeFormatter
21 | import java.util.Locale
22 |
23 | /** @author
24 | * 梦境迷离
25 | * @since 2022/2/12
26 | * @version 1.0
27 | */
28 | object DateHelper {
29 |
30 | val fromPattern: DateTimeFormatter = DateTimeFormatter
31 | .ofPattern("yyyy-MM-dd HH:mm:ss")
32 | .withLocale(Locale.CHINA)
33 | .withZone(ZoneId.of("Asia/Shanghai"))
34 |
35 | def getConstantTime: ZonedDateTime =
36 | ZonedDateTime.parse("2022-02-11 08:00:00", fromPattern)
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/modules/zim-server/src/test/scala/org/bitlap/zim/server/module/MysqlConfigSpec.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.module
18 |
19 | import org.bitlap.zim.server.ZIOBaseSuit
20 |
21 | import scalikejdbc._
22 | import zio.Scope
23 | import zio.test._
24 | import zio.test.Assertion._
25 |
26 | object MysqlConfigSpec extends ZIOBaseSuit {
27 |
28 | def spec: Spec[Environment with TestEnvironment with Scope, Any] = suite("MysqlConfigSpec")(
29 | test("test the database connect working state") {
30 | assert(isConnected)(equalTo(true))
31 | }
32 | )
33 |
34 | val isConnected: Boolean = NamedDB(Symbol(h2ConfigurationProperties.databaseName)).conn.isValid(0)
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/modules/zim-server/src/test/scala/org/bitlap/zim/server/util/DateUtilSpec.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.util
18 |
19 | import java.time.ZonedDateTime
20 |
21 | import org.bitlap.zim.infrastructure.util.DateUtil
22 | import org.scalatest.flatspec.AnyFlatSpec
23 | import org.scalatest.matchers.should.Matchers
24 |
25 | /** @author
26 | * 梦境迷离
27 | * @since 2022/2/8
28 | * @version 1.0
29 | */
30 | class DateUtilSpec extends AnyFlatSpec with Matchers {
31 |
32 | "getDateString" should "ok" in {
33 | val dateString = DateUtil.getDateString(ZonedDateTime.parse("2020-02-21 00:00:00", DateHelper.fromPattern))
34 | dateString shouldBe "2020-02-21"
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/static/layui/css/modules/code.css:
--------------------------------------------------------------------------------
1 | /**
2 |
3 | @Name: layui.code
4 | @Author: 贤心
5 | @Site: http://www.layui.com
6 |
7 | */
8 |
9 | /* 加载就绪标志 */
10 | html #layuicss-skincodecss{display:none; position: absolute; width:1989px;}
11 |
12 | /* 默认风格 */
13 | .layui-code-view{display: block; position: relative; margin: 10px 0; padding: 0; border: 1px solid #ddd; border-left-width: 6px; background-color: #F2F2F2; color: #333; font-family: Courier New; font-size: 12px;}
14 | .layui-code-h3{position: relative; padding: 0 10px; height: 30px; line-height: 30px; border-bottom: 1px solid #ddd; font-size: 12px;}
15 | .layui-code-h3 a{position: absolute; right: 10px; top: 0; color: #999;}
16 | .layui-code-view .layui-code-ol{position: relative; overflow: auto;}
17 | .layui-code-view .layui-code-ol li{position: relative; margin-left: 45px; line-height: 20px; padding: 0 5px; border-left: 1px solid #ddd; list-style-type: decimal-leading-zero; *list-style-type: decimal; background-color: #fff;}
18 | .layui-code-view pre{margin: 0;}
19 |
20 | /* notepadd++风格 */
21 | .layui-code-notepad{border: 1px solid #0C0C0C; border-left-color: #3F3F3F; background-color: #0C0C0C; color: #C2BE9E}
22 | .layui-code-notepad .layui-code-h3{border-bottom: none;}
23 | .layui-code-notepad .layui-code-ol li{background-color: #3F3F3F; border-left: none;}
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/repository/GroupRepository.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api.repository
18 |
19 | import org.bitlap.zim.domain.model._
20 |
21 | /** 群组的操作定义
22 | *
23 | * @author
24 | * 梦境迷离
25 | * @since 2021/12/29
26 | * @version 1.0
27 | */
28 | trait GroupRepository[F[_]] extends BaseRepository[F, GroupList] {
29 |
30 | def deleteGroup(id: Int): F[Int]
31 |
32 | def countGroup(groupName: Option[String]): F[Int]
33 |
34 | def createGroupList(group: GroupList): F[Long]
35 |
36 | def findGroups(groupName: Option[String]): F[GroupList]
37 |
38 | def findGroupById(gid: Int): F[GroupList]
39 |
40 | def findGroupsById(uid: Int): F[GroupList]
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/RegisterUserInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** 注册用户信息提交 输入
23 | *
24 | * @param username
25 | * 用户名
26 | * @param email
27 | * 邮箱
28 | * @param password
29 | * 密码
30 | */
31 | final case class RegisterUserInput(
32 | username: String,
33 | password: String,
34 | email: String
35 | )
36 |
37 | object RegisterUserInput {
38 |
39 | implicit val decoder: Decoder[RegisterUserInput] = deriveDecoder[RegisterUserInput]
40 |
41 | // 测试用
42 | implicit val encoder: Encoder[RegisterUserInput] = deriveEncoder[RegisterUserInput]
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/modules/zim-cache-redis4zio/src/main/scala/org/bitlap/zim/cache/redis4zio/ZioRedisConfiguration.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.cache.redis4zio
18 |
19 | import com.typesafe.config.{Config, _}
20 |
21 | import zio._
22 | import zio.redis._
23 |
24 | /** redis configuration
25 | *
26 | * @author
27 | * 梦境迷离
28 | * @since 2022/1/10
29 | * @version 2.1
30 | */
31 | object ZioRedisConfiguration {
32 |
33 | private val conf: Config = ConfigFactory.load().getConfig("cache.redis")
34 |
35 | lazy val redisConf: ULayer[RedisConfig] = ZLayer.succeed {
36 | if (conf.isEmpty) {
37 | RedisConfig.Default
38 | } else {
39 | RedisConfig(conf.getString("host"), conf.getInt("port"))
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/ZimError.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | /** 系统异常
20 | *
21 | * @author
22 | * 梦境迷离
23 | * @since 2021/12/25
24 | * @version 1.0
25 | */
26 | sealed trait ZimError extends Throwable with Product {
27 | val msg: String
28 | val code: Int
29 | }
30 |
31 | object ZimError {
32 |
33 | case class BusinessException(
34 | override val code: Int = SystemConstant.ERROR,
35 | override val msg: String = SystemConstant.ERROR_MESSAGE
36 | ) extends ZimError
37 |
38 | case class Unauthorized(
39 | override val code: Int = SystemConstant.ERROR,
40 | override val msg: String = SystemConstant.NOT_LOGIN
41 | ) extends ZimError
42 | }
43 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/Group.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** 群组
23 | *
24 | * @param id
25 | * 群组id
26 | * @param groupName
27 | * 群组名
28 | */
29 | @SerialVersionUID(1L) class Group(val id: Int, val groupName: String)
30 |
31 | object Group {
32 |
33 | implicit val decoder: Decoder[Group] = deriveDecoder[Group]
34 |
35 | implicit val encoder: Encoder[Group] = (a: Group) =>
36 | if (a == null) Json.Null
37 | else
38 | Json.obj(
39 | ("id", Json.fromInt(a.id)),
40 | ("groupname", Json.fromString(a.groupName)) // 表名是下划线,如果字段名不是标准驼峰不能自动转化。字段名改成驼峰后序列化时处理一下
41 | )
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/ChatHistory.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** 聊天记录
23 | *
24 | * @param id
25 | * 用户id
26 | * @param username
27 | * 用户名
28 | * @param avatar
29 | * 用户头像
30 | * @param content
31 | * 消息内容
32 | * @param timestamp
33 | * 时间
34 | */
35 | final case class ChatHistory(
36 | id: Int,
37 | username: String,
38 | avatar: String,
39 | content: String,
40 | timestamp: Long
41 | )
42 |
43 | object ChatHistory {
44 |
45 | implicit val decoder: Decoder[ChatHistory] = deriveDecoder[ChatHistory]
46 | implicit val encoder: Encoder[ChatHistory] = deriveEncoder[ChatHistory]
47 | }
48 |
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/repository/ReceiveRepository.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api.repository
18 |
19 | import org.bitlap.zim.domain.model._
20 |
21 | /** 消息的操作定义
22 | *
23 | * @author
24 | * LittleTear
25 | * @since 2021/12/30
26 | * @version 1.0
27 | */
28 | trait ReceiveRepository[F[_]] extends BaseRepository[F, Receive] {
29 |
30 | def saveMessage(receive: Receive): F[Int]
31 |
32 | def findOffLineMessage(uid: Int, status: Int): F[Receive]
33 |
34 | def findHistoryMessage(uid: Option[Int], mid: Option[Int], typ: Option[String]): F[Receive]
35 |
36 | def countHistoryMessage(uid: Option[Int], mid: Option[Int], typ: Option[String]): F[Int]
37 |
38 | def readMessage(mine: Int, to: Int, typ: String): F[Int]
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/util/LogUtil.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.infrastructure.util
18 |
19 | import zio._
20 | import zio.stream._
21 |
22 | /** @author
23 | * 梦境迷离
24 | * @since 2022/1/20
25 | * @version 1.0
26 | */
27 | object LogUtil {
28 | def info(msg: => String): UIO[Unit] = ZIO.logInfo(msg)
29 |
30 | def debug(msg: => String): UIO[Unit] = ZIO.debug(msg)
31 |
32 | def error(msg: => String): UIO[Unit] = ZIO.logError(msg)
33 |
34 | // 后面要把非必要的stream去掉
35 | def infoS(msg: => String): UStream[Unit] =
36 | ZStream.fromZIO(info(msg))
37 |
38 | def debugS(msg: => String): UStream[Unit] =
39 | ZStream.fromZIO(debug(msg))
40 |
41 | def errorS(msg: => String): UStream[Unit] =
42 | ZStream.fromZIO(error(msg))
43 | }
44 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/input/UpdateUserInput.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.input
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | /** 用户信息提交 输入
23 | *
24 | * @param id
25 | * @param username
26 | * 用户名
27 | * @param password
28 | * 密码
29 | * @param oldpwd
30 | * 旧密码
31 | * @param sign
32 | * 签名
33 | * @param sex
34 | * 性别
35 | */
36 | final case class UpdateUserInput(
37 | id: Int,
38 | username: String,
39 | password: Option[String],
40 | oldpwd: Option[String],
41 | sign: String,
42 | sex: String
43 | )
44 |
45 | object UpdateUserInput {
46 |
47 | implicit val decoder: Decoder[UpdateUserInput] = deriveDecoder[UpdateUserInput]
48 |
49 | implicit val encoder: Encoder[UpdateUserInput] = deriveEncoder[UpdateUserInput]
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/FriendAndGroupInfo.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | import org.bitlap.zim.domain.model._
20 |
21 | import io.circe._
22 | import io.circe.generic.semiauto._
23 |
24 | import zio.schema._
25 |
26 | /** 好友和群组整个信息集
27 | *
28 | * @param mine
29 | * 我的信息
30 | * @param friend
31 | * 好友列表
32 | * @param group
33 | * 群组信息列表
34 | */
35 | final case class FriendAndGroupInfo(
36 | mine: User,
37 | friend: List[FriendList],
38 | group: List[GroupList]
39 | )
40 |
41 | object FriendAndGroupInfo {
42 |
43 | implicit val decoder: Decoder[FriendAndGroupInfo] = deriveDecoder[FriendAndGroupInfo]
44 | implicit val encoder: Encoder[FriendAndGroupInfo] = deriveEncoder[FriendAndGroupInfo]
45 | implicit val schema: Schema[FriendAndGroupInfo] = DeriveSchema.gen[FriendAndGroupInfo]
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/modules/zim-server/src/test/scala/org/bitlap/zim/server/util/UuidSpec.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.util
18 |
19 | import org.bitlap.zim.infrastructure.util.UuidUtil
20 | import org.bitlap.zim.server.CommonTestSupport
21 | import org.scalatest.flatspec.AnyFlatSpec
22 | import org.scalatest.matchers.should.Matchers
23 |
24 | /** @author
25 | * 梦境迷离
26 | * @since 2022/1/9
27 | * @version 1.0
28 | */
29 | final class UuidSpec extends AnyFlatSpec with Matchers with CommonTestSupport {
30 |
31 | "getUuid64" should "ok" in {
32 | val uuid = unsafeRun(UuidUtil.getUuid64)
33 | println(uuid)
34 | assert(uuid != null)
35 | assert(uuid.length == 64)
36 | }
37 |
38 | "getUuid32" should "ok" in {
39 | val uuid = unsafeRun(UuidUtil.getUuid32)
40 | println(uuid)
41 | assert(uuid != null)
42 | assert(uuid.length == 32)
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/ApiEndpoint.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api
18 |
19 | import sttp.tapir._
20 |
21 | /** Open API的端点
22 | *
23 | * @author
24 | * 梦境迷离
25 | * @since 2021/12/25
26 | * @version 1.0
27 | */
28 | trait ApiEndpoint {
29 |
30 | lazy val apiResource: String = "api"
31 | lazy val apiVersion: String = "v1.0"
32 | private[api] lazy val apiNameResource: String = "api-resource"
33 | private[api] lazy val apiDescriptionResource: String = "Api Resources"
34 | private[api] lazy val baseApiEndpoint: EndpointInput[Unit] = apiResource / apiVersion
35 |
36 | private[api] lazy val baseEndpoint: PublicEndpoint[Unit, Unit, Unit, Any] =
37 | endpoint.in(baseApiEndpoint).name(apiNameResource).description(apiDescriptionResource)
38 |
39 | }
40 |
41 | object ApiEndpoint extends ApiEndpoint
42 |
--------------------------------------------------------------------------------
/modules/zim-server/src/test/scala/org/bitlap/zim/server/util/SecuritySpec.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.util
18 |
19 | import org.bitlap.zim.infrastructure.util._
20 | import org.bitlap.zim.server.CommonTestSupport
21 | import org.scalatest.flatspec._
22 | import org.scalatest.matchers.should._
23 |
24 | /** @author
25 | * 梦境迷离
26 | * @since 2022/1/9
27 | * @version 1.0
28 | */
29 | final class SecuritySpec extends AnyFlatSpec with Matchers with CommonTestSupport {
30 |
31 | "encrypt" should "ok" in {
32 | val encrypt = unsafeRun(SecurityUtil.encrypt("123456"))
33 | println(encrypt.value)
34 | assert(encrypt.value == "jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=")
35 | }
36 |
37 | "getUuid32" should "ok" in {
38 | val encrypt = unsafeRun(SecurityUtil.encrypt("123456"))
39 | val matchPwd = unsafeRun(SecurityUtil.matched("123456", encrypt.value))
40 | println(matchPwd)
41 | assert(matchPwd)
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/model/AddFriend.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.model
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | import scalikejdbc.{WrappedResultSet, _}
23 |
24 | /** 添加好友
25 | * @see
26 | * table:t_friend_group_friends
27 | * @param id
28 | * 表ID 无意义
29 | * @param uid
30 | * 用户ID
31 | * @param fgid
32 | * 分组ID
33 | */
34 | final case class AddFriend(uid: Int, fgid: Int, id: Int = 0)
35 |
36 | object AddFriend extends BaseModel[AddFriend] {
37 |
38 | override lazy val columns: collection.Seq[String] = autoColumns[AddFriend]()
39 |
40 | override def tableName: String = "t_friend_group_friends"
41 |
42 | implicit val decoder: Decoder[AddFriend] = deriveDecoder[AddFriend]
43 | implicit val encoder: Encoder[AddFriend] = deriveEncoder[AddFriend]
44 |
45 | override def apply(rs: WrappedResultSet)(implicit sp: SyntaxProvider[AddFriend]): AddFriend =
46 | autoConstruct[AddFriend](rs, sp)
47 | }
48 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/static/html/creategroup.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 创建群组
6 |
7 |
8 |
9 |
10 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | 注:上传的图片不能够超过500kb
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/modules/zim-server/src/test/scala/org/bitlap/zim/server/util/SchemaSpec.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.util
18 |
19 | import org.bitlap.zim.api.ApiJsonCodec
20 | import org.bitlap.zim.domain.input.UserToken.UserSecurityInfo
21 | import org.scalatest.flatspec.AnyFlatSpec
22 | import org.scalatest.matchers.should.Matchers
23 |
24 | import zio.schema.codec.ProtobufCodec
25 |
26 | /** @author
27 | * 梦境迷离
28 | * @since 2022/3/5
29 | * @version 1.0
30 | */
31 | class SchemaSpec extends AnyFlatSpec with Matchers with ApiJsonCodec {
32 |
33 | "Schema" should "ok" in {
34 | val userSecurityInfo =
35 | UserSecurityInfo(209, "dreamylost@qq.com", "jZae727K08KaOmKSgOaGzww/XVqGr/PKEgIMkjrcbJI=", "顶顶顶顶")
36 | val chunkByte = ProtobufCodec.protobufCodec[UserSecurityInfo].encode(userSecurityInfo)
37 | val str = ProtobufCodec.protobufCodec[UserSecurityInfo].decode(chunkByte)
38 | val id = str.map(_.id)
39 | id.getOrElse(0) shouldBe userSecurityInfo.id
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/repository/UserRepository.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api.repository
18 |
19 | import org.bitlap.zim.domain.model._
20 |
21 | /** 用户的操作定义
22 | *
23 | * @author
24 | * 梦境迷离
25 | * @since 2021/12/25
26 | * @version 1.0
27 | */
28 | trait UserRepository[F[_]] extends BaseRepository[F, User] {
29 |
30 | def countUser(username: Option[String], sex: Option[Int]): F[Int]
31 |
32 | def findUsers(username: Option[String], sex: Option[Int]): F[User]
33 |
34 | def updateAvatar(avatar: String, uid: Int): F[Int]
35 |
36 | def updateSign(sign: String, uid: Int): F[Int]
37 |
38 | def updateUserInfo(id: Int, user: User): F[Int]
39 |
40 | def updateUserStatus(status: String, uid: Int): F[Int]
41 |
42 | def activeUser(activeCode: String): F[Int]
43 |
44 | def findUserByGroupId(gid: Int): F[User]
45 |
46 | def findUsersByFriendGroupIds(fgid: Int): F[User]
47 |
48 | def saveUser(user: User): F[Long]
49 |
50 | def matchUser(email: String): F[User]
51 | }
52 |
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/service/PaginationApiService.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api.service
18 |
19 | import org.bitlap.zim.domain._
20 | import org.bitlap.zim.domain.model._
21 |
22 | /** 直接提供给endpoint使用 对userService做一定的包装
23 | *
24 | * @author
25 | * 梦境迷离
26 | * @since 2022/8/18
27 | * @version 2.0
28 | */
29 | trait PaginationApiService[F[_]] {
30 |
31 | /** 分页接口 内存分页
32 | *
33 | * TODO 没有使用数据的offset
34 | * @param id
35 | * @param `type`
36 | * @param page
37 | * @param mid
38 | * @return
39 | */
40 | def chatLog(id: Int, `type`: String, page: Int, mid: Int): F[ResultPageSet[ChatHistory]]
41 |
42 | def findAddInfo(uid: Int, page: Int): F[ResultPageSet[AddInfo]]
43 |
44 | def findUsers(name: Option[String], sex: Option[Int], page: Int): F[ResultPageSet[User]]
45 |
46 | def findGroups(name: Option[String], page: Int): F[ResultPageSet[GroupList]]
47 |
48 | def findMyGroups(createId: Int, page: Int): F[ResultPageSet[GroupList]]
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/model/GroupMember.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.model
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | import scalikejdbc.{WrappedResultSet, _}
23 |
24 | /** 群组成员
25 | *
26 | * @see
27 | * table:t_group_members
28 | * @param id
29 | * 表ID 无意义
30 | * @param gid
31 | * 群组编号
32 | * @param uid
33 | * 用户编号
34 | */
35 | final case class GroupMember(gid: Int, uid: Int, id: Int = 0)
36 |
37 | object GroupMember extends BaseModel[GroupMember] {
38 |
39 | override lazy val columns: collection.Seq[String] = autoColumns[GroupMember]()
40 |
41 | override def apply(rs: WrappedResultSet)(implicit sp: SyntaxProvider[GroupMember]): GroupMember =
42 | autoConstruct[GroupMember](rs, sp)
43 |
44 | override def tableName: String = "t_group_members"
45 |
46 | implicit val decoder: Decoder[GroupMember] = deriveDecoder[GroupMember]
47 | implicit val encoder: Encoder[GroupMember] = deriveEncoder[GroupMember]
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/scala/org/bitlap/zim/server/module/ZioActorModule.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.module
18 |
19 | import org.bitlap.zim.domain.ws._
20 | import org.bitlap.zim.server.actor._
21 |
22 | import zio._
23 | import zio.actors._
24 |
25 | /** zio actor configuration
26 | *
27 | * @author
28 | * 梦境迷离
29 | * @since 2021/12/25
30 | * @version 2.0
31 | */
32 | object ZioActorModule {
33 |
34 | lazy val scheduleActor: ZIO[Scope, Throwable, ActorRef[protocol.Command]] =
35 | live
36 | .flatMap(_.make(Constants.SCHEDULE_JOB_ACTOR, zio.actors.Supervisor.none, (), ScheduleStateful.stateful))
37 |
38 | lazy val userStatusActor: ZIO[Scope, Throwable, ActorRef[protocol.Command]] =
39 | live
40 | .flatMap(
41 | _.make(Constants.USER_STATUS_CHANGE_ACTOR, zio.actors.Supervisor.none, (), UserStatusStateful.stateful)
42 | )
43 |
44 | private lazy val live: ZIO[Scope, Throwable, ActorSystem] =
45 | ZIO.acquireReleaseExit(ActorSystem("zioActorSystem"))((release, _) => release.shutdown.ignore)
46 | }
47 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/scala/org/bitlap/zim/server/actor/UserStatusStateful.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.actor
18 |
19 | import org.bitlap.zim.domain.ws.protocol._
20 | import org.bitlap.zim.infrastructure.util.LogUtil
21 | import org.bitlap.zim.server.service.ws.WsService
22 |
23 | import zio._
24 | import zio.actors.Actor.Stateful
25 | import zio.actors.Context
26 |
27 | /** zio actor
28 | *
29 | * @author
30 | * 梦境迷离
31 | * @version 1.0,2022/1/11
32 | */
33 | object UserStatusStateful {
34 |
35 | val stateful: Stateful[Any, Unit, Command] = new Stateful[Any, Unit, Command] {
36 |
37 | override def receive[A](state: Unit, msg: Command[A], context: Context): UIO[(Unit, A)] = {
38 | val taskIO = msg match {
39 | case _ @UserStatusChangeMessage(uId, typ, _) =>
40 | WsService.changeOnline(uId, typ)
41 | case _ => ZIO.succeed(false)
42 | }
43 | taskIO.foldZIO(
44 | e => LogUtil.error(s"UserStatusStateful $e").as(() -> "".asInstanceOf[A]),
45 | _ => ZIO.succeed(() -> "".asInstanceOf[A])
46 | )
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/ws/protocol/Command.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.ws.protocol
18 |
19 | import org.bitlap.zim.domain.Message
20 |
21 | import akka.actor.ActorRef
22 |
23 | import io.circe.parser.decode
24 |
25 | /** ws actor command
26 | */
27 | sealed trait Command[+T]
28 |
29 | /** proxy
30 | * @param uId
31 | * @param msg
32 | * Now, default type is `String`, we use toJson to convert anything, should fix it in the future.
33 | * @param originActorRef
34 | * The message comes from user, who send message to server flow by akka.
35 | */
36 | final case class TransmitMessageProxy(
37 | uId: Int,
38 | msg: String,
39 | originActorRef: Option[ActorRef]
40 | ) extends Command[String] {
41 |
42 | def getMessage: Message = decode[Message](msg).getOrElse(null)
43 |
44 | }
45 |
46 | /** 在线用户
47 | */
48 | final case class OnlineUserMessage(description: Option[String]) extends Command[Unit]
49 |
50 | /** 用户状态变更
51 | */
52 | final case class UserStatusChangeMessage(uId: Int, typ: String, description: Option[String] = None)
53 | extends Command[Unit]
54 |
--------------------------------------------------------------------------------
/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/properties/ZimConfigurationProperties.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.infrastructure.properties
18 |
19 | import com.typesafe.config.{Config, ConfigFactory}
20 |
21 | import zio._
22 |
23 | /** application configuration(exclude database)
24 | *
25 | * @author
26 | * 梦境迷离
27 | * @since 2021/12/25
28 | * @version 1.0
29 | */
30 | final case class ZimConfigurationProperties(
31 | name: String,
32 | interface: String,
33 | port: Int,
34 | webHost: String
35 | )
36 |
37 | object ZimConfigurationProperties {
38 |
39 | lazy val config: Config = ConfigFactory.load().getConfig("application")
40 |
41 | lazy val live: ULayer[ZimConfigurationProperties] = ZLayer.succeed(ZimConfigurationProperties(config))
42 |
43 | def apply(config: Config = config): ZimConfigurationProperties =
44 | ZimConfigurationProperties(
45 | name = config.getString("name"),
46 | interface = config.getString("server.interface"),
47 | port = config.getInt("server.port"),
48 | webHost = config.getString("server.webHost")
49 | )
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/FriendList.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | import org.bitlap.zim.domain.model.User
20 |
21 | import io.circe._
22 | import io.circe.generic.semiauto._
23 | import io.circe.syntax.EncoderOps
24 |
25 | import zio.schema._
26 |
27 | /** 好友列表
28 | *
29 | * 好友列表也是一种group
30 | *
31 | * 一个好友列表有多个用户
32 | *
33 | * @param id
34 | * 好友列表id
35 | * @param groupName
36 | * 列表名称
37 | * @param list
38 | * 用户列表
39 | */
40 | final case class FriendList(override val id: Int, override val groupName: String, list: List[User])
41 | extends Group(id, groupName)
42 |
43 | object FriendList {
44 |
45 | implicit val decoder: Decoder[FriendList] = deriveDecoder[FriendList]
46 |
47 | implicit val encoder: Encoder[FriendList] = (a: FriendList) =>
48 | if (a == null) Json.Null
49 | else
50 | Json.obj(
51 | ("id", Json.fromInt(a.id)),
52 | ("groupname", Json.fromString(a.groupName)),
53 | ("list", a.list.asJson)
54 | )
55 | implicit val schema: Schema[FriendList] = DeriveSchema.gen[FriendList]
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/scala/org/bitlap/zim/server/module/AkkaModule.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.module
18 |
19 | import akka.actor.typed.ActorSystem
20 |
21 | import zio._
22 |
23 | /** akka actor configuration
24 | *
25 | * @author
26 | * 梦境迷离
27 | * @since 2021/12/25
28 | * @version 2.0
29 | */
30 | object AkkaModule {
31 |
32 | private lazy val akkaActorSystem: ActorSystem[Nothing] = ActorSystem.wrap(akka.actor.ActorSystem("akka_actor_system"))
33 |
34 | private lazy val wsAkkaActorSystem: ActorSystem[Nothing] =
35 | ActorSystem.wrap(akka.actor.ActorSystem("ws_akka_actor_system"))
36 |
37 | lazy val live: ZLayer[Any with Any with Scope, Throwable, ActorSystem[Nothing]] =
38 | ZLayer.fromZIO(ZIO.acquireRelease(ZIO.attempt(akkaActorSystem))(a => ZIO.attempt(a.terminate()).ignore))
39 |
40 | private lazy val actorSystemLive: ZLayer[Any, Throwable, ActorSystem[Nothing]] =
41 | ZLayer.fromZIO(ZIO.attempt(wsAkkaActorSystem))
42 |
43 | def make: ZIO[Any, Throwable, ActorSystem[Nothing]] = Scope.global.use {
44 | ZIO.service[ActorSystem[Nothing]].provideLayer(actorSystemLive)
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/AddInfo.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | import java.time.ZonedDateTime
20 |
21 | import org.bitlap.zim.domain.model.User
22 |
23 | import io.circe._
24 | import io.circe.generic.semiauto._
25 |
26 | /** 返回添加好友、群组消息
27 | *
28 | * @param id
29 | * @param uid
30 | * 用户id
31 | * @param content
32 | * 消息内容
33 | * @param from
34 | * 消息发送者id
35 | * @param from_group
36 | * 消息发送者申请加入的群id
37 | * @param `type`
38 | * 消息类型
39 | * @param remark
40 | * 附言
41 | * @param href
42 | * 来源,没使用,未知
43 | * @param read
44 | * 是否已读
45 | * @param time
46 | * 时间
47 | * @param user
48 | * 消息发送者
49 | */
50 | final case class AddInfo(
51 | id: Int,
52 | uid: Int,
53 | content: String,
54 | from: Int,
55 | from_group: Int,
56 | `type`: Int,
57 | remark: String,
58 | href: String,
59 | read: Int,
60 | time: ZonedDateTime,
61 | user: User
62 | )
63 |
64 | object AddInfo {
65 |
66 | implicit val decoder: Decoder[AddInfo] = deriveDecoder[AddInfo]
67 | implicit val encoder: Encoder[AddInfo] = deriveEncoder[AddInfo]
68 | }
69 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/static/html/find.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 查找/添加群组
6 |
7 |
8 |
9 |
10 |
11 |
12 |
找人
13 |
找群
14 |
15 |
16 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/modules/zim-server/src/test/scala/org/bitlap/zim/server/service/MailServiceSpec.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.service
18 |
19 | import org.bitlap.zim.infrastructure.properties._
20 | import org.bitlap.zim.server.CommonTestSupport
21 | import org.scalatest.flatspec._
22 | import org.scalatest.matchers.should._
23 |
24 | import com.typesafe.config.ConfigFactory
25 |
26 | import zio._
27 |
28 | /** @author
29 | * 梦境迷离
30 | * @since 2022/1/9
31 | * @version 1.0
32 | */
33 | final class MailServiceSpec extends AnyFlatSpec with Matchers with CommonTestSupport {
34 |
35 | // 本地
36 | lazy val live: ULayer[MailConfigurationProperties] = ZLayer.succeed(
37 | MailConfigurationProperties(ConfigFactory.load("application-test.conf").getConfig("infrastructure.javamail"))
38 | )
39 |
40 | "sendHtmlMail" should "send async ignore error" in {
41 | val task =
42 | MailServiceImpl
43 | .sendHtmlMail("12222@qq.com", "hello world", """""")
44 | .provide(MailConfigurationProperties.live, MailServiceImpl.live)
45 | val ret = unsafeRun(task)
46 | assert(ret != null)
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/project/ProjectSetting.scala:
--------------------------------------------------------------------------------
1 | import org.scalafmt.sbt.ScalafmtPlugin.autoImport.scalafmtOnCompile
2 |
3 | import ProjectSetting.optimizerOptions
4 | import sbt.{CrossVersion, Def, _}
5 | import sbt.Keys._
6 |
7 | /** @author
8 | * 梦境迷离
9 | * @version 1.0,2022/1/11
10 | */
11 | object ProjectSetting {
12 |
13 | lazy val scala213 = "2.13.8"
14 |
15 | def extraOptions(optimize: Boolean): List[String] = List("-Wunused:imports") ++ optimizerOptions(optimize)
16 |
17 | def optimizerOptions(optimize: Boolean): List[String] =
18 | if (optimize) List("-opt:l:inline", "-opt-inline-from:zio.internal.**") else Nil
19 |
20 | lazy val stdOptions = List("-deprecation", "-encoding", "UTF-8", "-feature", "-unchecked", "-Xfatal-warnings")
21 |
22 | lazy val std2xOptions =
23 | List(
24 | "-language:higherKinds",
25 | "-language:existentials",
26 | "-explaintypes",
27 | "-Yrangepos",
28 | "-Xlint:_,-missing-interpolator,-type-parameter-shadow",
29 | "-Ywarn-numeric-widen",
30 | "-Ywarn-value-discard"
31 | )
32 |
33 | val value: Seq[Def.Setting[_]] = Seq(
34 | scalaVersion := scala213,
35 | scalacOptions := (stdOptions ++ extraOptions(!isSnapshot.value)),
36 | testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"), TestFrameworks.ScalaTest),
37 | autoAPIMappings := true,
38 | version := (ThisBuild / version).value,
39 | Test / parallelExecution := false, // see https://www.scalatest.org/user_guide/async_testing
40 | Global / cancelable := true,
41 | // OneJar
42 | exportJars := true,
43 | scalafmtOnCompile := true
44 | )
45 |
46 | val noPublish: Seq[Def.Setting[_]] = Seq(
47 | publish / skip := true
48 | )
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/package.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim
18 |
19 | import java.time.ZonedDateTime
20 | import java.time.format.DateTimeFormatter
21 |
22 | import scala.util.Try
23 |
24 | import io.circe._
25 |
26 | import zio.schema._
27 |
28 | /** @author
29 | * 梦境迷离
30 | * @since 2022/2/2
31 | * @version 1.0
32 | */
33 | package object domain {
34 |
35 | implicit val encodeDate: Encoder[ZonedDateTime] =
36 | Encoder.encodeString.contramap[ZonedDateTime](t =>
37 | if (t == null) "" else t.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
38 | )
39 |
40 | implicit val decodeDate: Decoder[ZonedDateTime] = Decoder.decodeString.emapTry { str =>
41 | Try {
42 | if (str == null) ZonedDateTime.now() else ZonedDateTime.parse(str)
43 | }
44 | }
45 |
46 | // 定义自己的schema 用以描述日期序列化
47 | implicit val zonedDateTimeSchema: Schema[ZonedDateTime] = Schema[String].transformOrFail(
48 | f => Right(if (f == null) ZonedDateTime.now() else ZonedDateTime.parse(f)),
49 | g => Right(if (g == null) "" else g.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
50 | )
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/scala/org/bitlap/zim/server/route/ZimWsApi.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.route
18 |
19 | import scala.concurrent._
20 |
21 | import org.bitlap.zim.api._
22 | import org.bitlap.zim.server.service.ws._
23 |
24 | import akka._
25 | import akka.http.scaladsl.model.ws._
26 | import akka.http.scaladsl.server._
27 | import akka.stream._
28 | import akka.stream.scaladsl.Flow
29 |
30 | import sttp.tapir.server.akkahttp._
31 |
32 | import zio._
33 |
34 | /** @author
35 | * 梦境迷离
36 | * @since 2022/1/16
37 | * @version 1.0
38 | */
39 | final class ZimWsApi()(implicit materializer: Materializer) {
40 |
41 | implicit val ec: ExecutionContext = materializer.executionContext
42 |
43 | lazy val route: Route = AkkaHttpServerInterpreter().toRoute(WsEndpoint.wsEndpoint.serverLogic[Future] { uid =>
44 | val ret: Either[Unit, Flow[Message, String, NotUsed]] =
45 | try
46 | Unsafe.unsafe { implicit runtime =>
47 | Right(Runtime.default.unsafe.run(WsService.openConnection(uid)).getOrThrowFiberFailure())
48 | }
49 | catch { case _: Exception => Left(()) }
50 | Future.successful(ret)
51 | })
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/scala/org/bitlap/zim/server/route/ZimActuatorApi.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.route
18 |
19 | import scala.concurrent.ExecutionContext.Implicits.global
20 | import scala.concurrent.Future
21 |
22 | import org.bitlap.zim.ZimBuildInfo
23 | import org.bitlap.zim.api.ActuatorEndpoint
24 |
25 | import akka.http.scaladsl.server.Route
26 | import akka.http.scaladsl.server.directives.DebuggingDirectives
27 |
28 | import sttp.tapir.server.akkahttp.AkkaHttpServerInterpreter
29 |
30 | /** Actuator端点的API http://host:port/api/v1.0/health
31 | *
32 | * @author
33 | * 梦境迷离
34 | * @since 2021/12/25
35 | * @version 2.0
36 | */
37 | final class ZimActuatorApi {
38 |
39 | // https://doc.akka.io/docs/akka-http/current/routing-dsl/directives/debugging-directives/logRequestResult.html
40 | lazy val route: Route = DebuggingDirectives.logRequestResult("actuator-logger") {
41 | AkkaHttpServerInterpreter().toRoute(
42 | ActuatorEndpoint.healthEndpoint.serverLogic[Future](_ => Future.successful(Right(ZimBuildInfo.toMap)))
43 | )
44 | }
45 |
46 | }
47 |
48 | object ZimActuatorApi {
49 | def apply(): ZimActuatorApi = new ZimActuatorApi()
50 | }
51 |
--------------------------------------------------------------------------------
/docker-deploy.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | #sbt clean compile
4 |
5 | cp modules/zim-server/src/main/resources/application-docker.conf modules/zim-server/src/main/resources/application-docker-copy.conf
6 | cp modules/zim-server/src/main/resources/application.conf modules/zim-server/src/main/resources/application-copy.conf
7 | mv modules/zim-server/src/main/resources/application-docker.conf modules/zim-server/src/main/resources/application.conf
8 |
9 | # it can only executed for local pc, and used local image
10 | IFS=$'\n'
11 | maybeOld=`docker ps | grep liguobin/zim | awk '{print $1}'`
12 | if [[ -n "$maybeOld" ]];then
13 | for line in `cat version.sbt`
14 | do
15 | docker image rm liguobin/zim:$line -f
16 | done
17 | fi
18 |
19 |
20 | sbt docker:publishLocal
21 |
22 | mv modules/zim-server/src/main/resources/application-copy.conf modules/zim-server/src/main/resources/application.conf
23 | mv modules/zim-server/src/main/resources/application-docker-copy.conf modules/zim-server/src/main/resources/application-docker.conf
24 | mv modules/zim-server/target/scala-2.13/classes/application-copy.conf modules/zim-server/target/scala-2.13/classes/application.conf
25 |
26 |
27 | if [[ -d "/tmp/mysql/datadir/" ]];then
28 | rm -rf /tmp/mysql/datadir/*
29 | else
30 | mkdir -p /tmp/mysql/datadir/
31 | fi
32 |
33 | if [[ -d "/tmp/mysql/datadir/" ]];then
34 | docker-compose -f docker-compose.yml up -d
35 | zim_container_ip=`docker ps | grep liguobin/zim | awk '{print $1}' | xargs docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'`
36 | echo "zim server container ip: $zim_container_ip"
37 | else
38 | echo "Not found a folder named /tmp/mysql/datadir/ for docker mysql"
39 | exit -1
40 | fi
41 |
42 | # mac osx visit docker container network? see https://www.haoyizebo.com/posts/fd0b9bd8/ and close your VPN
--------------------------------------------------------------------------------
/modules/zim-api/src/main/scala/org/bitlap/zim/api/repository/package.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.api
18 |
19 | import eu.timepit.refined.api._
20 | import scalikejdbc.SQLSyntax
21 |
22 | package object repository {
23 |
24 | final case class Condition(key: String, value: Any)
25 |
26 | object Condition {
27 |
28 | /** define params value type
29 | */
30 | final case class ConditionValidator()
31 |
32 | object ConditionValidator {
33 |
34 | implicit val conditionValueValidate: Validate.Plain[Condition, ConditionValidator] = Validate.fromPredicate(
35 | p =>
36 | p != null ||
37 | p.value.isInstanceOf[Serializable] ||
38 | p.value.isInstanceOf[SQLSyntax] ||
39 | (p.value match {
40 | case Some(o) => o.isInstanceOf[Serializable] || o.isInstanceOf[SQLSyntax]
41 | case None => true
42 | case _ => false
43 | }),
44 | p => s"($p should be a instance of the `org.bitlap.zim.domain.Condition`)",
45 | ConditionValidator()
46 | )
47 | }
48 |
49 | // 有点丑, 目前仅支持常量的编译器校验
50 | type ZCondition = Condition Refined ConditionValidator
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/application.conf.example:
--------------------------------------------------------------------------------
1 | infrastructure {
2 | mysql {
3 | url = "jdbc:mysql://localhost:3306/zim?useUnicode=true&useSSL=false&characterEncoding=utf-8"
4 | user = "root"
5 | password = "root"
6 | databaseName = "zim"
7 | connection {
8 | initialPoolSize = 1,
9 | maxPoolSize = 5,
10 | timeoutMillis = 3000,
11 | validationQuery = "select 1",
12 | driver = "com.mysql.jdbc.Driver"
13 | }
14 | }
15 |
16 | javamail {
17 | host = "host",
18 | username = "",
19 | password = "",
20 | port = 0,
21 | threadPoolSize = 20,
22 | connectionPoolCoreSize = 10,
23 | debug = true
24 | sender = "111.@qq.com"
25 | }
26 | }
27 |
28 | cache {
29 | redis = {
30 | host = "localhost"
31 | port = 6379
32 | }
33 | }
34 |
35 | application {
36 | name = "ZIM"
37 | server {
38 | port = 9000
39 | interface = "0.0.0.0"
40 | webHost = "im.dreamylost.cn" # 根据需要,可能需要修改
41 | }
42 | }
43 |
44 | akka {
45 | akka.http.server.idle-timeout = 5 s
46 | akka.http.client.idle-timeout = 5 s
47 | actor.default-dispatcher.fork-join-executor.parallelism-max = 64
48 | http.server.websocket.periodic-keep-alive-max-idle = 3 second
49 | http.server.websocket.periodic-keep-alive-mode = pong
50 | actor.debug.unhandled = true
51 | actor.debug.receive = true
52 | loggers = ["akka.event.slf4j.Slf4jLogger"]
53 | loglevel = "DEBUG"
54 | stdout-loglevel = "DEBUG"
55 | logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
56 | akka.http.server.parsing.max-method-length = 4k
57 | }
58 | custom-dispatcher {
59 | type = Dispatcher
60 | executor = "thread-pool-executor"
61 | thread-pool-executor {
62 | fixed-pool-size = 32
63 | }
64 | throughput = 10
65 | }
66 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/static/html/friend.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 好友信息
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/model/FriendGroup.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain.model
18 |
19 | import io.circe._
20 | import io.circe.generic.semiauto._
21 |
22 | import scalikejdbc.{WrappedResultSet, _}
23 |
24 | /** 用户创建的好友列表
25 | *
26 | * @see
27 | * table:t_friend_group
28 | * @param id
29 | * 分组ID
30 | * @param uid
31 | * 用户id,该分组所属的用户ID
32 | * @param groupName
33 | * 群组名称
34 | */
35 | final case class FriendGroup(id: Int, uid: Int, groupName: String)
36 |
37 | object FriendGroup extends BaseModel[FriendGroup] {
38 |
39 | override lazy val columns: collection.Seq[String] = autoColumns[FriendGroup]()
40 |
41 | override def apply(rs: WrappedResultSet)(implicit sp: SyntaxProvider[FriendGroup]): FriendGroup =
42 | autoConstruct[FriendGroup](rs, sp)
43 |
44 | override def tableName: String = "t_friend_group"
45 |
46 | implicit val decoder: Decoder[FriendGroup] = deriveDecoder[FriendGroup]
47 |
48 | implicit val encoder: Encoder[FriendGroup] = (a: FriendGroup) =>
49 | if (a == null) Json.Null
50 | else
51 | Json.obj(
52 | ("id", Json.fromInt(a.id)),
53 | ("uid", Json.fromInt(a.id)),
54 | ("groupname", Json.fromString(a.groupName))
55 | )
56 | }
57 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/application-docker.conf:
--------------------------------------------------------------------------------
1 | # 将zim构建为容器时使用,区别就是MySQL host和Redis host用了容器名
2 | infrastructure {
3 | mysql {
4 | # 如果改了,docker-compose.yml中也得改
5 | url = "jdbc:mysql://zim_mysql_server:3306/zim?useUnicode=true&useSSL=false&characterEncoding=utf-8"
6 | user = "root"
7 | password = ""
8 | databaseName = "zim"
9 | connection {
10 | initialPoolSize = 1,
11 | maxPoolSize = 5,
12 | timeoutMillis = 3000,
13 | validationQuery = "select 1",
14 | driver = "com.mysql.jdbc.Driver"
15 | }
16 | }
17 | # 容器是为了快速启动zim,不使用注册功能的话,邮件可以不配,忽略即可。
18 | javamail {
19 | host = "host",
20 | username = "",
21 | password = "",
22 | port = 0,
23 | threadPoolSize = 20,
24 | connectionPoolCoreSize = 10,
25 | debug = true
26 | sender = "111.@qq.com"
27 | }
28 | }
29 |
30 | cache {
31 | redis = {
32 | host = "zim_redis_server"
33 | port = 6379
34 | }
35 | }
36 |
37 | application {
38 | name = "ZIM"
39 | server {
40 | port = 9000
41 | interface = "0.0.0.0"
42 | webHost = "im.dreamylost.cn" # 根据需要,可能需要修改
43 | }
44 | }
45 |
46 | akka {
47 | akka.http.server.idle-timeout = 5 s
48 | akka.http.client.idle-timeout = 5 s
49 | actor.default-dispatcher.fork-join-executor.parallelism-max = 64
50 | http.server.websocket.periodic-keep-alive-max-idle = 3 second
51 | http.server.websocket.periodic-keep-alive-mode = pong
52 | actor.debug.unhandled = true
53 | actor.debug.receive = true
54 | loggers = ["akka.event.slf4j.Slf4jLogger"]
55 | loglevel = "DEBUG"
56 | stdout-loglevel = "DEBUG"
57 | logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
58 | akka.http.server.parsing.max-method-length = 4k
59 | }
60 | custom-dispatcher {
61 | type = Dispatcher
62 | executor = "thread-pool-executor"
63 | thread-pool-executor {
64 | fixed-pool-size = 32
65 | }
66 | throughput = 10
67 | }
68 |
--------------------------------------------------------------------------------
/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/util/SecurityUtil.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.infrastructure.util
18 |
19 | import java.nio.charset.StandardCharsets.US_ASCII
20 |
21 | import zio._
22 | import zio.crypto.hash.{Hash, HashAlgorithm, MessageDigest}
23 |
24 | /** SpringSecurity加密工具 PasswordEncoder
25 | *
26 | * @since 2021年12月31日
27 | * @author
28 | * 梦境迷离
29 | */
30 | object SecurityUtil {
31 |
32 | /** 采用SHA-256算法
33 | *
34 | * @param rawPassword
35 | * @return
36 | * 80位加密后的密码
37 | */
38 | def encrypt(rawPassword: String): Task[MessageDigest[String]] =
39 | Hash.hash[HashAlgorithm.SHA256](rawPassword, US_ASCII).provideLayer(Hash.live)
40 |
41 | /** 验证密码和加密后密码是否一致
42 | *
43 | * @param rawPassword
44 | * 明文密码
45 | * @param password
46 | * 加密后的密码
47 | * @return
48 | * Boolean
49 | */
50 | def matched(rawPassword: String, password: String): Task[Boolean] =
51 | (if (rawPassword == null && password == null) ZIO.succeed(true)
52 | else if (rawPassword == null || password == null) ZIO.succeed(false)
53 | else if (rawPassword == "" || password == "") ZIO.succeed(false)
54 | else Hash.verify[HashAlgorithm.SHA256](rawPassword, MessageDigest[String](password), charset = US_ASCII))
55 | .provideLayer(Hash.live)
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/modules/zim-domain/src/main/scala/org/bitlap/zim/domain/Mine.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.domain
18 |
19 | import io.circe._
20 |
21 | /** 我发送的消息和我的信息
22 | *
23 | * @param id
24 | * 我的id
25 | * @param username
26 | * 我的昵称
27 | * @param mine
28 | * 是否我发的消息
29 | * @param avatar
30 | * 我的头像
31 | * @param content
32 | * 消息内容
33 | */
34 | final case class Mine(id: Int, username: String, mine: Boolean, avatar: String, content: String)
35 |
36 | object Mine {
37 |
38 | implicit val decoder: Decoder[Mine] = (c: HCursor) =>
39 | if (!c.succeeded) null
40 | else
41 | for {
42 | id <- c.getOrElse[Int]("id")(0)
43 | username <- c.getOrElse[String]("username")("")
44 | mine <- c.getOrElse[Boolean]("mine")(false)
45 | avatar <- c.getOrElse[String]("avatar")("")
46 | content <- c.getOrElse[String]("content")("")
47 | } yield Mine(id, username, mine, avatar, content)
48 |
49 | implicit val encoder: Encoder[Mine] = (a: Mine) =>
50 | if (a == null) Json.Null
51 | else
52 | Json.obj(
53 | ("id", Json.fromInt(a.id)),
54 | ("username", Json.fromString(a.username)),
55 | ("mine", Json.fromBoolean(a.mine)),
56 | ("avatar", Json.fromString(a.avatar)),
57 | ("content", Json.fromString(a.content))
58 | )
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/modules/zim-server/src/main/scala/org/bitlap/zim/server/actor/ScheduleStateful.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.server.actor
18 |
19 | import org.bitlap.zim.domain.ws.Constants
20 | import org.bitlap.zim.domain.ws.protocol._
21 | import org.bitlap.zim.infrastructure.util.LogUtil
22 | import org.bitlap.zim.server.service.ws.WsService
23 |
24 | import zio._
25 | import zio.actors.Actor.Stateful
26 | import zio.actors.Context
27 |
28 | /** zio actor
29 | *
30 | * @author
31 | * 梦境迷离
32 | * @version 1.0,2022/1/11
33 | */
34 | object ScheduleStateful {
35 |
36 | val stateful: Stateful[Any, Unit, Command] = new Stateful[Any, Unit, Command] {
37 |
38 | override def receive[A](state: Unit, msg: Command[A], context: Context): UIO[(Unit, A)] = {
39 | val taskIO = msg match {
40 | case OnlineUserMessage(descr) =>
41 | WsService.getConnections.flatMap { i =>
42 | LogUtil.debug(
43 | s"${descr.getOrElse("receive")}|actor:${Constants.SCHEDULE_JOB_ACTOR}| Total online user => $i"
44 | )
45 | }
46 | case _ => ZIO.unit
47 | }
48 |
49 | // FIXME: remove asInstanceOf
50 | taskIO.foldZIO(
51 | e => LogUtil.error(s"ScheduleStateful $e").as(() -> "".asInstanceOf[A]),
52 | _ => ZIO.succeed(() -> "".asInstanceOf[A])
53 | )
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/modules/zim-infra/src/main/scala/org/bitlap/zim/infrastructure/properties/MysqlConfigurationProperties.scala:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2023 bitlap
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bitlap.zim.infrastructure.properties
18 |
19 | import com.typesafe.config._
20 |
21 | /** mysql configuration
22 | *
23 | * @author
24 | * 梦境迷离
25 | * @since 2021/12/25
26 | * @version 1.0
27 | */
28 | final case class MysqlConfigurationProperties(
29 | url: String,
30 | user: String,
31 | password: String,
32 | databaseName: String,
33 | initialSize: Integer,
34 | maxSize: Integer,
35 | connectionTimeoutMillis: Long,
36 | validationQuery: String,
37 | driverName: String
38 | )
39 |
40 | object MysqlConfigurationProperties {
41 |
42 | lazy val conf: Config = ConfigFactory.load().getConfig("infrastructure.mysql")
43 |
44 | def apply(config: Config = conf): MysqlConfigurationProperties =
45 | MysqlConfigurationProperties(
46 | url = config.getString("url"),
47 | user = config.getString("user"),
48 | password = config.getString("password"),
49 | databaseName = config.getString("databaseName"),
50 | initialSize = config.getInt("connection.initialPoolSize"),
51 | maxSize = config.getInt("connection.maxPoolSize"),
52 | connectionTimeoutMillis = config.getLong("connection.timeoutMillis"),
53 | validationQuery = config.getString("connection.validationQuery"),
54 | driverName = config.getString("connection.driver")
55 | )
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/.github/workflows/ScalaCI.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | pull_request:
8 | branches:
9 | - master
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 | strategy:
15 | matrix:
16 | java-version: [ 11, 17]
17 | steps:
18 | - uses: actions/checkout@v2
19 | - name: Set up JDK
20 | uses: actions/setup-java@v1
21 | with:
22 | java-version: ${{ matrix.java-version }}
23 |
24 | - name: Build
25 | run: sbt compile
26 |
27 | - name: Checking Code Style
28 | run: sbt scalafmtCheckAll
29 |
30 | - name: Checking headers
31 | run: sbt headerCheckAll
32 |
33 | docker:
34 | runs-on: ubuntu-latest
35 | strategy:
36 | matrix:
37 | java-version: [ 11 ]
38 | steps:
39 | - uses: actions/checkout@v2
40 | - name: Set up JDK
41 | uses: actions/setup-java@v1
42 | with:
43 | java-version: ${{ matrix.java-version }}
44 |
45 | - name: Build Image
46 | run: sbt docker:publishLocal
47 |
48 | test:
49 | runs-on: ubuntu-latest
50 | strategy:
51 | matrix:
52 | redis-version: [ 4, 5, 6 ]
53 | java-version: [ 11, 17]
54 | steps:
55 | - uses: actions/checkout@v2
56 | - name: Set up JDK
57 | uses: actions/setup-java@v1
58 | with:
59 | java-version: ${{ matrix.java-version }}
60 |
61 | - name: Start Redis
62 | uses: supercharge/redis-github-action@1.4.0
63 | with:
64 | redis-version: ${{ matrix.redis-version }}
65 |
66 | - name: Run Test
67 | run: sbt coverage test coverageReport # test in scala2.13.x java 8
68 |
69 | - name: Aggregate coverage report
70 | run: sbt coverageAggregate
71 |
72 | - name: Upload test coverage report
73 | run: bash <(curl -s https://codecov.io/bash)
74 |
75 | ci:
76 | runs-on: ubuntu-latest
77 | needs: [ build, docker, test ]
78 | steps:
79 | - name: Aggregate outcomes
80 | run: echo "build succeeded"
--------------------------------------------------------------------------------
/modules/zim-server/src/main/resources/static/layui/lay/modules/code.js:
--------------------------------------------------------------------------------
1 | /**
2 |
3 | @Name:layui.code 代码修饰器
4 | @Author:贤心
5 | @License:LGPL
6 |
7 | */
8 |
9 | layui.define('jquery', function(exports){
10 | "use strict";
11 |
12 | var $ = layui.jquery;
13 | var about = 'http://www.layui.com/doc/modules/code.html'; //关于信息
14 |
15 | exports('code', function(options){
16 | var elems = [];
17 | options = options || {};
18 | options.elem = $(options.elem||'.layui-code');
19 | options.about = 'about' in options ? options.about : true;
20 |
21 | options.elem.each(function(){
22 | elems.push(this);
23 | });
24 |
25 | layui.each(elems.reverse(), function(index, item){
26 | var othis = $(item), html = othis.html();
27 |
28 | //转义HTML标签
29 | if(othis.attr('lay-encode') || options.encode){
30 | html = html.replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&')
31 | .replace(//g, '>').replace(/'/g, ''').replace(/"/g, '"')
32 | }
33 |
34 | othis.html('