Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
a7e0f63d
Commit
a7e0f63d
authored
Apr 29, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
`FileCacheStrategy`, `ReusableInput` fundamental
parent
9924d37e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
11 deletions
+120
-11
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Mirai.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Mirai.kt
+46
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
+18
-11
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/internal/asReusableInput.common.kt
.../net.mamoe.mirai/utils/internal/asReusableInput.common.kt
+23
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/Mirai.kt
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/Mirai.kt
+15
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/internal/asReusableInput.jvm.kt
...lin/net/mamoe/mirai/utils/internal/asReusableInput.jvm.kt
+18
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Mirai.kt
0 → 100644
View file @
a7e0f63d
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai
import
io.ktor.utils.io.ByteReadChannel
import
kotlinx.io.core.Input
import
net.mamoe.mirai.utils.ExternalImage
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.SinceMirai
import
net.mamoe.mirai.utils.internal.InputStream
import
kotlin.jvm.JvmStatic
/**
* Mirai 全局环境.
*/
@SinceMirai
(
"1.0.0"
)
expect
object
Mirai
{
@JvmStatic
var
fileCacheStrategy
:
FileCacheStrategy
/**
* 缓存策略.
*
* 图片上传时默认使用文件缓存.
*/
interface
FileCacheStrategy
{
@MiraiExperimentalAPI
fun
newImageCache
(
input
:
Input
):
ExternalImage
@MiraiExperimentalAPI
fun
newImageCache
(
input
:
ByteReadChannel
):
ExternalImage
@MiraiExperimentalAPI
fun
newImageCache
(
input
:
InputStream
):
ExternalImage
companion
object
Default
:
FileCacheStrategy
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt
View file @
a7e0f63d
...
...
@@ -23,6 +23,7 @@ import net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.sendTo
import
net.mamoe.mirai.message.data.toLongUnsigned
import
net.mamoe.mirai.utils.internal.asReusableInput
import
kotlin.jvm.JvmSynthetic
/**
...
...
@@ -33,37 +34,43 @@ import kotlin.jvm.JvmSynthetic
* @see ExternalImage.sendTo 上传图片并以纯图片消息发送给联系人
* @See ExternalImage.upload 上传图片并得到 [Image] 消息
*/
class
ExternalImage
private
constructor
(
@OptIn
(
MiraiInternalAPI
::
class
)
class
ExternalImage
internal
constructor
(
val
md5
:
ByteArray
,
val
input
:
Any
,
// Input from kotlinx.io, InputStream from kotlinx.io MPP, ByteReadChannel from ktor
val
inputSize
:
Long
// dont be greater than Int.MAX
@Suppress
(
"EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR"
)
@MiraiInternalAPI
(
"unstable API"
)
val
input
:
ReusableInput
,
// Input from kotlinx.io, InputStream from kotlinx.io MPP, ByteReadChannel from ktor
@MiraiInternalAPI
(
"unstable API"
)
val
inputSize
:
Int
// dont be greater than Int.MAX
)
{
@Deprecated
(
"changing soon in 1.0.0"
,
level
=
DeprecationLevel
.
ERROR
)
@SinceMirai
(
"1.0.0"
)
internal
interface
ReusableInput
{
fun
input
():
Input
}
constructor
(
md5
:
ByteArray
,
input
:
ByteReadChannel
,
inputSize
:
Long
// dont be greater than Int.MAX
)
:
this
(
md5
,
input
as
Any
,
inputSize
)
)
:
this
(
md5
,
input
.
asReusableInput
(),
inputSize
.
coerceAtMost
(
Int
.
MAX_VALUE
.
toLongUnsigned
()).
toInt
()
)
@Deprecated
(
"changing soon in 1.0.0"
,
level
=
DeprecationLevel
.
ERROR
)
constructor
(
md5
:
ByteArray
,
input
:
Input
,
inputSize
:
Long
// dont be greater than Int.MAX
)
:
this
(
md5
,
input
as
Any
,
inputSize
)
)
:
this
(
md5
,
input
.
asReusableInput
(),
inputSize
.
coerceAtMost
(
Int
.
MAX_VALUE
.
toLongUnsigned
()).
toInt
()
)
@Deprecated
(
"changing soon in 1.0.0"
,
level
=
DeprecationLevel
.
ERROR
)
constructor
(
md5
:
ByteArray
,
input
:
ByteReadPacket
)
:
this
(
md5
,
input
as
Any
,
input
.
remaining
)
)
:
this
(
md5
,
input
.
asReusableInput
(),
input
.
remaining
.
coerceAtMost
(
Int
.
MAX_VALUE
.
toLongUnsigned
()).
toInt
()
)
@Deprecated
(
"changing soon in 1.0.0"
,
level
=
DeprecationLevel
.
ERROR
)
@OptIn
(
InternalSerializationApi
::
class
)
constructor
(
md5
:
ByteArray
,
input
:
InputStream
)
:
this
(
md5
,
input
as
Any
,
input
.
available
().
toLongUnsigned
())
)
:
this
(
md5
,
input
.
asReusableInput
(),
input
.
available
())
init
{
require
(
inputSize
<
30L
*
1024
*
1024
)
{
"file is too big. Maximum is about 20MB"
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/internal/asReusableInput.common.kt
0 → 100644
View file @
a7e0f63d
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.utils.internal
import
kotlinx.coroutines.io.ByteReadChannel
import
kotlinx.io.InputStream
import
kotlinx.io.core.Input
import
kotlinx.serialization.InternalSerializationApi
import
net.mamoe.mirai.utils.ExternalImage
internal
expect
fun
ByteReadChannel
.
asReusableInput
():
ExternalImage
.
ReusableInput
internal
expect
fun
Input
.
asReusableInput
():
ExternalImage
.
ReusableInput
@OptIn
(
InternalSerializationApi
::
class
)
internal
expect
fun
InputStream
.
asReusableInput
():
ExternalImage
.
ReusableInput
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/Mirai.kt
0 → 100644
View file @
a7e0f63d
package
net.mamoe.mirai
/**
* Mirai 全局环境.
*/
actual
object
Mirai
{
actual
var
fileCacheStrategy
:
FileCacheStrategy
get
()
=
TODO
(
"Not yet implemented"
)
set
(
value
)
{}
actual
interface
FileCacheStrategy
{
}
}
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/internal/asReusableInput.jvm.kt
0 → 100644
View file @
a7e0f63d
package
net.mamoe.mirai.utils.internal
import
kotlinx.coroutines.io.ByteReadChannel
import
kotlinx.io.core.Input
import
net.mamoe.mirai.utils.ExternalImage
import
java.io.InputStream
internal
actual
fun
ByteReadChannel
.
asReusableInput
():
ExternalImage
.
ReusableInput
{
TODO
(
"Not yet implemented"
)
}
internal
actual
fun
Input
.
asReusableInput
():
ExternalImage
.
ReusableInput
{
TODO
(
"Not yet implemented"
)
}
internal
actual
fun
InputStream
.
asReusableInput
():
ExternalImage
.
ReusableInput
{
TODO
(
"Not yet implemented"
)
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment