forked from hectorqin/reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
172 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package com.htmake.reader.entity | ||
|
||
data class BasicError( | ||
val error: String, | ||
val exception: String, | ||
val message: String, | ||
val path: String, | ||
val status: Int, | ||
val timestamp: Long | ||
val error: String, | ||
val exception: String, | ||
val message: String, | ||
val path: String, | ||
val status: Int, | ||
val timestamp: Long | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.htmake.reader.entity | ||
|
||
data class MongoFile( | ||
var path: String = "", | ||
var content: String = "", | ||
var created_at: Long = System.currentTimeMillis(), | ||
var updated_at: Long = System.currentTimeMillis() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.htmake.reader.entity | ||
|
||
data class Size( | ||
val width: Double, | ||
val height: Double | ||
val width: Double, | ||
val height: Double | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package com.htmake.reader.entity | ||
|
||
data class User( | ||
var username: String="", | ||
var password: String="", | ||
var salt: String="", | ||
var token: String="", | ||
var last_login_at: Long = System.currentTimeMillis(), | ||
var created_at: Long = System.currentTimeMillis(), | ||
var enable_webdav: Boolean = false, // 是否开启 WebDAV 功能 | ||
var token_map: Map<String, Long>? = null, | ||
var enable_local_store: Boolean = false // 是否开启本地书仓功能 | ||
var username: String="", | ||
var password: String="", | ||
var salt: String="", | ||
var token: String="", | ||
var last_login_at: Long = System.currentTimeMillis(), | ||
var created_at: Long = System.currentTimeMillis(), | ||
var enable_webdav: Boolean = false, // 是否开启 WebDAV 功能 | ||
var token_map: Map<String, Long>? = null, | ||
var enable_local_store: Boolean = false // 是否开启本地书仓功能 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.htmake.reader.utils; | ||
|
||
// import com.mongodb.MongoClientSettings; | ||
import com.mongodb.MongoException; | ||
import com.mongodb.client.MongoClients; | ||
import com.mongodb.client.MongoClient; | ||
import com.mongodb.client.MongoDatabase; | ||
import com.mongodb.client.MongoCollection; | ||
import com.htmake.reader.entity.MongoFile | ||
import org.bson.codecs.pojo.PojoCodecProvider | ||
import com.mongodb.MongoClientSettings.getDefaultCodecRegistry; | ||
import org.bson.codecs.configuration.CodecRegistries.fromProviders; | ||
import org.bson.codecs.configuration.CodecRegistries.fromRegistries; | ||
|
||
object MongoManager { | ||
private lateinit var mongoClient: MongoClient | ||
|
||
fun isInit(): Boolean { | ||
return ::mongoClient.isInitialized | ||
} | ||
|
||
fun connect(uri: String) { | ||
try { | ||
mongoClient = MongoClients.create(uri) | ||
} catch (e: MongoException) { | ||
logger.info("mongodb 连接失败,请检查链接({})是否正确", uri) | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
fun db(db: String): MongoDatabase? { | ||
if (!isInit()) { | ||
return null | ||
} | ||
val pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build(); | ||
val pojoCodecRegistry = fromRegistries(getDefaultCodecRegistry(), fromProviders(pojoCodecProvider)); | ||
return mongoClient.getDatabase(db).withCodecRegistry(pojoCodecRegistry); | ||
} | ||
|
||
fun fileStorage(db: String, collection: String): MongoCollection<MongoFile>? { | ||
return db(db)?.getCollection(collection, MongoFile::class.java) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters