Initial commit

This commit is contained in:
筱锋xiao_lfeng 2023-12-23 16:47:47 +08:00
commit 9ed33299fd
16 changed files with 804 additions and 0 deletions

38
.gitignore vendored Normal file
View File

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

17
.idea/dataSources.xml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="waline@localhost" uuid="67345af7-f55e-46fd-bfe6-c3f1866fc5ff">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://localhost:3306/waline</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.host.port" />
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
<property name="com.intellij.clouds.kubernetes.db.container.port" />
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

7
.idea/encodings.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/kotlin" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

6
.idea/kotlinc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.21" />
</component>
</project>

15
.idea/misc.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
<option name="workspaceImportForciblyTurnedOn" value="true" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

6
.idea/sqldialects.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="PROJECT" dialect="MySQL" />
</component>
</project>

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

6
config.json Normal file
View File

@ -0,0 +1,6 @@
{
"mysql_url": "127.0.0.1:3306",
"mysql_user": "waline",
"mysql_password": "123456",
"mysql_database": "waline"
}

99
pom.xml Normal file
View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xlf</groupId>
<artifactId>lwtm</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
</properties>
<repositories>
<repository>
<id>mavenCentral</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>1.9.21</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>com.xlf.lwtm.MainKtKt</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>1.9.21</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.9.21</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,7 @@
package com.xlf.lwtm
object Data {
val commentJson = ArrayList<HashMap<String, Any>>()
val counterJson = ArrayList<HashMap<String, Any>>()
val usersJson = ArrayList<HashMap<String, Any>>()
}

View File

@ -0,0 +1,194 @@
package com.xlf.lwtm
import com.google.gson.Gson
import com.google.gson.internal.LinkedTreeMap
import java.io.File
import java.sql.*
import java.time.Instant
import kotlin.system.exitProcess
class Database {
private var connection: Connection? = null
fun checkConnect() {
val connectInfo =
Gson().fromJson(File("config.json").readText(), HashMap::class.java) as HashMap<String, String>
try {
Class.forName("com.mysql.cj.jdbc.Driver")
connection = DriverManager.getConnection(
"jdbc:mysql://${connectInfo["mysql_url"]}/${connectInfo["mysql_database"]}",
connectInfo["mysql_user"],
connectInfo["mysql_password"]
)
} catch (e: Exception) {
println("[ERROR] 数据库连接失败")
println("[ERROR] ${e.message}")
exitProcess(0)
}
}
fun insertUsers(): Boolean {
Data.usersJson.forEach { hashMap ->
try {
connection!!.prepareStatement("INSERT INTO wl_users (display_name, email, password, type, label, url, avatar, github, twitter, facebook, google, weibo, qq, `2fa`, createdAt, updatedAt, user_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
.also { it.setString(1, hashMap["display_name"] as String?) }
.also { it.setString(2, hashMap["email"] as String) }
.also { it.setString(3, hashMap["password"] as String) }
.also { it.setString(4, hashMap["type"] as String) }
.also { it.setString(5, hashMap["label"] as String?) }
.also { it.setString(6, hashMap["url"] as String?) }
.also { it.setString(7, hashMap["avatar"] as String?) }
.also { it.setString(8, hashMap["github"] as String?) }
.also { it.setString(9, hashMap["twitter"] as String?) }
.also { it.setString(10, hashMap["facebook"] as String?) }
.also { it.setString(11, hashMap["google"] as String?) }
.also { it.setString(12, hashMap["weibo"] as String?) }
.also { it.setString(13, hashMap["qq"] as String?) }
.also { it.setString(14, hashMap["2fa"] as String?) }.also {
it.setTimestamp(
15, Timestamp(Instant.parse(hashMap["createdAt"] as String).toEpochMilli())
)
}.also {
it.setTimestamp(
16, Timestamp(Instant.parse(hashMap["updatedAt"] as String).toEpochMilli())
)
}.also { it.setString(17, hashMap["objectId"] as String?) }.executeUpdate()
} catch (e: Exception) {
println("[ERROR] 数据库插入失败")
println("[ERROR] ${e.message}")
throw e
}
}
return true
}
fun insertCounter() {
Data.counterJson.forEach { hashMap ->
connection!!.prepareStatement("INSERT INTO wl_counter (time, reaction0, reaction1, reaction2, reaction3, reaction4, reaction5, reaction6, reaction7, reaction8, url, createdAt, updatedAt) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)")
.also { it.setString(1, hashMap["key"] as String) }.also { it.setInt(2, hashMap["value"] as Int) }
.executeUpdate()
}
}
fun insertComment(): Boolean {
Data.commentJson.forEach { hashMap ->
try {
connection!!.prepareStatement("INSERT INTO wl_comment (user_id, comment, insertedAt, ip, link, mail, nick, pid, rid, sticky, status, `like`, ua, url, createdAt, updatedAt, object_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
.also { data ->
if (hashMap["user_id"] == null) {
data.setNull(1, Types.INTEGER)
} else {
val getData =
connection!!.prepareStatement("SELECT id, user_id FROM wl_users WHERE user_id = ?")
.also { it.setString(1, hashMap["user_id"] as String) }.executeQuery()
.also { it.next() }
if (getData.getString("user_id") == hashMap["user_id"]) {
data.setInt(1, getData.getInt("id"))
}
}
}.also {
if (hashMap["comment"] == null) {
it.setNull(2, Types.VARCHAR)
} else {
it.setString(2, hashMap["comment"] as String)
}
}.also {
val insertAt = hashMap["insertedAt"] as LinkedTreeMap<*, *>
it.setTimestamp(
3, Timestamp(Instant.parse(insertAt["iso"] as String).toEpochMilli())
)
}.also { it.setString(4, hashMap["ip"] as String) }.also {
if (hashMap["link"] == null) {
it.setNull(5, Types.VARCHAR)
} else {
it.setString(5, hashMap["link"] as String)
}
}.also {
if (hashMap["mail"] == null) {
it.setNull(6, Types.VARCHAR)
} else {
it.setString(6, hashMap["mail"] as String)
}
}.also {
if (hashMap["nick"] == null) {
it.setNull(7, Types.VARCHAR)
} else {
it.setString(7, hashMap["nick"] as String)
}
}.also { comment ->
// 回复相关
if (hashMap["pid"] == null) {
comment.setNull(8, Types.INTEGER)
} else {
val getData =
connection!!.prepareStatement("SELECT id, object_id FROM wl_comment WHERE object_id = ?")
.also { it.setString(1, hashMap["pid"] as String) }.executeQuery()
.also { it.next() }
try {
if ((getData.getString("object_id") ?: null) == hashMap["pid"]) {
comment.setInt(8, getData.getInt("id"))
}
} catch (e: SQLException) {
comment.setNull(8, Types.INTEGER)
}
}
}.also { comment ->
// 回复相关
if (hashMap["rid"] == null) {
comment.setNull(9, Types.INTEGER)
} else {
val getData =
connection!!.prepareStatement("SELECT id, object_id FROM wl_comment WHERE object_id = ?")
.also { it.setString(1, hashMap["rid"] as String) }.executeQuery()
.also { it.next() }
try {
if ((getData.getString("object_id") ?: null) == hashMap["rid"]) {
comment.setInt(9, getData.getInt("id"))
}
} catch (e: SQLException) {
comment.setNull(9, Types.INTEGER)
}
}
}.also {
if (hashMap["sticky"] == null) {
it.setNull(10, Types.INTEGER)
} else {
it.setInt(10, hashMap["sticky"] as Int)
}
}.also { it.setString(11, hashMap["status"] as String) }.also {
if (hashMap["like"] == null) {
it.setNull(12, Types.INTEGER)
} else {
it.setInt(12, (hashMap["like"] as Double).toInt())
}
}.also {
if (hashMap["ua"] == null) {
it.setNull(13, Types.VARCHAR)
} else {
it.setString(13, hashMap["ua"] as String)
}
}.also {
if (hashMap["url"] == null) {
it.setNull(14, Types.VARCHAR)
} else {
it.setString(14, hashMap["url"] as String)
}
}.also {
it.setTimestamp(
15, Timestamp(Instant.parse(hashMap["createdAt"] as String).toEpochMilli())
)
}.also {
it.setTimestamp(
16, Timestamp(Instant.parse(hashMap["updatedAt"] as String).toEpochMilli())
)
}.also { it.setString(17, hashMap["objectId"] as String) }.executeUpdate()
} catch (e: Exception) {
println("[ERROR] 数据库插入失败")
println("[ERROR] ${e.message}")
throw e
}
}
return true
}
}

View File

@ -0,0 +1,78 @@
package com.xlf.lwtm
import com.google.gson.Gson
import java.io.File
object FileCheck {
private val getCommentFile = File("Comment.0.jsonl")
private val getCounterFile = File("Counter.0.jsonl")
private val getUsersFile = File("Users.0.jsonl")
fun check(): Boolean {
println("[INFO] 对文件进行检查")
// 查找 Comment.0.jsonl 文件
if (!getCommentFile.exists() && !getCommentFile.isFile) {
println("\t[ERROR] 未找到 Comment.0.jsonl 文件")
return false
} else {
println("\t[CHECK] 找到 Comment.0.jsonl 文件")
}
// 查找 Counter.0.jsonl 文件
if (!getCounterFile.exists() && !getCounterFile.isFile) {
println("\t[ERROR] 未找到 Counter.0.jsonl 文件")
return false
} else {
println("\t[CHECK] 找到 Counter.0.jsonl 文件")
}
// 查找 Users.0.jsonl 文件
if (!getUsersFile.exists() && !getUsersFile.isFile) {
println("\t[ERROR] 未找到 Users.0.jsonl 文件")
return false
} else {
println("\t[CHECK] 找到 Users.0.jsonl 文件")
}
return true
}
fun verify(): Boolean {
println("[INFO] 对文件进行校验")
// 获取文件并对 json 内容序列化
try {
val getCommentFile = getCommentFile.readLines()
val getCounterFile = getCounterFile.readLines()
val getUsersFile = getUsersFile.readLines()
// 判断是否为空
if (getCommentFile.isEmpty()) {
println("\t[ERROR] 文件内容为空")
return false
}
if (getCounterFile.isEmpty()) {
println("\t[ERROR] 文件内容为空")
return false
}
if (getUsersFile.isEmpty()) {
println("\t[ERROR] 文件内容为空")
return false
}
// 获取文件内容 json 序列化数组存储
try {
getCommentFile.forEach {
Data.commentJson.add(Gson().fromJson(it, HashMap::class.java) as HashMap<String, Any>)
}
getCounterFile.forEach {
Data.counterJson.add(Gson().fromJson(it, HashMap::class.java) as HashMap<String, Any>)
}
getUsersFile.forEach {
Data.usersJson.add(Gson().fromJson(it, HashMap::class.java) as HashMap<String, Any>)
}
} catch (e: Exception) {
println("\t[ERROR] 文件内容不是 json 格式")
return false
}
} catch (e: Exception) {
println("\t[ERROR] 文件读取错误")
return false
}
return true
}
}

View File

@ -0,0 +1,45 @@
package com.xlf.lwtm
fun main() {
println("========================================")
println(" Waline LeanCloud Converter")
println(" LeanCloud To Mysql")
println(" 筱锋xiao_lfeng")
println(" V1.0.0")
println("========================================")
print("\n\n")
println("[INFO] 请将 Comment.0.jsonl、Counter.0.jsonl、Users.0.jsonl 文件放置在本程序同目录下")
println("[INFO] 确认是否进行转换(转换过程中请勿关闭程序)")
print("\t1.确认; 2.取消):")
// 判断是否开始
val input = readlnOrNull()
if (input != null && input == "1") {
// 文件检查
if (FileCheck.check()) {
println("[SUCCESS] 文件检查成功")
} else {
return
}
// 文件校验
if (FileCheck.verify()) {
println("[SUCCESS] 文件校验成功")
} else {
return
}
// 数据库连接检查
val database = Database()
database.checkConnect()
if (database.insertUsers()) {
println("[SUCCESS] 用户数据导入成功")
} else {
return
}
if (database.insertComment()) {
println("[SUCCESS] 评论数据导入成功")
} else {
return
}
}
return
}

148
xf_blog_waline.sql Executable file
View File

@ -0,0 +1,148 @@
-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- 主机: 172.17.0.3
-- 生成日期: 2023-12-22 17:37:06
-- 服务器版本: 8.2.0
-- PHP 版本: 8.2.13
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- 数据库: `waline`
--
-- --------------------------------------------------------
--
-- 表的结构 `wl_comment`
--
CREATE TABLE `wl_comment` (
`id` int UNSIGNED NOT NULL,
`user_id` int DEFAULT NULL,
`comment` text,
`insertedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`ip` varchar(100) DEFAULT '',
`link` varchar(255) DEFAULT NULL,
`mail` varchar(255) DEFAULT NULL,
`nick` varchar(255) DEFAULT NULL,
`pid` int DEFAULT NULL,
`rid` int DEFAULT NULL,
`sticky` tinyint(1) DEFAULT NULL,
`status` varchar(50) NOT NULL DEFAULT '',
`like` int DEFAULT NULL,
`ua` text,
`url` varchar(255) DEFAULT NULL,
`createdAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`object_id` varchar(30) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- 表的结构 `wl_counter`
--
CREATE TABLE `wl_counter` (
`id` int UNSIGNED NOT NULL,
`time` int DEFAULT NULL,
`reaction0` int DEFAULT NULL,
`reaction1` int DEFAULT NULL,
`reaction2` int DEFAULT NULL,
`reaction3` int DEFAULT NULL,
`reaction4` int DEFAULT NULL,
`reaction5` int DEFAULT NULL,
`reaction6` int DEFAULT NULL,
`reaction7` int DEFAULT NULL,
`reaction8` int DEFAULT NULL,
`url` varchar(255) NOT NULL DEFAULT '',
`createdAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- 表的结构 `wl_users`
--
CREATE TABLE `wl_users` (
`id` int UNSIGNED NOT NULL,
`display_name` varchar(255) NOT NULL DEFAULT '',
`email` varchar(255) NOT NULL DEFAULT '',
`password` varchar(255) NOT NULL DEFAULT '',
`type` varchar(50) NOT NULL DEFAULT '',
`label` varchar(255) DEFAULT NULL,
`url` varchar(255) DEFAULT NULL,
`avatar` varchar(255) DEFAULT NULL,
`github` varchar(255) DEFAULT NULL,
`twitter` varchar(255) DEFAULT NULL,
`facebook` varchar(255) DEFAULT NULL,
`google` varchar(255) DEFAULT NULL,
`weibo` varchar(255) DEFAULT NULL,
`qq` varchar(255) DEFAULT NULL,
`2fa` varchar(32) DEFAULT NULL,
`createdAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`user_id` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
-- 转储表的索引
--
--
-- 表的索引 `wl_comment`
--
ALTER TABLE `wl_comment`
ADD PRIMARY KEY (`id`);
--
-- 表的索引 `wl_counter`
--
ALTER TABLE `wl_counter`
ADD PRIMARY KEY (`id`);
--
-- 表的索引 `wl_users`
--
ALTER TABLE `wl_users`
ADD PRIMARY KEY (`id`);
--
-- 在导出的表使用AUTO_INCREMENT
--
--
-- 使用表AUTO_INCREMENT `wl_comment`
--
ALTER TABLE `wl_comment`
MODIFY `id` int UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `wl_counter`
--
ALTER TABLE `wl_counter`
MODIFY `id` int UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `wl_users`
--
ALTER TABLE `wl_users`
MODIFY `id` int UNSIGNED NOT NULL AUTO_INCREMENT;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;