Skip to content

Commit 0a8bcb1

Browse files
committed
build: 1.4.0
1 parent 10f5f39 commit 0a8bcb1

5 files changed

Lines changed: 52 additions & 38 deletions

File tree

build.gradle.kts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ plugins {
22
kotlin("jvm") version "1.7.22"
33
kotlin("plugin.serialization") version "1.7.22"
44

5-
id("net.mamoe.mirai-console") version "2.13.2"
5+
id("net.mamoe.mirai-console") version "2.14.0-RC"
66
id("me.him188.maven-central-publish") version "1.0.0-dev-3"
77
}
88

99
group = "io.github.gnuf0rce"
10-
version = "1.3.7"
10+
version = "1.4.0"
1111

1212
mavenCentralPublish {
1313
useCentralS01()
@@ -26,16 +26,14 @@ repositories {
2626
}
2727

2828
dependencies {
29-
api("xyz.cssxsh.baidu:baidu-netdisk:3.3.0")
30-
compileOnly("xyz.cssxsh.mirai:mirai-hibernate-plugin:2.5.1")
29+
api("xyz.cssxsh.baidu:baidu-netdisk:3.3.2")
30+
compileOnly("xyz.cssxsh.mirai:mirai-hibernate-plugin:2.5.2")
3131
testImplementation(kotlin("test"))
3232
//
33-
implementation(platform("net.mamoe:mirai-bom:2.13.2"))
33+
implementation(platform("net.mamoe:mirai-bom:2.14.0-RC"))
3434
compileOnly("net.mamoe:mirai-console-compiler-common")
35-
testImplementation("net.mamoe:mirai-logging-slf4j")
3635
//
3736
implementation(platform("org.slf4j:slf4j-parent:2.0.6"))
38-
testImplementation("org.slf4j:slf4j-simple")
3937
}
4038

4139
mirai {

readme.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
[![Downloads](https://img.shields.io/github/downloads/gnuf0rce/Netdisk-FileSync-Plugin/total)](https://repo1.maven.org/maven2/io/github/gnuf0rce/netdisk-filesync-plugin/)
77
[![MiraiForum](https://img.shields.io/badge/post-on%20MiraiForum-yellow)](https://mirai.mamoe.net/topic/765)
88
[![maven-central](https://img.shields.io/maven-central/v/io.github.gnuf0rce/netdisk-filesync-plugin)](https://search.maven.org/artifact/io.github.gnuf0rce/netdisk-filesync-plugin)
9+
910

10-
本插件可以将接收到的群文件消息同步到百度网盘
11-
备份的文件在 `/apps/${app_name}/${group_id}/`
11+
本插件可以将接收到的`群文件`同步到百度网盘
12+
`2.14.0` 后可将接收到的`秒传码`或者`分享链接`保存到百度网盘
13+
14+
备份的文件在 `/apps/${app_name}/${current_date}/`, 其中的 `apps` 在百度网盘中显示为 [我的应用数据](https://pan.baidu.com/disk/main#/index?category=all&path=%2Fapps)
1215

1316
本插件也可作为前置插件为其他插件提供百度云上传的API
1417

@@ -18,16 +21,24 @@
1821

1922
| 指令 | 描述 |
2023
|:---------------------|:------------|
21-
| `/<baidu> <oauth>` | 百度账户的登陆 |
22-
| `/<baidu> <refresh>` | 使用 token 刷新 |
24+
| `/<baidu> <oauth>` | 默认百度账户的绑定 |
25+
| `/<baidu> <bind>` | 为当前用户绑定百度账户 |
26+
| `/<baidu> <host>` | 刷新HOST |
27+
| `/<baidu> <user>` | 刷新当前账号信息 |
28+
29+
PS: since `2.14.0`, 添加 `/baidu bind`, 用于`用户/群`绑定, 原 `/baidu oauth` 作为默认账号使用
30+
1. `/baidu bind` 具体用法/作用为: 私聊时,绑定到用户,群聊时,如果操作人是`管理员/群主`,则绑定到群,否则绑定到用户
31+
2. `/baidu oauth` 具体用法/作用为: 绑定后提供一个默认网盘
32+
3. `群文件` 同步时优先选择 `群聊绑定的网盘`, 其次 `默认网盘`
33+
4. `秒传码` 保存时优先选择 `用户绑定的网盘`, 其次 `群聊绑定的网盘`, 最后 `默认网盘`
2334

2435
## 设置
2536

2637
### oauth.yml
2738

2839
插件上传文件功能需要百度网盘API支持。
2940
请到 <https://pan.baidu.com/union/main/application/personal> 申请应用,并将获得的APP信息填入
30-
信息只在启动时读取,修改后需重启,并使用 `/baidu oauth` 认证百度账号
41+
信息只在启动时读取,修改后需重启
3142

3243
### upload.yml
3344

@@ -54,12 +65,12 @@ mirai {
5465
### 示例代码
5566

5667
```kotlin
57-
try {
58-
io.github.gnuf0rce.mirai.NetDisk.getUserInfo()
59-
} catch (exception: NoClassDefFoundError) {
60-
logger.warning { "相关类加载失败,请安装 https://github.com/gnuf0rce/Netdisk-FileSync-Plugin $exception" }
61-
throw exception
62-
}
68+
try {
69+
io.github.gnuf0rce.mirai.NetDisk.getUserInfo()
70+
} catch (error: NoClassDefFoundError) {
71+
logger.warning { "相关类加载失败,请安装 https://github.com/gnuf0rce/Netdisk-FileSync-Plugin $error" }
72+
throw error
73+
}
6374
```
6475

6576
## 安装

src/main/kotlin/io/github/gnuf0rce/mirai/netdisk/NetDisk.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.github.gnuf0rce.mirai.netdisk
22

33
import io.github.gnuf0rce.mirai.netdisk.data.*
44
import io.ktor.client.*
5+
import io.ktor.client.call.*
56
import io.ktor.client.engine.okhttp.*
67
import io.ktor.client.plugins.*
78
import io.ktor.client.plugins.compression.*
@@ -51,12 +52,11 @@ public object NetDisk : BaiduNetDiskClient(config = NetdiskOauthConfig), Listene
5152
public val SHORT_URL_REGEX: Regex = """(?:surl=|s/1)([A-z0-9=_-]+)\s*([A-z0-9]{4})?""".toRegex()
5253

5354
@JvmStatic
54-
public val STAND_CODE_REGEX: Regex = """[A-z0-9]{32}#[A-z0-9]{32}#\d+#\S+""".toRegex()
55+
public val STAND_CODE_REGEX: Regex = """[A-z0-9]{32}#([A-z0-9]{32}#)?\d+#\S+""".toRegex()
5556

5657
@JvmStatic
5758
public val BD_LINK_REGEX: Regex = """bdlink=(\S+)""".toRegex()
5859

59-
6060
@PublishedApi
6161
internal val logger: MiraiLogger by lazy {
6262
try {
@@ -74,7 +74,7 @@ public object NetDisk : BaiduNetDiskClient(config = NetdiskOauthConfig), Listene
7474
HttpResponseValidator {
7575
validateResponse { response ->
7676
if (response.headers[HttpHeaders.ContentType] == "text/octet") {
77-
val bytes = response.readBytes()
77+
val bytes = response.body<ByteArray>()
7878
throw ClientRequestException(response, bytes.joinToString("") { "\\x%02x".format(it) })
7979
}
8080
}
@@ -149,9 +149,10 @@ public object NetDisk : BaiduNetDiskClient(config = NetdiskOauthConfig), Listene
149149
}
150150
if (paths.isNotEmpty() && NetdiskUploadConfig.reply) {
151151
val info = netdisk.user()
152+
val name = info.netdiskName.ifEmpty { info.baiduName }
152153
subject.sendMessage(buildMessageChain {
153154
append(message.quote())
154-
appendLine("分享转存到 ${info.netdiskName} 成功")
155+
appendLine("分享转存到 $name 成功")
155156
paths.forEach { path ->
156157
appendLine(path)
157158
}
@@ -172,9 +173,10 @@ public object NetDisk : BaiduNetDiskClient(config = NetdiskOauthConfig), Listene
172173
}
173174
if (paths.isNotEmpty() && NetdiskUploadConfig.reply) {
174175
val info = netdisk.user()
176+
val name = info.netdiskName.ifEmpty { info.baiduName }
175177
subject.sendMessage(buildMessageChain {
176178
append(message.quote())
177-
appendLine("秒传码保存到 ${info.netdiskName} 成功")
179+
appendLine("秒传码保存到 $name 成功")
178180
paths.forEach { path ->
179181
appendLine(path)
180182
}
@@ -198,9 +200,10 @@ public object NetDisk : BaiduNetDiskClient(config = NetdiskOauthConfig), Listene
198200
}
199201
if (paths.isNotEmpty() && NetdiskUploadConfig.reply) {
200202
val info = netdisk.user()
203+
val name = info.netdiskName.ifEmpty { info.baiduName }
201204
subject.sendMessage(buildMessageChain {
202205
append(message.quote())
203-
appendLine("秒传链接到 ${info.netdiskName} 保存成功")
206+
appendLine("秒传链接保存到 $name 成功")
204207
paths.forEach { path ->
205208
appendLine(path)
206209
}
@@ -312,7 +315,6 @@ public object NetDisk : BaiduNetDiskClient(config = NetdiskOauthConfig), Listene
312315
}
313316

314317
val root = rest.view(surl = surl, key = key)
315-
316318
val dir = rest.mkdir(path = "${LocalDate.now()}/${root.uk}_${root.shareId}", ondup = OnDupType.NEW_COPY)
317319

318320
val info = TransferFileInfo(
@@ -329,7 +331,7 @@ public object NetDisk : BaiduNetDiskClient(config = NetdiskOauthConfig), Listene
329331

330332
rest.transfer(info = part, path = dir.path, ondup = OnDupType.NEW_COPY)
331333

332-
delay(30_000)
334+
delay(list.size.toLong())
333335
}
334336

335337
return dir.path
@@ -339,10 +341,10 @@ public object NetDisk : BaiduNetDiskClient(config = NetdiskOauthConfig), Listene
339341
internal suspend fun BaiduNetDiskClient.saveRapidUpload(upload: RapidUploadInfo): String {
340342
val path = "${LocalDate.now()}/${upload.path}"
341343

342-
mkdir(path = path.substringBeforeLast('/'))
344+
val dir = mkdir(path = path.substringBeforeLast('/'))
343345
rapid(upload = upload.copy(path = path), ondup = OnDupType.NEW_COPY)
344346

345-
return path
347+
return dir.path.ifEmpty { path }
346348
}
347349

348350
private suspend fun download(urlString: String, range: LongRange? = null): HttpStatement {

src/main/kotlin/io/github/gnuf0rce/mirai/netdisk/NetDiskFileSyncPlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import net.mamoe.mirai.console.util.*
1212
import net.mamoe.mirai.event.*
1313
import net.mamoe.mirai.utils.*
1414
import xyz.cssxsh.baidu.disk.data.*
15-
import java.io.File
15+
import java.io.*
1616

1717
public object NetDiskFileSyncPlugin : KotlinPlugin(
1818
JvmPluginDescription(
1919
id = "io.github.gnuf0rce.file-sync",
2020
name = "file-sync",
21-
version = "1.3.7",
21+
version = "1.4.0",
2222
) {
2323
author("cssxsh")
2424

src/main/kotlin/io/github/gnuf0rce/mirai/netdisk/NetDiskFileSyncRecorder.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,17 @@ public object NetDiskFileSyncRecorder {
127127
criteria.select(root)
128128
.where(
129129
equal(root.get<Long>("uploaderId"), uploaderId),
130-
between(root.get("upload_time"), start, end)
130+
between(root.get("uploadTime"), start, end)
131131
)
132-
.orderBy(desc(root.get<Long>("upload_time")))
132+
.orderBy(desc(root.get<Long>("uploadTime")))
133133
}.list()
134134
}
135135
} else {
136136
NetdiskSyncHistory.sync
137137
.asSequence()
138138
.filter { it.uploaderId == uploaderId && it.uploadTime in start..end }
139-
.toMutableList()
140-
.apply { sortByDescending { it.uploadTime } }
139+
.sortedByDescending { it.uploadTime }
140+
.toList()
141141
}
142142
}
143143

@@ -152,16 +152,19 @@ public object NetDiskFileSyncRecorder {
152152
val root = criteria.from<SyncUploadRecord>()
153153

154154
criteria.select(root)
155-
.where(equal(root.get<Long>("contactId"), contactId), between(root.get("time"), start, end))
156-
.orderBy(desc(root.get<Long>("upload_time")))
155+
.where(
156+
equal(root.get<Long>("contactId"), contactId),
157+
between(root.get("time"), start, end)
158+
)
159+
.orderBy(desc(root.get<Long>("uploadTime")))
157160
}.list()
158161
}
159162
} else {
160163
NetdiskSyncHistory.sync
161164
.asSequence()
162165
.filter { it.contactId == contactId && it.uploadTime in start..end }
163-
.toMutableList()
164-
.apply { sortByDescending { it.uploadTime } }
166+
.sortedByDescending { it.uploadTime }
167+
.toList()
165168
}
166169
}
167170
}

0 commit comments

Comments
 (0)